ArchiGram
Pre-alpha: ArchiGram is early-stage software. The CLI, MCP tools, spec format and output formats may change without notice.

Architecture diagrams should be compiled, not drawn.

ArchiGram reads your code and its runtime traces and compiles them into small, readable architecture diagrams. You choose what each diagram shows with a short spec, and five checks make sure it stays true to the code.

$uvx --from git+https://github.com/klcd/archigram archigram --help
01 · The Problem

Why architecture diagrams go wrong

Teams want diagrams that stay true as the code changes and are small enough to read. Today they usually fail in one of three ways.

Failure 1 · Drift

Hand-drawn diagrams go stale

Diagrams drawn in Excalidraw, Miro or Markdown have no link to the code. After a refactor, arrows point at deleted modules and new dependencies are missing.

Failure 2 · Hairballs

Generated graphs are unreadable

Dependency and trace visualizers put every symbol on one canvas, which is 361 symbols for ArchiGram itself. That is too much to read, and too big for Gitea’s 5,000-character Mermaid limit.

Failure 3 · Invention

LLM-drawn diagrams make things up

An LLM writing Mermaid or D2 directly invents classes, drops real dependencies while summarizing, breaks renderer syntax, and draws a different diagram on every run.

02 · The Idea

Programs extract the facts; you only choose what to show

Only deterministic programs read the code. Neither people nor AI agents write diagram syntax: they edit a declarative YAML spec through CLI commands such as archigram curate, which prune leaves, collapse groups or fold loops. Before a diagram is written, five gates check it:

  • Gate 1 Grounding: every ID and pattern in the spec must match a real symbol in the code or trace, so nothing is invented.
  • Gate 2 Protected boundaries: nodes marked as protected, such as security or API boundaries, can never be pruned or hidden.
  • Gate 3 Topology and order: paths that exist in the code stay connected, cycles are reported, and the order of async calls is kept. A failure names the exact path.
  • Gate 4 Budgets: each view stays within its node and edge limits, typically 10–25 nodes.
  • Gate 5 Syntax: the Mermaid, D2, PlantUML, LikeC4 or DOT output is validated before it is written, including Gitea’s 5,000-character Mermaid limit.
03 · Agent Moves

What an agent may do to a diagram

An agent never draws. It adds one rule to the spec, ArchiGram recompiles the diagram from the code, and the five gates decide whether it may be written. These are eight real runs on the six-module shop package from the quickstart.

Every move is checked against the same contract: keep shop.api and shop.repository visible shop.api must still import its way to shop.repository at most 12 boxes
  1. Allowed
  2. Refused
examples/agent-moves/00-start.yaml the code 1 / 8
shop

The agent adds

rules: []

The checks

  1. SSpec loads
  2. 1Grounding
  3. 2Protected boxes
  4. 3Paths and order
  5. 4Budget
  6. 5Syntax

The boxes, arrows and messages come from running each spec in examples/agent-moves; only the layout is fixed by hand so you can follow each change. The gates check rules against the contract, not the contract against your intent, so review changes to the spec like code.

04 · ArchiGram on ArchiGram

The Architecture, Drawn by the Tool Itself

Every diagram below is compiled from ArchiGram’s own code, or from one recorded run of it, and re-checked on every push. If the code changes and a picture would become wrong, the build fails.

What it does: one pipeline from code to a verified diagram

  1. 1 · Ingest

    Read facts, never guess

    Deterministic extractors read the Python AST, OpenTelemetry spans, SCIP indexes, DOT graphs and class models.

    ingest_python · ingest_otel · ingest_scip · ingest_dot · ingest_class
  2. 2 · Canonical IR

    One provenance-stamped IR

    Everything becomes a CanonicalIR, a structural graph or an interaction trace, with every node stamped by where it came from.

    src/archigram/domain
  3. 3 · Reduce

    Shrink it by declared rules

    A YAML spec (CurationSpecV1) prunes, bypasses and collapses the graph. Traces are compacted by R1–R6 loop folding and ordering rules.

    reduce_structural · reduce_trace
  4. 4 · Lint

    Five gates must pass

    Grounding, protected boundaries, topology and ordering, size budgets and syntax are all checked before a single byte is written.

    lint_grounding · lint_topology · lint_budget · lint_syntax
  5. 5 · Emit

    Render the same IR anywhere

    Mermaid, D2, PlantUML, LikeC4 and Graphviz DOT are rendered deterministically, so a rerun produces identical files.

    emit_mermaid · emit_d2 · emit_plantuml · emit_likec4

The patterns that keep it maintainable

Pattern 1 · Rings

Dependencies only point inward

Four rings: entrypoints, features, ports and domain. Every import points toward the domain, and the domain and ports may not import the CLI or MCP frameworks, subprocess, or any outer ring. The CLI and the MCP server are replaceable adapters around them.

Enforced by import-linter · layers and forbidden contracts
Pattern 2 · Slices

16 slices that cannot import each other

Each ingestor, reducer, gate and emitter lives in its own vertical slice and may only import the domain and ports. Adding a seventeenth slice never touches its siblings.

Enforced by import-linter · independence contract
Pattern 3 · Hub

Many inputs, one canonical hub

Every ingestor produces the same CanonicalIR and every emitter reads it, so supporting a new input or output format means adding one slice, not rewriting the pipeline.

Enforced by the typed ports in archigram.ports

Zoom in: four levels, each compiled from the real code

Zoom 0 · System

The whole system on one page

Nine capability groups inside the four rings. Read it from the outside in: the CLI and the MCP server call features, features call ports, and ports describe the domain.

Read the L0 guide →
l0_hexagonal_rings_d2.d2.svg
ArchiGram system map: nine capability groups inside the four hexagonal rings
Zoom 1 · Slices

Sixteen isolated vertical slices

Ingestors, reducers, gates and emitters side by side, each importing only the domain and ports. A contributor adding an input format, a diagram target or a lint rule works inside one slice and breaks no other.

Read the L1 guide →
l1_feature_slices_d2.d2.svg
ArchiGram feature-slice map: sixteen independent slices and the four rings
Zoom 2 · Subsystem

Inside the reduction engine

A focused neighbourhood of the reducers: graph simplification by strongly connected components and transitive reduction, and the R1–R6 rules that compact a runtime trace while keeping its causal order.

Read the L2 guide →
l2b_reduction_engine_d2.d2.svg
ArchiGram reduction engine: how graphs and traces are simplified
Zoom 3 · Runtime

One real run, recorded from itself

ArchiGram runs itself under Python’s sys.monitoring, records the call tree, compacts it to 15 participants and 48 events, and draws it with the same pipeline you just saw. Nobody typed this sequence diagram.

l3_runtime_pipeline_d2.d2.svg
Sequence diagram of ArchiGram's own pipeline run, recorded at runtime
05 · Curation in Action

Before, triage, after: one graph in three stages

This is ArchiGram’s own code. Stage 1 is the raw graph a plain extractor produces. Stage 2 is the same graph, colored by what the spec does to each node: remove, bypass, collapse or keep. Stage 3 is the result that passed all five gates. The CLI commands that produced it are listed below. Click a diagram to zoom.


          
06 · Animated Traces

Diagrams that show order, not just structure

Boxes and arrows cannot show what happens first. From a recorded run, ArchiGram also emits animated SVGs, driven by CSS alone, that play in Markdown, Gitea, GitHub and browsers without any JavaScript.

l3_runtime_pipeline_steps_d2.d2.svg
Step-by-Step Pipeline and Self-Repair Animated D2 SVG