How agents365-ai/drawio-skill works
1. What this repo is
- This is a tooling/skill repository, not a traditional application.
- Its core product is a single Agent Skills package (skills/drawio-skill/SKILL.md) that teaches AI agents to generate and refine draw.io diagrams from natural language or from source code structure.
2. Primary boundary: the skill package
- The main runtime boundary is the skills/drawio-skill/ folder.
- SKILL.md is the entry contract for agents.
- Everything else in the repo supports that skill: reference docs, helper scripts, style data, shape indexes, tests, and GitHub Pages docs.
3. End-to-end diagram generation flow
- User prompt or codebase description enters the skill.
- The skill plans the diagram, emits draw.io XML, then exports via the native draw.io desktop CLI to raster/vector formats such as PNG, SVG, PDF, and JPG.
- It then performs a visual self-check against the rendered PNG and can auto-fix issues before presenting the result back to the user.
- The repo’s architecture is therefore a pipeline: intent → layout/design → draw.io XML → render/export → validation/self-check → iterative refinement.
4. Codebase visualization subsystem
- A major feature is turning source trees into structure diagrams.
- The extractors in skills/drawio-skill/scripts/ cover:
- pyimports.py
- jsimports.py
- goimports.py
- rustimports.py
- pyclasses.py
- These produce graph data, which is then passed to autolayout.py to generate an editable .drawio diagram.
- This forms a separate input path from the natural-language diagram flow: source code → import/class graph → auto-layout → draw.io.
5. Layout and graph-processing boundary
- autolayout.py is the bridge between abstract graph data and visual diagram geometry.
- The repo explicitly depends on Graphviz for placement and routing when doing larger code-structure diagrams.
- The layout subsystem also supports:
- transitive reduction,
- grouped/nested containers,
- cleaner orthogonal routing around nodes.
- This is the key “algorithmic” layer of the repo.
6. Shape and icon resolution subsystem
- shapesearch.py resolves exact official draw.io shapes from a large local index (skills/drawio-skill/data/shape-index.json.gz).
- aiicons.py maps AI/LLM brand names to logo styles using lobe-icons.json.
- These two scripts are important because they prevent diagrams from degrading into generic boxes or guessed shape names.
- Architecturally, this is a local lookup layer that enriches diagram nodes with vendor-specific visual identity.
7. Style system
- The repo includes a style-presets subsystem under skills/drawio-skill/styles/.
- Built-in presets live in styles/built-in/ and are backed by schema.json.
- The skill can also learn styles from an existing .drawio file or image, which means style extraction is a separate concern from layout and content generation.
- This layer controls colors, fonts, edge styles, and shape appearance.
8. Validation and self-healing
- validate.py provides deterministic linting for generated .drawio files.
- The README describes a visual feedback loop where rendered PNGs are inspected for issues like overlaps, clipped labels, or stacked edges.
- This gives the repo a two-step quality gate:
1. structural validation on the XML/graph artifact,
2. visual validation on the rendered image.
- That separation is a key architectural boundary.
9. Supporting utilities
- encode_drawio_url.py supports creating diagrams.net links or encoded diagram payloads.
- Language-specific helpers like goimports.py, jsimports.py, pyimports.py, and rustimports.py are focused extractors rather than shared libraries.
- repair_png.py indicates the repo also deals with render artifacts, not just source diagrams.
10. Data and reference assets
- skills/drawio-skill/data/ contains the large shape index and AI-logo metadata.
- skills/drawio-skill/references/ contains domain knowledge for autolayout, diagram types, shapes, presets, extraction, and troubleshooting.
- assets/ contains example diagrams and visual documentation used by the README and docs, which helps illustrate expected output but is not part of the runtime pipeline.
11. Documentation and distribution
- docs/ is the published documentation site, including installation, usage, comparisons, and style preset guides.
- The repo is designed for distribution through agent ecosystems and plugin marketplaces, plus manual install.
- That means the repo serves both as runtime skill payload and as documentation artifact.
12. Tests and CI
- tests/test_scripts.py indicates the automated tests focus on the helper scripts rather than a full application stack.
- GitHub Actions workflows handle repo-level verification and a sync process for a broader 365-skills ecosystem.
- CI is therefore centered on script correctness and packaging integrity, not deployment of a service.
13. External dependencies that matter architecturally
- draw.io desktop CLI is the essential render/export dependency.
- Graphviz is required for the auto-layout path.
- Node appears only for the optional npx installer, not for the skill logic itself.
- The repo also references CDN-backed icon rendering for some AI logos when not embedded, which affects offline/online behavior.
14. How to diagram the architecture
- A good architecture diagram should show three main lanes:
- Agent/skill interface: prompt in, diagram intent out.
- Content generation and enrichment: diagram planning, shape lookup, style selection, codebase extraction, graph layout.
- Validation/rendering: draw.io XML generation, CLI export, PNG self-check, iterative fix loop.
- The boundaries to emphasize are:
- natural language vs codebase-derived input,
- abstract graph data vs rendered diagram,
- deterministic validation vs visual feedback refinement.
Main entry points: autolayout.py Autolayout · validate.py Validator · pyimports.py Python imports · jsimports.py JS imports
Components 25
Skill package
Core agent skill boundary and diagram generation pipeline.
- SKILL.md · Primary contract for agents and the main entry point for diagram generation.
skills/drawio-skill/SKILL.md - Diagram plan · Turns user intent or source context into a diagram plan and layout strategy.
- draw.io XML · Intermediate editable diagram representation produced by the skill.
Graph & layout
Codebase extraction, graph processing, and auto-layout.
- Code extractors · Language-specific import and class extraction path for turning codebases into graph data.
- Python imports · Parses Python import structure for graph generation.
skills/drawio-skill/scripts/pyimports.py - JS imports · Parses JavaScript and TypeScript import structure for graph generation.
skills/drawio-skill/scripts/jsimports.py - Go imports · Parses Go import structure for graph generation.
skills/drawio-skill/scripts/goimports.py - Rust imports · Parses Rust module and import structure for graph generation.
skills/drawio-skill/scripts/rustimports.py - Python classes · Extracts Python class structure for codebase diagrams.
skills/drawio-skill/scripts/pyclasses.py - Autolayout · Bridges abstract graph data to diagram geometry and routing, including grouped layouts and transitive reduction.
skills/drawio-skill/scripts/autolayout.py - Graphviz · Placement and routing engine used for larger structure diagrams.
Shape & style
Shape lookup, icon mapping, and style preset resolution.
- Shape search · Resolves exact official draw.io shapes from the local shape index.
skills/drawio-skill/scripts/shapesearch.py - AI icons · Maps AI and LLM brand names to icon styles and logo metadata.
skills/drawio-skill/scripts/aiicons.py - Style presets · Built-in and learned style presets for colors, fonts, edges, and appearance.
skills/drawio-skill/styles/schema.json - Shape index · Large local catalog of draw.io shapes used to keep diagrams precise.
skills/drawio-skill/data/shape-index.json.gz
Validation & export
Render/export, structural checks, and visual repair loop.
- Validator · Deterministic checks for generated draw.io files.
skills/drawio-skill/scripts/validate.py - PNG repair · Repairs or adjusts rendered image artifacts used in the feedback loop.
skills/drawio-skill/scripts/repair_png.py - draw.io CLI · Native desktop CLI dependency for rendering and exporting diagrams.
- Visual check · Inspects rendered PNGs for overlaps, clipping, and stacking issues before refinement.
- URL encode · Builds diagrams.net links or encoded diagram payloads.
skills/drawio-skill/scripts/encode_drawio_url.py
Docs & examples
Published documentation, references, and sample diagrams.
- References · Domain references for autolayout, diagram types, shapes, presets, extraction, and troubleshooting.
skills/drawio-skill/references/autolayout.md - Docs site · Installation, usage, style preset, and comparison documentation.
docs/index.html - Samples · Example diagrams and visual documentation assets.
assets/demo-layered.drawio
Automation
Tests and repository workflows.
- Script tests · Automated checks focused on helper scripts and packaging behavior.
tests/test_scripts.py - Workflows · GitHub Actions for tests and ecosystem sync.
.github/workflows/tests.yml
Connections 30
- SKILL.md → Diagram plan: accepts intent · The skill entry receives natural language or codebase-driven requests and starts planning.
- Diagram plan → Shape search: resolves shapes · Planning can request exact shapes for nodes.
- Diagram plan → AI icons: resolves icons · Planning can enrich AI-related nodes with branded icons.
- Diagram plan → Style presets: applies style · Style selection shapes colors, fonts, and edge appearance.
- Diagram plan → draw.io XML: emits XML · The plan is materialized into editable draw.io XML.
- Code extractors → Python imports: python · Python import graphs are extracted from source trees.
- Code extractors → JS imports: javascript · JavaScript import graphs are extracted from source trees.
- Code extractors → Go imports: go · Go import graphs are extracted from source trees.
- Code extractors → Rust imports: rust · Rust import graphs are extracted from source trees.
- Code extractors → Python classes: classes · Python class structure can be extracted for code diagrams.
- Python imports → Autolayout: graph data · Extractor output becomes layout-ready graph data.
- JS imports → Autolayout: graph data · Extractor output becomes layout-ready graph data.
- Go imports → Autolayout: graph data · Extractor output becomes layout-ready graph data.
- Rust imports → Autolayout: graph data · Extractor output becomes layout-ready graph data.
- Python classes → Autolayout: graph data · Extractor output becomes layout-ready graph data.
- Autolayout → Graphviz: routes via · Graphviz is used for placement and routing on larger diagrams.
- Autolayout → draw.io XML: lays out · Layout geometry is converted into final diagram XML.
- Shape search → Shape index: looks up · Exact official shapes are resolved from the local index.
- AI icons → Shape index: consults · Icon mapping is backed by local metadata and shape references.
- Style presets → References: informed by · Preset behavior is documented and described in references.
- draw.io XML → Validator: linted by · Generated XML is structurally validated before export.
- Validator → draw.io CLI: exports via · Validated diagrams are rendered and exported with the native CLI.
- draw.io CLI → Visual check: renders PNG · Rendered PNG output feeds the visual self-check loop.
- Visual check → PNG repair: fixes artifacts · Visual issues can trigger image repair or refinement.
- PNG repair → draw.io XML: iterates · Detected problems can send the workflow back for diagram refinement.
- URL encode → draw.io XML: encodes · Supports shareable encoded diagram payloads and links.
- Docs site → References: publishes guides · Documentation site presents installation, usage, and style guidance.
- Samples → Docs site: illustrates · Sample diagrams support documentation and visual examples.
- Script tests → Validator: checks · Tests focus on helper script behavior and expected outputs.
- Workflows → Script tests: runs · CI workflows execute repository checks and sync automation.