Summary
Separate Fastify app construction from process startup so the API is easier to test, reuse, and shut down cleanly.
Current Behaviour
apps/access-api/src/index.ts creates the Fastify server, registers plugins and routes, then immediately starts listening. This makes tests harder to write and couples route registration to process lifecycle.
Expected Behaviour
The API should expose a buildApp or createServer function that returns a configured Fastify instance. The entrypoint should only handle environment loading, startup, and shutdown.
Suggested Implementation
Create a new app module that registers Swagger, Swagger UI, and routes. Update index.ts to call this factory, parse environment configuration, start the server, and close resources on shutdown signals.
Files or Areas Likely Affected
apps/access-api/src/index.ts
apps/access-api/src/app.ts
apps/access-api/src/routes.ts
apps/access-api/src/services/prisma.ts
apps/access-api/src/**/*.test.ts
Acceptance Criteria
Additional Notes
This pairs well with route integration tests but can be implemented independently.
Summary
Separate Fastify app construction from process startup so the API is easier to test, reuse, and shut down cleanly.
Current Behaviour
apps/access-api/src/index.tscreates the Fastify server, registers plugins and routes, then immediately starts listening. This makes tests harder to write and couples route registration to process lifecycle.Expected Behaviour
The API should expose a
buildApporcreateServerfunction that returns a configured Fastify instance. The entrypoint should only handle environment loading, startup, and shutdown.Suggested Implementation
Create a new app module that registers Swagger, Swagger UI, and routes. Update
index.tsto call this factory, parse environment configuration, start the server, and close resources on shutdown signals.Files or Areas Likely Affected
apps/access-api/src/index.tsapps/access-api/src/app.tsapps/access-api/src/routes.tsapps/access-api/src/services/prisma.tsapps/access-api/src/**/*.test.tsAcceptance Criteria
index.tsremains responsible for process startup onlyAdditional Notes
This pairs well with route integration tests but can be implemented independently.