Your API is
a file tree.

Folders become paths. schemas.ts sits beside route.ts. Routa reads the tree, so your handlers only decide what happens.

Read the docs
An example route tree. src/routes/ holds status/, which serves GET /status, and tenants/$tenantId/. That folder holds projects/, whose route.ts declares GET and POST beside schemas.ts for params, query, and responses, and middleware.ts, which runs for everything below it.

The route is the spec.

Write the contract once. Routa generates the OpenAPI document from it, so there's nothing to keep in sync.

projects/route.tsyou write
const route = createRouteRoot("/tenants/:tenantId/projects");

export default route({
  get: createRoute({
    input: {
      params: ListProjectsParams,
      query: ListProjectsQuery,
    },
    responses: {
      success: { status: 200, schema: ListProjectsResponse },
    },
    run: ({ ctx, input }) =>
      ({ type: "success", data: list(ctx, input) }),
  }),
});
openapi.jsongenerated
"/tenants/{tenantId}/projects": {
  "get": {
    "parameters": [
      {
        "name": "tenantId", "in": "path", "required": true,
        "schema": { "type": "string" }
      },
      {
        "name": "status", "in": "query", "required": false,
        "schema": {
          "type": "string", "enum": ["active", "archived"]
        }
      }
    ],
    "responses": {
      "200": {
        "description": "Success",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ListProjectsResponse"
            }
          }
        }
      }
    }
  }
}

Folders branch

A folder is a path segment. $name folders are path params; input.params gives them a type.

Routes carry contracts

schemas.ts sits beside route.ts. One schema, three uses: types, validation, OpenAPI.

Checked at the root

routa check walks the whole tree before you ship.

Every folder is a path segment.

Read the tree. You've read the URL.

For example, src/routes/tenants/$tenantId/projects/route.ts serves /tenants/:tenantId/projects. tenants/ is a folder, $tenantId/ is a path param named from the folder, and projects/route.ts declares the operations GET and POST.

Add a route in three steps.

Start from a folder. Each step adds one thing, and nothing needs registering.

  1. Step 1

    Make a folder

    tenants/$tenantId/projects/ becomes /tenants/:tenantId/projects.

    mkdir -p 'src/routes/tenants/$tenantId/projects'
  2. Step 2

    Add the contract

    route.ts names the methods. schemas.ts holds what goes in and comes out.

    get: createRoute({ … })
  3. Step 3

    Run the check

    routa check validates the route graph, then runs TypeScript over it.

    ✓ Routa check passed.

Responses have names.

Return a name. Routa writes the rest.

success
200
the list of projects, shaped by ListProjectsResponse
created
201
the new project, with its id
forbidden
403
the caller can't see this tenant
notFound
404
no project with that id
return { type: "notFound", data: { message: "No such project." } }

Middleware covers its branch.

Put a middleware.ts in a folder and it runs for every route below it. What it adds to ctx is typed in each of those handlers.

ctx.tenant.id // typed below $tenantId/
routes/ holds tenants/$tenantId/ and status/. The middleware.ts in tenants/$tenantId/ runs for projects/ and members/ below it, and not for status/.

Diagnostics

Every failure says where and what to change.

Each diagnostic names its code, the file, and the fix. No stack trace to read, no guessing which layer drifted.

  • ROUTA_RESULT_TYPE

    src/routes/tenants/$tenantId/projects/route.ts:22:12

    Run result type "notFound" is not declared.

    Use one of the declared result types: success.

  • ROUTA_MIDDLEWARE_ORDER

    src/routes/tenants/$tenantId/middleware.ts

    withProjects requires ctx.tenant before it is provided.

    Move middleware that provides tenant before withProjects.

  • ROUTA_MISSING_SUCCESS_RESPONSE

    src/routes/status/route.ts

    GET /status is missing a 2xx success response.

    Add a declared success response with a 2xx HTTP status.

Every column has a source.

Nothing is typed twice. Each part of an operation is read from one place in your tree.

ColumnRead fromExample
Methodthe key in route.tsget: createRoute({ … })
Pathfolder names, $name → :nametenants/$tenantId → /tenants/:tenantId
Inputinput: params, query, headers, bodyquery: ListProjectsQuery
Responsenamed outcomes in responsessuccess: { status: 200, schema }
Middlewaremiddleware.ts in a parent folderctx.tenant, typed in every handler

Routa holds the HTTP edge. You own the app.

Routa owns

  • Routing
  • Validation
  • Middleware context
  • Response serialization
  • Diagnostics
  • OpenAPI

You own

  • Services
  • Domain models
  • Persistence
  • Business rules
  • Architecture

Write your first route.

One command, one folder, one passing check.

Read the docs