CodeVetter · Repo Unpack · Data flow
fastify/fastify
Route definitions become contexts whose hooks and compiled schemas are finalized during boot. Incoming transport objects become scoped Request and Reply objects before entering the hook and parsing pipeline. Validation can transform request parts, and handler results enter the reply serializer and output hooks. State is predominantly instance and route state; documented persistence crosses into separately registered database clients.
- Route options populate Context with a bound handler, schema, configuration, compiler overrides, body limit, and handler timeout.
- router.on stores routeHandler and Context together; preReady subsequently binds inherited and route-local hooks.
- routeHandler derives a request ID and logger, then creates context.Request and context.Reply from raw transport objects and router outputs.
- runPreParsing initially stores request.raw as the payload stream and passes through a preParsing runner before handleRequest.
- For body-bearing methods, handleRequest chooses a parser using Content-Type; invalid media types produce 415.
- rawBody accumulates buffers, enforces received and encoded byte limits, checks declared content length, and decodes or copies once before parser invocation.
- Successful parsing assigns request.body and proceeds to handler; parsing failure marks the reply as an error and requests connection closure.
- validateParam passes parentData to Ajv-compatible validators and permits synchronous custom results to replace a request part through value.
- preSerializationHookEnd chooses reply-specific, instance-default, or schema-based serialization, then enters onSendHook.
- The documented Redis persistence path reads req.body.key/value, calls the plugin-provided redis.set, and replies from its completion callback.