Skip to content

Syntax ​

A yuhwa file reads like notes: one thing per line, written the way you would say it. Start with arrows and add detail only where it helps.

yuhwa diagramyuhwa diagramEdit
yuhwa
web -> api -> db

Name things, label the edges and add a little colour:

yuhwa diagramyuhwa diagramEdit
yuhwa
web "Storefront" -> api "Orders API": place order
api -> db "Postgres" [cylinder, amber]: SQL

When a line gets long, put the props on their own lines below it:

Order pipelineOrder pipelineEdit
yuhwa
title: Order pipeline

api "Orders API"
  color: blue
  sub: Kotlin · 3 pods
  link: https://example.com/orders

db "Postgres" [cylinder, amber]

api -> db: SQL
  style: dashed

For a large diagram, name the look once with classes and variables, stamp out repeated parts with components, and split the file with imports.

// starts a comment at the start of a line or after a space, so the // in https://example.com stays text. There is no other comment syntax: a line starting with # is an error.

The statements:

  1. Settings
  2. Nodes
  3. Edges
  4. Classes, variables and components
  5. Groups
  6. Props
  7. The layout block

Settings ​

A setting is key: value on its own line, usually at the top of the file.

settingvaluesdefault
titletext, with inline markupnone
subtitlemuted line under the titlenone
footera | b | c: a strip under the diagram, items spread edge to edge (plugin)none
themepaper midnight blueprint mono pastel terminal sepia frost contrast ocean ember dusk, or your own (auto in the browser)paper
directionright down left up; Mermaid's LR RL TB TD BT work tooright
curvesmooth orthogonal straightsmooth
gapspace between nodes in a rank, px36
rank-gapspace between ranks, px72 (96 with groups)
max-widthfit the diagram into this width, px: ranks wrap into rows (more)none
paddingspace around the diagram, px24
shapedefault node shaperounded
fontfont family or fallback list, e.g. Inter, Lora, Georgia, serif (fonts)theme font
font-sizepxtheme size
backgroundcolour, or none for transparenttheme background
gridtrue, false or a colourtheme default
shadowtrue / falsetheme default
radiusnode corner radius, pxtheme default
stroke-widthnode border width, pxtheme default
edge-colordefault colour of every edge, sequence message and Gantt arrowtheme edge colour
edge-widththeir default width, pxtheme default
accentcolour of `code`, chips and bars in cardstheme accent
panelsrow column grid: how panels line up next to the graphrow
panel-gapspace between the graph and panels, px48
wrapwrap node labels wider than this, pxnone
legend.class Label | color Label | --> Label: a key under the diagram (plugin)none

An unknown setting gives a warning that suggests the closest known one (titel → title). The setting is kept, so typos stay visible.

Nodes ​

id ["Label"] [.class ...] [[props]]
yuhwa diagramyuhwa diagramEdit
yuhwa
web
api "API Gateway"
.store [amber]
db "Orders DB" .store [cylinder]
  • id is letters, digits, _ and -. It is what edges refer to.
  • The label defaults to the id. Labels use "double" or 'single' quotes. \n inside a label makes a line break.
  • Declaring the same id twice merges the props. The later value wins.

Several nodes can go on one line, separated by commas:

yuhwa diagramyuhwa diagramEdit
yuhwa
a "Alpha", b "Beta", c "Gamma" [green]

A node does not have to be declared. Using an id in an edge creates it.

Edges ​

a -> b [-> c ...] [: label] [.class ...] [[props]]
yuhwa diagramyuhwa diagramEdit
yuhwa
user -> web -> api
api -> db: SQL
api -> cache: read-through [dashed]
api -> audit: [flow]

Arrows ​

arrowlineheads
->solidat the end
-->dashedat the end
..>dottedat the end
=> ==>thickat the end
<->solidat both ends
-- -solidnone

Props can override all of these: style, width, head and tail.

Labels and props after a colon ​

Edge labels, classes and props always go after a colon. The colon keeps them apart from inline node declarations (see the next section).

yuhwa diagramyuhwa diagramEdit
yuhwa
a -> b: add item
.warn [red]
a -> b: "label: with a colon"
a -> b: retry .warn [width: 2]
a -> b: [dotted]

A label without quotes runs to the first class or [. Use quotes when the label contains :, [, . at the start of a word, or leading spaces.

Inline nodes ​

A label, classes or props written directly after an id in an edge declare that node, exactly like a node statement:

yuhwa diagramyuhwa diagramEdit
yuhwa
web "Web" [blue] -> api "API" -> db "DB" [cylinder]: SQL

Here [cylinder] belongs to db and SQL labels every edge on the line.

A quoted string after the last node without a colon is an error. The message shows the fix: (edge labels go after a colon: a -> b: "label").

In the same way, a -> b [dashed] dashes the border of b, not the edge. Write a -> b: [dashed], or put style: dashed on the next line. An edge-only prop on a node, like [thick], gives a warning that says so.

Chains and fan-out ​

a -> b -> c creates two edges. Commas fan out:

yuhwa diagramyuhwa diagramEdit
yuhwa
web, mobile -> api          // two edges
api -> users, orders, cart  // three edges

The label, classes and props after the colon apply to every edge created by the statement.

Repeated edges ​

Two edges between the same nodes are both drawn. In the layout block the second one is addressed as a->b#2.

Classes ​

A class is a named set of props.

yuhwa diagramyuhwa diagramEdit
yuhwa
.svc [blue, rounded]
.store [amber, cylinder]
.async [dashed, flow]

orders "Orders" .svc
db .store
orders -> queue: publish .async
  • A class can apply to nodes, edges and groups. Props that do not fit the target are ignored.
  • Several classes apply left to right. Props written on the element override all classes.
  • An unknown class gives a warning.

A class can build on other classes. The new class gets their props, then its own:

yuhwa diagramyuhwa diagramEdit
yuhwa
.svc [blue, rounded]
.primary .svc [bold, stroke-width: 2]
.legacy .svc [gray, dashed]

api "API" .primary
old "Old API" .legacy
api -> old

Variables ​

A variable holds a value you use in many places. Define it with $name: value, then write $name in labels, props, settings and panel bodies.

ShopShopEdit
yuhwa
$brand: violet
$db: "Postgres 16"
title: Shop
accent: $brand

.svc [$brand]
api "API" .svc -> orders-db "$db" [cylinder]
  • Define a variable before you use it. A later definition replaces the value for the lines after it.
  • Write ${name} when letters follow directly: ${id}_db.
  • $$ is a literal $. A $ before a digit stays as it is: "costs $5".
  • An unknown variable gives a warning and the text stays unchanged.

Components ​

A component stamps out the same lines many times. Define it with def, then call it like a function:

yuhwa diagramyuhwa diagramEdit
yuhwa
$db: Postgres
.svc [blue, rounded]
.store [amber, cylinder]

def service(id, label, lang = Go) {
  $id "$label" .svc [sub: $lang]
  ${id}_db "$db" .store
  $id -> ${id}_db
}

service(orders, "Orders")
service(payments, "Payments", Rust)
service(search, "Search", lang: Kotlin)
gateway "Gateway" -> orders, payments, search
  • Parameters are variables inside the body. name = value gives a default.
  • Arguments go by position or by name (lang: Rust). Quote an argument that holds a comma.
  • A body can hold nodes, edges, groups, cards and calls to other components.
  • File variables are fixed when the component is defined, so a component works the same after it is imported.
  • def is top-level only. Errors inside a call point at the call line.
  • The visual editor cannot edit a generated line in place. A prop you change there is added as a new line for that node.

Groups ​

group id ["Label"] [.class ...] [[props]] {
  members
}
yuhwa diagramyuhwa diagramEdit
yuhwa
group backend "Backend" [blue] {
  api "API"
  worker "Worker"
  group data "Data" {
    db [cylinder]
  }
}

group edge "Edge" { cdn, waf }
  • The id is optional: group "Order service" { gets the id order-service.
  • Nodes declared or referenced inside the braces become members.
  • Groups nest.
  • Edges can be written inside or outside a group. Where an edge is written does not change membership of nodes that are already in a group.
  • Edges can not point at a group.

Props ​

Props are a comma-separated list in square brackets:

[key: value, key: "quoted value", flag]

A key without a value means true. Values can be bare words, numbers, colours or quoted strings.

A bare value that only fits one key stands for that key:

writtenmeans
[blue][blue]
[cylinder][shape: cylinder]
[orthogonal][curve: orthogonal]
[dashed], [dotted]a dashed or dotted line or border
[thick]a line twice as wide (edges)

So db "Postgres" [cylinder, amber, bold] needs no keys at all.

One prop per line ​

Props can also go on their own lines, indented below the statement. This reads better than a long [...] list:

yuhwa diagramyuhwa diagramEdit
yuhwa
.svc
  color: blue
  shape: rounded

group payments "Payments" {
  color: green
  pay "Payment API" .svc
    sub: Rust
    tooltip: "charges, refunds, payouts"
  ledger [cylinder]
}

pay -> ledger: write
  style: dashed
  caption: append only
  • A key: value line indented deeper than a node, edge, class or group line belongs to that statement.
  • Inside a group, a key: value line at the members' indent belongs to the group.
  • The value runs to the end of the line, so commas need no quotes.
  • Both styles can be mixed. A line below wins over the same key in [...].
  • The visual editor keeps the style: it edits the prop line, and adds new props as lines too.

Colours ​

Any colour prop accepts:

  • a CSS colour: #2563eb, rgb(…), tomato
  • a palette name: blue, amber, … The theme picks a fitting shade.
  • a palette name with a shade: blue-600, slate-100 (50, 100 … 900, 950)

color ​

color sets fill, border and text colour together. It is the quickest way to colour something. Write it bare, [blue], or as [color: blue].

Palette names: slate gray red orange amber lime green tealcyan blue indigo purple pink. The theme picks shades that fit, so they look right in light and dark themes.

Any CSS colour works too, bare or with the key: [#e11d48], [#e11d4880], [rgb(225, 29, 72)], [hsl(350 80% 50%)], [tomato]. Yuhwa derives the fill, border and text from it.

tone is the old name of color and still works.

Node props ​

propvalues
shaperounded box pill circle ellipse diamond hexagon cylinder parallelogram document note text
colorpalette name or any CSS colour: fill, border and label in one
fillcolour
strokeborder colour
textlabel colour
subsecond, smaller line of text
sub-colorcolour of the sub line
iconemoji or short text shown before the label
border / stroke-widthborder width, px
border-stylesolid dashed dotted
dashedshorthand for border-style: dashed
radiuscorner radius, px
bold / italicflags
fontlabel font: sans serif mono or font names (quote a list: font: "Lora, serif")
font-size / font-weightnumbers
shadowtrue / false
opacity0 to 1
width / heightbox size, px
max-widthwrap the label at this width, px (overrides the wrap setting)
linkURL; the node becomes a link in the SVG. Only http(s), mailto, #anchor and relative links render
tooltiptext shown on hover
metamuted text at the top right of a card
capssmall-caps header label
monofalse sets a card body in the diagram font
body-size / body-weightcard body font size, px, and weight (cards)
body-colorcard body text colour; defaults to text
line-heightcard body row height as a multiple of body-size, default 1.75
framebrowser <url>, window <title> or terminal <path>: window chrome around a card (plugin)
below / abovenode id: place this node under or over that one (placement)
right-of / left-ofnode id: place this node to the right or left of that one
ranknode id: put this node in the same rank as that one

shape: text draws only the label, with no box. Use it for annotations.

Edge props ​

propvalues
stylesolid dashed dotted
widthline width, px
colorline and label colour: palette name or any CSS colour
strokeline colour only
curvesmooth orthogonal straight
headarrow open dot diamond bar none
tailsame values as head, for the start
flow / animateanimated dashes along the edge
opacity0 to 1
textlabel text colour (label-color works too)
fontlabel font: sans serif mono or font names
font-sizelabel font size, px
font-weightlabel weight: 400, 600, 700 ...
italicitalic label
label-bglabel background colour
exit / from-sidetop right bottom left
enter / to-sidetop right bottom left
constraintfalse keeps the edge from affecting the layout
lengthranks the edge spans, 1 to 12 (default 1): pushes the target further away
captionsmall muted text under the label
rotatetrue turns the label to run vertically

The curve: setting picks the default for the whole diagram. An edge's own curve overrides it, so one diagram can mix all three. A class works too:

yuhwa diagramyuhwa diagramEdit
yuhwa
direction: right
curve: smooth

.wire [orthogonal, dashed]

api "API" -> db "DB" [shape: cylinder]: [orthogonal]
api -> cache "Cache": [straight]
api -> queue "Queue": .wire
queue -> worker "Worker"

Use constraint: false for feedback edges that would pull the layout apart.

Group props ​

propvalues
colorpalette name or any CSS colour
fillbackground colour
strokeborder colour
texttitle colour
fonttitle font: sans serif mono
font-sizetitle font size, px
font-weighttitle weight, default 600
italicitalic title
border-stylesolid dashed dotted
dashedshorthand for border-style: dashed
metamuted text at the top right
capssmall-caps title

A group is as wide as its label and meta need. When other nodes leave too little room beside the group, the label wraps onto more lines instead.

Text ​

Every element takes the same five text props: text (colour), font, font-size, font-weight and italic. They style a node's label, an edge's label, a group's title and a panel's title. On a panel, font-size also scales the text inside it.

font takes the same values as the font setting: sans, serif, mono or font names. Quote a list, since commas separate props: [font: "Lora, serif"].

To style only part of a text, wrap it in a span: {keys | text}. The keys are color, size, weight, font and italic, separated by commas. A span's font takes one name: {font: mono | code}. A bare colour sets the colour, and a bare bold or italic sets that flag. Spans work in every text: labels, sub, edge labels and captions, group and panel titles, card bodies and panel items.

spanresult
{color: red | text}coloured text
{size: 18 | text}bigger text, px
{weight: 700 | text}heavier text
{italic | text}italic text
{font: mono | text}monospace text
{red, bold, size: 18 | text}all at once, short form
{red: text}coloured text, as before

The other inline markup (**bold**, *muted*, [[chip]] ...) works in these texts too.

yuhwa diagramyuhwa diagramEdit
yuhwa
direction: right

api "{size: 18, weight: 800 | API} {font: mono | v2}" [sub: "{green | ●} healthy", italic]
db "Orders" [shape: cylinder, font: serif, font-size: 16, font-weight: 700, text: indigo]

group back "Backend" [font-size: 14, font-weight: 800, text: teal] {
  api
  db
}

api -> db: "{bold | writes}, {italic | async}" [font-size: 13, text: orange]

Cards ​

A node with a { } body becomes a card: a header with the label, a divider, and monospace lines below. A body opens with { at the end of the node line and closes with a line that is only }.

yuhwa diagramEdit
yuhwa
theme: terminal

checks "checks" [meta: 42s, caps] {
  ✓ typecheck || [[green: pass]]
  ✓ tests     || [[green: 128]]
  *skipped: e2e*
  ---
  bars: 3 5 4 6 8 7 9
}

release "release" [meta: v0.1.0, caps] {
  | type  | bump  |
  |-------|-------|
  | feat  | minor |
  | fix   | patch |
  ---
  ~~manual tagging~~
}

checks -> release: green
  caption: on main

Body lines:

lineresult
texta line of text
left || rightright is aligned to the right edge
---a divider
empty linea small gap
bars: 3 5 8a bar chart; bars green: … picks a colour
spark: 3 5 4 8a sparkline with a soft area
progress: 72% testsa labelled progress bar; 9/12 deploys works too
stat: 99.9% uptime | 42ms p95big numbers with labels, side by side
| a | b |a table row; a |---| row makes the row above a header

bars, spark, progress, stat and tables come from the built-in plugins. Each takes an optional colour after its keyword.

Inline markup inside a line:

markupresult
**bold**bold
*muted*muted colour
~~text~~struck through
`code`accent colour
[[chip]] / [[green: chip]]a small outlined chip
{red: text} / {#f97316: text}coloured text
{size: 18, weight: 700 | text}styled text (text)

meta puts muted text at the top right, caps turns the header into small caps. With shape: text the card has no frame.

The header and the body are styled apart. font-size, font-weight and text set the header label. body-size, body-weight, body-color and line-height set the body lines; inline colours still win over body-color.

yuhwa diagramEdit
yuhwa
theme: midnight

laptop "~/shop" [frame: window your laptop, font-size: 18, body-size: 15, body-weight: 500, body-color: #e2e8f0, line-height: 1.6] {
  $ lf setup vps --host <server-ip>
  {green: ✓} docker · ufw · fail2ban · traefik
  $ lf deploy
  {green: ✓} live → https://shop.example.com
}

Placement ​

A placement prop puts one node next to another. The value is the other node's id.

yuhwa diagramyuhwa diagramEdit
yuhwa
firewall -> traefik -> app
journal [below: traefik]
cron [right-of: app]
propwhere the node goes
belowunder the other node
aboveover the other node
right-ofto the right of the other node
left-ofto the left of the other node
rankin the same rank (column or row) as the other

The directions are on screen. They do not turn with direction. A placement draws no edge. It replaces the old trick of an invisible edge (a -> b: [opacity: 0]). Placement works inside groups, and across them.

A node takes one placement prop. An unknown id, a group id, the node's own id and a loop of placements each give a warning with the line. Edges win over placement. When an edge runs the other way, the placement is dropped with a warning.

Fitting a narrow column ​

The max-width setting keeps a wide diagram inside a column. When the diagram is wider than the limit, its ranks wrap into rows, like words in a paragraph. Each row starts at the left. Edges to the next row run through the gap between the rows.

yuhwa diagramyuhwa diagramEdit
yuhwa
max-width: 640
commit -> lint -> test -> build -> scan -> stage -> e2e -> prod

A diagram that already fits does not change. A group is never split: all its ranks stay in one row. Only direction: right and direction: left wrap. A down or up diagram grows in height, so it is left as it is. A single rank or group wider than the limit stays wider. Pinned nodes (the layout block) turn wrapping off.

The layout block ​

The visual editor writes manual positions into a layout block at the end of the file. It can also be written by hand.

yuhwa diagramyuhwa diagramEdit
yuhwa
a -> b: HTTPS
b -> c

layout {
  a at 40 40
  b at 260 40 size 160 64
  c at 40 200
  a->b label 0 -14
  b->c via 340 224 ports bottom right
}
linemeaning
id at X Ypin a node or group at this top-left position
id ... size W Hfixed size
a->b via X Y [X Y ...]waypoints the edge passes through
a->b ... ports S Sstart and end sides: top right bottom left (auto to let the router pick)
a->b ... label DX DYmove the label from its default place
a->b#2 ...the second edge from a to b, when there are several
rank a b ckeep these nodes in the same rank (row or column)
panel at X Ypin a panel at this top-left position (panels take no size)
panel:part Dnudge one part of a panel along the axis it moves on; the panel kind names its parts (see git)
panel:part DX DYnudge a part that moves freely in both directions

Nodes without a position are still laid out automatically around the pinned ones. Delete the block to return to full auto-layout.

rank lines are layout hints, not positions: the nodes still get placed automatically, but share one rank. Nothing in a rank set is pinned.

Panels, imports and exports ​

Sequence diagrams, timelines, charts and git histories can sit next to the graph in the same file. A diagram can be split over files:

import "./styles.yu"                       // everything the file exports
import { api, .svc as .service } from "./x"    // only some things, renamed
import { service, $brand } from "./kit"        // components and variables
export api, data, .svc                         // what importers may take
export db "Orders DB" .store                   // export in front of a declaration
export $brand: violet                          // ... or a variable
export def service(id) { ... }                 // ... or a component

See Combining diagrams.

Other input formats ​

Every API and CLI command also accepts JSON and Mermaid flowcharts. See From Mermaid or JSON. For the look of each theme, see Themes and styling.

Released under the MIT License.