Diagrams as Code

Choosing the right diagramming tool. Comparison of D2, Mermaid, GraphViz, and PlantUML with workflow patterns and Catppuccin theming.

Tool Selection Guide

Tool Best For Strengths Learning Curve

D2

Infrastructure diagrams, architecture

Clean syntax, native dark themes, containers

Low

Mermaid

Flowcharts, sequences, Gantt charts

GitHub/GitLab native rendering, wide adoption

Low

GraphViz

Graph theory, dependency trees, large graphs

Mature layout algorithms, record-based nodes

Medium

PlantUML

UML (class, sequence, component, state)

Full UML coverage, extensive documentation

Medium

Decision Framework

When to pick each tool

D2 — first choice for infrastructure and network diagrams. Cleanest syntax, best container (nesting) support, native Catppuccin-compatible theming.

Mermaid — first choice when the diagram must render on GitHub/GitLab without Kroki. Flowcharts and sequences are its sweet spot.

GraphViz — when you need automatic layout of complex graphs with many nodes. Subgraph clustering. Force-directed layouts for undirected graphs.

PlantUML — when the diagram is genuinely UML: class hierarchies, detailed sequence diagrams with activation bars, state machines with guards.

Workflow Pattern

Diagram development cycle
# 1. Write diagram source
nvim docs/modules/ROOT/pages/reference/diagrams/network.adoc

# 2. Build locally with Kroki
cd ~/atelier/_bibliotheca/domus-docs && make serve

# 3. Check rendered output
# http://localhost:8000/captures/reference/diagrams/network.html

# 4. Iterate until satisfied, then commit
git -C ~/atelier/_bibliotheca/domus-captures add -A && \
git -C ~/atelier/_bibliotheca/domus-captures commit -m "$(cat <<'EOF'
docs(diagrams): Add network topology diagram
EOF
)"

Syntax Comparison

D2
client -> server: HTTPS
server -> database: SQL
database: PostgreSQL {shape: cylinder}
Mermaid
graph LR
    client[Client] -->|HTTPS| server[Server]
    server -->|SQL| database[(PostgreSQL)]
GraphViz
digraph {
    rankdir=LR
    database [shape=cylinder]
    client -> server [label="HTTPS"]
    server -> database [label="SQL"]
}
PlantUML
@startuml
client -> server: HTTPS
server -> database: SQL
@enduml

Embedding in AsciiDoc

All four tools share the same Kroki integration pattern in AsciiDoc:

Generic pattern
[TOOL,target=OUTPUT_NAME,format=svg]
....
diagram source here
....

Replace TOOL with d2, mermaid, graphviz, or plantuml.

File Organization

Diagram source in the repo
pages/reference/diagrams/
├── index.adoc          # Gallery with inline diagrams
├── architecture.adoc   # System architecture diagrams
├── network.adoc        # Network topology diagrams
├── security.adoc       # Security flow diagrams
├── flows.adoc          # Process flow diagrams
└── projects.adoc       # Project-specific diagrams

Diagrams live inline in AsciiDoc pages. Kroki renders them at build time — no separate image files to manage.

Catppuccin Mocha Palette Reference

Color Hex Use

Base

#1e1e2e

Background

Surface0

#313244

Container fill

Overlay0

#6c7086

Subtle borders

Text

#cdd6f4

Labels, text

Blue

#89b4fa

Primary elements

Green

#a6e3a1

Success, databases

Pink

#f5c2e7

Connections, highlights

Red

#f38ba8

Errors, warnings

Peach

#fab387

Accents

Subtext0

#a6adc8

Secondary text, arrows

See Also

  • D2 — primary diagramming language

  • Mermaid — flowcharts and sequences

  • GraphViz — graph layout engine

  • PlantUML — UML diagrams

  • Kroki — unified rendering server