code-to-diagram
Code to Diagram
Generate production-quality diagrams from source code via Mermaid.js, rendered to SVG/PNG with mmdc.
Environment
Executor required: This skill needs the diagram executor (Chromium + Node.js + mmdc pre-installed).
If mmdc is not available, install first:
npm install -g @mermaid-js/mermaid-cli
Puppeteer config for headless environments — create at /tmp/puppeteer-config.json if missing:
{"args": ["--no-sandbox", "--disable-setuid-sandbox"]}
Workflow
- Analyze — Read the codebase to understand structure (
glob,grep,read) - Plan — Decide diagram type(s) based on user request and code patterns
- Generate — Write
.mmdfile with Mermaid syntax - Render — Run
mmdcto produce SVG and PNG - Verify — Read the output image and check correctness
Diagram Type Selection
| User Intent | Diagram Type | Mermaid Keyword |
|---|---|---|
| System overview, module layout | Architecture | graph TD + subgraph |
| Database tables, ORM models | ER Diagram | erDiagram |
| API flow, request lifecycle | Sequence Diagram | sequenceDiagram |
| Inheritance, interfaces | Class Diagram | classDiagram |
| Business logic, conditionals | Flowchart | flowchart TD |
| Task states, lifecycle | State Diagram | stateDiagram-v2 |
| Import/dependency tree | Dependency Graph | graph LR |
| Timeline, project phases | Gantt Chart | gantt |
Analysis Strategy
Do NOT read every file. Use progressive analysis:
Step 1 — Directory scan:
glob("**/*.py") or glob("**/*.ts") to understand module structure.
Step 2 — Entry points:
- Python:
main.py,app.py,__init__.py,pyproject.toml - Node.js:
package.json,index.ts,app.ts - Java:
pom.xml,Application.java
Step 3 — Targeted reads by diagram type:
- ER → ORM models (
models.py,schema.prisma,*.entity.ts) - Architecture → Router registrations, dependency injection, config
- Sequence → Specific endpoint handler + service call chain
- Class → Class definitions via
grep("class ")
Step 4 — GitHub repos:
git clone --depth 1 <url> /tmp/repo-name
Then apply the same progressive scan.
Rendering
# SVG (transparent background, good for docs)
mmdc -i diagram.mmd -o diagram.svg -b transparent -p /tmp/puppeteer-config.json
# PNG (white background, 2x scale for sharpness)
mmdc -i diagram.mmd -o diagram.png -b white -s 2 -p /tmp/puppeteer-config.json
Always generate both formats. Use -s 2 for PNG (sharp at any zoom level).
Mermaid Syntax Reference
For detailed patterns and examples per diagram type, see references/mermaid-patterns.md.
Key rules:
- Short IDs, descriptive labels:
DB[("PostgreSQL 16")] - Use
subgraphfor logical grouping in architecture diagrams - Limit ER diagrams to ~10 entities — split by domain if larger
participantaliases in sequence diagrams for short names- Quote labels with special chars:
A["Node (v1)"] - Max ~20 nodes per diagram — split into multiple if larger
Output Conventions
- Write
.mmdsource + rendered files to workspace - Descriptive names:
architecture.mmd,er-diagram.png,api-sequence.svg - Multiple diagrams → create
diagrams/folder with index
Quality Checklist
- All entities/modules from the code are represented
- Relationships and data flow directions are correct
- Labels readable, not truncated or overlapping
- No Mermaid syntax errors
- Output image visually verified
More from dp-archive/archive
skill-finder
Helps users discover and install agent skills from the open skills ecosystem (skills.sh). Use when users ask 'how do I do X', 'find a skill for X', 'is there a skill that can...', want to search for tools/templates/workflows, or express interest in extending agent capabilities.
12brand-identity
>
12canvas-design
Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.
8skill-evolver
Analyze skill execution traces to identify issues and automatically evolve/improve skills. Use when users provide trace files (JSON) from skill runs and want to improve skill performance based on real execution data. Triggers on requests like "analyze traces", "evolve skill based on traces", "improve skill from execution history", "find issues in skill traces", or when working with skill trace/log files.
8humanizer
|
8skills-planner
Plan which skills are needed to fulfill user requirements. Use when the user wants to design an agent workflow, plan skill composition, or determine what skills are needed for a task. Input includes user requirements and existing skills list. Output includes recommended existing skills, new skills to create, and a system prompt for the composed agent.
7