How it works
The compile-time and runtime halves of Smite, the IR between them, and the life of a request.
Smite runs your application code twice, under two values of one compile-time constant. Understanding those two modes explains every other part of the framework.
Two modes, one codebase
- Collect mode (
smite dev,smite build,smite generate, and tests). The CLI bundles your entry with esbuild, definesALLOW_GLOBAL_REGISTRYastrue, and executes it. Each DSL call registers descriptor nodes and edges in the global registry. Generator plugins then walk that graph; nothing is parsed from source. - Runtime mode (production bundles). The constant is folded to
false. Every registration guard becomes dead code and esbuild removes it, together with the registry. Executors navigate the IR through child references that the descriptors carry themselves.
the guard must stay inline
esbuild only substitutes the literal identifier. Guards are written as typeof ALLOW_GLOBAL_REGISTRY === "boolean" && ALLOW_GLOBAL_REGISTRY at each call site; an imported constant could not be folded and would keep the registry in production. A bundle test in @smitejs/http enforces this.
The IR
The graph is made of descriptors (nodes with a kind, a composite key and frozen data) and relationships (typed edges). An app is a junction that routers attach endpoints to; aspects hang off the app.
Routers are inert until app.use(router) writes their endpoints into the app. The same value is then handed to every consumer: serve turns it into a request handler, client() emits a typed client, openapi() writes a document. The details are in Internals.
The life of a request
serve(app) builds the pipeline once from the app's aspects, in registration order within each kind.
- Middleware and interceptors wrap everything: they run first, call
next(), and see the final response on the way out. - Guards gate the request. Returning a response short-circuits it, so it never reaches dispatch or the filters.
- Dispatch matches the method and path, validates every declared input bucket with zod and calls the handler with typed values.
- Filters post-process every response dispatch produces, including
400and404.
The whole request runs inside an AsyncLocalStorage scope, so code anywhere in the call stack can read request-scoped state. See Scopes and shared context.
Package layers
Dependencies point one way: a package only imports the public API of the packages below it.
@smitejs/client/runtime, the only part of the client that ships with your consumers, never references the registry or @smitejs/http.