Execution Pipeline & Lifecycle
Explore the request lifecycle, caching layers, middleware hooks, and AST tokenization pipeline.
Lifecycle Stages
Every request transitions through four deterministic lifecycle phases:
- Routing & Match Resolution: URL slug is matched against the inverted index.
- Middleware Evaluation: Custom headers, auth guards, and telemetry run.
- Token AST Hydration: Code blocks are parsed into syntax-colored spans.
- Viewport Render: Breadcrumbs, TOC observer, and reading progress hydrate.
Custom Middleware Example
Register custom middleware in the pipeline to log telemetry or rewrite paths:
export const auditMiddleware = (req: any, next: () => any) => {
const start = Date.now();
console.log(`[DocuCraft] Navigating to: ${req.slug}`);
const result = next();
console.log(`[DocuCraft] Rendered in ${Date.now() - start}ms`);
return result;
};