How nodejs/doc-kit works
1. What this repo is
- @node-core/doc-kit is a Node.js CLI for turning Node API markdown sources into multiple documentation artifacts.
- The core architecture is a single ingestion pipeline that fans out into several generator backends, each targeting a different output format.
2. Entry point and command layer
- The executable starts in bin/cli.mjs, with command definitions in bin/commands/*.
- The main user-facing commands are generate and interactive, so the repo is centered on batch doc generation plus a guided setup flow.
3. Input model
- The primary input is a set of markdown files, usually Node.js API docs under doc/api/*.md.
- The repository also accepts version, changelog, git-ref, ignore patterns, output directory, and thread count, which become part of the generation context.
4. Parsing and normalization
- Markdown parsing lives in src/parsers/markdown.mjs and shared markdown/AST helpers under src/utils/remark.mjs, src/utils/unist.mjs, and related utilities.
- This layer converts source documents into an internal representation that generators can consume consistently, regardless of output format.
5. Shared pipeline utilities
- src/utils/ contains cross-cutting helpers for file handling, configuration templates, loaders, highlighters, HTML minification, URL handling, arrays, and query utilities.
- These modules form the “common substrate” used by most generators rather than each generator reimplementing its own parsing or formatting logic.
6. Parallel processing
- src/threading/ provides chunk-based parallel execution for expensive generation work.
- The CLI’s --threads option maps to this layer, so large doc sets can be processed concurrently without each generator managing concurrency directly.
7. Generator architecture
- src/generators/ is the main fan-out point: each subdirectory is a separate output target with its own generate.mjs, index.mjs, types, and often test fixtures.
- The root src/generators.mjs and src/utils/generators.mjs act as orchestration/glue around selecting and running one or more targets in a single invocation.
8. Legacy and compatibility outputs
- legacy-html, legacy-html-all, legacy-json, and legacy-json-all exist to reproduce older Node.js documentation tooling behavior as closely as possible.
- These generators are important as compatibility boundaries: they preserve historical output formats while the newer pipeline evolves.
9. Modern web documentation output
- src/generators/web/ is the redesigned documentation site generator.
- It includes a serverless/static build pipeline, HTML template, CSS bundling, and a React-like UI subtree under ui/ for page chrome, sidebar, search, banners, and theming.
10. Search and client-side data
- src/generators/orama-db/ builds the search index used by the web docs.
- The web generator and the Orama generator are coupled by output contract: the site expects a generated search database alongside the static pages.
11. Other specialized exports
- api-links extracts cross-reference links from symbols and exports, addon-verify emits verification-oriented artifacts, llms-txt generates an LLM-friendly text summary, and man-page emits a Unix man page.
- ast, ast-js, and jsx-ast are structure-oriented generators focused on AST-like representations rather than human-facing docs.
12. Metadata and reference mapping
- src/generators/metadata/ builds auxiliary metadata using builtin and MDN mapping tables plus YAML/transformer utilities.
- This acts like an enrichment layer for names, slugs, and reference resolution rather than a primary presentation layer.
13. Logging and diagnostics
- src/logger/ centralizes console and GitHub-compatible logging, with time/color utilities and transport abstractions.
- This is the observability boundary for both local CLI runs and CI automation.
14. Tooling, tests, and delivery
- The repo is ESM Node.js code with extensive unit tests under src/**/__tests__, plus Playwright e2e coverage for the web experience.
- GitHub Actions handles CI, code scanning, dependency review, publishing, and generated artifact checks; Vercel-related scripts indicate the web docs can also be previewed/deployed as a static build.
15. High-level data flow
- In practice, the flow is: markdown API sources → parsing/normalization → shared enrichment and threading → one or more generators → output directories/files.
- The architectural diagram should show the CLI as the control plane, shared parsing/utilities as the core pipeline, and generators as isolated output sinks with the web/search pair forming the most coupled subsystem.
Main entry points: generators.mjs Gen orchestrator · file.mjs File utils · generate.mjs Generate cmd · index.mjs Commands
Components 21
CLI
Executable entrypoint and command dispatch
- CLI entry · Starts the command-line interface
bin/cli.mjs - Commands · Registers CLI commands
bin/commands/index.mjs - Generate cmd · Batch generation command
bin/commands/generate.mjs
Pipeline
Shared parsing, normalization, threading, and logging
- Markdown parse · Converts markdown sources into normalized document data
src/parsers/markdown.mjs - Remark utils · Shared remark/AST helpers
src/utils/remark.mjs - Unist utils · Tree utilities for unist/AST processing
src/utils/unist.mjs - Parallel run · Chunk-based concurrent execution
src/threading/parallel.mjs
Generators
Output backends and orchestration
- Gen orchestrator · Selects and runs generator targets
src/generators.mjs - Web docs · Modern static documentation site generator
src/generators/web/generate.mjs - Search DB · Builds the search index used by the web docs
src/generators/orama-db/generate.mjs - Legacy HTML · Legacy HTML output for historical Node docs
src/generators/legacy-html/generate.mjs - Legacy JSON · Legacy JSON output for historical Node docs
src/generators/legacy-json/generate.mjs - API links · Extracts cross-reference link data
src/generators/api-links/generate.mjs - Metadata · Builds auxiliary metadata and reference mappings
src/generators/metadata/generate.mjs - LLM text · Produces an LLM-friendly summary artifact
src/generators/llms-txt/generate.mjs - Man page · Emits a Unix man-page output
src/generators/man-page/generate.mjs - AST export · AST-oriented structured output
src/generators/ast/generate.mjs - JSX AST · JSX/AST-oriented structured output
src/generators/jsx-ast/generate.mjs
Support
Shared helpers used across the repo
- Generator utils · Shared helper layer for generator selection and execution
src/utils/generators.mjs - Logger · Console and GitHub-compatible diagnostics
src/logger/logger.mjs - File utils · Common file and path helpers
src/utils/file.mjs
Connections 31
- CLI entry → Commands: loads · CLI bootstraps the command registry
- Commands → Generate cmd: exposes · Registers the generate workflow
- Commands → Logger: logs through · Commands report status and diagnostics
- Generate cmd → Markdown parse: reads · Generate command starts from markdown sources
- Generate cmd → Parallel run: threads · CLI thread count flows into parallel execution
- Generate cmd → Gen orchestrator: runs · Generation command invokes the orchestrator
- Markdown parse → Remark utils: uses · Markdown parsing relies on shared remark helpers
- Remark utils → Unist utils: traverses · AST normalization depends on unist helpers
- Gen orchestrator → Generator utils: coordinates · Orchestrator delegates target resolution to shared generator glue
- Gen orchestrator → Web docs: fans out · Runs the modern web docs backend
- Gen orchestrator → Search DB: fans out · Runs search-index generation alongside the site
- Gen orchestrator → Legacy HTML: fans out · Runs legacy HTML compatibility output
- Gen orchestrator → Legacy JSON: fans out · Runs legacy JSON compatibility output
- Gen orchestrator → API links: fans out · Runs cross-reference extraction
- Gen orchestrator → Metadata: fans out · Runs metadata enrichment generation
- Gen orchestrator → LLM text: fans out · Runs LLM-oriented text export
- Gen orchestrator → Man page: fans out · Runs man-page export
- Gen orchestrator → AST export: fans out · Runs AST-shaped structured output
- Gen orchestrator → JSX AST: fans out · Runs JSX AST-shaped structured output
- Web docs → Search DB: expects · The web site consumes the generated search database
- Web docs → File utils: writes via · Web build stages rely on file/output helpers
- Legacy HTML → File utils: writes via · Legacy HTML generation emits files through shared helpers
- Legacy JSON → File utils: writes via · Legacy JSON generation emits files through shared helpers
- Metadata → File utils: reads/writes · Metadata generation uses common file utilities
- API links → File utils: reads/writes · Link extraction and artifact emission use shared file utilities
- LLM text → File utils: writes via · Text export uses shared file utilities
- Man page → File utils: writes via · Man-page generation uses shared file utilities
- AST export → File utils: writes via · Structured AST output uses shared file utilities
- JSX AST → File utils: writes via · JSX AST output uses shared file utilities
- Parallel run → File utils: chunks · Parallel execution splits work over file-backed tasks
- Logger → Parallel run: reports · Execution status and errors are logged during parallel runs