# yuhwa — diagram language reference (for AI tools) yuhwa is a text diagram language that renders to a self-contained SVG. One statement per line. `//` at line start or after a space starts a comment, so URLs in labels stay text. There is no `#` comment. Workflow: write the source, run `yuhwa check file.yu --json` (or read the `diagnostics` of `render`), fix every error and warning, then render. Done when it reports 0 diagnostics; they name the fix ("did you mean ..."). ## Example ```yuhwa title: Checkout direction: right .svc [blue] .store [color: amber, shape: cylinder] user "Customer" [shape: circle, color: purple] group core "Core services" [blue] { api "API Gateway" .svc [sub: "auth + rate limit"] orders "Orders" .svc } db "Postgres" .store user -> api -> orders orders -> db: SQL orders --> queue "Events" [shape: hexagon]: publish [flow: true] ``` ## Statements - Setting: `key: value` at top level. Keys: title, subtitle, theme, accent, direction (right|down|left|up), curve (smooth|orthogonal|straight), gap, rank-gap, max-width, font, font-size, background, padding, shadow, radius, stroke-width, shape, grid, panels (row|column|grid|wrap), panel-gap, wrap, edge-color, edge-width, legend, footer. - Node: `id "Label" .class [props]`; label, classes and props are optional. Ids: letters (any script), digits, `_`, inner `-`; start with a letter or `_`. The label defaults to the id; multi-word labels need quotes. `\n` breaks a line. Several nodes per line: `a "A", b "B"`. - Edge: `a -> b`, chains `a -> b -> c`, fan-out `a, b -> c, d`. Nodes may be declared inline: `web "Web" -> db "DB" [shape: cylinder]`. The edge's label, classes and props go after a colon: `a -> b: label .cls [props]`. Quote a label containing `:` or `[`. - Arrows: `->` solid, `-->` dashed, `..>` dotted, `=>` thick. A leading `<` adds a start head (`<->`, `<-->`, `<=>`); `a <- b` is `b -> a`. Without `>` there is no head: `--` / `-` solid, `..` dotted, `==` thick. - Class: `.name [props]` defines, `.name` after a node, edge or group applies. `.primary .svc [bold]` builds on other classes. - Variable: `$name: value`, then `$name` or `${name}` in later lines (labels, props, settings, panel bodies). `$$` is a literal `$`. - Component: `def name(a, b = "default") {` ... `}` at top level, the body uses `$a`. `name(x, "Label, with comma", b: y)` stamps it out. Use one per repeated shape of nodes instead of copying lines. - Group: `group id "Label" .class [props] { ... }`, may nest. `group "Label" {` gets a slug id. Edges connect nodes and panel ids (`plan -> sales`), never groups. - Props: `[key: value, key: "a, b", flag]`; a bare flag means true, a bare value names its key: `[cylinder, amber, dashed]`. - Props on their own lines: a `key: value` line indented under a node, edge, class or group line belongs to it. Prefer this over long `[...]` lists: ``` api "Orders API" .svc sub: Kotlin, 3 pods api -> db: SQL style: dashed ``` - Card: a node line ending in `{` takes body lines until a line that is only `}`. It draws a header (label, `meta` right, `caps` small caps), a divider and a monospace body. `font-size`/`font-weight`/`text` style the header; `body-size`, `body-weight`, `body-color` and `line-height` style the body. ## Values - `color` sets fill, border and text in one: `[blue]` or `[color: blue]`. Palette: slate, gray, red, orange, amber, lime, green, teal, cyan, blue, indigo, purple, pink; shades like blue-600; any CSS colour. The colour props (color, fill, stroke, text, sub-color, body-color, label-color, label-bg, background, edge-color) take the same values and colour one part. - Shapes: rounded, box, pill, circle, ellipse, diamond, hexagon, cylinder, parallelogram, document, note, text. - Line styles: solid, dashed, dotted. Heads: arrow, open, dot, diamond, bar, none. Sides (`exit`, `enter`): top, right, bottom, left, auto. - Themes: paper, midnight, blueprint, mono, pastel, terminal, sepia, frost, contrast, ocean, ember, dusk. Define one with `theme brand [base: midnight, accent: orange]` or `theme brand {` and one `key: value` per line, then `theme: brand`. Keys: base, dark, background, font, font-size, node-fill, node-stroke, node-text, node-sub, group-fill, group-stroke, group-text, group-border, edge-color, edge-text, label-bg, title-color, accent, radius, stroke-width, edge-width, shadow, grid. ## Props - Node: shape, color, fill, stroke, text, font, font-size, font-weight, italic, sub, sub-color, icon, border, stroke-width, border-style, dashed, dotted, radius, bold, shadow, opacity, width, height, link, tooltip, meta, caps, mono, body-size, body-color, body-weight, line-height, max-width, below, above, right-of, left-of, rank, frame. - Edge: style, width, color, stroke, curve, head, tail, flow, animate, opacity, text, font, font-size, font-weight, italic, label-color, label-bg, dashed, dotted, thick, exit, from-side, enter, to-side, constraint, caption, rotate, length. - Group: color, fill, stroke, text, font, font-size, font-weight, italic, border-style, dashed, dotted, meta, caps. `sub` is a second, smaller line; `icon` an emoji before the label; `link` makes a node clickable; `flow: true` animates an edge; `constraint: false` keeps an edge out of the layout; `shape: text` is an annotation without a box. `below: `, `above`, `right-of`, `left-of` and `rank` place a node next to another node without drawing an edge; do not use invisible edges for that. The `max-width: ` setting wraps the ranks of a right or left diagram into rows that fit that width. `frame: ` draws window chrome: browser, window, terminal. ## Card bodies ```yuhwa theme: terminal checks "checks" [meta: 42s, caps: true] { ✓ typecheck || [[green: pass]] *skipped: e2e* --- bars: 3 5 4 6 8 | type | bump | |------|-------| | feat | minor | } ``` Lines: text, `left || right` (right-aligned part), `---` divider, empty gap. Rows: `bars [color]: 3 5 4 8 6`, `spark [color]: 3 5 4 8 6`, `progress [color]: 72% Label`, `stat [color]: 99.9% uptime | 42ms p95`, `| a | b |`; a `|---|` row makes a table header. Inline markup (in every text: labels, `sub`, edge labels, group and panel titles, `title`, `subtitle`, `footer`): `**bold**`, `*muted*`, `~~strike~~`, ``code``, `[[chip]]` / `[[green: chip]]`, `{red: text}`, and styled spans `{color: red, size: 18, weight: 700, italic | text}` (short: `{red, bold | text}`). Text props on every element (node, edge label, group and panel title): `text`, `font-size`, `font-weight`, `italic`; a panel's `font-size` scales all its text. `legend: .svc Service | --> async | red Deprecated` and `footer: a | b` draw strips under the diagram; a legend item starts with a class, colour or arrow. ## Panels: more diagram types in one file A panel is a block `kind id "Title" [props] { ... }` next to the graph; its plugin reads the body line by line. `panels:` arranges graph and panels, `panel-gap` spaces them. A file may hold only panels. ```yuhwa panels: row web -> api -> db sequence login "Sign in" [numbered] { actor user "Customer" [purple] user -> web: open /login web -> api: POST /login api --> web: 200 + cookie } chart p95 "Latency p95" [type: column, unit: ms] { checkout: 120 search [green]: 48 } ``` Every panel takes `color`, `theme`, `background`, `fill`, `border`, `stroke`, `text`, `font`, `font-size`, `font-weight`, `italic`, `border-width`, `border-style`, `radius`, `shadow`, `frame`, `edge-color`, `edge-width`, `width`, `height`; `frame: false` drops the box. Body lines take `[props]` before the colon or at the end of the line. - `sequence`: `participant|actor id "Label" [color]` (`participant a, b, c` fixes the order), `a -> b: msg` (`-->` reply, `..>` dotted, `=>` thick, `a -> a` self call), `note a, b: text`, `--- section ---`. A message takes edge props at its end: `a -> b: retry [red, style: dotted]`. Header: `numbered`, `lifeline: `, `lifeline-style: dashed|dotted|solid`. - `timeline`: `when [color]: title`, then indented `- detail` lines. The colon needs a space after it, so `12:30: deploy` works. Header: `direction: right|down`. - `chart`: `label [color]: number` per line; `unit` is appended to values. Header: `type: bar|column|line|pie|donut`, `unit: …`. - `git`: `commit ["msg"] [tag: v1, id: a1b2, color, highlight|reverse]`, `branch name [from ] [color, order: 2, label: "…"]` (creates and checks out), `checkout name` / `switch name`, `merge name ["msg"] [tag: v2]`, `cherry-pick `, `tag v1`. Starts on `main` (`[main: trunk]` renames it); `order` moves a lane. Header: `direction: right|down`. - `mindmap`: indentation is the tree, the first line the root; `-` / `*` bullets are optional. A trailing `[color]` tints a subtree, `[shape: box|pill|plain|circle]` changes one node, `[text: red, font-size: 18, font-weight: 700]` styles its text. Header: `layout: both|vertical|right|left|down|up`, `colors: branches|mono`. - `gantt`: `id "Label" [color, done, active, crit, milestone, progress: 60%, owner: ana]: start, length`. start: a date or `after a b` (empty: after the task above); length: 3h, 5d, 2w or an end date. `--- Section [color] ---` groups rows. Header: `today: …`, `scale: day|week|month`, `bars: soft|solid|outline|thin`, `labels: left|bar`, `notes: length|dates|none`, `density: compact|normal|loose`, `rows: striped|plain`, `grid: show|none`, `summary: show|hide`, `weekends: hide|show`, `arrows: elbow|curved|hide`. - `quadrant`: `x-axis Low -> High`, `y-axis Low -> High`, `q1..q4 [color]: label` (q1 top right, counter-clockwise), points `Name [color]: x, y` from 0 to 1. - `kanban`: a line at the outer indent is a column `Todo [color, limit: 3]`, `- text [owner: ana, ticket: X-1, priority: low|medium|high, color]` a card, deeper lines its details. - `treeview`: indentation is the tree (several top-level entries are fine); `-` bullets and the `├──` / `│` prefixes of `tree` output are optional; `...` stands for more files. A folder has children, ends in `/` or says `[folder]`. `name: note` or `name # note` adds a note. Trailing props: a colour, `icon: folder|folder-open|file|code|doc|image|config|lock|package|git|database|test|font|media|terminal|yuhwa|`, `badge: text`, `size: text`, `collapsed`, `highlight`, `dim`, `added|modified|deleted|renamed|ignored`. `match [props]` gives every matching entry those props (`*`, `**`, `?`, `{a,b}`; a trailing `/` matches folders only). Header: `icons: color|mono|emoji|none`, `lines: solid|rounded|dashed|dotted|none`, `sort: none|name|folders`, `notes: column|inline`, `chevrons`, `rows: plain|striped`, `spacing: compact|normal|relaxed`, `slashes: true|false`, `compact`, `counts: collapsed|all|none`, `marks: letter|dot|none`, `rollup: true|false`, `depth: N`, `indent: N`, `folder-color: `, `line-color: `, `highlight-color: `, `badge-color: `, `note-color: `, `strike-color: `, `strike-width: N`. ## Imports `import "./shared.yu"` at top level pulls in another file's classes, nodes, groups, edges, panels, variables and components; paths resolve against the importing file, and the importing file wins on conflicts. `import { api, .svc as .service, $brand } from "./x.yu"` takes only those. A file with `export api, .svc` (or `export` before a declaration: `export def ...`, `export $x: 1`, `export theme brand {`) offers only those. Custom themes come along with every import. Settings stay in their file unless written `export theme: midnight`; the importer's own setting wins. In the browser pass `render(src, { resolve: (path) => source | undefined })`. ## Layout Auto-layout by default: pick `direction`, cluster with groups. Manual positions live in an optional `layout { }` block at the end, written by the visual editor; do not invent one unless asked. ```yuhwa a -> b layout { a at 40 40 b at 260 40 size 160 64 a->b via 150 0 ports right left } ``` `panel at X Y` pins a panel. `panel:part D` (`panel:part DX DY` for free parts) nudges one part: - `sequence`: a participant id (`p-` when the id looks like a row) moves its lifeline and the ones after it; `m` (message), `note`, `d` (divider) add room above that row. - `timeline`: an event by its one-word `when`, else `e`, adds room before it. - `chart`: `size DX DY` grows the plot. - `git`: a branch name (its lane), a commit (id, first tag or `c`; a branch name wins), `^1` / `^2` (the bend from its first / second parent), `^pick`. - `mindmap`: a node by its one-word text, else `n`, adds room before it among its siblings. - `gantt`: a task id adds room above its row. - `quadrant`: a point by its name (lower case, `-` for spaces), else `p`, moves by `DX DY`; `size DX DY` grows the plot. - `kanban`: a column by its title (lower case, `-` for spaces), else `c`, adds room before it. ## JSON and Mermaid input Every API and the CLI accept JSON; non-structural keys are props. ```json { "title": "Checkout", "direction": "right", "classes": { "svc": { "color": "blue" } }, "groups": [{ "id": "core", "label": "Core" }], "nodes": [{ "id": "api", "label": "API", "group": "core", "class": "svc" }, { "id": "db", "label": "DB", "shape": "cylinder" }], "edges": [{ "from": "api", "to": "db", "label": "SQL", "arrow": "-->" }] } ``` Mermaid input renders as is: flowcharts become a graph, most other types a panel. `yuhwa convert file.mmd` prints the yuhwa source. ## Common mistakes - `Web Server -> db`: give multi-word labels an id: `web "Web Server" -> db`. - `a -> b [dashed]` styles node b. Edge props go after a colon: `a -> b: [dashed]`. - `a -> b "calls"` renames b. Edge labels: `a -> b: calls`. - Mermaid habits (`%%`, `-->|label|`, `subgraph ... end`, `A[Label]`) are `//`, `a -> b: label`, `group id "Label" { }`, `a "Label"` here. - A node lives in one group; declaring it in a second one moves it. - A `layout { }` line for a node that no longer exists warns: delete it. ## Tips Keep labels short and put detail in `sub`. One colour per kind of thing, defined once as a class. 5 to 20 nodes read best; split larger systems.