Code Generation & Compiler Pipeline
How the Nooh compiler processes your project and transforms files into code.
Nooh is powered by a high-performance compiler (@nooh-ts/compiler) that transforms filesystem routes and containers into native Hono handlers.
Compilation Pipeline
The compiler follows a 5-stage pipeline:
1. Discovery (discover)
Scans your routes/ and dependencies/ folders from the filesystem or in-memory source snapshots. Discovers all .ts endpoint files and group.ts group configurations.
2. Parsing (parse)
Analyzes filenames to determine:
- HTTP method (e.g.
.get.ts,.post.ts). - URL segment types (static segments,
[param]dynamic segments,[...splat]catch-all segments). - Group hierarchies and nesting.
3. Analysis (analyze)
- Builds the complete dependency graph.
- Runs cycle detection algorithms (
NOOH023). - Validates dependency scope hierarchy (prevents singletons from capturing request-scoped dependencies).
- Checks for duplicate route definitions or naming collisions.
4. Planning (plan)
Determines the minimal set of output files needed in .nooh/ and generates an execution plan.
5. Generation (generate)
Renders TypeScript code for:
.nooh/app.ts: Root Hono router instance..nooh/router/**/*.ts: Route-specific helper functions with strong typing..nooh/router/middleware.ts: Middleware type utilities.
Bundler Integration (Unplugin)
Nooh provides @nooh-ts/plugin, an unplugin implementation compatible with Vite, Rollup, Webpack, and esbuild.
import { defineConfig } from "vite";
import nooh from "@nooh-ts/plugin/vite";
export default defineConfig({
plugins: [
nooh({
config: "nooh.config.ts",
outputRoot: ".nooh",
}),
],
});
The plugin automatically hooks into your build tool’s file watcher, rebuilding changed routes whenever you save a file.