From d2-diagrams
This skill should be used when the user asks to "create a diagram", "draw an architecture diagram", "visualize a flow", "make a system diagram", "generate a D2 diagram", or mentions D2, architecture diagrams, flow diagrams, sequence diagrams, or system visualization.
How this skill is triggered — by the user, by Claude, or both
Slash command
/d2-diagrams:d2-diagramsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Generate professional diagrams using [D2](https://d2lang.com/), render them to PNG, visually evaluate the output, and iterate until the result is clean and readable.
Generate professional diagrams using D2, render them to PNG, visually evaluate the output, and iterate until the result is clean and readable.
Verify D2 is installed before starting:
which d2 || brew install d2
Use the C4 model to decide the right level of abstraction before drawing anything. C4 defines four zoom levels — pick the one that matches what the diagram needs to communicate.
Reference: D2 has first-class C4 support since v0.7. See the official D2 C4 guide for examples including the C4 theme, c4-person shape, markdown labels, d2-legend, and the suspend keyword for multi-view models.
When: Showing how the system fits into the wider world. For stakeholders, onboarding, high-level architecture.
[Person] → [Your System] → [External System]
D2: Use shape: person for actors, single node for the system, ovals for external systems.
When: Showing the major technical building blocks inside a system. For developers, debugging, understanding how services connect.
D2: Use a container with boundary class for the system boundary. Use technology classes (go/java/ts) for services, db class for databases, queue class for message brokers.
When: Zooming into a single container to show its internal components. For deep debugging, code review, design discussions.
Rarely needed. Class diagrams, sequence diagrams. Usually auto-generated from code rather than hand-drawn.
| Situation | Level | Example |
|---|---|---|
| "How does the platform work?" | L1 Context | User → Platform → Payment Provider |
| "How do our services connect?" | L2 Container | API Gateway → Order Service → DB |
| "How does the order service handle a request?" | L3 Component | Validator → Processor → Notifier |
| "What are the classes in the processor?" | L4 Code | Usually skip — read the code instead |
Default to Level 2 (Container) unless the user specifies otherwise. It's the most useful level for debugging and onboarding.
Before writing D2, decide:
down for hierarchies/pipelines, right for sequential flowsRule of thumb: If a diagram has more than ~10 nodes or arrows that must cross, split it.
Before putting a service or component on a diagram, verify its actual name from the codebase or deployment configs. Don't guess or use colloquial names — check K8s manifests, Terraform modules, or service entrypoints. Wrong names on architecture diagrams erode trust in the documentation.
No codebase? For conceptual/design diagrams, skip this step. See references/d2-advanced.md § "Conceptual Diagrams" for naming conventions.
Place .d2 files where they'll be maintained alongside the project:
# In a project — keep diagrams with docs
mkdir -p docs/diagrams
# Write to docs/diagrams/<name>.d2, renders to docs/diagrams/<name>.svg
# Standalone / exploratory — use a scratch directory
mkdir -p /tmp/d2-work
Convention: Name files after what they show, not the system: payment-flow.d2, auth-sequence.d2, system-context.d2. Keep the .d2 source committed alongside the rendered output so anyone can re-render.
Follow the style guide in references/d2-style.md.
# SVG — preferred for docs, wikis, web (scalable, searchable text, smaller files)
d2 --theme 0 --layout elk --pad 60 <input>.d2 <output>.svg
# PNG — for presentations, chat, or when SVG isn't supported
d2 --theme 0 --layout elk --pad 60 <input>.d2 <output>.png
# Add --scale 2 for higher-DPI output (retina/print)
--theme 0 — clean light theme (best for docs/presentations). For standard C4 look, use --theme 200 (C4 theme)--layout elk — Eclipse Layout Kernel, handles complex graphs better than default dagre--pad 60 — breathing room around edgesRead the rendered PNG using the Read tool and evaluate against these criteria. Score each 1-10, iterate until ALL are >= 8:
| Criteria | What to check |
|---|---|
| C4 compliance | Does the diagram follow C4 conventions for the chosen level? See the checklist below. |
| Flow | Do arrows follow one dominant direction (top→bottom or left→right)? Are there crossing arrows? Arrows going backwards? |
| Readability | Is all text legible? Are labels truncated? Is the diagram too wide/flat or too tall/narrow? |
| Grouping | Are related nodes visually close? Is there clear visual hierarchy? |
| Simplicity | Is every node and arrow necessary? Could anything be removed or split into a separate diagram? |
Run through this before every render. If any item is "no", fix the D2 source first.
"name\n[Container: Tech]" (e.g., "order-service\n[Container: Go]") or shorthand "name\n[Tech — role]" (e.g., "scheduler\n[Go — K8s CronJob]"). No node should be just a name with no context."description\n[Protocol]" (e.g., "creates order\n[SQL]"). Use [SQL], [gRPC], [Pub/Sub], [HTTPS], [REST].boundary class container wrapping internal components. External actors sit outside it.Common fixes by symptom:
| Symptom | Fix |
|---|---|
| Too wide/flat, text tiny | Switch direction: right → direction: down |
| Crossing arrows | Reorder node declarations. D2/ELK places nodes in declaration order |
| Spaghetti connections | Split into multiple diagrams. Remove secondary connections |
| Nodes scattered randomly | Use containers to group related nodes |
| Labels truncated | Shorten label text, use \n for line breaks |
| Too many edge labels | Remove obvious labels, keep only the non-obvious ones |
If any criterion scores below 8:
.d2 source (reorder nodes, change direction, split diagram, adjust labels)Do not stop until all criteria score >= 8. Typically takes 2-3 iterations.
Once the diagram passes evaluation:
.d2 source file alongside the rendered output so it can be edited laterd2 --theme 0 --layout elk --pad 60 <file>.d2 <file>.svgdirection: down or direction: rightsystem class, actors use person class, external systems use external-system class"sends orders\n[HTTPS/JSON]"boundary class container for the system boundary"System Name — Focus Area" (e.g., "Order Platform — Payment Flow")go/java/ts), databases (db), queues (queue)"sends events\n[Pub/Sub]", "reads\n[SQL]", "config\n[gRPC]"Message queues — explicit node vs edge label:
[Pub/Sub] when most or all edges are async — adding queue nodes everywhere just adds noisedirection: down for vertical pipelines (data processing, ETL flows)direction: right for sequential processesshape: sequence_diagram-> for requests, <- or --> (dashed) for responses/async"Step Name": { ... }actor -> actor: "description"flow: {
shape: sequence_diagram
client: "Client"
gateway: "API Gateway"
auth: "Auth Service"
orders: "Order Service"
db: "Database"
client -> gateway: "POST /orders\n[HTTPS]"
gateway -> auth: "validate token\n[gRPC]"
auth -> gateway: "200 OK"
gateway -> orders: "create order\n[gRPC]"
orders -> db: "INSERT\n[SQL]"
db -> orders: "order_id"
orders -> gateway: "201 Created"
gateway -> client: "{ order_id }"
}
direction: right with sources on the left, target on the rightdown for pipelines, right for sequences[Pub/Sub], [SQL], [gRPC], [HTTPS]detail class for internals — when showing database tables, config values, or other internals without adding full nodes, use the detail rectangle class from the style guidenpx claudepluginhub denisraison/claude-plugins --plugin d2-diagramsGenerates D2 diagrams from textual descriptions for system architectures, flowcharts, network topologies, data flows, and component relationships.
Generate architecture diagrams, flowcharts, decision trees, workflows, sequence flows, ERDs from declarative D2 text with automatic layouts, themes, and styling.
Generates professional diagrams (flowcharts, architecture diagrams, comparisons, mind maps, timelines) as draw.io XML files from concepts or documents.