Automatically generate C4 architecture docs for your TypeScript codebase.
AutoDoc (formerly C4-Auto) is a standalone CLI package (@jonverrier/auto-doc) that walks your TypeScript (and TSX) directories, uses an LLM to write module-level summaries, and produces Mermaid C4 diagrams so you can see how your system is structured—without maintaining docs by hand.
It was originally built for the Strong AI fitness-coaching platform; the default generated filenames follow that convention but you can override them for any project.
The C4 model is a simple way to describe software architecture in layers:
- Context – How your system fits in the world: users, other systems, and boundaries.
- Container – The main applications, services, or data stores inside your system.
- Component – The building blocks inside each container and how they talk to each other.
- Deployment – How it all runs on servers and infrastructure.
C4 is built for “just enough” documentation: enough to onboard people and navigate the codebase, without the docs rotting. Diagrams stay useful because they’re generated from the code and can be refreshed on a schedule.
- Traverses your project (by default skips
node_modules,dist,.git). - Module headers – For each
.ts/.tsxfile it can add or refresh a short LLM-generated comment at the top (with a date so you only regenerate when stale). - C4 diagrams – For each directory it can write generated markdown files (default names below).
- Rollup (
--rollup) – For nested source trees, synthesizes package-level summaries at the scan root from subdirectory docs, root-level module headers, and optional human-authored design intent (Design.md/DESIGN.md). Skipped for flat trees. Never modifies your projectREADME.mdor design files. - Time windows – You choose how old a file can be before it’s refreshed (one week, two weeks, or one month).
AutoDoc uses dedicated generated-doc names so it never overwrites your hand-written README.md:
| Diagram type | Default filename |
|---|---|
| Component | README.StrongAI.Component.md |
| Context | README.StrongAI.Context.md |
These names come from the Strong AI tooling convention. Override them with --component-file and --context-file if your project uses different names (e.g. ARCHITECTURE.Component.md).
AutoDoc is published to GitHub Packages as @jonverrier/auto-doc with an auto-doc CLI binary. The legacy c4-auto binary name remains available as a compatibility alias.
Prerequisites: Node.js 24, OPENAI_API_KEY when generating docs, GitHub Packages auth for install.
.npmrc (repo root):
@jonverrier:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}package.json:
{
"devDependencies": {
"@jonverrier/auto-doc": "^1.0.0"
},
"scripts": {
"generate-docs": "auto-doc --dir ./src --files \"*.ts\" \"*.tsx\" --one-month --c4component --c4context --rollup"
}
}Set NODE_AUTH_TOKEN (PAT with read:packages) for install.
npm install --save-dev @jonverrier/auto-docSee MIGRATION.md if upgrading from @jonverrier/c4-auto.
Generate docs for ./src, refresh files older than one month, and produce both diagram types:
npx auto-doc --dir ./src --files "*.ts" "*.tsx" --one-month --c4component --c4contextFor packages with nested source trees, add --rollup:
npx auto-doc --dir ./src --files "*.ts" "*.tsx" --one-month --c4component --c4context --rollupWhen rolling up, AutoDoc auto-detects Design.md or DESIGN.md at the scan root or its parent directory and includes it as read-only context. Override with --design-file:
npx auto-doc --dir ./src --files "*.ts" --one-month --c4component --rollup --design-file DESIGN.mdUse custom output filenames:
npx auto-doc --dir ./src --files "*.ts" --one-month --c4component \
--component-file ARCHITECTURE.Component.md \
--context-file ARCHITECTURE.Context.mdOr via npm script (pass extra flags after --):
npm run generate-docs -- --one-week --c4componentRequired
| Flag | Description |
|---|---|
--dir <path> |
Root directory to scan (e.g. ./src) |
--files <spec...> |
One or more globs (e.g. "*.ts" "*.tsx") |
| Exactly one time window | --one-week, --two-weeks, or --one-month |
Optional
| Flag | Description |
|---|---|
--c4component |
Write Component diagram markdown in each directory |
--c4context |
Write Context diagram markdown in each directory |
--rollup |
Synthesize root-level summaries from subdirectory docs (requires --c4component and/or --c4context) |
--design-file <path> |
Human-authored design intent for rollup (default: auto-detect Design.md/DESIGN.md) |
--component-file <name> |
Basename for Component output (default: README.StrongAI.Component.md) |
--context-file <name> |
Basename for Context output (default: README.StrongAI.Context.md) |
--help, -h |
Print usage |
Output filename rules: basename only (no paths), must end with .md, must not be README.md.
Use --rollup when your scan root has subdirectories with source (e.g. src/checks/, src/config/). The tool pre-scans the tree before traversal.
| Tree shape | Per-directory C4 at root | Rollup at root |
|---|---|---|
Flat (src/*.ts only) |
Yes | Skipped (nothing to roll up) |
Nested (src/ + subdirs) |
No — rollup owns root | Yes — package-level summary |
When rollup runs:
- Subdirectories get normal per-directory generated markdown files.
- Root-level
.tsfiles still receive module header comments only. RollupC4Visitor.finalize()writes root summaries from subdirectory READMEs, root-level module headers (labelled(root)in the prompt), and optional design intent.- Only generated markdown files are overwritten — never
README.mdor human-authored design documents. - Rollup uses its own staleness rules (child README, root header, or design file change ≥ existing root rollup date).
Visitor pipeline (ascending priority):
- ModuleHeaderVisitor (
kFirst) – Refreshes stale module header comments in source files. - C4DiagramVisitor (
kSecond) – Writes per-directory diagram markdown from module headers. Skips scan root when--rollupand nested sources are detected. - RollupC4Visitor (
kThird, when--rollup) – Accumulates subdirectory READMEs during traversal; writes root summaries infinalize().
Headers are always up to date before diagram generation. Rollup runs after the full tree walk.
Generated docs for this repo:
npm install
npm run build
npm run test:ci # unit + integration (no OPENAI_API_KEY)
npm run test:e2e # real LLM (needs OPENAI_API_KEY)Released from this repository to GitHub Packages:
- Commit on
develop, merge tomain. - On
main:npm install,npm run build,npm publishwithNODE_AUTH_TOKEN. - Return to
develop.
GitHub Actions workflow .github/workflows/publish.yml also publishes on GitHub Release or manual dispatch.
- AgentDoc – MCP server for interactive C4 diagram generation from your IDE. AutoDoc is the automated CLI sibling.
MIT