Flowchart code reference
The complete Mermaid flowchart syntax the app reads, the drawing style and the patterns, exactly as the assistant and connected AI apps get them.
This is the reference the in-app assistant has in its instructions when you work on a flowchart, and connected AI apps get from lookup_guidance with the topic flowchart-code. For a walk-through, see Flowchart code.
Flowchart code: Mermaid flowchart syntax (what write_diagram takes and get_diagram returns)
flowchart TD the first line; TD top to bottom, LR left to right, also BT and RL
--- title: <text> --- front matter before it, on three lines, gives the chart its title
id[Label] a process step; the id is how the code, comments and arrows name it
id{Question?} a decision, with an arrow out for each answer
id([Label]) start or end
id(Label) an event; id[(Label)] a database; id[[Label]] a subroutine
id[/Label/] input or output; id{{Label}} preparation
id@{ shape: doc, label: "Label" } any Mermaid shape by name: doc, docs, delay, sl-rect (manual input), curv-trap (display), brace (comment)
id@{ shape: sm-circ } UML's start dot; fr-circ its end; fork a fork or join bar
a --> b an arrow
a -->|yes| b an arrow with a label; also written a -- yes --> b
a -.-> b dotted: optional, or later; a ==> b thick, for the main path
a --- b a line with no head; a --o b ends in a circle, a --x b in a cross, a <--> b two-way
a ---> b a longer arrow: its ends sit a step further apart
a --> b --> c a chain; a & b --> c fans arrows in or out
subgraph id [Title] ... end a frame round nodes that belong together; nest them, and give one its own "direction LR" on its first line
a --> frameId an arrow to a frame ends on its edge
style id fill:#E1F4E9,stroke:#27AE60 a node's colour: its stroke, with the fill a pale wash of it
classDef warn stroke:#DC2626 a class of styles; class a,b warn gives it to nodes
%% <text> a comment on a line of its own
Ids are letters, digits and underscores (check_stock), never a Mermaid keyword: end, graph, subgraph, click, style, class, direction. Put a label with brackets, quotes or symbols in quotes: id["Plan (draft)"]; a " inside is #quot;. <br> breaks a line.
Labels can be styled with Mermaid's Markdown strings: id["`**Pay** now`"]. Use it sparingly.
Declare a node with its shape and label once, on its own line or where it first appears; later lines name it by id alone.
get_diagram prints the code, then every arrow's id. Node ids are in the code itself: keep them when you rewrite a chart, so comments stay on their nodes.Example
The reference ends with this example.
---
title: Approve an invoice
---
flowchart TD
received([Invoice received]) --> check{Over 1,000?}
check -->|no| pay[Pay invoice]
check -->|yes| approve[Manager approves]
approve --> ok{Approved?}
ok -->|yes| pay
ok -->|no| reject[Return to supplier]
pay --> done([Paid])
reject --> closed([Closed])Drawing style
The topic flowchart-style is the style the assistant follows when it draws a flowchart.
Flowchart style
- One flow per chart, named for what it does ("Approve an invoice", "Reset a password"), with one start.
- Steps say what is done, verb first: "Check stock", not "Stock checking". Decisions are questions: "In stock?", "Over budget?". Each way out of a decision is labelled with its answer.
- Start and end are stadiums with a few words ("Order placed", "Refund sent"). UML activity diagrams use sm-circ for the start, fr-circ for the end and fork bars for work that runs at the same time.
- Classic symbols only where they say something: lean-r for data in or out, cyl for a database, doc for a document, fr-rect for a step drawn in full elsewhere, delay for a wait, brace for a remark joined by a dotted line.
- Top to bottom by default; left to right for a wide, shallow chart. Loops go back up to the step they repeat, and every loop has a way out.
- Thick arrows (==>) can mark the main path; dotted ones (-.->) an optional or later step. Use them sparingly.
- Frames (subgraphs) for a team's or a phase's steps, titled with its name.
- One level of detail, picked from the request: an overview of about 6-12 nodes and up to five decisions, the main path and how it ends; or a detailed chart of up to 25 nodes with every rule stated. A detailed part folds into a subroutine named for it in a few words, charted on its own; the decision that picks who does the work or can end the flow stays.Patterns
When a request fits a common shape of flow, the assistant can look up a pattern and adapt it to your steps and names. These are the texts lookup_guidance returns, with each chart drawn.
Approval flow (adapt names and thresholds to the user's)
Topic approval-flow.
flowchart TD
submitted([Request submitted]) --> complete{Complete?}
complete -->|no| return_it[Return to requester] --> submitted
complete -->|yes| amount{Over the limit?}
amount -->|no| approve[Approve]
amount -->|yes| manager[Manager reviews]
manager --> decision{Approved?}
decision -->|yes| approve
decision -->|no| reject[Reject with reason]
approve --> notify[Notify requester]
reject --> notify
notify --> done([Closed])Each decision has a labelled way out per answer; incomplete requests loop back to the start; both outcomes end at one close.
Troubleshooting tree
Topic troubleshooting-tree.
flowchart TD
start([Printer won't print]) --> power{Is it on?}
power -->|no| switch_on[Switch it on] --> works{Printing now?}
power -->|yes| paper{Paper loaded?}
paper -->|no| load[Load paper] --> works
paper -->|yes| queue{Jobs stuck in the queue?}
queue -->|yes| clear[Clear the queue] --> works
queue -->|no| support[Call support]
works -->|yes| fixed([Fixed])
works -->|no| support
support --> escalated([Escalated])One question per decision, cheapest check first; every fix leads to the same "working now?" test; the last resort is an end of its own.
Retry loop with a limit
Topic retry-loop.
flowchart TD
send[Send request] --> ok{Succeeded?}
ok -->|yes| done([Done])
ok -->|no| tries{Tried 3 times?}
tries -->|no| wait@{ shape: delay, label: "Wait, then double the wait" } --> send
tries -->|yes| alert[Alert the on-call engineer] --> failed([Failed])The loop goes back up to the step it repeats; the limit is a decision of its own, so the loop always has a way out.