1
---
2
name: draw-io-diagram-generator
3
description: Use when creating, editing, or generating draw.io diagram files (.drawio, .drawio.svg, .drawio.png). Covers mxGraph XML authoring, shape libraries, style strings, flowcharts, system architecture, sequence diagrams, ER diagrams, UML class diagrams, network topology, layout strategy, the hediet.vscode-drawio VS Code extension, and the full agent workflow from request to a ready-to-open file.
4
---
5
6
# Draw.io Diagram Generator
7
8
This skill enables you to generate, edit, and validate draw.io (`.drawio`) diagram files with
9
correct mxGraph XML structure. All generated files open immediately in the
10
[Draw.io VS Code extension](https://marketplace.visualstudio.com/items?itemName=hediet.vscode-drawio)
11
(`hediet.vscode-drawio`) without any manual fixes required. You can also open the files in the draw.io web app or desktop app if you prefer.
12
13
---
14
15
## 1. When to Use This Skill
16
17
**Trigger phrases (load this skill when you see these)**
18
19
- "create a diagram", "draw a flowchart", "generate an architecture diagram"
20
- "design a sequence diagram", "make a UML class diagram", "build an ER diagram"
21
- "add a .drawio file", "update the diagram", "visualise the flow"
22
- "document the architecture", "show the data model", "diagram the service interactions"
23
- Any request to produce or modify a `.drawio`, `.drawio.svg`, or `.drawio.png` file
24
25
**Supported diagram types**
26
27
| Diagram Type | Template Available | Description |
28
|---|---|---|
29
| Flowchart | `assets/templates/flowchart.drawio` | Process flows with decisions and branches |
30
| System Architecture | `assets/templates/architecture.drawio` | Multi-tier / layered service architecture |
31
| Sequence Diagram | `assets/templates/sequence.drawio` | Actor lifelines and timed message flows |
32
| ER Diagram | `assets/templates/er-diagram.drawio` | Database tables with relationships |
33
| UML Class Diagram | `assets/templates/uml-class.drawio` | Classes, interfaces, enums, relationships |
34
| Network Topology | (use shape library) | Routers, servers, firewalls, subnets |
35
| BPMN Workflow | (use shape library) | Business process events, tasks, gateways |
36
| Mind Map | (manual) | Central topic with radiating branches |
37
38
---
39
40
## 2. Prerequisites
41
42
- If running with VS Code integration enabled, Install the drawio extension: **draw.io VS Code extension** — `hediet.vscode-drawio` (extension id). Install with:
43
```
44
ext install hediet.vscode-drawio
45
```
46
- **Supported file extensions**: `.drawio`, `.drawio.svg`, `.drawio.png`
47
- **Python 3.8+** (optional) — for the validation and shape-insertion scripts in `scripts/`
48
49
---
50
51
## 3. Step-by-Step Agent Workflow
52
53
Follow these steps in order for every diagram generation task.
54
55
### Step 1 — Understand the Request
56
57
Ask or infer:
58
1. **Diagram type** — What kind of diagram? (flowchart, architecture, UML, ER, sequence, network...)
59
2. **Entities / actors** — What are the main components, actors, classes, or tables?
60
3. **Relationships** — How are they connected? What direction? What cardinality?
61
4. **Output path** — Where should the `.drawio` file be saved?
62
5. **Existing file** — Are we creating new or editing an existing file?
63
64
If the request is ambiguous, infer the most sensible diagram type from context (e.g. "show the tables" → ER diagram, "show how the API call flows" → sequence diagram).
65
66
### Step 2 — Select a Template or Start Fresh
67
68
- **Use a template** when the diagram type matches one in `assets/templates/`. Copy the template structure and replace placeholder values.
69
- **Start fresh** for novel layouts. Begin with the minimal valid skeleton:
70
71
```xml
72
<!-- Set modified="" to the current ISO 8601 timestamp when generating a new file -->
73
<mxfile host="Electron" modified="" version="26.0.0">
74
<diagram id="page-1" name="Page-1">
75
<mxGraphModel dx="1422" dy="762" grid="1" gridSize="10" guides="1"
76
tooltips="1" connect="1" arrows="1" fold="1"
77
page="1" pageScale="1" pageWidth="1169" pageHeight="827"
78
math="0" shadow="0">
79
<root>
80
<mxCell id="0" />
81
<mxCell id="1" parent="0" />
82
<!-- Your cells go here -->
83
</root>
84
</mxGraphModel>
85
</diagram>
86
</mxfile>
87
```
88
89
> **Rule**: ids `0` and `1` are ALWAYS required and must be the first two cells. Never reuse them.
90
91
### Step 3 — Plan the Layout
92
93
Before generating XML, sketch the logical placement:
94
- Organise into **rows** or **tiers** (use swimlanes for layers)
95
- **Horizontal spacing**: 40–60px between same-row shapes
96
- **Vertical spacing**: 80–120px between tier rows
97
- Standard shape size: `120x60` px for process boxes, `160x80` px for swimlanes
98
- Default canvas: A4 landscape = `1169 x 827` px
99
100
### Step 4 — Generate the mxGraph XML
101
102
**Vertex cell** (every shape):
103
```xml
104
<mxCell id="unique-id" value="Label"
105
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;"
106
vertex="1" parent="1">
107
<mxGeometry x="100" y="100" width="120" height="60" as="geometry" />
108
</mxCell>
109
```
110
111
**Edge cell** (every connector):
112
```xml
113
<mxCell id="edge-id" value="Label (optional)"
114
style="edgeStyle=orthogonalEdgeStyle;html=1;"
115
edge="1" source="source-id" target="target-id" parent="1">
116
<mxGeometry relative="1" as="geometry" />
117
</mxCell>
118
```
119
120
**Critical rules**:
121
- Every cell id must be **globally unique** within the file
122
- Every vertex must have an `mxGeometry` child with `x`, `y`, `width`, `height`, `as="geometry"`
123
- Every edge must have `source` and `target` matching existing vertex ids — **exception**: floating edges (e.g. sequence diagram lifelines) use `sourcePoint`/`targetPoint` inside `<mxGeometry>` instead; see §4 Sequence Diagram
124
- Every cell's `parent` must reference an existing cell id
125
- Use `html=1` in style when the label contains HTML (`<b>`, `<i>`, `<br>`)
126
- Escape XML special characters in labels: `&` => `&`, `<` => `<`, `>` => `>`
127
128
### Step 5 — Apply Correct Styles
129
130
Use the standard semantic color palette for consistency:
131
132
| Purpose | fillColor | strokeColor |
133
|---|---|---|
134
| Primary / Info | `#dae8fc` | `#6c8ebf` |
135
| Success / Start | `#d5e8d4` | `#82b366` |
136
| Warning / Decision | `#fff2cc` | `#d6b656` |
137
| Error / End | `#f8cecc` | `#b85450` |
138
| Neutral | `#f5f5f5` | `#666666` |
139
| External / Partner | `#e1d5e7` | `#9673a6` |
140
141
Common style strings by diagram type:
142
143
```
144
# Rounded process box (flowchart)
145
rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;
146
147
# Decision diamond
148
rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;
149
150
# Start/End terminal
151
ellipse;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;
152
153
# Database cylinder
154
shape=mxgraph.flowchart.database;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;
155
156
# Swimlane container (tier)
157
swimlane;startSize=30;fillColor=#dae8fc;strokeColor=#6c8ebf;fontStyle=1;
158
159
# UML class box
160
swimlane;fontStyle=1;align=center;startSize=40;fillColor=#dae8fc;strokeColor=#6c8ebf;
161
162
# Interface / stereotype box
163
swimlane;fontStyle=3;align=center;startSize=40;fillColor=#f5f5f5;strokeColor=#666666;
164
165
# ER table container
166
shape=table;startSize=30;container=1;collapsible=1;childLayout=tableLayout;
167
168
# Orthogonal connector
169
edgeStyle=orthogonalEdgeStyle;html=1;
170
171
# ER relationship (crow's foot)
172
edgeStyle=entityRelationEdgeStyle;html=1;endArrow=ERmany;startArrow=ERone;
173
```
174
175
> See `references/style-reference.md` for the complete style key catalog and `references/shape-libraries.md` for all shape library names.
176
177
### Step 6 — Save and Validate
178
179
1. **Write the file** to the requested path with `.drawio` extension
180
2. **Run the validator** (optional but recommended):
181
```bash
182
python .github/skills/draw-io-diagram-generator/scripts/validate-drawio.py <path-to-file.drawio>
183
```
184
3. **Tell the user** how to open the file:
185
> "Open `<filename>` in VS Code — it will render automatically with the draw.io extension. You can use draw.io's web app or desktop app as well if you prefer."
186
4. **Provide a brief description** of what is in the diagram so the user knows what to expect.
187
188
---
189
190
## 4. Diagram-Type Recipes
191
192
### Flowchart
193
194
Key elements: Start (ellipse) => Process (rounded rectangle) => Decision (diamond) => End (ellipse)
195
196
```xml
197
<!-- Start node -->
198
<mxCell id="start" value="Start"
199
style="ellipse;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;"
200
vertex="1" parent="1">
201
<mxGeometry x="500" y="80" width="120" height="60" as="geometry" />
202
</mxCell>
203
204
<!-- Process -->
205
<mxCell id="p1" value="Process Step"
206
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;"
207
vertex="1" parent="1">
208
<mxGeometry x="500" y="200" width="120" height="60" as="geometry" />
209
</mxCell>
210
211
<!-- Decision -->
212
<mxCell id="d1" value="Condition?"
213
style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;"
214
vertex="1" parent="1">
215
<mxGeometry x="460" y="320" width="200" height="100" as="geometry" />
216
</mxCell>
217
218
<!-- Arrow: start to p1 -->
219
<mxCell id="e1" value=""
220
style="edgeStyle=orthogonalEdgeStyle;html=1;"
221
edge="1" source="start" target="p1" parent="1">
222
<mxGeometry relative="1" as="geometry" />
223
</mxCell>
224
```
225
226
### Architecture Diagram (3-tier)
227
228
Use **swimlane containers** for each tier. All service boxes are children of their swimlane.
229
230
```xml
231
<!-- Tier swimlane -->
232
<mxCell id="tier1" value="Client Layer"
233
style="swimlane;startSize=30;fillColor=#dae8fc;strokeColor=#6c8ebf;fontStyle=1;"
234
vertex="1" parent="1">
235
<mxGeometry x="60" y="100" width="1050" height="130" as="geometry" />
236
</mxCell>
237
238
<!-- Service inside tier (parent="tier1", coords are relative to tier) -->
239
<mxCell id="webapp" value="Web App"
240
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;"
241
vertex="1" parent="tier1">
242
<mxGeometry x="80" y="40" width="120" height="60" as="geometry" />
243
</mxCell>
244
```
245
246
> Connectors between tiers use absolute coordinates with `parent="1"`.
247
248
### Sequence Diagram
249
250
Key elements: Actors (top), Lifelines (dashed vertical lines), Activation boxes, Message arrows.
251
252
- Lifelines: `edge="1"` with `endArrow=none` and `dashed=1`, no source/target — use `sourcePoint`/`targetPoint` in geometry
253
- Synchronous message: `endArrow=block;endFill=1`
254
- Return message: `endArrow=open;endFill=0;dashed=1`
255
- Self-call: loop the edge via two Array points to the right and back
256
257
**Minimal XML snippet:**
258
259
```xml
260
<!-- Actor (stick figure) -->
261
<mxCell id="actorA" value="Client"
262
style="shape=mxgraph.uml.actor;pointerEvents=1;dashed=0;whiteSpace=wrap;html=1;aspect=fixed;"
263
vertex="1" parent="1">
264
<mxGeometry x="110" y="80" width="60" height="80" as="geometry" />
265
</mxCell>
266
267
<!-- Service box -->
268
<mxCell id="actorB" value="API Server"
269
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;"
270
vertex="1" parent="1">
271
<mxGeometry x="480" y="100" width="160" height="60" as="geometry" />
272
</mxCell>
273
274
<!-- Lifeline — floating edge: uses sourcePoint/targetPoint, NOT source/target attributes -->
275
<mxCell id="lifA" value=""
276
style="edgeStyle=none;dashed=1;endArrow=none;"
277
edge="1" parent="1">
278
<mxGeometry relative="1" as="geometry">
279
<mxPoint x="140" y="160" as="sourcePoint" />
280
<mxPoint x="140" y="700" as="targetPoint" />
281
</mxGeometry>
282
</mxCell>
283
284
<!-- Activation box (thin rectangle on lifeline) -->
285
<mxCell id="actA1" value=""
286
style="fillColor=#dae8fc;strokeColor=#6c8ebf;"
287
vertex="1" parent="1">
288
<mxGeometry x="130" y="220" width="20" height="180" as="geometry" />
289
</mxCell>
290
291
<!-- Synchronous message -->
292
<mxCell id="msg1" value="POST /orders"
293
style="edgeStyle=elbowEdgeStyle;elbow=vertical;html=1;endArrow=block;endFill=1;"
294
edge="1" source="actA1" target="actorB" parent="1">
295
<mxGeometry relative="1" as="geometry" />
296
</mxCell>
297
298
<!-- Return message (dashed) -->
299
<mxCell id="msg2" value="201 Created"
300
style="edgeStyle=elbowEdgeStyle;elbow=vertical;dashed=1;html=1;endArrow=open;endFill=0;"
301
edge="1" source="actorB" target="actA1" parent="1">
302
<mxGeometry relative="1" as="geometry" />
303
</mxCell>
304
```
305
306
> **Note:** Lifelines are floating edges that use `sourcePoint`/`targetPoint` in `<mxGeometry>` instead of `source`/`target` attributes. This is the standard draw.io pattern for sequence diagrams.
307
308
### ER Diagram
309
310
Use `shape=table` containers with `childLayout=tableLayout`. Rows are `shape=tableRow` cells with `portConstraint=eastwest`. Columns inside each row are `shape=partialRectangle`.
311
312
Relationship arrows use `edgeStyle=entityRelationEdgeStyle`:
313
- One-to-One: `startArrow=ERone;endArrow=ERone`
314
- One-to-Many: `startArrow=ERone;endArrow=ERmany`
315
- Many-to-Many: `startArrow=ERmany;endArrow=ERmany`
316
- Mandatory: `ERmandOne`, Optional: `ERzeroToOne`
317
318
### UML Class Diagram
319
320
Class boxes are swimlane containers. Attributes and methods are plain text cells. Dividers are zero-height swimlane children.
321
322
Arrow styles by relationship type:
323
324
| Relationship | Style String |
325
|---|---|
326
| Inheritance (extends) | `edgeStyle=orthogonalEdgeStyle;html=1;endArrow=block;endFill=0;` |
327
| Realization (implements) | `edgeStyle=orthogonalEdgeStyle;dashed=1;html=1;endArrow=block;endFill=0;` |
328
| Composition | `edgeStyle=orthogonalEdgeStyle;html=1;startArrow=diamond;startFill=1;endArrow=none;` |
329
| Aggregation | `edgeStyle=orthogonalEdgeStyle;html=1;startArrow=diamond;startFill=0;endArrow=none;` |
330
| Dependency | `edgeStyle=orthogonalEdgeStyle;dashed=1;html=1;endArrow=open;endFill=0;` |
331
| Association | `edgeStyle=orthogonalEdgeStyle;html=1;endArrow=open;endFill=0;` |
332
333
---
334
335
## 5. Multi-Page Diagrams
336
337
Add multiple `<diagram>` elements for complex systems:
338
339
```xml
340
<mxfile host="Electron" version="26.0.0">
341
<diagram id="overview" name="Overview">
342
<!-- overview mxGraphModel -->
343
</diagram>
344
<diagram id="detail" name="Detail View">
345
<!-- detail mxGraphModel -->
346
</diagram>
347
</mxfile>
348
```
349
350
Each page has its own independent cell id namespace. The same id value can appear in different pages without conflict.
351
352
---
353
354
## 6. Editing Existing Diagrams
355
356
When modifying an existing `.drawio` file:
357
358
1. **Read** the file first to understand existing cell ids, positions, and parent hierarchy
359
2. **Identify the target diagram page** — by index or `name` attribute
360
3. **Assign new unique ids** that do not collide with existing ids
361
4. **Respect the container hierarchy** — children of a swimlane use coordinates relative to their parent
362
5. **Verify edges** — after repositioning nodes, confirm edge source/target ids remain valid
363
364
Use `scripts/add-shape.py` to safely add a single shape without editing raw XML:
365
```bash
366
python .github/skills/draw-io-diagram-generator/scripts/add-shape.py docs/arch.drawio "New Service" 700 380
367
```
368
369
---
370
371
## 7. Best Practices
372
373
**Layout**
374
- Align shapes to the 10px grid (all coordinates divisible by 10)
375
- Group related shapes inside swimlane containers
376
- One diagram topic per page; use multi-page files for complex systems
377
- Aim for 40 or fewer cells per page for readability
378
379
**Labels**
380
- Add a title text cell (`text;strokeColor=none;fillColor=none;fontSize=18;fontStyle=1`) at top of every page
381
- Always set `whiteSpace=wrap;html=1` on vertex shapes
382
- Keep labels concise — 3 words or fewer per shape where possible
383
384
**Style consistency**
385
- Use the semantic color palette from Section 3 Step 5 consistently across a project
386
- Prefer `edgeStyle=orthogonalEdgeStyle` for clean right-angle connectors
387
- Do not inline arbitrary HTML in labels unless necessary
388
389
**File naming**
390
- Use kebab-case: `order-service-flow.drawio`, `database-schema.drawio`
391
- Place diagrams alongside the code they document: `docs/` or `architecture/`
392
393
---
394
395
## 8. Troubleshooting
396
397
| Problem | Likely Cause | Fix |
398
|---|---|---|
399
| File opens blank in VS Code | Missing id=0 or id=1 cell | Add both root cells before any other cells |
400
| Shape at wrong position | Child inside container — coords are relative | Check `parent`; adjust x/y relative to container |
401
| Edge not visible | source or target id does not match any vertex | Verify both ids exist exactly as written |
402
| Diagram shows "Compressed" | mxGraphModel is base64-encoded | Open in draw.io web, File > Export > XML (uncompressed) |
403
| Shape style not rendering | Typo in shape= name | Check `references/shape-libraries.md` for exact style string |
404
| Label shows escaped HTML | html=0 on a cell with HTML label | Add `html=1;` to the cell style |
405
| Container children overlap container edge | Container height too small | Increase container height in mxGeometry |
406
407
---
408
409
## 9. Validation Checklist
410
411
Before delivering any generated `.drawio` file, verify:
412
413
- [ ] File starts with `<mxfile>` root element
414
- [ ] Every `<diagram>` has a non-empty `id` attribute
415
- [ ] `<mxCell id="0" />` is the first cell in every diagram
416
- [ ] `<mxCell id="1" parent="0" />` is the second cell in every diagram
417
- [ ] All cell `id` values are unique within each diagram
418
- [ ] Every vertex cell has `vertex="1"` and a child `<mxGeometry as="geometry">`
419
- [ ] Every edge cell has `edge="1"` and either: (a) `source`/`target` pointing to existing vertex ids, or (b) `<mxPoint as="sourcePoint">` and `<mxPoint as="targetPoint">` in its `<mxGeometry>` (floating edge — used for sequence diagram lifelines)
420
- [ ] Every cell (except id=0) has a `parent` pointing to an existing id
421
- [ ] `html=1` is in the style for any label containing HTML tags
422
- [ ] XML is well-formed (no unclosed tags, no unescaped `&`, `<`, `>` in attribute values)
423
- [ ] A title label cell exists at the top of each page
424
425
Run the automated validator:
426
```bash
427
python .github/skills/draw-io-diagram-generator/scripts/validate-drawio.py <file.drawio>
428
```
429
430
---
431
432
## 10. Output Format
433
434
When delivering a diagram, always provide:
435
436
1. **The `.drawio` file** written to the requested path
437
2. **A one-sentence summary** of what the diagram shows
438
3. **How to open it**:
439
> "Open `<filename>` in VS Code — the draw.io extension will render it automatically. Or you can open it in the draw.io web app or desktop app if you prefer."
440
4. **How to edit it** (if the user is likely to customise):
441
> "Click any shape to select it. Double-click to edit the label. Drag to reposition."
442
5. **Validation status** — whether the validator script was run and passed
443
444
---
445
446
## 11. References
447
448
All companion files are in `.github/skills/draw-io-diagram-generator/`:
449
450
| File | Contents |
451
|---|---|
452
| `references/drawio-xml-schema.md` | Complete mxfile / mxGraphModel / mxCell attribute reference, coordinate system, reserved cells, validation rules |
453
| `references/style-reference.md` | All style keys with allowed values, vertex and edge style keys, shape catalog, semantic color palette |
454
| `references/shape-libraries.md` | All shape library categories (General, Flowchart, UML, ER, Network, BPMN, Mockup, K8s) with style strings |
455
| `assets/templates/flowchart.drawio` | Ready-to-use flowchart template |
456
| `assets/templates/architecture.drawio` | 4-tier system architecture template |
457
| `assets/templates/sequence.drawio` | 3-actor sequence diagram template |
458
| `assets/templates/er-diagram.drawio` | 3-table ER diagram with crow's foot relationships |
459
| `assets/templates/uml-class.drawio` | Interface + 2 classes + enum with relationship arrows |
460
| `scripts/validate-drawio.py` | Python script to validate XML structure of any .drawio file |
461
| `scripts/add-shape.py` | Python CLI to add a new shape to an existing diagram |
462
| `scripts/README.md` | How to use the scripts with examples |
463