josh-a.dev blog ← Portfolio
On this page

Making my Issue-Tracker

How the API issue tracker came together — modelling issues, routes, and the bits I'd redo.

This started as coursework and turned into the project I actually reach for. It is a REST API for tracking the bugs inside a codebase — the ones that go quiet in a chat thread and never come back. There is a running copy deployed on Cloud Run.

The problem

Every project I have worked on fails the same way: something breaks, someone notices, and by the time anyone goes looking the context is gone — who hit it, how to reproduce it, whether it was ever fixed.

So the design goal was narrow: one issue should be enough on its own. No "see the thread", no "ask the person who found it". If a single document does not tell you what is wrong and what to do next, the tracker has already failed.

Modelling an issue

One issue is most of the design. The shape I settled on:

{
  "title": "Dark mode drops websocket messages when suspended",
  "description": "…",
  "status": "open",
  "priority": "high",
  "stepsToReproduce": "1. Create a test account…\n2. Trigger the action twice…",
  "classification": "unclassified",
  "author": { "userId": "…", "fullName": "…" },
  "assignedTo": { "userId": "…", "fullName": "…" },
  "createdOn": "…",
  "comments": [],
  "testCases": [],
  "timeLog": []
}

Status (open/in-progress/closed) answers where is the work. Priority (low/medium/high) answers how soon. Classification (unclassified/approved/unapproved/duplicate) answers is this even real. Comments, test cases and time logs are embedded arrays — one document, one read, no joins.

Fields worth keeping

  • stepsToReproduce as one string, not an array. In the repo it is a single free-text field. A numbered block pasted into one string is easier to write and read than structured steps, and nothing downstream needs the structure.
  • classification separate from status. Keeping triage and progress apart stopped me conflating "we decided this is a duplicate" with "the work is done".
  • Embedded sub-resources. Comments, test cases and time entries live inside the issue document. The trade is that sub-resource writes go through $push/$pull and, for a single test case, an arrayFilters update — but reads stay a single lookup.
  • { userId, fullName } snapshots. Author and assignee carry their display name with them, so rendering an issue never depends on another service being up.

The API surface

Fifteen endpoints under /issues, plus a /health. Listing them is the fastest way to see the shape of the thing:

GET    /issues                             list; ?q= searches titles and descriptions
GET    /issues/:id                         one issue
POST   /issues                             create
PATCH  /issues/:id                         partial update
PATCH  /issues/:id/status                  open | in-progress | closed
PATCH  /issues/:id/classify                unclassified | approved | unapproved | duplicate
PATCH  /issues/:id/assign                  { userId, fullName }
DELETE /issues/:id

POST   /issues/:id/comments                add
PATCH  /issues/:id/comments/:commentId     edit
DELETE /issues/:id/comments/:commentId     remove

POST   /issues/:id/test-cases              add
PATCH  /issues/:id/test-cases/:testCaseId  { passed }

POST   /issues/:id/time-log                { hoursWorked }
GET    /issues/:id/time-log/summary        total hours for one issue

Status, classification and assignment get their own verbs instead of riding on the general PATCH. It reads better — a client setting a status is saying something narrower than "update this" — and each transition gets a schema of its own rather than one loose partial.

Validation at the edge

Nothing reaches a controller unparsed. Every route that takes input runs it through a Zod schema first — validateBody, validateQuery or validateParams — which parses the value and replaces it on the request, so a handler only ever sees data that already typechecks. A failure short-circuits with a 400 that names the field that failed:

{
  "error": "ValidationFailed",
  "details": [
    { "path": "status",
      "message": "Invalid option: expected one of \"open\"|\"in-progress\"|\"closed\"" }
  ]
}

Two details in there are worth copying. The list route's query is validated like a body, so ?status=done is a 400 instead of a silent empty result — and page and limit come out of that same schema already coerced to numbers and capped at 50. And updateIssueSchema is the create schema made partial, plus a refinement that rejects an empty object, so PATCH cannot be used to send nothing and still get a 200.

Who is writing

The routes that create something — an issue, a comment, a test case, a time entry — carry an attachCurrentUser middleware. Author and commenter come from the request and never from the body, so an author field in the JSON is ignored, which is the only reason the embedded { userId, fullName } snapshots can be trusted at all. Today that middleware is a stub handing back one hardcoded user. It is the seam where real authentication goes.

What I'd do differently

The first version of this list was four complaints about code that has since changed. insertIssue is awaited now and returns the inserted document rather than the object createIssue assembled; ids are hex strings, not a cast that ended in as unknown as number; the isValid guard left the data layer for parseId, which rejects a malformed id at the edge before any controller runs; and timeLog has the two endpoints it was missing. What survives is below.

  • Naming still drifts. stepsToReproduce, createdOn, assignedTo, loggedOn — I would pick one convention and hold it across the schema.
  • One field is still a promise. The FixInfo type sits commented out in types/issue.ts, with fixed alongside it. Either finish it or delete it; a commented-out type is not a plan.
  • The controllers still repeat themselves. Extracting parseId and parseCommentId removed the duplicated guard, but every handler that takes an id still opens with the same preamble — const objectId = parseId(req, res); if (!objectId) return; — before it does anything else. A wrapper that parsed the id and passed it down would delete those lines from all thirteen.
  • Splitting app.ts from index.ts was the best late call. It let the tests run without a live Atlas cluster. I would do it on day one next time.