Draw.io Diagram Generation Skill
When to use this skill
- User requests a database diagram, ERD, or entity-relationship diagram
- User requests a class diagram or UML class structure
- User requests a sequence diagram or interaction diagram
- User requests a flowchart or process flow
- User requests an architecture diagram or system overview
- User mentions "draw.io", "diagram", "table", "entity", "class", "sequence", "flow"
⚠️ MANDATORY RULES — READ BEFORE GENERATING ANYTHING
- ALWAYS detect the diagram type first before writing any XML
- NEVER mix styles between diagram types — each type has its own strict XML structure
- ALWAYS assign unique sequential IDs to every
mxCell starting from 0
- NEVER use
\n inside a value attribute — use separate rows/cells instead
- ALWAYS calculate table/class heights correctly using the formulas provided
- ALWAYS validate the XML structure before saving
- ALWAYS export to PNG and include the PNG in the response before asking about other formats — this step is non-negotiable
- NEVER use generic rounded rectangles for database tables or class entities
- ALWAYS apply consistent spacing between diagram elements
- Horizontal spacing between elements: minimum 120px
- Vertical spacing between rows or steps: minimum 100px
- Tables/classes must not overlap
- Relationship lines must not cross through table headers
STEP 0 — Diagram Type Detection
Before generating any XML, identify the diagram type from the user's request:
| User says... |
Diagram type |
| "database", "ERD", "tables", "entities", "foreign key" |
→ TYPE 1: ERD |
| "class", "UML", "inheritance", "attributes", "methods" |
→ TYPE 2: Class Diagram |
| "sequence", "interaction", "lifeline", "actor calls" |
→ TYPE 3: Sequence Diagram |
| "flowchart", "flow", "process", "decision", "steps" |
→ TYPE 4: Flowchart |
| "architecture", "system", "services", "components" |
→ TYPE 5: Architecture |
Diagram Type References
Use the detailed rules/templates in these files based on the detected type.
- ERD / Database:
ERD.md
- UML Class:
CLASS.md
- Sequence:
SEQUENCE.md
- Flowchart:
FLOWCHART.md
- Architecture:
LAYOUT.md
Generation Workflow — ALWAYS follow this exact order
Step 1 — Identify diagram type
Determine TYPE 1–5 from the user's message before writing any XML.
Step 2 — Plan all elements
List every entity/class/participant and all relationships before coding.
Step 3 — Create output folder
mkdir -p ./diagrams
Step 4 — Write and save the XML
Save to ./diagrams/<diagram-name>.drawio
Mandatory pre-save checklist:
Step 5 — Export to PNG
# macOS
/Applications/draw.io.app/Contents/MacOS/draw.io -x -f png --scale 2 -o ./diagrams/<name>.png ./diagrams/<name>.drawio
# Linux / headless
xvfb-run -a drawio -x -f png --scale 2 -o ./diagrams/<name>.png ./diagrams/<name>.drawio
Step 6 — Verify output
ls -lh ./diagrams/<name>.png
Step 7 — Show PNG first (MANDATORY)
Always respond with the PNG image first (embed/attach it in the response).
Step 8 — Ask the user for delivery format (MANDATORY)
After showing the PNG, ALWAYS ask the user which additional format they want:
The diagram is ready! Which format would you like?
1 - PNG image (ready to view)
2 - .drawio file (editable in draw.io)
3 - SVG (scalable vector)
4 - PDF
5 - All of the above
Reply with the number(s) of your choice.
Then based on the response:
- 1 → send the PNG file
- 2 → send the .drawio file
- 3 → export SVG and send it
- 4 → export PDF and send it
- 5 → send all formats
- Multiple numbers (e.g. "1 2") → send all requested formats
Other export formats
# SVG (scalable vector)
/Applications/draw.io.app/Contents/MacOS/draw.io -x -f svg -o ./diagrams/<name>.svg ./diagrams/<name>.drawio
# PDF
/Applications/draw.io.app/Contents/MacOS/draw.io -x -f pdf -o ./diagrams/<name>.pdf ./diagrams/<name>.drawio
# High-res PNG (scale 3)
/Applications/draw.io.app/Contents/MacOS/draw.io -x -f png --scale 3 -o ./diagrams/<name>_hd.png ./diagrams/<name>.drawio
# Transparent background
/Applications/draw.io.app/Contents/MacOS/draw.io -x -f png -t --scale 2 -o ./diagrams/<name>_transparent.png ./diagrams/<name>.drawio
1---2name: drawio3description: Generate professional draw.io diagrams (ERD/database tables, class diagrams, sequence diagrams, flowcharts, architecture diagrams) and export them as PNG. Use when the user requests any kind of diagram, database model, class structure, flow, or system visualization.4---56# Draw.io Diagram Generation Skill78## When to use this skill9- User requests a database diagram, ERD, or entity-relationship diagram10- User requests a class diagram or UML class structure11- User requests a sequence diagram or interaction diagram12- User requests a flowchart or process flow13- User requests an architecture diagram or system overview14- User mentions "draw.io", "diagram", "table", "entity", "class", "sequence", "flow"1516---1718## ⚠️ MANDATORY RULES — READ BEFORE GENERATING ANYTHING19201. **ALWAYS detect the diagram type first** before writing any XML212. **NEVER mix styles** between diagram types — each type has its own strict XML structure223. **ALWAYS assign unique sequential IDs** to every `mxCell` starting from 0234. **NEVER use `\n` inside a `value` attribute** — use separate rows/cells instead245. **ALWAYS calculate table/class heights correctly** using the formulas provided256. **ALWAYS validate the XML structure** before saving267. **ALWAYS export to PNG and include the PNG in the response before asking about other formats** — this step is non-negotiable278. **NEVER use generic rounded rectangles** for database tables or class entities289. **ALWAYS apply consistent spacing between diagram elements**29 - Horizontal spacing between elements: **minimum 120px**30 - Vertical spacing between rows or steps: **minimum 100px**31 - Tables/classes must not overlap32 - Relationship lines must not cross through table headers3334---3536## STEP 0 — Diagram Type Detection3738Before generating any XML, identify the diagram type from the user's request:3940| User says... | Diagram type |41|---|---|42| "database", "ERD", "tables", "entities", "foreign key" | → **TYPE 1: ERD** |43| "class", "UML", "inheritance", "attributes", "methods" | → **TYPE 2: Class Diagram** |44| "sequence", "interaction", "lifeline", "actor calls" | → **TYPE 3: Sequence Diagram** |45| "flowchart", "flow", "process", "decision", "steps" | → **TYPE 4: Flowchart** |46| "architecture", "system", "services", "components" | → **TYPE 5: Architecture** |4748---4950## Diagram Type References51Use the detailed rules/templates in these files based on the detected type.5253- ERD / Database: `ERD.md`54- UML Class: `CLASS.md`55- Sequence: `SEQUENCE.md`56- Flowchart: `FLOWCHART.md`57- Architecture: `LAYOUT.md`585960---6162## Generation Workflow — ALWAYS follow this exact order6364### Step 1 — Identify diagram type65Determine TYPE 1–5 from the user's message before writing any XML.6667### Step 2 — Plan all elements68List every entity/class/participant and all relationships before coding.6970### Step 3 — Create output folder71```bash72mkdir -p ./diagrams73```7475### Step 4 — Write and save the XML76Save to `./diagrams/<diagram-name>.drawio`7778**Mandatory pre-save checklist:**79- [ ] All `mxCell` elements have unique sequential numeric IDs80- [ ] ERD tables use `shape=table` with `shape=tableRow` rows (never generic shapes)81- [ ] Class diagrams use `swimlane` with attribute block, divider line, and method block82- [ ] Sequence diagrams have lifelines, activation boxes, and correct arrow styles83- [ ] ERD relationship arrows connect to **row cell IDs**, not table container IDs84- [ ] Heights calculated correctly: `30 + (columns x 30)` for ERD tables85- [ ] No literal `\n` in value attributes (use `
` for multiline text cells only)86- [ ] XML is well-formed and all tags are closed8788### Step 5 — Export to PNG89```bash90# macOS91/Applications/draw.io.app/Contents/MacOS/draw.io -x -f png --scale 2 -o ./diagrams/<name>.png ./diagrams/<name>.drawio9293# Linux / headless94xvfb-run -a drawio -x -f png --scale 2 -o ./diagrams/<name>.png ./diagrams/<name>.drawio95```9697### Step 6 — Verify output98```bash99ls -lh ./diagrams/<name>.png100```101102### Step 7 — Show PNG first (MANDATORY)103104Always respond with the PNG image first (embed/attach it in the response).105106### Step 8 — Ask the user for delivery format (MANDATORY)107108After showing the PNG, ALWAYS ask the user which additional format they want:109110---111The diagram is ready! Which format would you like?1121131 - PNG image (ready to view)1142 - .drawio file (editable in draw.io)1153 - SVG (scalable vector)1164 - PDF1175 - All of the above118119Reply with the number(s) of your choice.120---121122Then based on the response:123- **1** → send the PNG file124- **2** → send the .drawio file125- **3** → export SVG and send it126- **4** → export PDF and send it127- **5** → send all formats128- **Multiple numbers** (e.g. "1 2") → send all requested formats129130---131132## Other export formats133```bash134# SVG (scalable vector)135/Applications/draw.io.app/Contents/MacOS/draw.io -x -f svg -o ./diagrams/<name>.svg ./diagrams/<name>.drawio136137# PDF138/Applications/draw.io.app/Contents/MacOS/draw.io -x -f pdf -o ./diagrams/<name>.pdf ./diagrams/<name>.drawio139140# High-res PNG (scale 3)141/Applications/draw.io.app/Contents/MacOS/draw.io -x -f png --scale 3 -o ./diagrams/<name>_hd.png ./diagrams/<name>.drawio142143# Transparent background144/Applications/draw.io.app/Contents/MacOS/draw.io -x -f png -t --scale 2 -o ./diagrams/<name>_transparent.png ./diagrams/<name>.drawio145```