mir-backend-node-fastifylisted
Install: claude install-skill anantbhandarkar/make-it-right
# /mir-backend-node-fastify · Make It Right (Fastify)
Bottom tier of the chain: `mir-backend` (generic gates) → `mir-backend-node` (V8/Node event-loop model) → **this** (Fastify library mechanics). Run the gates first; load the Node runtime tier for event-loop and process-model concerns; reach for *this* at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. **Runtime-level concerns (blocking the event loop, worker_threads, unhandled rejections, stream backpressure, AbortController timeouts, heap limits) live in `mir-backend-node` — not here.**
**Stack assumed:** Fastify 4.x (or 5.x; breaking changes called out) on Node 20+ LTS.
## The Fastify footguns AI walks into most
### 1. Skipping the response schema leaks internal fields
Fastify's JSON serialization is powered by `fast-json-stringify`, driven by the JSON Schema on the route. The response schema does two things: it makes serialization 2–5× faster than `JSON.stringify`, **and it strips any field not declared in the schema**. Omitting it hands the full internal object to the client:
```js
// WRONG — no response schema; entire DB row (including passwordHash, internalFlags) goes to client
fastify.get('/users/:id', async (request, reply) => {
return db.findUser(request.params.id);
});
// RIGHT — response schema is the serialization + security boundary
fastify.get('/users/:id', {
schema: {
params: { type: 'object', properties: { id: { type: 'string', format: 'uuid' } }, required: ['id'] },