- For Node.js: Use Fastify as the web framework for TypeScript API servers.
- Define type-safe routes using Fastify's schema-based declarations.
- Validate all request inputs with Fastify JSON schemas.
- Design all routes to be idempotent for safe client retries.
- For Node.js: Define JSON schemas for routes: `{ schema: { body: bodySchema, response: { 200: responseSchema } } }` — Fastify uses them for validation and serialization.
- Use `fastify.register(plugin, opts)` for modular route organization — each plugin gets its own encapsulated scope.
- Use `fastify.decorate('db', dbClient)` to add shared services — access via `fastify.db` in route handlers.
- Use `preHandler` hooks for authentication: `{ preHandler: [authenticate] }` on protected routes.