Skip to content

qbtrix/c4-gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

c4-gen

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.

Install

go build -o c4 .

Quick Start

# 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

Commands

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

Flags

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

What Gets Detected

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

Storage

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

Workflow

  1. Scan -- Parse source code, detect container boundaries, extract imports, build draft model
  2. Refine -- Send the draft to Claude for human-readable names, better descriptions, people actors
  3. Views -- Slice the master model into per-level view files
  4. Link -- Cross-reference elements with KB wiki articles (from kb-go)

Steps 2-4 are optional. The scan alone produces a usable model.

Environment

Variable Required for Description
ANTHROPIC_API_KEY refine command Anthropic API key

Supported Languages

  • Go (stdlib go/ast parser)
  • Python (regex-based parser)
  • TypeScript/JavaScript (regex-based parser)

Testing

go test -v ./...

About

Generate C4 architecture diagrams from source code. Heuristic AST scan, optional LLM refinement, native Mermaid output. Single Go binary, no deps.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages