Ask an LLM to describe a system and it’ll nail the words — “the web app calls the search API, which checks the cache before hitting the index.” Ask it to draw that system and you usually get a mess: overlapping labels, lines slicing through boxes, text that doesn’t fit its container. Diagram generation has been the part of “draw me an architecture diagram” that still needed a human to clean up afterward.
open-diagram, a new open-source Python library from Luke Deasy, closes that gap by treating diagram layout as something that can be verified — not just rendered.
The core idea: measure, place, check #
Instead of hand-tuning pixel positions, you describe panels, tiles, lines, and groups in a short Python script (or JSON, or an existing Mermaid flowchart):
from open_diagram import Diagram, Panel, Tile
d = Diagram("How a search request is answered", tag="EXAMPLE")
app = d.add(Panel("Web app", ["Search box", "Results page", "Filters"], footer="Owner: Web team"))
api = d.right_of(app, Panel("Search API", [Tile("Checks access"), Tile("Caches results", status="building")],
footer="Owner: Platform team"), align="center")
index = d.right_of(api, Panel("Search index", ["Product text", Tile("Spelling fixes", status="planned")],
status="planned"), align="center")
d.link(app, api)
d.link(api, index, kind="planned", label="new")
d.save("quickstart") # writes quickstart.svg and quickstart.png
open-diagram measures every label directly from the font’s own spacing and kerning, so boxes fit their words exactly. Then it checks the result: if two panels sit too close together or a line crosses through a panel it shouldn’t, save() prints the exact problem by name and raises a LayoutError with the full list — for example:
'Storage' and 'Recommendations' are only 9px apart (minimum 16) or
line 'Where videos come from' -> 'Storage' crosses 'Processing'; route it with via_x/via_y, move a block, or pass cross_ok=True
That’s the key design decision: a diagram tool built for agents needs to tell the agent what’s wrong, not just produce something that looks plausible. An agent can read the error, adjust the script, and retry — the same iterate-until-correct loop it already uses for code and tests.
Built for AI agents specifically #
The README is explicit that this is meant to be written by an LLM as much as by a person. Output is SVG (shapes, not font-dependent — renders identically in a browser, PowerPoint, Keynote, or Figma with or without the font installed) plus a PNG rendered via headless Chrome/Chromium/Edge.
It supports several input formats so an agent (or a pipeline) can pick whichever is easiest to generate:
- Python script with a
build()function returning aDiagram - JSON — a plain-data description any language or agent can emit without touching Python
- Mermaid flowcharts (
.mmd) — re-laid out with the same measuring and collision checks, including subgraphs becoming shaded groups and dotted edges (-.->) becoming “planned” connections
A CLI ties it together:
open-diagram draw plan.json # writes plan.svg/.png, exits 1 on layout problems
open-diagram check docs/*.json # validates without writing files — good for CI
open-diagram describe plan.json # prints what the picture says, in plain words
That describe command is a nice touch for agent workflows: it returns a plain-text summary of every block, its tiles and states, every link and its label — the same text that’s embedded in the SVG’s accessibility description. An agent can diff that description against the original request to self-check without even looking at the rendered image.
Status tracking across a diagram #
Panels and tiles carry a status (Live, Being built, In trial, Planned, Retiring by default, fully customizable via Theme). You can update all the statuses across a diagram from one small file:
{"Fraud checks": "live", "Parcel lockers": "building"}
Names match panel titles, ids, or tile labels — so when something ships, you change one word and every diagram that references it updates. There’s also a bundled GitHub Action that redraws diagrams on every push and fails CI if a layout problem appears, which makes architecture diagrams something that can live in a repo and stay accurate instead of rotting in a wiki.
MCP server and Agent Skills #
For agent integration specifically, open-diagram ships:
- An MCP server (
open-diagram-mcp) — installable in one line for Claude Code (claude mcp add open-diagram -- uvx --python 3.12 --from "open-diagram[mcp]" open-diagram-mcp) or configured in Claude Desktop / Cursor. It exposesformat_guide,check,draw, anddescribeas callable actions, and writes files only inside one designated output folder. - An Agent Skill folder (
skills/open-diagram/) that can be copied straight into~/.claude/skills/— instructions for planning columns, writing the script, running it, fixing named problems, and reviewing the PNG before responding. - A cloud-icons skill with pre-mapped AWS/Azure/GCP service icons (30 services each, pinned to fixed versions) so an agent can drop real provider icons into a diagram without hunting down SVGs manually.
Worth trying if #
You’re already asking agents to draw system diagrams — onboarding docs, architecture reviews, release pipelines — and getting back something that needs manual fixing before it’s presentable. open-diagram’s bet is that layout correctness should be checkable the same way code correctness is: with a clear pass/fail and a named reason for failure. That’s a genuinely useful primitive for agent-authored documentation, and the MCP + Agent Skill packaging means it slots into an existing Claude Code or Cursor workflow with minimal setup.
pip install open-diagram
MIT licensed, 235 stars and counting as of this writing.