/d2:d2-architectfrom d2
Scans a codebase and auto-generates relevant D2 diagrams (ER, sequence, architecture, class) based on project structure. Useful for documenting existing codebases.
Ships in d2. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
User request: "$ARGUMENTS"
Analyze a codebase or project path and generate a relevant suite of D2 diagrams (typically 3-4 types based on what's found).
/d2-diagram generates one diagram from a text description/d2-architect generates multiple diagrams from actual code/files at a given pathPLUGIN_DIR=$(find "$HOME/.claude/plugins/cache" -type d -name "d2" -path "*/skills/d2" 2>/dev/null | head -1)
[ -z "$PLUGIN_DIR" ] && PLUGIN_DIR=$(find "$HOME" -maxdepth 8 -type d -name "d2" -path "*/skills/d2" 2>/dev/null | head -1)
If still empty, stop: "Plugin not found. Is it installed?"
bash "$PLUGIN_DIR/scripts/ensure-deps.sh"
If .claude/d2.json does not exist, display a one-time nudge before continuing:
First time using the d2 plugin? Run
/d2-configto pick a theme and output settings. Using defaults for now (theme 0 / Neutral,./diagrams).
If .claude/d2.json exists, read output_directory, theme_id, layout, sketch, auto_validate, auto_render.
Resolve output path:
output_directory is "same" AND an input path is known: OUTPUT_DIR={input_directory}OUTPUT_DIR={output_directory or ./diagrams}find {path} \( -name "*.py" -o -name "*.ts" -o -name "*.js" -o -name "*.rb" -o -name "*.go" \) | grep -v node_modules | grep -v dist | head -50
find {path} \( -name "*.sql" -o -name "*.prisma" -o -name "*schema*" \) | grep -v node_modules | head -20
find {path} \( -name "routes*" -o -name "router*" -o -name "urls*" -o -name "endpoints*" \) | grep -v node_modules | head -20
find {path} \( -name "docker-compose*" -o -name "Dockerfile*" -o -name "k8s" -o -name "*.yaml" \) | grep -v node_modules | head -10
Read key files to understand the domain (models, routes, services, main entry point).
Based on what's found:
| Found | Generates |
|---|---|
Database models / ORM / schema files / .sql / .prisma | ER diagram |
| API routes / controllers / endpoints | Sequence diagram (request flow) |
Service classes / modules / services/ directory | Architecture diagram |
Class files with inheritance (extends, implements) | Class diagram |
| Config / deployment files (docker, k8s, cloud) | Architecture diagram (deployment view) |
Select 2-4 most relevant types. Do not generate all 4 unless the codebase clearly warrants it.
Read the global policies from $PLUGIN_DIR/SKILL.md. For each diagram to generate:
If a diagram would exceed the visual budget, split into overview + detail.
For each selected type, load the specialist:
cat "$PLUGIN_DIR/specialists/d2-{type}.md"
Follow the specialist's compositional patterns using the actual code found in Step 5. The structural decisions from Step 6b (abstraction, grouping, direction, engine) govern the output. After generating, run the repair pass from $PLUGIN_DIR/SKILL.md before validating.
For each generated diagram:
d2 validate {output_file}
Fix any errors using $PLUGIN_DIR/references/guides/troubleshooting.md.
auto_render=true or user requests)d2 {file} {OUTPUT_DIR}/{basename}.svg
Analyzed: {path}
Generated {N} diagrams:
✅ {OUTPUT_DIR}/er-{name}-{timestamp}.d2 (ER — 5 tables, 4 relationships)
✅ {OUTPUT_DIR}/sequence-{name}-{timestamp}.d2 (Sequence — 4 actors, 8 messages)
✅ {OUTPUT_DIR}/architecture-{name}-{timestamp}.d2 (Architecture — 6 components)
Validation: all passed
If 3 or more diagrams were generated:
Generated {N} diagrams — want me to assemble them into a system design document?
I'll embed each diagram in the relevant section.
If fewer than 3 diagrams: skip silently.
-not -path "*/node_modules/*" and -not -path "*/dist/*".What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub diegomarino/claude-toolshed --plugin d27 skills in this plugin
/d2-diagramOther plugins' skills for the same job