drawio-skill
Original:🇺🇸 English
Translated
2 scriptsChecked / no sensitive code detected
Use when user requests diagrams, flowcharts, architecture charts, or visualizations. Also use proactively when explaining systems with 3+ components, complex data flows, or relationships that benefit from visual representation. Generates .drawio XML files and exports to PNG/SVG/PDF locally using the native draw.io desktop CLI.
15installs
Sourceagents365-ai/365-skills
Added on
NPX Install
npx skill4agent add agents365-ai/365-skills drawio-skillTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Draw.io Diagrams
Overview
Generate XML files and export to PNG/SVG/PDF/JPG locally using the native draw.io desktop app CLI.
.drawioSupported formats: PNG, SVG, PDF, JPG — no browser automation needed.
PNG, SVG, and PDF exports support () — the exported file contains the full diagram XML, so opening it in draw.io recovers the editable diagram. Use double extensions () to signal embedded XML.
--embed-diagram-ename.drawio.pngBundled resources
When the workflow references one of these, read it on demand — none of them need to be in context up front.
| File | Read it when |
|---|---|
| The user names a specific diagram type (ERD, UML class, sequence, architecture, ML/DL, flowchart) |
| The user asks to learn / save / list / set-default / delete a style preset, or you've resolved an active preset and need the application rules |
| You're inside the Learn flow and need the extraction procedure (called from |
| An export fails, vision rejects a PNG, or a rendering looks wrong |
| After every |
| The CLI is unavailable and you need a browser-fallback diagrams.net URL |
Prerequisites
The draw.io desktop app must be installed and the CLI accessible:
bash
# macOS (Homebrew — recommended)
brew install --cask drawio
draw.io --version
# macOS (full path if not in PATH)
/Applications/draw.io.app/Contents/MacOS/draw.io --version
# Windows
"C:\Program Files\draw.io\draw.io.exe" --version
# Linux
draw.io --versionInstall draw.io desktop if missing:
- macOS: or download from https://github.com/jgraph/drawio-desktop/releases
brew install --cask drawio - Windows: download installer from https://github.com/jgraph/drawio-desktop/releases
- Linux: download /
.debfrom https://github.com/jgraph/drawio-desktop/releases — do not use snap (AppArmor sandbox denies secrets/keyring on servers, causes crash).rpm
Workflow
Before starting the workflow, assess whether the user's request is specific enough. If key details are missing, ask 1-3 focused questions:
- Diagram type — which preset? (ERD, UML, Sequence, Architecture, ML/DL, Flowchart, or general)
- Output format — PNG (default), SVG, PDF, or JPG?
- Output location — default is the user's working dir; honor any explicit path the user gives (e.g. "put it in "). Don't ask if they didn't mention one.
./artifacts/ - Scope/fidelity — how many components? Any specific technologies or labels?
Skip clarification if the request already specifies these details or is clearly simple (e.g., "draw a flowchart of X").
-
Update check (notify, don't pull) — first use per conversation. Throttle to once per 24 h via; never mutate the skill directory without explicit user consent.
<this-skill-dir>/.last_update-
Ifexists and is <24 h old, skip this step entirely.
.last_update -
Otherwise, fetch the latest tag from upstream:bash
git -C <this-skill-dir> ls-remote --tags origin 'v*' 2>/dev/null \ | awk '{print $2}' | sed 's|refs/tags/||' | sort -V | tail -1 -
Compare with this skill'sfrom the frontmatter. If the upstream tag is strictly newer (semver), tell the user one line and ask:
metadata.version"A newer version of this skill is available: vX.Y.Z → vA.B.C. Want me to?"git pullIf they say yes, run. Refreshgit -C <this-skill-dir> pull --ff-onlyeither way so the prompt doesn't repeat for 24 hours..last_update -
If upstream is the same or older, refreshsilently and continue.
.last_update -
On any failure (offline, not a git checkout — e.g. ClawHub-installed copy, read-only path, no permission), swallow the error silently and continue with the user's task. Do not mention the failure.
-
Step 0.5 — Resolve active preset. Determine which (if any) user-defined style preset applies to this generation.
- Scan the user's message for a phrase that clearly names a style preset: "use my style", "with my
<name>style", "in<name>mode", "in the style of<name>". A bare<name>does not count — "draw a diagram with redis" names a component, not a style. If a clear match is found → active preset =with <name>.<name> - Else, check for any file with
~/.drawio-skill/styles/. If found → active preset = that one."default": true - Else → no preset active; fall through to the built-in color/shape/edge conventions for the rest of the workflow.
Load the preset JSON from , falling back to . If the named preset exists in neither location, tell the user the name is unknown, list the available presets (user dir + built-in), and stop — do not silently fall back to defaults.
~/.drawio-skill/styles/<name>.json<this-skill-dir>/styles/built-in/<name>.jsonWhen a preset loads successfully, mention it in the first line of the reply: "Using preset (confidence: )." See the Applying a preset subsection below for how the preset changes color/shape/edge/font decisions.
<name><level>- Check deps — verify succeeds; note platform for correct CLI path
draw.io --version - Plan — identify shapes, relationships, layout (LR or TB), group by tier/layer
- Generate — write XML file to disk. Default output dir is the user's working dir; if the user specified an output path or directory (e.g.
.drawio,./artifacts/), use that instead —docs/images/the target dir first. Apply the same dir choice to PNG/SVG/PDF exports in steps 4 and 7.mkdir -p - Export draft — run CLI to produce a preview PNG. Do NOT pass at this step — the embedded
-echunk it adds causes vision APIs (Claude included) to return 400 "Could not process image" in step 5. Save the clean preview aszTXt mxGraphModel(single extension). Embedding is for the final export only (step 7).<name>.png - Self-check — use the agent's built-in vision capability to read the exported PNG, catch obvious issues, auto-fix before showing user (requires a vision-enabled model such as Claude Sonnet/Opus). If reading the PNG returns a 400 / "Could not process image" error, you almost certainly exported with by mistake — re-export without
-eand retry once. If it still fails, skip self-check and continue to step 6.-e - Review loop — show image to user, collect feedback, apply targeted XML edits, re-export, repeat until approved
- Final export — re-export the approved version to all requested formats. Use here (PNG/SVG/PDF) so the deliverable stays editable in draw.io; save as
-eto signal embedded XML. For PNG with<name>.drawio.png, run-eimmediately after — draw.io's CLI truncates the IEND chunk inpython3 <this-skill-dir>/scripts/repair_png.py <name>.drawio.pngPNG output (8 bytes missing), producing a corrupt file that vision APIs and strict PNG decoders reject (issue #8). Report file paths.-e
Step 5: Self-Check
After exporting the draft PNG, use the agent's vision capability (e.g., Claude's image input) to read the image and check for these issues before showing the user. If the agent does not support vision, skip self-check and show the PNG directly.
Important: the draft PNG read here must have been exported without . Draw.io's flag emits a PNG with a truncated IEND chunk (8 bytes of type+CRC missing) that the Anthropic vision API rejects with 400 "Could not process image" (issue #8). The simplest fix for the preview step is to skip entirely; the final export in step 7 keeps and runs the repair snippet. If you see the 400 error here, re-export without and retry once; if it still fails (any other reason), skip self-check and proceed to step 6.
-e-e-e-e-e| Check | What to look for | Auto-fix action |
|---|---|---|
| Overlapping shapes | Two or more shapes stacked on top of each other | Shift shapes apart by ≥200px |
| Clipped labels | Text cut off at shape boundaries | Increase shape width/height to fit label |
| Missing connections | Arrows that don't visually connect to shapes | Verify |
| Off-canvas shapes | Shapes at negative coordinates or far from the main group | Move to positive coordinates near the cluster |
| Edge-shape overlap | An edge/arrow visually crosses through an unrelated shape | Add waypoints ( |
| Stacked edges | Multiple edges overlap each other on the same path | Distribute entry/exit points across the shape perimeter (use different exitX/entryX values) |
- Max 2 self-check rounds — if issues remain after 2 fixes, show the user anyway
- Re-export after each fix and re-read the new PNG
Step 6: Review Loop
After self-check, show the exported image and ask the user for feedback.
Targeted edit rules — for each type of feedback, apply the minimal XML change:
| User request | XML edit action |
|---|---|
| Change color of X | Find |
| Add a new node | Append a new |
| Remove a node | Delete the |
| Move shape X | Update |
| Resize shape X | Update |
| Add arrow from A to B | Append a new |
| Change label text | Update the |
| Change layout direction | Full regeneration — rebuild XML with new orientation |
Rules:
- For single-element changes: edit existing XML in place — preserves layout tuning from prior iterations
- For layout-wide changes (e.g., swap LR↔TB, "start over"): regenerate full XML
- Overwrite the same (no
{name}.png) each iteration — do not create-e,v1,v2files.v3is reserved for the final export in step 7.-e - After applying edits, re-export and show the updated image
- Loop continues until user says approved / done / LGTM
- Safety valve: after 5 iteration rounds, suggest the user open the file in draw.io desktop for fine-grained adjustments
.drawio
Step 7: Final Export
Once the user approves:
- Export to all requested formats (PNG, SVG, PDF, JPG) — default to PNG if not specified
- Report file paths for both the source file and exported image(s)
.drawio - Auto-launch: offer to open the file in draw.io desktop for fine-tuning —
.drawio(macOS),open diagram.drawio(Linux),xdg-open(Windows)start - Confirm files are saved and ready to use
Style Presets
A style preset is a named JSON file capturing a user's visual preferences (palette, shapes, font, edges). When active, it fully replaces the built-in color/shape conventions in this skill.
Lookup order when SKILL.md's step 0.5 resolves a preset name:
- — user presets (survive
~/.drawio-skill/styles/<name>.json)git pull - — shipped built-ins (
<this-skill-dir>/styles/built-in/<name>.json,default,corporate)handdrawn
Always lowercase the user-provided name before any file operation — the schema enforces lowercase.
For everything else — Learn flow (extracting a preset from a file), management ops (list/default/delete/rename), application rules (color lookup, shape keywords, edges, fonts, extras, interaction with diagram-type presets), and validation — read . It's only needed when the user invokes those flows or when an active preset must be applied to the current generation.
references/style-presets.mdDraw.io XML Structure
File skeleton
xml
<?xml version="1.0" encoding="UTF-8"?>
<mxfile host="drawio" version="26.0.0">
<diagram name="Page-1">
<mxGraphModel>
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<!-- user shapes start at id="2" -->
</root>
</mxGraphModel>
</diagram>
</mxfile>Rules:
- and
id="0"are required root cells — never omit themid="1" - User shapes start at and increment sequentially
id="2" - All shapes have (unless inside a container — then use container's id)
parent="1" - All text uses in style for proper rendering
html=1 - Never use inside XML comments — it's illegal per XML spec and causes parse errors
-- - Escape special characters in attribute values: ,
&,<,>" - Multi-line text in labels: use for line breaks inside

attributes (not literalvalue). Example:\nvalue="Line 1
Line 2"
Shape types (vertex)
| Style keyword | Use for |
|---|---|
| plain rectangle (default) |
| rounded rectangle — services, modules |
| circles/ovals — start/end, databases |
| diamond — decision points |
| AWS icons |
| cylinder — databases |
| group/container with title bar |
Required properties
xml
<!-- Rectangle / rounded box -->
<mxCell id="2" value="Label" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="160" height="60" as="geometry" />
</mxCell>
<!-- Cylinder (database) -->
<mxCell id="3" value="DB" style="shape=cylinder3;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontColor=#333333;" vertex="1" parent="1">
<mxGeometry x="350" y="100" width="120" height="80" as="geometry" />
</mxCell>
<!-- Diamond (decision) -->
<mxCell id="4" value="Check?" style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="1">
<mxGeometry x="100" y="220" width="160" height="80" as="geometry" />
</mxCell>Containers and groups
For architecture diagrams with nested elements, use draw.io's parent-child containment — do not just place shapes on top of larger shapes.
| Type | Style | When to use |
|---|---|---|
| Group (invisible) | | No visual border needed, container has no connections |
| Swimlane (titled) | | Container needs a visible title bar, or container itself has connections |
| Custom container | Add | Any shape acting as a container without its own connections |
Key rules:
- Add to container styles that should not capture connections between children
pointerEvents=0; - Children set and use coordinates relative to the container
parent="containerId"
xml
<!-- Swimlane container -->
<mxCell id="svc1" value="User Service" style="swimlane;startSize=30;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="300" height="200" as="geometry"/>
</mxCell>
<!-- Child inside container — coordinates relative to parent -->
<mxCell id="api1" value="REST API" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="svc1">
<mxGeometry x="20" y="40" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="db1" value="Database" style="shape=cylinder3;whiteSpace=wrap;html=1;" vertex="1" parent="svc1">
<mxGeometry x="160" y="40" width="120" height="60" as="geometry"/>
</mxCell>Connector (edge)
CRITICAL: Every edge must contain a child element. Self-closing edge cells () are invalid and will not render. Always use the expanded form.
mxCell<mxGeometry relative="1" as="geometry" /><mxCell ... edge="1" ... />xml
<!-- Directed arrow — always include rounded, orthogonalLoop, jettySize for clean routing -->
<mxCell id="10" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="2" target="3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<!-- Arrow with label + explicit entry/exit points to control direction -->
<mxCell id="11" value="HTTP/REST" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="2" target="4">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<!-- Arrow with waypoints — use when edge must route around other shapes -->
<mxCell id="12" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="3" target="5">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="500" y="50" />
</Array>
</mxGeometry>
</mxCell>Edge style rules:
- Animated connectors: add to any edge style to show a moving dot animation along the arrow. Works in SVG export and draw.io desktop — ideal for data-flow and pipeline diagrams. Example:
flowAnimation=1;style="edgeStyle=orthogonalEdgeStyle;flowAnimation=1;rounded=1;..." - Always include — these enable smart routing that avoids overlaps
rounded=1;orthogonalLoop=1;jettySize=auto - Pin on every edge when a node has 2+ connections — distributes lines across the shape perimeter
exitX/exitY/entryX/entryY - Add waypoints when an edge must detour around an intermediate shape
<Array as="points"> - Leave room for arrowheads: the final straight segment between the last bend and the target shape must be ≥20px long. If too short, the arrowhead overlaps the bend and looks broken. Fix by increasing node spacing or adding explicit waypoints
Distributing connections on a shape
When multiple edges connect to the same shape, assign different entry/exit points to prevent stacking:
| Position | exitX/entryX | exitY/entryY | Use when |
|---|---|---|---|
| Top center | 0.5 | 0 | connecting to node above |
| Top-left | 0.25 | 0 | 2nd connection from top |
| Top-right | 0.75 | 0 | 3rd connection from top |
| Right center | 1 | 0.5 | connecting to node on right |
| Bottom center | 0.5 | 1 | connecting to node below |
| Left center | 0 | 0.5 | connecting to node on left |
Rule: if a shape has N connections on one side, space them evenly (e.g., 3 connections on bottom → exitX = 0.25, 0.5, 0.75)
Color palette (fillColor / strokeColor)
Used only when no preset is active (see "Applying a preset" above).
| Color name | fillColor | strokeColor | Use for |
|---|---|---|---|
| Blue | | | services, clients |
| Green | | | success, databases |
| Yellow | | | queues, decisions |
| Orange | | | gateways, APIs |
| Red/Pink | | | errors, alerts |
| Grey | | | external/neutral |
| Purple | | | security, auth |
Layout tips
Spacing — scale with complexity:
| Diagram complexity | Nodes | Horizontal gap | Vertical gap |
|---|---|---|---|
| Simple | ≤5 | 200px | 150px |
| Medium | 6–10 | 280px | 200px |
| Complex | >10 | 350px | 250px |
Routing corridors: between shape rows/columns, leave an extra ~80px empty corridor where edges can route without crossing shapes. Never place a shape in a gap that edges need to traverse.
Grid alignment: snap all , , , values to multiples of 10 — this ensures shapes align cleanly on draw.io's default grid and makes manual editing easier.
xywidthheightGeneral rules:
- Plan a grid before assigning x/y coordinates — sketch node positions on paper/mentally first
- Group related nodes in the same horizontal or vertical band
- Use cells for logical grouping with visible borders
swimlane - Place heavily-connected "hub" nodes centrally so edges radiate outward instead of crossing
- To force straight vertical connections, pin entry/exit points explicitly on edges:
exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0 - Always center-align a child node under its parent (same center x) to avoid diagonal routing
- Event bus pattern: place Kafka/bus nodes in the center of the service row, not below — services on either side can reach it with short horizontal arrows (left side,
exitX=1right side), eliminating all line crossingsexitX=0 - Horizontal connections (or
exitX=1) never cross vertical nodes in the same row; use them for peer-to-peer and publish connectionsexitX=0
Avoiding edge-shape overlap:
- Before finalizing coordinates, trace each edge path mentally — if it must cross an unrelated shape, either move the shape or add waypoints
- For tree/hierarchical layouts: assign nodes to layers (rows), connect only between adjacent layers to minimize crossings
- For star/hub layouts: place the hub center, satellites around it — edges stay short and radial
- When an edge must span multiple rows/columns, route it along the outer corridor, not through the middle of the diagram
Export
Commands
There are two export modes:
- Preview / self-check (step 4 of the workflow) — no . Output
-e. Required for vision self-check; usingdiagram.pnghere triggers a 400 "Could not process image" error from the vision API (issue #8).-e - Final / deliverable (step 7) — pass . Output
-e. The embedded XML keeps the file editable in draw.io.diagram.drawio.png
bash
# Preview PNG (use this in step 4, before self-check) — NO -e
draw.io -x -f png -s 2 -o diagram.png input.drawio
# Final PNG (step 7, after user approval) — WITH -e, double extension
draw.io -x -f png -e -s 2 -o diagram.drawio.png input.drawio
# macOS — full path (if not in PATH); preview / final variants
/Applications/draw.io.app/Contents/MacOS/draw.io -x -f png -s 2 -o diagram.png input.drawio
/Applications/draw.io.app/Contents/MacOS/draw.io -x -f png -e -s 2 -o diagram.drawio.png input.drawio
# Windows
"C:\Program Files\draw.io\draw.io.exe" -x -f png -e -s 2 -o diagram.drawio.png input.drawio
# Linux (headless — requires xvfb-run; on servers add HOME and --disable-gpu)
export HOME=${HOME:-/tmp}
xvfb-run -a --server-args="-screen 0 1280x1024x24" \
draw.io -x -f png -e -s 2 -o diagram.drawio.png input.drawio --disable-gpu
# Running as root (CI / Docker)? Append --no-sandbox AT THE END (placing it earlier makes drawio treat it as the input filename)
# SVG export (final — -e is safe; SVG is text)
draw.io -x -f svg -e -o diagram.svg input.drawio
# PDF export (final)
draw.io -x -f pdf -e -o diagram.pdf input.drawio
# Custom output directory (e.g. CI artifacts dir) — create if missing, then export there
mkdir -p ./artifacts && draw.io -x -f png -e -s 2 -o ./artifacts/diagram.drawio.png input.drawioPost-export PNG repair (required after -e
PNG export)
-edraw.io CLI truncates the IEND chunk when emitting PNGs — the file ends with the 4-byte IEND length field but the type + CRC (8 bytes) are missing. Result: vision APIs return 400 "Could not process image" and strict PNG decoders error out. SVG/PDF are unaffected.
-eIENDRun this immediately after every PNG export:
-ebash
python3 <this-skill-dir>/scripts/repair_png.py diagram.drawio.pngThe script's guard makes it a no-op once draw.io fixes the bug upstream — safe to run unconditionally.
endswith(IEND)Key flags:
- — export mode (required)
-x - — format:
-f,png,svg,pdfjpg - — embed diagram XML in output (PNG, SVG, PDF) — exported file remains editable in draw.io. Skip for the preview PNG used in step 5 self-check —
-ePNGs have a truncated IEND chunk that vision APIs reject (issue #8). For final PNG export, keep-eand run-e(see Post-export PNG repair). SVG/PDF unaffected.scripts/repair_png.py - — scale:
-s,1,2(2 recommended for PNG)3 - — output file path; accepts any directory (e.g.
-o) —./artifacts/diagram.drawio.pngthe target dir first. Usemkdir -pdouble extension when embedding..drawio.png - — border width around diagram (default: 0, recommend 10)
-b - — transparent background (PNG only)
-t - — export specific page (default: all)
--page-index 0
Browser fallback (no CLI needed)
When the draw.io desktop CLI is unavailable, generate a client-side viewer URL:
bash
python3 <this-skill-dir>/scripts/encode_drawio_url.py input.drawioPrints a URL with the diagram XML deflate-compressed and base64-encoded into the URL fragment. The fragment (after ) is never sent to the server, so nothing is uploaded — the diagram opens client-side for viewing and editing. Useful when the user cannot install the desktop app.
https://viewer.diagrams.net/...#Fallback chain
When tools are unavailable, degrade gracefully:
| Scenario | Behavior |
|---|---|
| draw.io CLI missing, Python available | Use browser fallback (diagrams.net URL) |
| draw.io CLI missing, Python missing | Generate |
| Vision unavailable for self-check | Skip self-check (step 5); proceed directly to showing user the exported PNG |
| Export fails (Chromium/display issues) | On Linux, retry with |
| Export fails on Linux server (headless) | Try in order: (1) |
Checking if draw.io is in PATH
bash
# Try short command first
if command -v draw.io &>/dev/null; then
DRAWIO="draw.io"
elif [ -f "/Applications/draw.io.app/Contents/MacOS/draw.io" ]; then
DRAWIO="/Applications/draw.io.app/Contents/MacOS/draw.io"
else
echo "draw.io not found — install from https://github.com/jgraph/drawio-desktop/releases"
fiCommon Mistakes
When something looks wrong (export fails, vision rejects a PNG, layout broken, edges misroute), see for a row-by-row mistake → fix table.
references/troubleshooting.mdDiagram Type Presets
When the user requests a specific diagram type, read for the matching preset (shapes, edges, layout direction). Pick by user phrasing:
references/diagram-types.md| User says | Section in |
|---|---|
| "ER diagram", "schema diagram", "data model" | ERD |
| "UML class diagram", "class diagram" | UML Class |
| "sequence diagram", "interaction diagram", "lifeline" | Sequence |
| "architecture", "system diagram", "service diagram" | Architecture |
| "neural network", "model architecture", "ML diagram", "deep learning" | ML / Deep Learning Model |
| "flowchart", "decision tree", "process flow" | Flowchart |
The diagram-type preset sets structural style keywords. If a user style preset is also active (see ), keep the structural keywords and layer color/font/edge/extras on top — read → "Interaction with diagram-type presets" for the merge rules.
## Style Presetsreferences/style-presets.md