The problem: asking an AI for an architecture diagram usually takes several rounds of corrections (“that’s a database”, “move the cache down”), and every round re-sends the whole diagram.

The code

The author writes only the structure, in D2:

users: "End Users"
web_tier: "Web Tier" {
  cdn: "CDN"
  lb: "Load Balancer"
}
app_tier: "App Tier" {
  api: "API service"
  worker: "Background Worker"
}
data_tier: "Data Tier" {
  db: "orders-db"
  cache: "Session Cache"
}
users -> web_tier.cdn: "https"
web_tier.cdn -> web_tier.lb: "origin"
web_tier.lb -> app_tier.api: "https"
app_tier.api -> data_tier.db: "sql"
app_tier.api -> data_tier.cache: "cache"

Rune recognizes each box and appends the styling as ordinary D2, for example:

data_tier.db.style.fill: "#DBEAFE"
data_tier.db.style.stroke: "#2563EB"

How it works

  1. Parse the diagram into nodes, edges and groups.
  2. Classify every node into one of twelve roles from its label and icon, using plain rules. Each role has a tier: clients at the top, then gateways, compute, queues and caches, and datastores at the bottom.
  3. Enrich: roles become fills, strokes, icons and edge colors, appended to the source so it stays readable text.
  4. Render the enriched source to SVG with D2.
  5. Clean up: sanitize, then optimize, and cache the result.

On five reference diagrams, the styling Rune adds on its own is 3.9 to 5.7 times the size of what the author wrote, and none of it costs a model token. The full write-up, with the module map, is in the gist.

View the source

⌃