DocTreen
Reference

Architecture

How doctreen is put together — RouteRegistry, adapter flow, zero-runtime-deps UI.

DocTreen is a framework-agnostic API documentation library built on a middleware-injection pattern.

Core components

  • RouteRegistry — framework-agnostic route store. Adapters populate it; the UI reads from it.
  • normalizeConfig — normalises the user's config object; enabled defaults to NODE_ENV !== 'production'.
  • shouldExclude — filter for the exclude list (strings + RegExp). * and /* are excluded by default.

Adapter contract

Every adapter follows the same four steps:

  1. Take the framework instance
  2. Discover routes (eager or lazy)
  3. Call registry.add(routeEntry)
  4. Serve the UI at docsPath (default /docs)

Zero runtime dependencies in the UI

The docs UI is shipped as inline HTML / CSS / JS strings. No CDN, no extra package. The Postman and OpenAPI export buttons run as in-browser IIFEs.

This is why a single npm install doctreen is enough — no companion @nestjs/swagger-style ecosystem.

Lazy vs eager discovery

AdapterModeWhen routes are read
ExpressLazyapp._router.stack (v4) / app.router.stack (v5) on the first /docs hit. Solves the "middleware-before-routes" ordering problem.
FastifyEagerVia the onRoute hook at registration time. Adapter must be installed before routes.
HonoLazyapp.routes on the first docs request.
KoaLazyrouter.stack on the first docs request.
NestJSEagerapp.container.getModules() for metadata discovery, called before app.listen().

Schema priority order

  1. Explicit schema via defineRoute<T>(...) / @DocRoute({ ... })
  2. Framework-native schema (Fastify JSON Schema; nothing for the others)
  3. JSDoc parsing (Express / Hono / Koa)

The same priority feeds the docs UI, the OpenAPI export, and the schema drift comparator.

On this page