Draw.io Diagram Generator
Generate professional diagrams as valid draw.io XML. Every request flows through four phases — Understand, Propose, Generate, Validate — before the file is written. Body content is intentionally lean to respect the agent's context budget; depth lives in references/.
Part of the diagram-generator suite. For a hand-drawn / sketch look, use excalidraw-generator instead; the diagram-generator umbrella routes between the two.
Environment Check
If the Agent tool is available, use subagents per the Subagent Architecture section. This provides fresh-context validation loops and avoids single-pass context overflow on large diagrams.
If the Agent tool is unavailable (e.g., Claude.ai), execute each phase inline:
- Phase 1 & 2: Gather requirements directly in conversation
- Phase 3: Generate the XML in this context
- Phase 4: Self-review against the 9 checks (less rigorous, but functional)
Core Workflow
Phase 1: Understand
Confirm what to draw before generating anything.
- Clear request — restate briefly and propose a visualization type:
"I'll create a C4 container diagram with a layered layout: API gateway on top, services in the middle, databases at the bottom. Sound good?"
- Ambiguous input — ask targeted questions: main entities, relationships, flow direction, multi-page need.
- Code, schema, or config provided — extract structure:
- Code → class/dependency/architecture
- SQL/schema → ER diagram
- JSON/YAML config → architecture, deployment
- Steps/process → flowchart, sequence
Phase 2: Propose
Present a numbered plan and wait for confirmation. For straightforward requests, use sensible defaults and proceed.
- Diagram type (offer alternatives if multiple fit)
- Key elements — list nodes/shapes
- Layout — e.g.
(A) Top-to-bottom, (B) Left-to-right, (C) Layered
- Style —
(1) Professional, (2) C4 official, (3) Monochrome
- Multi-page? — for C4, offer one page per level
- Estimated complexity — small (<10), medium (10–30), large (30+)
Phase 3: Generate
Generate the draw.io XML and write a .drawio file (raw XML).
Read references/xml-authoring.md for shape/edge/container syntax, sizing rules, multi-page structure, and file naming. Read references/drawio-format.md for the full XML schema and color palettes.
Critical rules every shape must follow:
- Always include
html=1;whiteSpace=wrap; in the style string
- Use descriptive kebab-case IDs (
node-api-gateway)
- Provide
<mxGeometry x y width height as="geometry"/> sized to fit the label
- Edges need
source, target, and <mxGeometry relative="1" as="geometry"/>
Phase 4: Validate
Run all 9 checks before writing the file. Fix and re-check until every check passes. See references/validation-checks.md for the full check list, fix patterns, and the validation-report template.
Summary of checks:
- Valid XML structure (mxfile → diagram → mxGraphModel → root, system cells present)
- All shapes have required attributes (
html=1;whiteSpace=wrap; mandatory)
- Unique IDs per page
- Edge
source/target reference existing vertices
- Every edge has
<mxGeometry relative="1" as="geometry"/>
- No overlapping shapes (>10px)
- Container hierarchy valid; child coordinates relative to container
- Semantic completeness — every requested entity/relationship is represented
- Text readable:
fontSize ≥ 11, shapes sized to fit value
Expected Output
A valid .drawio file written to disk (raw XML). Minimal example:
<mxfile>
<diagram name="Flow" id="page-1">
<mxGraphModel dx="1422" dy="762" grid="1" gridSize="10" page="1" pageWidth="1169" pageHeight="827">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="node-start" value="Start" style="ellipse;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;" vertex="1" parent="1">
<mxGeometry x="100" y="80" width="120" height="50" as="geometry"/>
</mxCell>
<mxCell id="node-process" value="Process Request" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
<mxGeometry x="100" y="200" width="160" height="60" as="geometry"/>
</mxCell>
<mxCell id="edge-start-process" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;html=1;" edge="1" parent="1" source="node-start" target="node-process">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
After file write, the skill reports:
Validation: 9/9 checks passed
- Pages: 1
- Elements: 2 shapes, 1 edge
- Containers: 0
- All IDs unique, all edges bound, no overlaps
File written: flow.drawio
Acceptance Criteria
Verify these for every run:
Edge Cases
- Empty or vague input ("make a diagram"): ask targeted clarifying questions before generating — never produce a placeholder.
- Very large diagram (>50 elements): warn that one page will be crowded; offer multi-page or hierarchical C4.
- Unsupported diagram type (e.g., Gantt with real date-axis ticks): explain the limitation and propose the closest supported alternative (e.g., swimlane timeline).
- Existing
.drawio file extension: read it first, preserve existing cell IDs, append new elements — never regenerate from scratch.
- Conflicting layout constraints: surface the conflict and ask which takes priority.
- Cross-page ID collision: each
<diagram> has its own ID namespace; system cells id="0" and id="1" must be present on every page independently.
- Text exceeds shape capacity: auto-grow shape height ~20px per extra line rather than letting text overflow silently.
Step Completion Reports
After completing each major step, output a status report:
◆ [Step Name] ([step N of M] — [context])
··································································
[Check 1]: √ pass
[Check 2]: √ pass (note if relevant)
[Check 3]: × fail — [reason]
[Criteria]: √ N/M met
____________________________
Result: PASS | FAIL | PARTIAL
Per-phase checks:
- Understand —
Requirements gathered, Scope confirmed
- Propose —
Proposal approved, User confirmed
- Generate —
XML valid, Layout correct, Requirements covered
- Validate —
XML valid, Layout correct, Quality checks 9/9
Style Guidelines
- Professional (default) — Helvetica, fontSize 14 for labels / 11 for descriptions, draw.io Professional palette,
orthogonalEdgeStyle with rounded=1.
- C4 — official C4 colors, white text on dark fills, bold titles, dashed boundaries.
- Color assignment — flowcharts: blue=process, green=start/end, orange=decision, red=error. Architecture: color by layer (frontend/backend/data/external). C4: depth-by-blue.
Full palettes and tokens: references/drawio-format.md.
Supported Diagram Types
| Category |
Types |
| Flow & Process |
Flowchart, sequence, swimlane, state machine, activity, BPMN |
| Architecture |
System, microservices, network, cloud, C4, deployment |
| Data & Relationships |
ER, class, dependency graph, mind map, tree, org chart |
| Planning |
Gantt, roadmap, timeline, Kanban |
| Comparison |
Quadrant, SWOT, comparison matrix, Venn |
| UX/Design |
Wireframe, user flow, sitemap |
| Custom |
Any freeform diagram |
Iteration
When iterating on an existing diagram, read the file, modify the XML in place, and rewrite. Preserve element IDs that haven't changed. Common requests: add/remove elements, change layout, adjust style, add a page.
Subagent Architecture
When a diagram exceeds 30 elements, spawn a review loop to avoid single-context degradation. Use the complexity estimate from Phase 2 step 6: large (30+) spawns the subagent review loop below; small/medium proceed inline.
Phase 3 — agents/xml-generator.md
- Receives: diagram type, elements, edges, style, complexity
- Outputs: complete draw.io XML with all required attributes
- Constraint: shapes sized to fit text labels
Phase 4 — review loop (max 3 cycles)
- Validate — spawn
agents/xml-validator.md. Outputs PASS/FAIL for all 9 checks.
- Fix — if NEEDS_FIX, spawn
agents/xml-fixer.md with the report. Patches XML; never regenerates. Skips semantic/structure issues (those require generator revision).
- Re-validate with cycle++ until PASS or cycle == 3.
- Return to main agent for file write or user review.
Fallback — without the Agent tool, validate inline using references/validation-checks.md. Less rigorous but functional.
1---2name: drawio-generator3description: Generate professional diagrams as valid draw.io XML — flowcharts, architecture, C4 models, ER diagrams, sequence diagrams, mind maps, and swimlanes. Don't use for Excalidraw or Mermaid output, hand-drawn sketch styles, or slide decks/presentations.4license: MIT5---67# Draw.io Diagram Generator89Generate professional diagrams as valid draw.io XML. Every request flows through four phases — **Understand**, **Propose**, **Generate**, **Validate** — before the file is written. Body content is intentionally lean to respect the agent's context budget; depth lives in `references/`.1011> Part of the **diagram-generator** suite. For a hand-drawn / sketch look, use `excalidraw-generator` instead; the `diagram-generator` umbrella routes between the two.1213## Environment Check1415If the Agent tool is available, use subagents per the **Subagent Architecture** section. This provides fresh-context validation loops and avoids single-pass context overflow on large diagrams.1617If the Agent tool is unavailable (e.g., Claude.ai), execute each phase inline:18- Phase 1 & 2: Gather requirements directly in conversation19- Phase 3: Generate the XML in this context20- Phase 4: Self-review against the 9 checks (less rigorous, but functional)2122## Core Workflow2324### Phase 1: Understand2526Confirm what to draw before generating anything.2728- **Clear request** — restate briefly and propose a visualization type:29 > "I'll create a C4 container diagram with a layered layout: API gateway on top, services in the middle, databases at the bottom. Sound good?"30- **Ambiguous input** — ask targeted questions: main entities, relationships, flow direction, multi-page need.31- **Code, schema, or config provided** — extract structure:32 - Code → class/dependency/architecture33 - SQL/schema → ER diagram34 - JSON/YAML config → architecture, deployment35 - Steps/process → flowchart, sequence3637### Phase 2: Propose3839Present a numbered plan and wait for confirmation. For straightforward requests, use sensible defaults and proceed.40411. **Diagram type** (offer alternatives if multiple fit)422. **Key elements** — list nodes/shapes433. **Layout** — e.g. `(A) Top-to-bottom`, `(B) Left-to-right`, `(C) Layered`444. **Style** — `(1) Professional`, `(2) C4 official`, `(3) Monochrome`455. **Multi-page?** — for C4, offer one page per level466. **Estimated complexity** — small (<10), medium (10–30), large (30+)4748### Phase 3: Generate4950Generate the draw.io XML and write a `.drawio` file (raw XML).5152Read `references/xml-authoring.md` for shape/edge/container syntax, sizing rules, multi-page structure, and file naming. Read `references/drawio-format.md` for the full XML schema and color palettes.5354Critical rules every shape must follow:55- Always include `html=1;whiteSpace=wrap;` in the style string56- Use descriptive kebab-case IDs (`node-api-gateway`)57- Provide `<mxGeometry x y width height as="geometry"/>` sized to fit the label58- Edges need `source`, `target`, and `<mxGeometry relative="1" as="geometry"/>`5960### Phase 4: Validate6162Run all 9 checks before writing the file. Fix and re-check until every check passes. See `references/validation-checks.md` for the full check list, fix patterns, and the validation-report template.6364Summary of checks:65661. Valid XML structure (mxfile → diagram → mxGraphModel → root, system cells present)672. All shapes have required attributes (`html=1;whiteSpace=wrap;` mandatory)683. Unique IDs per page694. Edge `source`/`target` reference existing vertices705. Every edge has `<mxGeometry relative="1" as="geometry"/>`716. No overlapping shapes (>10px)727. Container hierarchy valid; child coordinates relative to container738. Semantic completeness — every requested entity/relationship is represented749. Text readable: `fontSize` ≥ 11, shapes sized to fit `value`7576---7778## Expected Output7980A valid `.drawio` file written to disk (raw XML). Minimal example:8182```xml83<mxfile>84 <diagram name="Flow" id="page-1">85 <mxGraphModel dx="1422" dy="762" grid="1" gridSize="10" page="1" pageWidth="1169" pageHeight="827">86 <root>87 <mxCell id="0"/>88 <mxCell id="1" parent="0"/>89 <mxCell id="node-start" value="Start" style="ellipse;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;" vertex="1" parent="1">90 <mxGeometry x="100" y="80" width="120" height="50" as="geometry"/>91 </mxCell>92 <mxCell id="node-process" value="Process Request" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">93 <mxGeometry x="100" y="200" width="160" height="60" as="geometry"/>94 </mxCell>95 <mxCell id="edge-start-process" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;html=1;" edge="1" parent="1" source="node-start" target="node-process">96 <mxGeometry relative="1" as="geometry"/>97 </mxCell>98 </root>99 </mxGraphModel>100 </diagram>101</mxfile>102```103104After file write, the skill reports:105```106Validation: 9/9 checks passed107- Pages: 1108- Elements: 2 shapes, 1 edge109- Containers: 0110- All IDs unique, all edges bound, no overlaps111File written: flow.drawio112```113114## Acceptance Criteria115116Verify these for every run:117118- [ ] A `.drawio` file is written to disk with valid XML (parses without error).119- [ ] Every page contains system cells `id="0"` and `id="1" parent="0"`.120- [ ] Every shape style includes `html=1;whiteSpace=wrap;` and every edge has `<mxGeometry relative="1" as="geometry"/>`.121- [ ] Edge `source`/`target` attributes resolve to existing vertex IDs in the same page.122- [ ] No two vertex bounding boxes overlap by >10px (containers excluded).123- [ ] All `fontSize` values ≥ 11; shapes are sized so labels fit without overflow.124- [ ] The validation report prints `9/9 checks passed`. Given the user's request, then every entity and relationship described is represented in the output.125126## Edge Cases127128- **Empty or vague input** ("make a diagram"): ask targeted clarifying questions before generating — never produce a placeholder.129- **Very large diagram (>50 elements)**: warn that one page will be crowded; offer multi-page or hierarchical C4.130- **Unsupported diagram type** (e.g., Gantt with real date-axis ticks): explain the limitation and propose the closest supported alternative (e.g., swimlane timeline).131- **Existing `.drawio` file extension**: read it first, preserve existing cell IDs, append new elements — never regenerate from scratch.132- **Conflicting layout constraints**: surface the conflict and ask which takes priority.133- **Cross-page ID collision**: each `<diagram>` has its own ID namespace; system cells `id="0"` and `id="1"` must be present on every page independently.134- **Text exceeds shape capacity**: auto-grow shape height ~20px per extra line rather than letting text overflow silently.135136---137138## Step Completion Reports139140After completing each major step, output a status report:141142```143◆ [Step Name] ([step N of M] — [context])144··································································145 [Check 1]: √ pass146 [Check 2]: √ pass (note if relevant)147 [Check 3]: × fail — [reason]148 [Criteria]: √ N/M met149 ____________________________150 Result: PASS | FAIL | PARTIAL151```152153Per-phase checks:154- **Understand** — `Requirements gathered`, `Scope confirmed`155- **Propose** — `Proposal approved`, `User confirmed`156- **Generate** — `XML valid`, `Layout correct`, `Requirements covered`157- **Validate** — `XML valid`, `Layout correct`, `Quality checks 9/9`158159## Style Guidelines160161- **Professional (default)** — Helvetica, fontSize 14 for labels / 11 for descriptions, draw.io Professional palette, `orthogonalEdgeStyle` with `rounded=1`.162- **C4** — official C4 colors, white text on dark fills, bold titles, dashed boundaries.163- **Color assignment** — flowcharts: blue=process, green=start/end, orange=decision, red=error. Architecture: color by layer (frontend/backend/data/external). C4: depth-by-blue.164165Full palettes and tokens: `references/drawio-format.md`.166167---168169## Supported Diagram Types170171| Category | Types |172|---|---|173| Flow & Process | Flowchart, sequence, swimlane, state machine, activity, BPMN |174| Architecture | System, microservices, network, cloud, C4, deployment |175| Data & Relationships | ER, class, dependency graph, mind map, tree, org chart |176| Planning | Gantt, roadmap, timeline, Kanban |177| Comparison | Quadrant, SWOT, comparison matrix, Venn |178| UX/Design | Wireframe, user flow, sitemap |179| Custom | Any freeform diagram |180181## Iteration182183When iterating on an existing diagram, read the file, modify the XML in place, and rewrite. Preserve element IDs that haven't changed. Common requests: add/remove elements, change layout, adjust style, add a page.184185---186187## Subagent Architecture188189When a diagram exceeds 30 elements, spawn a review loop to avoid single-context degradation. Use the complexity estimate from Phase 2 step 6: large (30+) spawns the subagent review loop below; small/medium proceed inline.190191**Phase 3 — `agents/xml-generator.md`**192- Receives: diagram type, elements, edges, style, complexity193- Outputs: complete draw.io XML with all required attributes194- Constraint: shapes sized to fit text labels195196**Phase 4 — review loop (max 3 cycles)**1971981. **Validate** — spawn `agents/xml-validator.md`. Outputs PASS/FAIL for all 9 checks.1992. **Fix** — if NEEDS_FIX, spawn `agents/xml-fixer.md` with the report. Patches XML; never regenerates. Skips semantic/structure issues (those require generator revision).2003. **Re-validate** with cycle++ until PASS or cycle == 3.2014. Return to main agent for file write or user review.202203**Fallback** — without the Agent tool, validate inline using `references/validation-checks.md`. Less rigorous but functional.