/software-engineering:gen-diagram [--type=arch|sequence|er|deployment|c4|pipeline] [--no-render] [--no-mise] [--output=<path>] [--dry-run] [<description>]from software-engineering
Generates d2 architecture diagrams from free-text descriptions or repo analysis, embedding Terrastruct icons and rendering SVG when the d2 binary is installed. Stores diff-able sources in docs/diagrams/.
Ships in software-engineering. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Produce a .d2 source file (and a rendered .svg when the d2 binary is installed) that captures a software or infrastructure architecture. Default engine is d2 (https://d2lang.com/), default icons come from https://icons.terrastruct.com/.
Problem: Architecture diagrams in design docs and READMEs are usually either missing, drawn in a closed-source tool that no one can edit, or pasted as PNG screenshots that drift from reality. Running through d2 syntax and the icon catalog by hand takes 10-20 minutes per diagram.
Solution: One invocation that:
.d2 source file from a free-text description or repo analysisicons.terrastruct.com only when the URL is known to resolved2 is installeddocs/diagrams/ for diff-able, PR-reviewable diagramsCRITICAL: When generating any content (.d2 source, file headers, descriptions, or any other output):
Validate Git repository:
git rev-parse --git-dir
Detect d2 and the mise toolchain (non-blocking, and no writes in this phase):
command -v d2
command -v mise
test -f mise.toml && grep -qE '^[[:space:]]*"?d2"?[[:space:]]*=' mise.toml
d2 on PATH: store d2Installed = true. Capture version: d2 --version.d2 absent: store d2Installed = false (will warn later, but proceed — the .d2
source is produced either way).mise on PATH: store miseAvailable = true.mise.toml already pins d2: store d2Pinned = true.When miseAvailable && !d2Pinned && !--no-mise, the pin is added in Phase 5 and
disclosed in the Phase 4 preview first. mise use edits mise.toml, which is a project
file change and must pass through the confirmation gate like any other write.
Verify skill assets:
${CLAUDE_PLUGIN_ROOT}/assets/gen-diagram/d2-cheatsheet.md exists.Resolve repository root for output path defaults:
git rev-parse --show-toplevel
Store as repoRoot.
Parse $ARGUMENTS (or $argument, depending on host syntax). Tokenize on spaces, then partition into flags and a free-text remainder.
Supported flags:
--type=<arch|sequence|er|deployment|c4|pipeline> — diagram style. Default: inferred from description, falls back to arch.--no-render — skip the SVG render step even if d2 is installed.--output=<path> — explicit target path for the .d2 file. Default: docs/diagrams/<slug>.d2.--dry-run — produce the preview only; do not write any files.--no-mise — never touch mise.toml; rely on whatever d2 is already on PATH.Everything else is joined back with spaces as description.
Slugification:
description is non-empty: lowercase, replace non-alphanumerics with -, collapse repeats, trim leading/trailing -, cap at 60 chars.description is empty: slug = architecture.Type inference (when --type is omitted):
/sequence|flow|step.*step|request.*response/i → sequence/er|entity|schema|table/i → er/deploy|infra|vpc|cluster|kubernetes|aws|gcp|azure/i → deployment/c4|context|container|component/i → c4/pipeline|ci\/cd|workflow|jobs/i → pipelinearchDefault output path:
--output provided: use it verbatim (resolve relative to cwd).<repoRoot>/docs/diagrams/<slug>.d2.The accompanying SVG path is the same path with .d2 replaced by .svg.
Read the cheatsheet to ground the LLM in real d2 syntax and verified icon URLs:
Read: ${CLAUDE_PLUGIN_ROOT}/assets/gen-diagram/d2-cheatsheet.md
If description is empty, launch one Explore subagent to summarize the repo's architecture:
Task(
subagent_type: "Explore",
description: "Repo architecture summary",
prompt: "
Summarize this repository's architecture for a system diagram. Return:
{
entryPoints: [list of binaries / servers / endpoints discovered],
services: [list of internal services or modules],
datastores: [databases, caches, queues with vendor names],
externalDeps: [third-party APIs, SaaS],
deploymentTargets: [k8s, AWS service, etc., if obvious from IaC],
language: dominant language,
shape: 'monolith' | 'modular' | 'microservices' | 'library' | 'cli'
}
Detection strategy:
- Languages: glob for *.go, *.py, *.js, *.ts, *.rs, *.java
- Entry points: cmd/*/main.go, main.py, src/index.{ts,js}, bin/*
- Datastores: search go.mod / package.json / requirements.txt for postgres, mysql, redis, kafka, mongo, sqlite, elasticsearch
- Deployment: presence of Dockerfile, k8s/, helm/, *.tf, .github/workflows/
Return concise JSON, no prose.
"
)
Use the returned summary as the modeling input. Otherwise, skip this step.
If description is non-empty, treat it as the modeling input directly. Use the cheatsheet patterns to expand abbreviations (e.g. "auth flow with JWT and Redis" → sequence diagram with user, SPA, API, Redis cache).
Build the preview message:
📐 d2 Diagram Preview
Type: <type>
Description: <description or "(auto-detected from repo)">
Output: <relative path>.d2
Render: <"yes (d2 → SVG)" if d2Installed && !--no-render else "no (source only)">
d2 tooling: <"mise.toml → pin d2 0.7.1 (new)" | "mise.toml already pins d2" | "PATH d2 <version>" | "none — source only">
Planned content:
• Layout: <direction> / <layout-engine>
• Nodes (~N): <comma-separated short list>
• Icons: <count of icons.terrastruct.com URLs that will be embedded>
<CONDITIONAL WARNINGS>
Conditional warnings:
If d2Installed = false:
ℹ️ d2 binary not found
.d2 source will be created; rendering depends on provisioning d2.
Preferred — pins the version for this repo, local dev and CI alike:
• mise use [email protected] # adds d2 to mise.toml [tools] and installs it
Without mise:
• macOS: brew install d2
• Linux: curl -fsSL https://d2lang.com/install.sh | sh -s --
• Verify: d2 --version
If miseAvailable && !d2Pinned && !--no-mise:
ℹ️ mise.toml will gain a d2 pin
Adding: d2 = "0.7.1" (under [tools])
<"mise.toml will be created" | "existing pins are preserved">
This keeps local renders and CI on the same d2 version.
Skip with --no-mise.
If target .d2 file already exists:
⚠️ WARNING: <path>.d2 already exists
This will OVERWRITE the existing diagram source.
Consider committing or backing up the current version first.
Confirmation logic:
If --dry-run:
[DRY RUN MODE - No files will be written]
Proceed straight to Phase 6 to print the preview and the would-be .d2 content. Do not write or render.
If target .d2 exists and not --dry-run:
Use AskUserQuestion:
Question: "Overwrite existing diagram at <path>.d2?"
Options:
- "Yes, overwrite" (proceed to Phase 5)
- "No, cancel" (exit with "Operation cancelled by user")
If target does not exist and not --dry-run:
Use AskUserQuestion:
Question: "Create diagram at <path>.d2?"
Options:
- "Yes, create" (proceed to Phase 5)
- "No, cancel" (exit with "Operation cancelled by user")
Synthesize the .d2 source following the cheatsheet:
# <Title> and a sentence on scope/audience.sequence: start the body with shape: sequence_diagram.er: each table is a shape: sql_table block.deployment: nest containers by trust boundary (region → VPC → subnet).c4: use shape: c4-person for actors and shape: package for containers.arch / pipeline: pick direction: right and label every edge.icon: URLs that appear in the cheatsheet's verified list. If the design needs an icon not in the list, omit it (the user can add it manually) rather than guessing.dagre by default. Switch to elk if node count > 10.Ensure parent directory exists:
mkdir -p "$(dirname <output>)"
Write the file with Write to the resolved output path.
Pin d2 in mise.toml when miseAvailable && !d2Pinned && !--no-mise:
mise use [email protected]
Run it from repoRoot. mise use is idempotent: it records d2 = "0.7.1" under
[tools], creates mise.toml when absent, leaves every other pin untouched, and
installs the binary — so the Phase 6 render can proceed even if d2 was missing.
On success set d2Installed = true and misePinWritten = true.
d2Installed unchanged, and continue — the .d2 source is
written regardless. A first run may need mise trust before mise use succeeds.Render to SVG when d2Installed && !--no-render && !--dry-run:
d2 <output>.d2 <output>.svg
If d2 was just provisioned by the Phase 5 mise use it may not be on PATH in this
shell yet — route through mise instead:
mise exec -- d2 <output>.d2 <output>.svg
Capture exit code. If non-zero, report the d2 error to the user but treat as a soft failure (the .d2 source was still produced).
Verify written files:
test -f <output>.d2 && wc -l <output>.d2
test -f <output>.svg # only if render attempted
Success report (normal execution):
✅ Diagram created
Files:
✓ <output>.d2 (<N> lines)
✓ <output>.svg # only if render succeeded
✓ mise.toml (d2 = "0.7.1") # only if misePinWritten
Type: <type>
Layout: <direction> / <layout-engine>
Icons used: <count>
Next steps:
1. Preview the SVG:
open <output>.svg # macOS
xdg-open <output>.svg # Linux
2. Edit the source:
${EDITOR:-vi} <output>.d2
3. Re-render after edits:
d2 <output>.d2 <output>.svg
4. Try a different layout:
d2 --layout=elk <output>.d2 <output>.svg
5. Embed in docs:

6. Browse the icon catalog:
https://icons.terrastruct.com/
7. d2 reference:
https://d2lang.com/tour/intro
Success report (dry-run):
✅ [DRY RUN] Preview only — no files written
Would create:
• <output>.d2 (~<N> lines)
• <output>.svg # only if d2Installed && !--no-render
--- Preview of <output>.d2 ---
<full d2 source>
--- end preview ---
Run again without --dry-run to write.
If d2Installed = false, append:
⚠️ Install d2 to render automatically next time:
mise use [email protected] # preferred: pins it in mise.toml for dev + CI
# or: brew install d2
# or: curl -fsSL https://d2lang.com/install.sh | sh -s --
If d2 render failed, append:
⚠️ d2 render failed (.d2 source was written successfully):
<stderr from d2>
Try manually: d2 <output>.d2 <output>.svg
d2 is pinned through mise rather than installed ad hoc, so the version that renders a diagram locally is the version CI renders it with.
Pinned version: [email protected]. Bump it in one place — this section — and in the Phase 4/5/6
strings above.
mise use [email protected]
What that does:
d2 = "0.7.1" under [tools] in the repo-root mise.tomlmise.toml if the repo has none; preserves every existing pin if it doesRules this skill follows:
mise use mutates a tracked project file, so it
sits behind the same confirmation gate as the .d2 output and never runs under --dry-run.mise.toml already lists d2 at any version, leave it
alone and use it — the project's choice wins over this skill's default.--no-mise for repos that manage tooling another way (Nix, Homebrew,
devcontainer, distro packages).mise use never blocks the .d2 source from being written.Once pinned, collaborators and CI get d2 from:
mise install # provision every pinned tool
mise exec -- d2 --version
CI needs no extra step when the pipeline already uses jdx/mise-action (GitHub/Forgejo) or
the jdx/mise image (GitLab) — the same pattern the go-specialist CI generators emit.
/gen-diagram: none required./gen-diagram:
/gen-claude will pick up the new docs/diagrams/ directory in subsequent runs./gen-diagram proactively pulls in the diagram-architect agent for ongoing edits to .d2 files in the repo.# Architecture from a description, render SVG if d2 is installed
/gen-diagram simple web app with frontend, API, postgres, redis
# Sequence diagram for an auth flow, custom output path
/gen-diagram --type=sequence --output=docs/diagrams/login.d2 login flow with JWT
# ER diagram from existing schema description
/gen-diagram --type=er users have many orders, orders have many line items
# Auto-discover from the repo (no description)
/gen-diagram
# Preview only, don't write
/gen-diagram --dry-run kafka-fronted ingestion service
# Skip rendering even when d2 is installed
/gen-diagram --no-render deployment topology on AWS
d2 is missing and cannot be provisioned. mise use [email protected] fixes that permanently for the repo; --no-mise opts out.description is empty, the Explore subagent summarizes what it can find — clean up the resulting diagram by hand for unusual layouts.d2 --target=png manually for raster output.-context.d2, -containers.d2) rather than fighting the layout.If mise use [email protected] fails:
mise trust in the repo root, then retry.mise ls-remote d2.brew install d2, or re-run with
--no-mise to skip the pin entirely. The .d2 source is written either way.If d2 --version errors or d2 rendering fails:
d2 --version (require ≥ 0.6), or mise exec -- d2 --version when pinned.d2 --layout=elk <file>.d2.If an icon URL 404s:
%20)..d2 file or remove the icon: attribute and the surrounding shape: image.If the diagram is too dense:
--type=c4 to layer it.diagram-architect (auto-activates on .d2 files)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
18 skills in this plugin
/auto-mrPush current branch, create MR/PR on GitHub, GitLab, or Forgejo, wait for CI pipeline, merge, and clean up branch using auto-mr CLInpx claudepluginhub sgaunet/claude-plugins --plugin software-engineeringOther plugins' skills for the same job