Generated Files
Routa writes exactly four files, all inside .routa/. They hold what Routa learned from
your source: the route table, the test application entry point, a record of what
scaffolding generated, and the accepted OpenAPI contract. Commit all four.
Directory.routa/
- routes.gen.ts route table and type augmentation
- testing.gen.ts project-bound createTestApp and service factory types
- manifest.json scaffold tracking and content hashes
- openapi-baseline.json accepted OpenAPI contract
How It Works
Section titled “How It Works”Every command that validates a project also refreshes routes.gen.ts and
testing.gen.ts when validation passes, so check, build, dev, and generate can all legitimately change your
working tree. Validation runs first: a project with diagnostics leaves the previous file
untouched rather than writing partial metadata.
The other two files change only when you ask. manifest.json is written by
routa scaffold, and openapi-baseline.json is written by routa scaffold and by
routa openapi breaking --update-baseline.
The Files
Section titled “The Files”.routa/routes.gen.ts
Section titled “.routa/routes.gen.ts”Exports routaRoutes, an array describing every route: file, path, methods, response
statuses, declared input sources, middleware chains, provided context keys, reject
outcomes, groups, and segments. The runtime loads it to register routes, and the CLI reads
it during checks.
It also augments the Register interface from @routa-ts/core. That augmentation is what
makes createRouteRoot("/users/:userId") know the context available at that path, and
what lets a deprecation.replacement pointing at a local path be checked in the editor.
When src/routa.ts declares application services, the file
also exports routaApplicationServices, the contract’s sorted service names, and
RoutaApplicationServices, a type-only reference to the contract that types
ctx.services. A route file that declares route-file or method
services adds their contracts to its
routaRoutes entry and services to its handler context, and the file exports
RoutaFactoryCtxByPath, the context each request factory receives. A middleware with
service requirements adds its
requirement interface to its routaRoutes entry as requiresServices, and the file exports
RoutaServiceRequirementChecks, one type check per placement that TypeScript fails when the
services there do not satisfy the requirement. Projects without services or requirements get
none of these.
When src/routa.ts configures authentication,
the file exports routaAuthenticationSchemes, the scheme names in priority order, and
routaMultipleCredentials, the multiple-credential mode, which startup compares with the
configuration. It also exports RoutaPrincipal, the principal
schema’s output read from src/routa.ts, RoutaAuthenticationScheme, and RoutaAuth, and it
adds auth to every operation’s context: RoutaAuth, or the authenticated branch behind
requireAuth. A requireAuth guard appears in its routaRoutes chain with the schemes it
allows, named requireAuth when written inline or by its export name when a folder
middleware.ts exports it, every operation lists 401 among its statuses, and with
multipleCredentials: "reject", every operation that accepts two or more schemes also lists
400. Each routaRoutes entry also lists middlewareFiles: every folder middleware.ts on
the route’s path, root first, including one with no export Routa reads. Startup loads each of
them and refuses a requireAuth guard export the route’s chain does not list, and it asks you
to run routa generate when an entry has no middlewareFiles. Projects without
authentication get none of these, and their startup does not check folder files, because no
guard can run there.
Refresh it after adding, moving, or removing a route file, changing which methods a route declares, or changing middleware layout:
routa generateGenerated .routa/routes.gen.ts and .routa/testing.gen.ts for 4 route file(s)..routa/testing.gen.ts
Section titled “.routa/testing.gen.ts”Exports createTestApp, which builds an isolated, in-memory instance of your project for
tests, with no network listener and no app argument. See Testing
for how to use it. The file also exports two types:
ServicesFactory<Scope>, the factory type of each scope that declares services. The scope is"application", a route file’s path such as"/orders", or a method and path such as"POST /orders". Annotate a factory you declare on its own with it, and TypeScript checks the factory against that scope’s contract and context without you repeating either.TestAppOptions, the replacement factoriescreateTestAppaccepts, keyed by the same scopes. A route or method that declares no services has no key.
The file lists every module the application loads, src/routa.ts, each route file, and
each filesystem middleware file, as a lazy import(). Importing it runs none of your code
and no factory; createTestApp loads the modules when you call it. Every project gets this
file, with or without services. It imports @routa-ts/core/testing, and routa build
compiles it to dist/.routa/testing.gen.js with the rest of .routa/.
.routa/manifest.json
Section titled “.routa/manifest.json”Records each file scaffolding produced, along with its source operationId, its kind, and
a hash of the content Routa wrote. Regeneration compares current file contents against
those hashes to classify each file as an update, unchanged, a conflict with your edits, or
a removal — which is what makes routa scaffold --preview trustworthy.
.routa/openapi-baseline.json
Section titled “.routa/openapi-baseline.json”The OpenAPI contract your team has accepted. routa openapi check compares the freshly
generated document against it to detect drift, and routa openapi breaking uses it to
detect removed operations and newly required inputs. It never feeds generation: the
current document, including info, components.schemas, security, and operationId,
comes from source alone, and --update-baseline overwrites the file with it.
- Commit
.routa/. It is the shared reference that makes drift checks and regeneration safety work across machines and in CI. - Review its diff like source. A change in
routes.gen.tsis a change to your API surface. - Never edit
routes.gen.ts,testing.gen.ts, ormanifest.jsonby hand; the next command overwrites them. - Generation is deterministic. Identical source produces identical output, so an unexpected diff means an unexpected contract change.
Limits
Section titled “Limits”Generated metadata is only as fresh as the last successful command. A stale
routes.gen.ts produces confusing type errors, and a stale testing.gen.ts may not list a
route file you added since, because context types come from the
generated file rather than from the source Routa has not read yet. When types disagree
with the code in front of you, run routa generate first.