Diagram Generator
ACTION REQUIRED (execute immediately after reading)
NOW: Confirm whether the current task falls within this skill's scope
NOW: Read ../tool-index.md, validate tool availability and actual paths
NEXT: If tools are missing, invoke bootstrap — do not guess paths
ACT: Enter step one of the "Workflow" and execute; do not stop at a confirmation state
Purpose
Create clear, editable diagrams from messy or structured inputs. Prefer text-based diagram source first so the result can be reviewed, versioned, and refined. Render to files only when the user asks for an image/PDF or when a downloadable artifact would materially help.
Default workflow
- Identify the user's intent, audience, and source material.
- Choose the diagram family and language using the decision table below.
- Normalize entities, relationships, labels, states, branches, and time/order information before writing diagram code.
- Generate concise, readable diagram source.
- Validate the syntax mentally and, when creating files, run
scripts/render_diagram.py.
- Return the diagram source plus a short note about assumptions. When files are generated, include links to the output files.
Do not over-ask for clarification. If the request is underspecified, make reasonable assumptions and label them briefly.
Diagram language decision table
Use Mermaid unless another language is clearly better.
| User wants |
Prefer |
Why |
| process flow, decision tree, simple swimlane |
Mermaid flowchart |
readable and easy to paste into Markdown |
| sequence of system/user interactions |
Mermaid sequenceDiagram or PlantUML sequence |
Mermaid for docs; PlantUML for UML formality |
| lifecycle, state machine, transitions |
Mermaid stateDiagram-v2 or PlantUML state |
compact transition syntax |
| database schema, entities, relationships |
Mermaid erDiagram |
portable ER notation |
| class/interface/object model |
Mermaid classDiagram or PlantUML class |
Mermaid for docs; PlantUML for detailed UML |
| project schedule |
Mermaid gantt |
concise timeline syntax |
| hierarchy, ideas, notes |
Mermaid mindmap |
good default for idea maps |
| customer/product journey |
Mermaid journey |
built-in journey notation |
| git history |
Mermaid gitGraph |
built-in git notation |
| dependency graph, package graph, large network |
Graphviz DOT |
better layout engines for dense graphs |
| architecture with layers, clusters, boundaries |
Mermaid flowchart with subgraphs, Graphviz clusters, or PlantUML C4-style |
choose based on requested fidelity |
| weighted flow/sankey-like relationship |
Mermaid sankey-beta when supported, otherwise SVG or Graphviz |
Mermaid support may vary by renderer |
| custom visual where source languages fit poorly |
SVG |
precise control over layout and styling |
Output policy
- Always provide editable source unless the user explicitly asks only for an image.
- Default to a single best diagram. Offer alternatives only when genuinely useful.
- Prefer stable, simple syntax over fancy features that may not render in older Mermaid/PlantUML versions.
- Use short labels. Split long text into notes outside the diagram when needed.
- Avoid ambiguous node IDs. Use ASCII IDs and human-readable labels.
- Preserve user terminology, but standardize capitalization within a diagram.
- For technical diagrams, include boundaries such as client, service, database, queue, external API, and operator/user when they are implied.
- For business-process diagrams, distinguish happy path, decision points, failures, retries, and manual steps when present.
- For diagrams created from uncertain text, include an
Assumptions section after the code.
Mermaid generation rules
Consult references/diagram-patterns.md for compact templates.
General Mermaid rules:
- Start with the correct diagram directive, for example
flowchart TD, sequenceDiagram, erDiagram, gantt, mindmap, or journey.
- For flowcharts, use
flowchart TD unless the user asks for left-to-right; use flowchart LR for architecture and pipelines.
- Use subgraphs for swimlanes or architecture layers. Name subgraphs with readable labels.
- Keep node IDs stable and ASCII-only, for example
ingest_service[Ingest Service].
- Quote labels that contain punctuation likely to confuse the parser.
- Use decision diamonds for branching:
decision{Condition?}.
- Use consistent edge labels:
-- yes -->, -- no -->, -. async .->, or == critical ==> only when meaningful.
- In sequence diagrams, declare participants before messages. Use
actor for humans and participant for systems.
- Use
alt/else/end, opt/end, loop/end, and par/and/end blocks for conditional, optional, repeated, and parallel flows.
Graphviz DOT generation rules
Use Graphviz for large, dense, or layout-sensitive relationship diagrams.
- Prefer
digraph G for directed relationships and graph G for undirected networks.
- Set layout-friendly graph attributes at the top:
rankdir=LR, nodesep, ranksep, and splines=true when helpful.
- Use
subgraph cluster_name for boundaries and subsystems.
- Use plain labels and restrained styling.
- Use edge labels only when they add meaning.
- For many nodes, group by domain with clusters and avoid crossing-heavy all-to-all edges.
PlantUML generation rules
Use PlantUML when the user asks for UML or needs formal UML notation.
- Wrap diagrams with
@startuml and @enduml.
- Use
actor, participant, database, queue, collections, or component stereotypes when useful.
- Use
package, rectangle, or node for architecture boundaries.
- For class diagrams, include only important fields/methods unless the user asks for exhaustive detail.
- For activity diagrams, use clear start/end markers and explicit branch labels.
SVG generation rules
Use SVG only when text diagram languages cannot express the requested visual reliably.
- Keep SVG simple, accessible, and editable.
- Include
<title> and meaningful text labels.
- Prefer rectangles, lines, arrows, and groups over complex paths.
- Do not embed external fonts or remote images.
Rendering files
When the user asks for PNG/SVG/PDF, create a source file and run:
python "<SKILL_ROOT>/diagram-generator/scripts/render_diagram.py" input.mmd --format svg --out output.svg
python "<SKILL_ROOT>/diagram-generator/scripts/render_diagram.py" input.dot --format png --out output.png
python "<SKILL_ROOT>/diagram-generator/scripts/render_diagram.py" input.puml --format svg --out output.svg
<SKILL_ROOT> is the actual path of this package's skills/ directory; the AI should auto-detect it.
The renderer is intentionally dependency-tolerant. It tries common local tools and reports actionable installation hints if a renderer is unavailable. Do not claim an image was rendered unless the script completed successfully and the output file exists.
Validation checklist
Before finalizing:
- The diagram type matches the user's task.
- The source is syntactically plausible for the chosen language.
- Labels are short enough to fit.
- Edges and message order reflect the input accurately.
- Assumptions are called out when the input was incomplete.
- For generated files, the output exists and opens or has nonzero size.
Common response template
Use this structure for most diagram answers:
Below is the editable [language] version:
```[language]
[source]
Assumptions:
Rendered file: [link] [only if generated]
For English user requests, respond in English. For Chinese user requests, respond in Chinese unless they ask otherwise.
---
## On-Demand Bootstrap
### Automation capability boundary
| Tool | Auto-installable | Installation | Notes |
|------|-----------|---------|------|
| Mermaid CLI (mmdc) | ✓ | npm install -g @mermaid-js/mermaid-cli | Renders Mermaid to PNG/SVG |
| Graphviz (dot) | ✗ | manual install | https://graphviz.org/download/ |
| PlantUML | ✗ | requires Java + plantuml.jar | https://plantuml.com/download |
| Python (render script) | ✓ | already in bootstrap | dependency of `scripts/render_diagram.py` |
### Notes
This skill mainly outputs text-format diagram source (Mermaid/DOT/PlantUML) and does not necessarily need local rendering tools. Renderers are only needed when the user explicitly asks for PNG/SVG/PDF file generation.
If a renderer is unavailable, `scripts/render_diagram.py` outputs installation hints instead of raising an error.
---
## Routing Context
**Upstream entry points**: `skills/SKILL.md` (master control), `routing.md`
**Trigger condition**: the user says "draw a diagram", "flowchart", "architecture diagram", "attack path diagram", "sequence diagram", "Mermaid", "Graphviz", "PlantUML"
**Downstream exits**:
- Generated diagrams can be embedded into `docs-generator/` reports
- Attack path diagrams can accompany `pentest-tools/` penetration reports
**Peer related modules**: `docs-generator/` (embed diagrams into reports)
## Task Completion Self-Check (MUST pass before claiming completion)
- [ ] Did I execute every step of the workflow (rather than just reading it)?
- [ ] Did I use real tool paths based on `tool-index`?
- [ ] Did I produce reproducible evidence (commands/scripts/screenshots/reports)?
- [ ] Did I complete and write back the Checklist items required by RULES?
1---2name: router-reverse-skill-router-diagram-generator3description: generate, refine, validate, and render diagrams from natural language, notes, code snippets, schemas, tables, or existing diagram source. use for flowcharts, swimlanes, sequence diagrams, state diagrams, er diagrams, class diagrams, architecture/c4-style diagrams, dependency graphs, gantt charts, mind maps, user journeys, sankey-style flows, org charts, network graphs, and other visual models. supports mermaid by default, graphviz dot for complex graph layout, plantuml for uml-heavy engineering diagrams, and svg output when direct markup is more reliable.4---56# Diagram Generator78## ACTION REQUIRED (execute immediately after reading)9101. `NOW`: Confirm whether the current task falls within this skill's scope112. `NOW`: Read `../tool-index.md`, validate tool availability and actual paths123. `NEXT`: If tools are missing, invoke bootstrap — do not guess paths134. `ACT`: Enter step one of the "Workflow" and execute; do not stop at a confirmation state1415## Purpose1617Create clear, editable diagrams from messy or structured inputs. Prefer text-based diagram source first so the result can be reviewed, versioned, and refined. Render to files only when the user asks for an image/PDF or when a downloadable artifact would materially help.1819## Default workflow20211. Identify the user's intent, audience, and source material.222. Choose the diagram family and language using the decision table below.233. Normalize entities, relationships, labels, states, branches, and time/order information before writing diagram code.244. Generate concise, readable diagram source.255. Validate the syntax mentally and, when creating files, run `scripts/render_diagram.py`.266. Return the diagram source plus a short note about assumptions. When files are generated, include links to the output files.2728Do not over-ask for clarification. If the request is underspecified, make reasonable assumptions and label them briefly.2930## Diagram language decision table3132Use Mermaid unless another language is clearly better.3334| User wants | Prefer | Why |35|---|---|---|36| process flow, decision tree, simple swimlane | Mermaid flowchart | readable and easy to paste into Markdown |37| sequence of system/user interactions | Mermaid sequenceDiagram or PlantUML sequence | Mermaid for docs; PlantUML for UML formality |38| lifecycle, state machine, transitions | Mermaid stateDiagram-v2 or PlantUML state | compact transition syntax |39| database schema, entities, relationships | Mermaid erDiagram | portable ER notation |40| class/interface/object model | Mermaid classDiagram or PlantUML class | Mermaid for docs; PlantUML for detailed UML |41| project schedule | Mermaid gantt | concise timeline syntax |42| hierarchy, ideas, notes | Mermaid mindmap | good default for idea maps |43| customer/product journey | Mermaid journey | built-in journey notation |44| git history | Mermaid gitGraph | built-in git notation |45| dependency graph, package graph, large network | Graphviz DOT | better layout engines for dense graphs |46| architecture with layers, clusters, boundaries | Mermaid flowchart with subgraphs, Graphviz clusters, or PlantUML C4-style | choose based on requested fidelity |47| weighted flow/sankey-like relationship | Mermaid sankey-beta when supported, otherwise SVG or Graphviz | Mermaid support may vary by renderer |48| custom visual where source languages fit poorly | SVG | precise control over layout and styling |4950## Output policy5152- Always provide editable source unless the user explicitly asks only for an image.53- Default to a single best diagram. Offer alternatives only when genuinely useful.54- Prefer stable, simple syntax over fancy features that may not render in older Mermaid/PlantUML versions.55- Use short labels. Split long text into notes outside the diagram when needed.56- Avoid ambiguous node IDs. Use ASCII IDs and human-readable labels.57- Preserve user terminology, but standardize capitalization within a diagram.58- For technical diagrams, include boundaries such as client, service, database, queue, external API, and operator/user when they are implied.59- For business-process diagrams, distinguish happy path, decision points, failures, retries, and manual steps when present.60- For diagrams created from uncertain text, include an `Assumptions` section after the code.6162## Mermaid generation rules6364Consult `references/diagram-patterns.md` for compact templates.6566General Mermaid rules:67- Start with the correct diagram directive, for example `flowchart TD`, `sequenceDiagram`, `erDiagram`, `gantt`, `mindmap`, or `journey`.68- For flowcharts, use `flowchart TD` unless the user asks for left-to-right; use `flowchart LR` for architecture and pipelines.69- Use subgraphs for swimlanes or architecture layers. Name subgraphs with readable labels.70- Keep node IDs stable and ASCII-only, for example `ingest_service[Ingest Service]`.71- Quote labels that contain punctuation likely to confuse the parser.72- Use decision diamonds for branching: `decision{Condition?}`.73- Use consistent edge labels: `-- yes -->`, `-- no -->`, `-. async .->`, or `== critical ==>` only when meaningful.74- In sequence diagrams, declare participants before messages. Use `actor` for humans and `participant` for systems.75- Use `alt/else/end`, `opt/end`, `loop/end`, and `par/and/end` blocks for conditional, optional, repeated, and parallel flows.7677## Graphviz DOT generation rules7879Use Graphviz for large, dense, or layout-sensitive relationship diagrams.8081- Prefer `digraph G` for directed relationships and `graph G` for undirected networks.82- Set layout-friendly graph attributes at the top: `rankdir=LR`, `nodesep`, `ranksep`, and `splines=true` when helpful.83- Use `subgraph cluster_name` for boundaries and subsystems.84- Use plain labels and restrained styling.85- Use edge labels only when they add meaning.86- For many nodes, group by domain with clusters and avoid crossing-heavy all-to-all edges.8788## PlantUML generation rules8990Use PlantUML when the user asks for UML or needs formal UML notation.9192- Wrap diagrams with `@startuml` and `@enduml`.93- Use `actor`, `participant`, `database`, `queue`, `collections`, or `component` stereotypes when useful.94- Use `package`, `rectangle`, or `node` for architecture boundaries.95- For class diagrams, include only important fields/methods unless the user asks for exhaustive detail.96- For activity diagrams, use clear start/end markers and explicit branch labels.9798## SVG generation rules99100Use SVG only when text diagram languages cannot express the requested visual reliably.101102- Keep SVG simple, accessible, and editable.103- Include `<title>` and meaningful text labels.104- Prefer rectangles, lines, arrows, and groups over complex paths.105- Do not embed external fonts or remote images.106107## Rendering files108109When the user asks for PNG/SVG/PDF, create a source file and run:110111```bash112python "<SKILL_ROOT>/diagram-generator/scripts/render_diagram.py" input.mmd --format svg --out output.svg113python "<SKILL_ROOT>/diagram-generator/scripts/render_diagram.py" input.dot --format png --out output.png114python "<SKILL_ROOT>/diagram-generator/scripts/render_diagram.py" input.puml --format svg --out output.svg115```116117> `<SKILL_ROOT>` is the actual path of this package's `skills/` directory; the AI should auto-detect it.118119The renderer is intentionally dependency-tolerant. It tries common local tools and reports actionable installation hints if a renderer is unavailable. Do not claim an image was rendered unless the script completed successfully and the output file exists.120121## Validation checklist122123Before finalizing:124125- The diagram type matches the user's task.126- The source is syntactically plausible for the chosen language.127- Labels are short enough to fit.128- Edges and message order reflect the input accurately.129- Assumptions are called out when the input was incomplete.130- For generated files, the output exists and opens or has nonzero size.131132## Common response template133134Use this structure for most diagram answers:135136```markdown137Below is the editable [language] version:138139```[language]140[source]141```142143Assumptions:144- [only if needed]145146Rendered file: [link] [only if generated]147```148149For English user requests, respond in English. For Chinese user requests, respond in Chinese unless they ask otherwise.150151---152153## On-Demand Bootstrap154155### Automation capability boundary156157| Tool | Auto-installable | Installation | Notes |158|------|-----------|---------|------|159| Mermaid CLI (mmdc) | ✓ | npm install -g @mermaid-js/mermaid-cli | Renders Mermaid to PNG/SVG |160| Graphviz (dot) | ✗ | manual install | https://graphviz.org/download/ |161| PlantUML | ✗ | requires Java + plantuml.jar | https://plantuml.com/download |162| Python (render script) | ✓ | already in bootstrap | dependency of `scripts/render_diagram.py` |163164### Notes165166This skill mainly outputs text-format diagram source (Mermaid/DOT/PlantUML) and does not necessarily need local rendering tools. Renderers are only needed when the user explicitly asks for PNG/SVG/PDF file generation.167168If a renderer is unavailable, `scripts/render_diagram.py` outputs installation hints instead of raising an error.169170---171172## Routing Context173174**Upstream entry points**: `skills/SKILL.md` (master control), `routing.md`175**Trigger condition**: the user says "draw a diagram", "flowchart", "architecture diagram", "attack path diagram", "sequence diagram", "Mermaid", "Graphviz", "PlantUML"176**Downstream exits**:177- Generated diagrams can be embedded into `docs-generator/` reports178- Attack path diagrams can accompany `pentest-tools/` penetration reports179180**Peer related modules**: `docs-generator/` (embed diagrams into reports)181182183## Task Completion Self-Check (MUST pass before claiming completion)184185- [ ] Did I execute every step of the workflow (rather than just reading it)?186- [ ] Did I use real tool paths based on `tool-index`?187- [ ] Did I produce reproducible evidence (commands/scripts/screenshots/reports)?188- [ ] Did I complete and write back the Checklist items required by RULES?