Registry map and IR consumers
Where state lives and what happens to the descriptor graph.
package @smitejs/core
A snapshot of the current architecture: every registry-shaped thing in the repo, and the two lives of the generated IR (build-time collection, runtime execution).
Registries, mapped
- Global descriptor registry —
packages/core/src/registry.ts. A singleMaponglobalThis.globalRegistryholding every node and edge created in collect mode, keyed by composite__key(duplicates throw). Written bydefineDescriptorandrelate; read bylookup/lookupAll/relationshipsand emptied byclear. It is the build-time window into the app. - Runtime child index —
packages/core/src/descriptor.ts. A non-enumerableMap<relation, Descriptor[]>attached to parent descriptors underSymbol.for("@smitejs/core/children"), walked withchildrenOf. This is the graph that survives production builds and is what executors actually use. - Collect-mode flag —
packages/core/src/constants.ts. Registration is gated by the esbuilddefineALLOW_GLOBAL_REGISTRY; folded tofalsein production so the registry code is dead-stripped. - CLI collection sessions —
packages/cli/src/compile.ts. Each entry is bundled with the flag on, the registry is cleared, the bundle executes, andlookupAll()snapshots the graph per entry. Runtime bundles then fold the flag off (build.ts). - Request-scoped context —
packages/core/src/scope.ts. AnAsyncLocalStoragecarrying per-request values (logger, tracer) throughrunWithScope/currentScope/registerLogger. - Provider config —
packages/aws/src/context.ts. A secondAsyncLocalStorage(runWithProviderConfig/getProviderConfig) sharing deployment region/service with AWS client factories, falling back to env. - Symbol-keyed function metadata —
Symbol.forhandles on functions:@smitejs/fp/compositionMetadataandextractorMetadata, and@smitejs/domain/handler(read byhttp/src/endpoint.ts) plus the domain*DescriptorSymbols. They link runtime artifacts back to IR nodes across package boundaries and duplicated module instances, with no dependency. - Module-local registries — duplicate-name detection and per-instance resolution caches in
@smitejs/env, and plugin name dispatch in@smitejs/cli.
What happens to the IR
Build time: artifact generation
The CLI compiles entries, snapshots the registry, and hands the app nodes to plugins, which traverse the graph via childrenOf (or entry-scoped descriptor snapshots):
@smitejs/client—collectEndpointsemits a typed builder client.@smitejs/openapi—routesOf(app)produces an OpenAPI 3.1 document and swagger UI.@smitejs/serverless+@smitejs/aws—routesOf(app)becomes HTTP API events;aws.resourceandaws.permissionnodes become CloudFormation resources and IAM statements inserverless.yml.httproutesOf— the shared collected-route view reused by the above.env.varnodes — registered but not yet consumed; reserved for.env.examplescaffolding and compile-time validation.- Domain cross-links — collect mode adds a
handler -> domain.usecaseedge via the@smitejs/domain/handlersymbol so generators see usecase metadata without a domain-to-http dependency.
The artifacts are generated source and configs; the IR itself is consumed and discarded inside the compile process.
Runtime: execution only
Production bundles fold the registry away. serve(app) deep-freezes the graph (finalizeDescriptor) and builds matchers by walking the child index — never the registry — reading the handler function off the http.handler node. Each request runs inside a request scope. serveNode adapts the router to node:http.
Lifecycle in one line
Build-time DSL calls register into the registry; plugins read it to emit artifacts; the child index rides along on the descriptors so the folded runtime can serve without any global state.