# nodejs/doc-kit architecture

> Architecture diagram of the GitHub repository nodejs/doc-kit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nodejs/doc-kit
- Repository: https://github.com/nodejs/doc-kit

## Overview

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: [`src/generators.mjs`](https://github.com/nodejs/doc-kit/blob/main/src/generators.mjs) (Gen orchestrator), [`src/utils/file.mjs`](https://github.com/nodejs/doc-kit/blob/main/src/utils/file.mjs) (File utils), [`bin/commands/generate.mjs`](https://github.com/nodejs/doc-kit/blob/main/bin/commands/generate.mjs) (Generate cmd), [`bin/commands/index.mjs`](https://github.com/nodejs/doc-kit/blob/main/bin/commands/index.mjs) (Commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI"]
  node_bin_cli(("CLI entry<br/>entrypoint<br/>[cli.mjs]"))
  node_bin_commands_index["Commands<br/>command-registry<br/>[index.mjs]"]
  node_bin_commands_generate["Generate cmd<br/>command<br/>[generate.mjs]"]
end

subgraph group_pipeline["Pipeline"]
  node_parsers_markdown["Markdown parse<br/>parser<br/>[markdown.mjs]"]
  node_utils_remark["Remark utils<br/>markdown-helpers<br/>[remark.mjs]"]
  node_utils_unist["Unist utils<br/>ast-helpers<br/>[unist.mjs]"]
  node_threading_parallel["Parallel run<br/>threading<br/>[parallel.mjs]"]
end

subgraph group_generators["Generators"]
  node_generators_orchestrator["Gen orchestrator<br/>orchestration<br/>[generators.mjs]"]
  node_gen_web["Web docs<br/>site-generator<br/>[generate.mjs]"]
  node_gen_orama[("Search DB<br/>index-generator<br/>[generate.mjs]")]
  node_gen_legacy_html["Legacy HTML<br/>compat-generator<br/>[generate.mjs]"]
  node_gen_legacy_json["Legacy JSON<br/>compat-generator<br/>[generate.mjs]"]
  node_gen_api_links["API links<br/>reference-generator<br/>[generate.mjs]"]
  node_gen_metadata["Metadata<br/>enrichment-generator<br/>[generate.mjs]"]
  node_gen_llms_txt["LLM text<br/>text-generator<br/>[generate.mjs]"]
  node_gen_man_page["Man page<br/>doc-generator<br/>[generate.mjs]"]
  node_gen_ast{{"AST export<br/>structure-generator<br/>[generate.mjs]"}}
  node_gen_jsx_ast{{"JSX AST<br/>structure-generator<br/>[generate.mjs]"}}
end

subgraph group_support["Support"]
  node_utils_generators["Generator utils<br/>generator-glue<br/>[generators.mjs]"]
  node_logger["Logger<br/>logging<br/>[logger.mjs]"]
  node_utils_file["File utils<br/>io-helpers<br/>[file.mjs]"]
end

node_bin_cli -->|"loads"| node_bin_commands_index
node_bin_commands_index -->|"exposes"| node_bin_commands_generate
node_bin_commands_index -->|"logs through"| node_logger
node_bin_commands_generate -->|"reads"| node_parsers_markdown
node_bin_commands_generate -->|"threads"| node_threading_parallel
node_bin_commands_generate -->|"runs"| node_generators_orchestrator
node_parsers_markdown -->|"uses"| node_utils_remark
node_utils_remark -->|"traverses"| node_utils_unist
node_generators_orchestrator -->|"coordinates"| node_utils_generators
node_generators_orchestrator -->|"fans out"| node_gen_web
node_generators_orchestrator -->|"fans out"| node_gen_orama
node_generators_orchestrator -->|"fans out"| node_gen_legacy_html
node_generators_orchestrator -->|"fans out"| node_gen_legacy_json
node_generators_orchestrator -->|"fans out"| node_gen_api_links
node_generators_orchestrator -->|"fans out"| node_gen_metadata
node_generators_orchestrator -->|"fans out"| node_gen_llms_txt
node_generators_orchestrator -->|"fans out"| node_gen_man_page
node_generators_orchestrator -->|"fans out"| node_gen_ast
node_generators_orchestrator -->|"fans out"| node_gen_jsx_ast
node_gen_web -->|"expects"| node_gen_orama
node_gen_web -->|"writes via"| node_utils_file
node_gen_legacy_html -->|"writes via"| node_utils_file
node_gen_legacy_json -->|"writes via"| node_utils_file
node_gen_metadata -->|"reads/writes"| node_utils_file
node_gen_api_links -->|"reads/writes"| node_utils_file
node_gen_llms_txt -->|"writes via"| node_utils_file
node_gen_man_page -->|"writes via"| node_utils_file
node_gen_ast -->|"writes via"| node_utils_file
node_gen_jsx_ast -->|"writes via"| node_utils_file
node_threading_parallel -->|"chunks"| node_utils_file
node_logger -->|"reports"| node_threading_parallel

click node_bin_cli "https://github.com/nodejs/doc-kit/blob/main/bin/cli.mjs"
click node_bin_commands_index "https://github.com/nodejs/doc-kit/blob/main/bin/commands/index.mjs"
click node_bin_commands_generate "https://github.com/nodejs/doc-kit/blob/main/bin/commands/generate.mjs"
click node_parsers_markdown "https://github.com/nodejs/doc-kit/blob/main/src/parsers/markdown.mjs"
click node_utils_remark "https://github.com/nodejs/doc-kit/blob/main/src/utils/remark.mjs"
click node_utils_unist "https://github.com/nodejs/doc-kit/blob/main/src/utils/unist.mjs"
click node_threading_parallel "https://github.com/nodejs/doc-kit/blob/main/src/threading/parallel.mjs"
click node_generators_orchestrator "https://github.com/nodejs/doc-kit/blob/main/src/generators.mjs"
click node_utils_generators "https://github.com/nodejs/doc-kit/blob/main/src/utils/generators.mjs"
click node_gen_web "https://github.com/nodejs/doc-kit/blob/main/src/generators/web/generate.mjs"
click node_gen_orama "https://github.com/nodejs/doc-kit/blob/main/src/generators/orama-db/generate.mjs"
click node_gen_legacy_html "https://github.com/nodejs/doc-kit/blob/main/src/generators/legacy-html/generate.mjs"
click node_gen_legacy_json "https://github.com/nodejs/doc-kit/blob/main/src/generators/legacy-json/generate.mjs"
click node_gen_api_links "https://github.com/nodejs/doc-kit/blob/main/src/generators/api-links/generate.mjs"
click node_gen_metadata "https://github.com/nodejs/doc-kit/blob/main/src/generators/metadata/generate.mjs"
click node_gen_llms_txt "https://github.com/nodejs/doc-kit/blob/main/src/generators/llms-txt/generate.mjs"
click node_gen_man_page "https://github.com/nodejs/doc-kit/blob/main/src/generators/man-page/generate.mjs"
click node_gen_ast "https://github.com/nodejs/doc-kit/blob/main/src/generators/ast/generate.mjs"
click node_gen_jsx_ast "https://github.com/nodejs/doc-kit/blob/main/src/generators/jsx-ast/generate.mjs"
click node_logger "https://github.com/nodejs/doc-kit/blob/main/src/logger/logger.mjs"
click node_utils_file "https://github.com/nodejs/doc-kit/blob/main/src/utils/file.mjs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_bin_cli,node_bin_commands_index,node_bin_commands_generate toneBlue
class node_parsers_markdown,node_utils_remark,node_utils_unist,node_threading_parallel toneAmber
class node_generators_orchestrator,node_gen_web,node_gen_orama,node_gen_legacy_html,node_gen_legacy_json,node_gen_api_links,node_gen_metadata,node_gen_llms_txt,node_gen_man_page,node_gen_ast,node_gen_jsx_ast toneMint
class node_utils_generators,node_logger,node_utils_file toneRose
```

## Components

### CLI

Executable entrypoint and command dispatch

- [CLI entry](https://github.com/nodejs/doc-kit/blob/main/bin/cli.mjs): entrypoint · Starts the command-line interface · `bin/cli.mjs`
- [Commands](https://github.com/nodejs/doc-kit/blob/main/bin/commands/index.mjs): command-registry · Registers CLI commands · `bin/commands/index.mjs`
- [Generate cmd](https://github.com/nodejs/doc-kit/blob/main/bin/commands/generate.mjs): command · Batch generation command · `bin/commands/generate.mjs`

### Pipeline

Shared parsing, normalization, threading, and logging

- [Markdown parse](https://github.com/nodejs/doc-kit/blob/main/src/parsers/markdown.mjs): parser · Converts markdown sources into normalized document data · `src/parsers/markdown.mjs`
- [Remark utils](https://github.com/nodejs/doc-kit/blob/main/src/utils/remark.mjs): markdown-helpers · Shared remark/AST helpers · `src/utils/remark.mjs`
- [Unist utils](https://github.com/nodejs/doc-kit/blob/main/src/utils/unist.mjs): ast-helpers · Tree utilities for unist/AST processing · `src/utils/unist.mjs`
- [Parallel run](https://github.com/nodejs/doc-kit/blob/main/src/threading/parallel.mjs): threading · Chunk-based concurrent execution · `src/threading/parallel.mjs`

### Generators

Output backends and orchestration

- [Gen orchestrator](https://github.com/nodejs/doc-kit/blob/main/src/generators.mjs): orchestration · Selects and runs generator targets · `src/generators.mjs`
- [Web docs](https://github.com/nodejs/doc-kit/blob/main/src/generators/web/generate.mjs): site-generator · Modern static documentation site generator · `src/generators/web/generate.mjs`
- [Search DB](https://github.com/nodejs/doc-kit/blob/main/src/generators/orama-db/generate.mjs): index-generator · Builds the search index used by the web docs · `src/generators/orama-db/generate.mjs`
- [Legacy HTML](https://github.com/nodejs/doc-kit/blob/main/src/generators/legacy-html/generate.mjs): compat-generator · Legacy HTML output for historical Node docs · `src/generators/legacy-html/generate.mjs`
- [Legacy JSON](https://github.com/nodejs/doc-kit/blob/main/src/generators/legacy-json/generate.mjs): compat-generator · Legacy JSON output for historical Node docs · `src/generators/legacy-json/generate.mjs`
- [API links](https://github.com/nodejs/doc-kit/blob/main/src/generators/api-links/generate.mjs): reference-generator · Extracts cross-reference link data · `src/generators/api-links/generate.mjs`
- [Metadata](https://github.com/nodejs/doc-kit/blob/main/src/generators/metadata/generate.mjs): enrichment-generator · Builds auxiliary metadata and reference mappings · `src/generators/metadata/generate.mjs`
- [LLM text](https://github.com/nodejs/doc-kit/blob/main/src/generators/llms-txt/generate.mjs): text-generator · Produces an LLM-friendly summary artifact · `src/generators/llms-txt/generate.mjs`
- [Man page](https://github.com/nodejs/doc-kit/blob/main/src/generators/man-page/generate.mjs): doc-generator · Emits a Unix man-page output · `src/generators/man-page/generate.mjs`
- [AST export](https://github.com/nodejs/doc-kit/blob/main/src/generators/ast/generate.mjs): structure-generator · AST-oriented structured output · `src/generators/ast/generate.mjs`
- [JSX AST](https://github.com/nodejs/doc-kit/blob/main/src/generators/jsx-ast/generate.mjs): structure-generator · JSX/AST-oriented structured output · `src/generators/jsx-ast/generate.mjs`

### Support

Shared helpers used across the repo

- [Generator utils](https://github.com/nodejs/doc-kit/blob/main/src/utils/generators.mjs): generator-glue · Shared helper layer for generator selection and execution · `src/utils/generators.mjs`
- [Logger](https://github.com/nodejs/doc-kit/blob/main/src/logger/logger.mjs): logging · Console and GitHub-compatible diagnostics · `src/logger/logger.mjs`
- [File utils](https://github.com/nodejs/doc-kit/blob/main/src/utils/file.mjs): io-helpers · Common file and path helpers · `src/utils/file.mjs`

## Connections

- 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
