Single-binary CLI that generates C4 architecture diagrams from source code. Uses a hybrid approach: heuristic AST scanning builds a draft model, then an optional LLM pass refines it.
go build -o c4 .# Scan your project
c4 scan ./src/myapp --scope myapp
# (Optional) Refine with LLM
export ANTHROPIC_API_KEY=sk-...
c4 refine --scope myapp
# Generate per-level views
c4 views --scope myapp
# Cross-reference with KB wiki articles
c4 link --scope myapp
# See what was generated
c4 show --scope myapp
c4 stats --scope myapp| Command | What it does |
|---|---|
c4 scan <path> |
Parse source code heuristically into a draft C4 model |
c4 refine |
LLM pass: Claude improves names, descriptions, adds people |
c4 views |
Generate per-level view files (context, container, component) |
c4 link |
Match model elements to KB wiki articles |
c4 show |
Print the current C4 model |
c4 stats |
Show model statistics |
c4 clear |
Delete generated C4 data for a scope |
| Flag | Description | Default |
|---|---|---|
--scope NAME |
Knowledge scope (shared with kb-go) | directory name |
--json |
Machine-readable JSON output | off |
--model MODEL |
LLM model for refinement | claude-haiku-4-5-20251001 |
The heuristic scanner infers C4 elements from code structure:
| Code Signal | C4 Element |
|---|---|
go.mod, package.json, pyproject.toml |
Container boundary |
__init__.py packages, sub-directories |
Components |
| Import statements between modules | Relationships |
sqlalchemy, mongo, redis, pg |
Container tagged "database" |
fastapi, express, gin, flask |
Container tagged "web" |
celery, rabbitmq, kafka, nats |
Container tagged "queue" |
Dockerfile, docker-compose.yml |
Container boundaries |
anthropic, stripe, telegram |
External systems |
All data lives under ~/.knowledge-base/{scope}/c4/, alongside kb-go's wiki data:
~/.knowledge-base/{scope}/
├── wiki/ <- kb-go's articles (untouched)
├── c4/ <- c4-gen writes here
│ ├── model.json <- Master model (all elements + relationships)
│ ├── views/
│ │ ├── system-context.json
│ │ ├── containers.json
│ │ └── components/
│ │ └── {container-id}.json
│ └── cache/ <- Content hash cache for incremental rebuilds
- Scan -- Parse source code, detect container boundaries, extract imports, build draft model
- Refine -- Send the draft to Claude for human-readable names, better descriptions, people actors
- Views -- Slice the master model into per-level view files
- Link -- Cross-reference elements with KB wiki articles (from kb-go)
Steps 2-4 are optional. The scan alone produces a usable model.
| Variable | Required for | Description |
|---|---|---|
ANTHROPIC_API_KEY |
refine command |
Anthropic API key |
- Go (stdlib
go/astparser) - Python (regex-based parser)
- TypeScript/JavaScript (regex-based parser)
go test -v ./...