HomeArchitecture x-rays

JavaScript

The architecture of Fastify, x-rayed

Fastify's lib/ directory is a study in single-responsibility: 32 files, 32 modules, essentially one concern per file — route.js, reply.js, decorate.js, hooks.js. The x-ray shows a framework that pushed its architecture into its ecosystem: the core stays small because everything else is a plugin.

Auto-generated by archsteer xray v0.4.1 against fastify/fastify@94bcbcc (lib/) on 2026-07-05. Read-only static analysis — no code executed, no architecture rules declared. Structure, not judgment.
32
components
32
modules
92
internal edges
15
runtime deps

Module dependency graph

Top 14 modules by connectivity; an arrow means "imports from".

graph LR
    m0["content-type-parser"]
    m1["error-handler"]
    m2["errors"]
    m3["four-oh-four"]
    m4["handle-request"]
    m5["hooks"]
    m6["logger-factory"]
    m7["plugin-override"]
    m8["reply"]
    m9["request"]
    m10["route"]
    m11["schemas"]
    m12["server"]
    m13["symbols"]
    m0 --> m2
    m0 --> m13
    m1 --> m2
    m1 --> m11
    m1 --> m13
    m3 --> m1
    m3 --> m2
    m3 --> m5
    m3 --> m6
    m3 --> m8
    m3 --> m9
    m3 --> m13
    m4 --> m2
    m4 --> m5
    m4 --> m13
    m5 --> m2
    m5 --> m13
    m6 --> m2
    m6 --> m13
    m7 --> m0
    m7 --> m5
    m7 --> m8
    m7 --> m9
    m7 --> m13
    m8 --> m1
    m8 --> m2
    m8 --> m4
    m8 --> m5
    m8 --> m6
    m8 --> m11
    m8 --> m13
    m9 --> m2
    m9 --> m13
    m10 --> m1
    m10 --> m2
    m10 --> m4
    m10 --> m5
    m10 --> m6
    m10 --> m11
    m10 --> m13
    m11 --> m2
    m11 --> m13
    m12 --> m2
    m12 --> m5
    m12 --> m13

Components by module

config-validator · 1content-type-parser · 1content-type · 1context · 1decorate · 1error-handler · 1error-serializer · 1error-status · 1errors · 1four-oh-four · 1handle-request · 1head-route · 1hooks · 1initial-config-validation · 1log-controller · 1logger-factory · 1

Most connected components

Top 20 of 32 by exported API surface and dependency count.

ComponentModuleKey exports
route.jsroutedefault
logger-factory.jslogger-factorydefault
server.jsserverdefault
reply.jsreplydefault
four-oh-four.jsfour-oh-fourdefault
handle-request.jshandle-requestdefault
content-type-parser.jscontent-type-parserdefault
error-handler.jserror-handlerdefault
plugin-override.jsplugin-overridedefault
request.jsrequestdefault
plugin-utils.jsplugin-utilsdefault
schemas.jsschemasdefault
validation.jsvalidationdefault
log-controller.jslog-controllerdefault
schema-controller.jsschema-controllerdefault
wrap-thenable.jswrap-thenabledefault
initial-config-validation.jsinitial-config-validationdefault
hooks.jshooksdefault
decorate.jsdecoratedefault
logger-pino.jslogger-pinodefault

Declared runtime dependencies

@fastify/ajv-compiler@fastify/error@fastify/fast-json-stringify-compiler@fastify/proxy-addrabstract-loggingavviofast-json-stringifyfind-my-waylight-my-requestpinoprocess-warningrfdcsecure-json-parsesemvertoad-cache

What the structure teaches

One file, one concern, no exceptions

Every component in lib/ maps to exactly one framework capability: content-type parsing, error serialization, request decoration, hook execution. The 1:1 file-to-module ratio in the x-ray isn't an accident of counting — it's the codebase's actual organizing principle.

The @fastify/ scope is the architecture

Most of the 15 runtime dependencies are Fastify's own packages — ajv-compiler, fast-json-stringify-compiler, error, proxy-addr. The framework factored its subsystems into independently-versioned modules under one npm scope: the monorepo pattern without the monorepo.

Speed is a structural choice

route.js and reply.js — the hottest request-path components — are the most connected in the graph. Fastify compiles JSON serialization (fast-json-stringify) and validation (ajv) ahead of time per route, which is why the routing layer, not a middleware chain, is the center of the architecture.

X-ray your own repo

This page is unedited archsteer xray output plus commentary. The same map of your codebase takes one command, runs locally, and never sends code anywhere: pip install archsteer && archsteer xray

FAQ

How is Fastify structured internally?

As ~32 single-purpose modules in lib/ — route registration, reply handling, hooks, decorators, content-type parsing, error handling — coordinated by fastify.js as the composition root. Cross-cutting subsystems (schema compilation, JSON serialization) live in separate @fastify/-scoped packages among its 15 runtime dependencies.

What makes Fastify fast architecturally?

Ahead-of-time compilation per route: JSON schemas compile to specialized validation functions (ajv) and serializers (fast-json-stringify) at registration time, not per-request. Plus an encapsulated plugin tree instead of a linear middleware chain, so requests only pay for what their route actually registered.

How was this architecture map generated?

By running `archsteer xray` (an open-source, MIT-licensed CLI) against the lib/ directory of the public GitHub repo — read-only static analysis, no code executed. Reproduce it with `pip install archsteer && archsteer xray`.

More x-rays