Draw.io Diagram Skill
Overview
Generate .drawio XML files and export to PNG/SVG/PDF/JPG locally using the native draw.io desktop app CLI.
Supported formats: PNG, SVG, PDF, JPG — no browser automation needed.
PNG, SVG, and PDF exports support --embed-diagram (-e) — the exported file contains the full diagram XML, so opening it in draw.io recovers the editable diagram. Use double extensions (name.drawio.png) to signal embedded XML.
Installation Notes for Sharing
When sharing this skill with another user, include the full drawio-diagram-skill/ folder, not only SKILL.md, because referenced scripts/, references/, styles, and bundled helpers are part of the workflow.
This skill needs draw.io Desktop for local PNG/SVG/PDF export. The diagrams.net web app alone is not enough for local CLI export.
Recommended install:
brew install --cask drawio
drawio --version
If Homebrew or command-line downloads are slow, download draw.io Desktop manually from GitHub Releases:
https://github.com/jgraph/drawio-desktop/releases
Choose the installer for your OS:
- macOS:
.dmg - Windows:
.exe - Linux:
.debor.rpm(avoid snap when possible)
After installation, verify the CLI:
drawio --version
On macOS, if drawio is not on PATH, try:
/Applications/draw.io.app/Contents/MacOS/draw.io --version
Graphviz is optional and only needed for some auto-layout workflows:
brew install graphviz
If the draw.io CLI is unavailable or crashes in a sandboxed environment, this skill can still produce .drawio XML and diagrams.net edit links, but local image/PDF export may need to be done outside the sandbox.
Missing draw.io user prompt
When dependency checks show that draw.io Desktop is not installed or the drawio / draw.io command cannot be found, do not only say "export unavailable". Tell the user plainly:
You do not currently have draw.io Desktop installed, or the
drawiocommand cannot be found in this environment. I can send an install command to your Agent, or you can install it manually.
Then offer these choices:
- Agent install command:
brew install --cask drawioon macOS. - Manual install: download draw.io Desktop from https://github.com/jgraph/drawio-desktop/releases, then install the
.dmg,.exe,.deb, or.rpmfor the user's OS. - Continue without export: generate the
.drawioXML and a diagrams.net edit link, then let the user export PNG/SVG/PDF after installing draw.io.
Expected output
Return the saved .drawio source path and every exported artifact path. When export is unavailable, return the .drawio XML path plus the specific fallback used. For user-facing reviews, include a short note on diagram type, key layout choices, and any export or validation limitations.
When to use / when NOT to use
Use this skill for: polished, precise diagrams (architecture, network, strict UML, ERD), anything needing solid opaque fills, 10,000+ stock/branded shapes, swimlanes, or custom geometry, exported as editable PNG/SVG/PDF.
Do NOT use it — route elsewhere — for:
- A casual hand-drawn / whiteboard look → excalidraw or tldraw.
- Diagrams-as-code that live in git / render in Markdown → mermaid (general) or plantuml (UML).
- Freeform infinite-canvas sketching or freehand strokes → tldraw.
Report-style / Executive Diagrams
Use this mode when the user asks for executive flow architecture diagram, solution diagram, management closed-loop diagram, leadership report diagram, or any diagram that explains organization / roles / mechanisms rather than a literal system or data flow.
Rules:
- Treat the diagram as a sectioned narrative, not a plain flowchart.
- Plan 2-4 horizontal bands before drawing, such as summary, role flow, shared foundation, and mechanisms.
- Use uniform card sizes within each band; align card x/y positions and keep spacing consistent.
- Separate card title, description, bullet dots, and bullet text into aligned cells instead of one large paragraph.
- Reserve explicit arrow corridors between rows and columns before placing cards.
- Route cross-row arrows through the empty band between rows, with waypoints that keep lines away from labels and card contents.
- Validate visual hierarchy before export: page title > section title > card title > body > bullet.
- Prefer restrained report styling: clean fills, clear section markers, large readable text, and no decorative clutter.
Bundled 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 |
|---|---|
references/toolbox.md | You're not sure which bundled script fits a request, or want to chain several — a map of all 31 scripts grouped by use-case (author / import code / import IaC / import API spec / live infra / compare / annotate / reverse-export / utilities) with an "I have X, I want Y → use Z" guide |
references/xml-authoring.md | You're about to hand-write .drawio XML (workflow step 3) — file skeleton, shape/edge cells, containers, connection distribution, palette, spacing/grid rules. Not needed when a bundled generator writes the XML |
references/mermaid-authoring.md | The diagram is a standard type with no custom styling/icon needs (flowchart, state, gantt, mindmap, timeline, journey, pie, …) and the CLI is ≥ v30 — author it as Mermaid text and let the CLI convert to native .drawio (structure only, layout free). Also documents the CLI's ELK --layout pass for XML |
references/diagram-types.md | The user names a specific diagram type (ERD, UML class, sequence, C4, architecture, ML/DL, flowchart, SysML, BPMN, network topology, swimlane) |
references/shapes.md + scripts/shapesearch.py | The diagram needs a specific shape — a cloud icon (AWS/Azure/GCP), Cisco/Kubernetes/network symbol, UML/BPMN/ER/electrical/P&ID element — or any time you'd otherwise guess a style= string. shapesearch.py "<keywords>" returns the exact official style for 10k+ shapes |
scripts/aiicons.py | The diagram involves an AI/LLM brand (OpenAI, Claude, Gemini, Mistral, Llama, HuggingFace, Ollama, LangChain, …) — aiicons.py "<brand>" returns a draw.io image style for the brand logo (lobe-icons via CDN; --embed to inline). draw.io has no built-in AI logos. See references/shapes.md → "AI / LLM brand logos" |
references/style-presets.md | 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 |
references/style-extraction.md | You're inside the Learn flow and need the extraction procedure (called from style-presets.md) |
references/troubleshooting.md | An export fails, vision rejects a PNG, or a rendering looks wrong |
scripts/repair_png.py | After every -e PNG export — fixes draw.io's truncated IEND chunk (issue #8) |
scripts/encode_drawio_url.py | The CLI is unavailable and you need a browser-fallback diagrams.net URL (--edit for an editable editor URL) |
references/autolayout.md | The diagram is large or layout-heavy (dependency/call graph, code structure, >~15 nodes) and you want Graphviz to place nodes + route edges instead of hand-placing coordinates |
scripts/pyimports.py · jsimports.py · goimports.py · rustimports.py | The user wants to visualize a Python, JS/TS, Go, or Rust project structure — extracts the import graph (transitive-reduced, optional --group containers, nested by sub-package) for autolayout |
scripts/pyclasses.py | The user wants a Python class hierarchy / class diagram — extracts classes + inheritance edges (boxed by module with --group) for autolayout |
scripts/tfimports.py · k8simports.py · composeimports.py | The user wants to visualize declared infrastructure (Terraform .tf, Kubernetes manifests, or docker-compose) — extracts the resource/service reference graph (official AWS/Azure/GCP/K8s icons for tf/k8s; service boxes + volume cylinders for compose) for autolayout |
scripts/tfstate.py · dockerimports.py (+ k8simports.py) | The user wants to draw what is ACTUALLY running / deployed — pipe terraform show -json (deployed state), docker inspect $(docker ps -q) (live containers), or kubectl get all,ing,cm,secret,pvc -o json (live cluster, via k8simports) and get the real topology with the same official icons. See references/live-infra.md |
scripts/drawiodiff.py | The user wants to compare / diff two diagrams or two snapshots ("what changed", infra drift) — drawiodiff.py old.drawio new.drawio -o diff.json emits a colour-coded graph (added=green, removed=red, changed=orange, same=grey) for autolayout. Matches by cell id (importer/live-snapshot output) or --by-label (hand-drawn) |
scripts/timelapse.py | The user wants an architecture time-lapse / to see how a codebase's structure evolved over git history — timelapse.py <dir> --importer pyimports re-runs an importer at each sampled commit and assembles a self-contained HTML player (embedded frames, play/step controls). Best on a package with real import edges (point <dir> at the module root) |
scripts/explain.py | The user wants to describe / document / summarize an existing .drawio in words (reverse of generating one) — explain.py diagram.drawio emits structured Markdown: components grouped by container/tier, relations (A —label→ B), per-page sections for multi-page/C4. Good for a README/PR summary or a text-only read-out |
scripts/drawio2pptx.py | The user wants a PowerPoint deck / slides from a diagram — drawio2pptx.py diagram.drawio -o deck.pptx puts each page on its own 16:9 slide (page name as title), so a multi-page C4 model becomes a ready-to-present deck. Needs python-pptx (pip install python-pptx) + the draw.io CLI |
scripts/drawiohtml.py | The user wants a shareable interactive viewer for a diagram (pan / zoom / search, no draw.io needed) — drawiohtml.py diagram.drawio -o viewer.html inlines every page's SVG into ONE self-contained HTML with page tabs, drag-pan, wheel-zoom, node search (Enter cycles + centres matches) and working drill-down links (a C4 model's data:page/id links switch tabs). No server, no external requests — send the file to anyone |
scripts/svgflow.py | The user wants an animated / "flowing" diagram (data-flow, moving edges) — svgflow.py diagram.drawio -o flow.svg exports to SVG and makes every edge a marching-ants animation (dashes travel along the arrows). Self-contained looping .svg that renders on GitHub / any browser; --speed / --dash / --reverse |
scripts/drawio2mermaid.py | The user wants to convert a .drawio into Mermaid text (diagrams-as-code for a Markdown file that GitHub renders) — drawio2mermaid.py diagram.drawio emits a flowchart (containers → subgraphs, edge labels kept, cylinder/rhombus shapes mapped); --fenced wraps in ```mermaid, multi-page → one graph per page. Structural only (styling/icons don't survive) |
scripts/sqlerd.py | The user wants an ER diagram from SQL DDL — parses CREATE TABLE statements into per-table nodes (columns with PK/FK markers) and crow's-foot FK edges for autolayout |
scripts/ciimports.py | The user wants a CI pipeline diagram (GitHub Actions workflows or GitLab CI) — ciimports.py <repo-root> reads .github/workflows/*.yml + .gitlab-ci.yml and emits jobs (runner, matrix size, reusable-workflow calls), needs: dependency edges, per-workflow trigger nodes, and stage/workflow containers for autolayout. Needs PyYAML |
scripts/openapiimports.py | The user wants an API diagram from an OpenAPI / Swagger spec — openapiimports.py spec.yaml maps each operation to a node coloured by HTTP method (GET blue, POST green, PUT/PATCH orange, DELETE red) plus one node per component schema, with edges from operations to the schemas they use and between nested schemas. --group boxes by tag, --no-schemas shows just the endpoint surface; feeds autolayout |
scripts/heatmap.py | The user wants to colour an existing .drawio by data (a cost / latency / traffic / error-rate heat map) — heatmap.py diagram.drawio -m metrics.csv matches each metric (CSV key,value or JSON {key:value}) to a node by id or label and recolours it along a gradient (`--palette heat |
scripts/seqlayout.py | The user wants a sequence diagram — describe participants + messages as JSON and the script computes all lifeline/activation/arrow geometry deterministically (no hand-placed coordinates, no Graphviz needed) |
scripts/c4.py | The user wants a C4 model (System Context / Container / Component) — levels JSON in, one multi-page .drawio out with official C4 shapes/colors and click-to-drill-down links between levels |
scripts/relabel.py | The user wants a language variant or bulk text swap of an existing .drawio (e.g. an EN diagram re-labelled in Chinese for a bilingual README) — relabel.py diagram.drawio --extract -o labels.json dumps every label as an identity JSON map; translate the values (keep the keys), then relabel.py diagram.drawio --map labels.json -o diagram_cn.drawio swaps them with layout/styles/ids untouched |
scripts/restyle.py | The user wants to re-theme an EXISTING .drawio ("make this dark", "apply my corporate style to this diagram") — restyle.py diagram.drawio --preset <name> remaps every vertex fill/stroke to the preset palette by hue, applies font/extras (dark fontColor, edge color, background), and leaves layout, shapes, and edge routing untouched. Presets resolve like Step 0 (user dir, then built-ins) |
scripts/validate.py | You generated a .drawio (especially via autolayout or for a large hand-placed diagram) and want a fast deterministic structural lint (dangling edges, dup/reserved ids, broken parents, overlaps) before the |