Fastify endpoints
Read AGENTS.md, the affected module, app/src/routes/v1.ts, and neighboring route tests before editing an endpoint.
Workflow
- Trace the existing module boundary through
index.ts,routes.ts,schemas.ts, and any service or external client. - Define or update request, success, and reachable error schemas before changing the handler. Use
$typebox-schemasfor non-trivial schema work. - Change business or upstream behavior in the service or client. Construct dependencies once at plugin registration and pass
request.signalthrough every outbound layer. - Keep the route handler limited to HTTP input, service invocation, status and headers, and response mapping.
- Export new feature routes from the module index and register business modules under
/v1inapp/src/routes/v1.ts. Keep infrastructure routes unversioned. - Apply
$adversarial-testing, then cover the route at the narrowest boundary that proves its public behavior.
Contract checklist
- Use
FastifyPluginAsyncTypeboxand schema every request input and reachable response. - Define a stable unique
operationId, accurate summary, description, tags, constraints, success response, and reachableErrorModelSchemastatuses. - Declare the formats the route implements with
schema.consumesandschema.produces; do not advertise media types supplied only by a serializer or parser elsewhere. - Protect authenticated routes with
preHandler: [fastify.authenticate]and derive identity fromrequest.user. - Use the existing content-negotiation, pagination, and link-header utilities. Do not implement route-local variants.
- Add
$idonly to reusable response schemas and register them when OpenAPI components or/schemas/<Name>.jsonmust expose them. - Preserve controlled upstream errors and generic production 5xx details.
For a public contract change, also apply $openapi-contract and verify generated documentation, schema discovery when applicable, runtime media types, and response headers.
Verification
Run the focused test first, then:
just check
pnpm --dir app build