Guidance topics
The modeling guidance the AI can look up with lookup_guidance, word for word.
The AI calls lookup_guidance with one of these topics before drafting a diagram in a known domain, or when it is unsure of the syntax or a pattern. There are topics for BPMN processes, sequence diagrams, ER diagrams and flowcharts, in that order below. The in-app assistant has the same topics. Select a topic to see the exact text the AI gets back.
BPMN patterns
For BPMN processes: the Flowmark syntax, the modeling style the app follows, and patterns that apply to any process.
Flowmark syntax (what write_diagram takes and get_diagram returns)
process <name>
lanes <Lane A> | <Lane B> optional, fixes lane order
lane <name> following nodes go in this lane
lanes Sales | Operations > Warehouse | Operations > Shipping
"A > B" makes B a lane inside A (a team in a department); steps go in the inner lanes,
so write "lane Warehouse", never "lane Operations", before a step
pool <name> [(below)] an outside party (customer, supplier, bank) drawn as a black-box pool above the process, or below it
pool <name> (below, beside <pool>, multiple)
options in one bracket, any of them: beside puts it on the right of that pool, in its row on its side,
each pool only as wide as it needs (pools side by side); multiple marks a party with many participants
data <name> [(list)] a data object: a document or record the process passes along (an order, a form); (list) for many of them
store <name> a data store: a system or database that keeps data beyond the process (CRM, ERP)
<kind>[:<event>[(<arg>)]] <name> [#id]
kinds: start end catch throw task user service manual script rule send receive call sub xor and or eventgw complex
events: message timer error signal conditional escalation terminate compensation link cancel multiple parallel; timer args are ISO 8601 (P2D, PT4H, R/P1W), or ${field} for a date each case holds that no duration gives (catch:timer(${startDate}) First day arrives); a time after something (day 25, 30 days after) is a duration (P25D)
a message, signal, error, escalation or link arg names what is sent or awaited when it isn't the event's name, in brackets (start:message(Claim form) Claim received; throw:signal(Order cancelled) Tell warehouse); without them it's all the name. Events with the same one share it
Indented lines under a node:
<label> [<condition>] (default) -> <target> explicit flow; label, condition and (default) are optional
on:<event>(<arg>) <name> -> <target> interrupting boundary event; on~<event>(<arg>) for non-interrupting
doc: <text> documentation: the longer description, hidden on the diagram; repeat for more lines
note: <text> a short note shown beside the node on the diagram (an SLA, a system, "manual for now"); repeat for more lines
right under a "lane <name>", "data <name>" or "store <name>" line, note: notes the lane or the data; indented deeper than an arrow (or on: line, or => / <= line) right above it, it notes that flow or message:
yes -> Ship order
note: Same day if before noon
=> Customer: Invoice
note: By email
=> <pool>: <message> the node sends a message to an outside pool, or to another party's step (by name or #id)
<= <pool>: <message> the node receives a message from an outside pool, or from another party's step;
indented under an on:message line, that boundary event receives it ("Customer cancels" while the task runs)
reads: <data> the node uses a data object or store; writes: <data> when it creates or changes one
repeat: loop | parallel | sequential an activity that repeats: while a condition holds, or once for each item (all at once, or one after another)
property: <name> = <value> a custom property, not drawn (Owner = Finance, System = SAP)
calls: <process> under a call activity: the process it runs, by the name of its diagram (list_diagrams shows them), or of a process outside Penna
color: <name or #RRGGBB> colours the node above it: its outline, and a faint wash in its fill. Indented deeper than an arrow, the flow; under a lane, pool, data, store, group or => line, that element
note <text> a note on its own, drawn above the process (who owns it, when it was reviewed); several "note" lines in a row are one note (a color: line under it colours it)
group <label>: <step>, <step> a dashed box with a label round steps that belong together (a phase); "group: A, B" has no label. Changes no flow; group steps that follow one another
on:compensation <name> -> <activity> links a task to the activity that undoes it; that activity has no other flows.
throw:link <name> ends a path that goes on at catch:link <name> (an off-page connector, for a long diagram or a path that would cross it); several throws may lead to one catch.
multiple: any one of several triggers; parallel: all of them (start, catch, on:). throw and end take multiple too. cancel: an end or on: event of a transaction.
complex: a gateway with a rule xor, and, or can't say ("two of three reviews in"); name it with the rule.
Steps indented under a sub, after its own lines, are drawn inside it, as a path of their own with a start and an end. Flows stay inside;
the flow from the line above goes into the sub-process, and the sub-process goes on to the line after its steps, like any step:
sub Handle return
start Return received
user Inspect item
end Return checked
user Refund customer
sub <name> (collapsed) draws a sub-process that has steps inside small, with a +, its steps kept but hidden until someone expands it; write it only when the user asks to collapse one.
sub:event <name> an event sub-process: it runs when its start's trigger happens while the process runs (start:message Order cancelled), with no flows in or out;
start~<event> lets the work round it go on, start:<event> stops it. Put it after the main path, with a blank line before it.
Its start can also be start:error, start:escalation or start:compensation: it catches what the work round it throws (only an event sub-process's start can).
It's for what can happen at any point (a cancellation); a deadline or failure on one step is an on: boundary event on that step.
Steps indented under a pool line are that party's own steps, a path of their own with a start and an end;
flows stay inside the pool, and messages join it to the process. Write them only when the user asks for that party's side, as in "from both sides" or "show what the supplier does":
pool Customer
start Needs goods
send Place order
=> Receive order: Order
end Order placed
lane and lanes lines indented under a pool line split its steps into the pool's own lanes, nested and written as the process's are; use them only when the user names roles on that party's side:
pool Supplier
lane Sales
receive Take order
lane Warehouse
task Ship goods
end Shipped
"=>" or "<=" lines under a pool line, before its steps, are the pool's own messages, to or from another pool.
A message line can end with (envelope: start) or (envelope: reply): it draws the message itself on its line, a white envelope for the message that starts an exchange, a grey one for its reply.
sub:transaction <name> a transaction: its steps complete together or are undone; end:cancel inside cancels it, and on:cancel on it leads to what happens then.
sub:adhoc <name> an ad-hoc sub-process: the steps indented under it are done in any order, as often as needed (research, a checklist, an AI agent's tools).
It has no start or end inside, and its steps don't connect to the line above; write an arrow only where one step must wait for another.
A doc: line before the first node documents the process.
Names, labels and notes can be styled: **bold**, *italic*, `code` and ~~struck~~. Use it sparingly, when the user asks or a word needs stress.
Inside a paragraph each node connects to the node on the line above it. A blank line starts a new paragraph (a new path).
A node with explicit "->" lines does not continue to the next line, and end events never do.
Targets are node names (case-insensitive) or #id; give a node an #id when its name is not unique or it has no name (e.g. merge gateways: "xor #merge").
// starts a comment when it begins the line or follows a space (links like https://… are kept).
get_diagram prints every node with its #id. Keep those ids when you rewrite a diagram, so the user's references stay stable.
Example
process Purchase request
pool Supplier (below)
data Purchase request
store ERP
lanes Employee | Manager | Procurement
lane Employee
start Need identified
user Submit purchase request
writes: Purchase request
lane Manager
xor #resubmitted
user Review request
reads: Purchase request
note: SLA 2 working days
on~timer(P2D) Review pending two days -> Send reminder
xor Request approved?
yes -> Send purchase order
needs changes -> Revise request
no (default) -> Notify rejection
lane Procurement
send Send purchase order
=> Supplier: Purchase order
writes: ERP
end Order placed
lane Employee
user Revise request
-> #resubmitted
lane Manager
send Notify rejection
end Request rejected
send Send reminder
end Reminder sentModeling style (BPMN Method & Style conventions)
- Your process is one pool; its lanes are roles or departments, not people or systems unless the system does the work. When the user names teams within a department, make them lanes inside its lane ("lanes Operations > Warehouse | Operations > Shipping"); otherwise keep lanes flat. Outside parties (customer, supplier, bank) are separate black-box pools that exchange messages with it.
- Name activities verb + object ("Approve invoice"), events as a state ("Invoice received", "Payment overdue"), decision gateways as a question ("Amount over 10k?"), and the flows leaving them as answers ("yes", "no", "over 10k").
- Start and end events are always explicit. Use distinct end events for distinct outcomes ("Order shipped", "Order cancelled") so the outcomes are readable at a glance.
- Never let a task split or merge flows implicitly: use a gateway for every split and every merge, and match the gateway type of a split with its join (parallel with parallel, inclusive with inclusive).
- Keep one level of detail per diagram, picked from the request: an overview of about 6-12 activities, or a detailed diagram of up to about 25 (see "scope-and-detail"). Wrap a detailed area in a call activity or sub-process instead of growing the diagram.
- Pick task types deliberately: userTask (a person in a system), manualTask (offline work), serviceTask (automated), sendTask/receiveTask (messages to/from another party), businessRuleTask (decision table), callActivity (reusable sub-process).
- List the happy path first; exceptions and rework branch off it. The layout keeps the first branch straight.
- Model time limits and failures as boundary events on the activity they interrupt, not as gateways after it.
- Notes (note: lines) are for a short fact people should see on the diagram: an SLA, the system used, "manual for now". Documentation (doc:) holds the longer description and is hidden on the diagram. A note never replaces a step, timer or decision the user described: "the underwriter can lower the loan amount" is a decision and a task, not a note.
- A note goes on what it is about: a step, a flow (indent note: under its arrow), a lane (note: right after its lane line), or the whole process (a "note" line of its own, drawn above it, for an owner or a review date).
- A group (group Label: Step, Step) draws a labelled dashed box round steps that belong together, such as a phase or stage the user names. It changes no flow. Group steps that follow one another, so the box holds only them.Scope and level of detail: deciding what goes on the canvas
A long description is not a request to draw everything. Decide the level first, then keep to it.
Which level
- Overview: "overview", "high level", "one page", "for management", "the main steps", "explain", or a short description. Show the lifecycle (the main stages in order), the key decisions and their answers, who does what (lanes and outside parties) and every way it can end. About 6-12 activities. Leave out deadlines and reminders, data objects and stores, and the inside of sub-processes, unless one is the point of the diagram.
- Detailed: "in detail", "complete", "every rule", "step by step", "operational", "so the team can work from it", or a long description full of rules, exceptions, retries and deadlines. Show every rule, exception, retry, deadline and escalation the person described, with the timers, messages and loops drawn. Up to about 25 activities; past that, a detailed area goes into a call activity with a diagram of its own.
- Not said, and the description is long: draft the overview, fold the detail as below, and offer the detail as the next step ("Say which part to expand"). Don't ask the person to choose unless you need to ask something else anyway.
Keeping every rule without crowding the canvas
- A stated rule that doesn't fit the level goes into a call activity named for what it does: "Investigate suspected fraud" stands for the investigation unit's steps, "Chase failed payment" for the card-update request, the retries and the grace period. A note: line on it may name what it covers in a few words. Say in your summary what each call activity holds, so nothing stated goes missing in silence.
- At the overview, fold what isn't a stage or a key decision: an exception loop (a dispute, a retry, a reassessment, a request for more information) into the activity it returns to, with a note saying so ("note: Reassessed if the customer disputes"); a request and its reply with an outside party into the one step that waits for it ("Assess damage" sends the estimate request and receives the estimate); a reminder into a note on the step it watches, while a deadline the person or the team's context sets keeps its timer. A decision stays on the canvas only when it changes who does the work or how the process ends: "Policy covers it?", "Fraud suspected?", "Over 10,000?" stay; "Customer disputes?" folds. Six decisions is a lot for an overview.
- Don't add what wasn't described and a reader doesn't need: no "Log the request", "Update the system", "Notify stakeholders" or "Archive the file" steps, no decision for a rule the person didn't state, no data stores the person never named.
- One end event per outcome. Several paths that end the same way point to the same end event: give it an #id if its name repeats a step's.
- Flows stay at one level. Steps inside a sub-process connect to each other and have their own start and end; the sub-process connects to the rest. A lane line goes before the sub-process line, never between its steps. Draw steps inside a sub-process only when the person asks to see them; otherwise a call activity.
- When a write fails, change the line the error names before you send the whole diagram again; the same markup gets the same error. Write an explicit arrow only for a jump: each node already flows to the line above it, so listing that flow again is a duplicate arrow. After two failed writes of the same construct, simplify it instead of trying a third variation.
Example: the same claims process as an overview. The detailed version would draw the estimate request and reply with the repair shop, the day-25 reminder as a non-interrupting timer on the handler's step, and the dispute as a loop back to the assessment; here they live in the call activities and their notes.
process Motor claim
pool Policyholder
pool Repair shop (below)
lanes Claims handler | Adjuster | SIU
lane Claims handler
start:message Accident reported
<= Policyholder: Accident report
user Register claim
xor Policy covers it?
yes -> #assess
no (default) -> Deny claim
send Deny claim
=> Policyholder: Denial letter
end Claim denied
and #assess
-> Assess damage
-> Screen for fraud
lane Adjuster
call Assess damage
note: Inspection and the repair shop's estimate; reassessed if the customer disputes
-> #assessed
lane Claims handler
rule Screen for fraud
xor Fraud suspected?
yes -> Investigate suspected fraud
no (default) -> #screened
lane SIU
call Investigate suspected fraud
xor Claim cleared?
yes -> #screened
no (default) -> Claim closed as fraudulent
end:terminate Claim closed as fraudulent
lane Claims handler
xor #screened
-> #assessed
and #assessed
user Approve settlement
note: The claims manager approves over 10,000 EUR
service Pay repair shop
=> Repair shop: Payment
end Claim settled
Summary to give with it: "An overview with 7 steps. Assess damage covers the inspection, the repair shop's estimate and a reassessment if the customer disputes; Investigate suspected fraud covers the SIU's work. Left for the detailed view: the day-25 reminder, the manager's approval over 10,000 EUR as its own decision, and recovering the cost from the other driver's insurer. Say which part to expand."Gateway patterns (Flowmark)
Exclusive decision with a default:
xor Credit check passed?
yes -> Approve loan
no (default) -> Decline application
Parallel work (fork + join with matching parallel gateways):
and #fork
-> Ship goods
-> Send invoice
service Ship goods
and #join
...
service Send invoice
-> #join
Inclusive (one or more branches): use "or" for the split and an "or" join; give each branch a condition.
Event-based race (whichever happens first):
eventgw Wait for reply
-> Reply received
-> Five days passed
catch:message Reply received
...
catch:timer(P5D) Five days passed
Rework loop: a "needs changes" branch goes to a revise task, which points back at an unnamed merge gateway placed just before the earlier task ("xor #resubmitted" ... "-> #resubmitted"), so no task gets two incoming flows. The same goes for an event a loop comes back to.
A decision inside parallel work: a parallel join waits for every flow into it, so merge the decision's branches with an exclusive gateway first and lead that one flow into the join:
and #fork
-> Inspect vehicle
-> Screen for fraud
manual Inspect vehicle
-> #join
service Screen for fraud
xor Fraud suspected?
yes -> Investigate claim
no (default) -> #screened
user Investigate claim
-> #screened
xor #screened
-> #join
and #join
A branch that has to stop everything (a claim closed as fraudulent while other work runs) ends in end:terminate instead of reaching the join.
Avoid: a gateway that both merges and splits; joining parallel branches with an exclusive gateway (creates duplicate tokens); leading a decision's branches straight into a parallel join (it waits forever for the branch not taken); a loop from after a parallel join back into one of its branches (on the next pass the join waits forever for the others), so a rework that starts after the join comes back to a merge after it.Events and exceptions
- Start: none (manual start), message (a request arrives), timer (scheduled, e.g. start:timer(R/P1M) Month started), signal, conditional.
- Intermediate catch: timer waits (catch:timer(P3D)), message waits for another party.
- A wait for a date each case holds that no duration gives (the start date, the completion date, the next maintenance window) writes the field the case keeps it in: catch:timer(${startDate}) First day arrives. A time after something ("on day 25", "30 days after registration") is still a duration on the step it watches: on~timer(P25D). Never leave a timer without a value.
- Boundary events attach to the activity they interrupt:
user Review contract
on:timer(P5D) Review overdue -> Escalate review (interrupting)
on~timer(P2D) Reminder due -> Send reminder (non-interrupting: work continues)
on:error Validation failed -> Correct data
- End: none, message (notify a party), error (process fails), terminate (stop all parallel work), escalation.
- Every exception path should end in its own named end event or rejoin the main flow.
- A reminder or deadline over several steps ("remind the handler on day 25", "decide within 30 days"): put the timer on the activity that keeps the work open, or group the steps in a call activity and put it there; non-interrupting (on~) for a reminder. Don't add a parallel branch that waits on a timer: it never joins, keeps the case open, and still fires after the work is done. In an existing diagram, put the timer on the step that keeps the work open; don't merge or rename steps to make room for it.Pools and messages
- Your process is the main pool; each outside party it deals with (customer, supplier, carrier, bank, regulator) is a pool of its own, drawn as a band. By default it's a black box: only its exchanges show, not its internal steps.
- A message goes between two parties: a step of your process and an outside pool, or a step of that pool's own. Name it after what is sent ("Purchase order", "Tracking update"), not the action.
- Keep a pool a black box even when the request says what the party sends or does ("the customer places an order"): its messages show that. Only when the user asks for that party's side ("model it from both sides", "show what the supplier does"), give its pool steps of its own: indent them under its pool line, with a start and an end, and no lanes. Its flows stay inside it; messages join its steps to yours ("=> Receive order: Order" names the other step). Keep the party's steps to what the user said.
- Send with a send task, or a message intermediate throw or end event: "=> Pool: message". Receive with a receive task, or a message start or intermediate catch event: "<= Pool: message". Plain tasks can do both.
- Gateways never send or receive. Boundary events can't take messages here; put the message on the task or on a message catch event after an event-based gateway.
- Messages are not sequence flow: the process still needs its own flows from start to end. Waiting for a reply is a receive task or message catch event on the flow.
- Put the customer above the process and partners (suppliers, carriers, banks) below it: "pool Carrier (below)".
- Each pool is a band as wide as the process. When several parties each have steps of their own and deal with different parts of the process, set them side by side, each under the steps it deals with: "pool Expert (below, beside Nominator)" puts Expert on the right of Nominator, in its row.
- Mark a pool multiple when many of that party take part, such as nominators or suppliers bidding: "pool Supplier (below, multiple)".
- BPMN can draw the message itself on its line: "=> Carrier: Pickup request (envelope: start)" puts a white envelope on the message that starts an exchange, "<= Carrier: Pickup confirmation (envelope: reply)" a grey one on its reply. Add envelopes only when asked, or when copying a diagram or file that shows them (keep them as drawn); otherwise leave messages plain.
- Add pools when the conversation matters to the reader. Every pool should have at least one message.
Example
process Order tracking
pool Customer
pool Carrier (below)
lanes Warehouse | Customer service
lane Warehouse
start Order packed
send Book pickup
=> Carrier: Pickup request
receive Pickup confirmed
<= Carrier: Pickup confirmation
lane Customer service
send Tell customer it shipped
=> Customer: Shipping notice
end Order shippedApproval pattern
Roles: Requester, Approver (often Manager), sometimes Finance/Compliance for thresholds.
Shape: submit -> review -> decision (approved / needs changes / rejected).
- "needs changes" loops back to the requester's revise task, which returns to review.
- Threshold routing: an exclusive gateway on amount before review ("Amount over limit?") adds a second-level approver.
- Four-eyes principle: the second approver is a different role/lane.
- Add a non-interrupting timer reminder and an interrupting escalation timer on the review task.
- Outcomes: "Request approved", "Request rejected" (and notify the requester with a send task).Escalation and SLA patterns
- Reminder without interrupting: on~timer(P1D) Reminder due -> Send reminder, then end "Reminder sent".
- Escalation that takes over: on:timer(P3D) SLA breached -> Escalate to supervisor, rejoining the main flow after.
- Measure SLA from a clear start event; name timers after the condition ("SLA breached"), not the mechanism.
- For multi-level escalation, chain escalation tasks or loop back with a counter decision ("Escalation level < 3?").Layout and polish: making a diagram easier to read without changing the process
The app lays the diagram out on a grid. You can't place shapes, but edit_diagram's set_layout sets how far apart steps sit and puts steps moved by hand back in place. get_diagram's "Layout:" line shows the spacing each way, how many steps were moved by hand, and the lanes top to bottom as they are drawn.
Spacing steps, tightest first: compact, standard (the default), roomy, spacious. "across" is the gap between columns of steps, left to right; "down" is the gap between rows and lanes. "spacing" sets both.
What people ask, and what to do
Steps count from where each direction is now, and the two can differ: when they do, set across and down separately, each its own step on (across spacious and down roomy, one step tighter, is across roomy and down standard).
- "Improve the spacing", "more spacious", "a bit more room", "easier to read", "less cramped", "it's crowded": one step roomier each way (standard -> roomy, roomy -> spacious).
- "A lot more room", "really spread it out": two steps roomier, up to spacious.
- "More room between the steps", "wider", "the arrows are squashed": one step roomier across only.
- "More room between the lanes", "between the rows", "taller", "the lanes are tight": one step roomier down only.
- "More compact", "tighter", "too spread out", "fit it on one screen", "smaller": one step tighter each way (or in the one direction they name), down to compact.
- "Normal spacing", "back to default", "reset the spacing": standard both ways.
- "Tidy up", "tidy the layout", "put the steps back", "straighten it out", "line it up": tidy: true, which puts steps moved by hand back in their automatic spots. If none were moved, say the layout is already on its grid and offer roomier spacing.
- "Put Check order back", "undo my move of the invoice": putBack with just those steps, notes, data or groups; the rest stay where they were moved.
- "Clean up the layout", "polish the diagram", "make it look nicer", "make it presentable", /polish: tidy: true, one step roomier each way that is at compact or standard, and check the lane order below. Do it all in one edit_diagram call.
- Already at spacious and asked for more room: say it's at the roomiest spacing, and suggest a call activity for a detailed area if the diagram is large.
- Already at compact and asked for less: say it's at the tightest spacing.
A plain "clean it up" or "fix it" is about modeling problems, not layout: follow the fixing rules.
Lane order
Order lanes top to bottom in the order the work first reaches them, the lane with the start event at the top, so flows run mostly down and right. When polishing, check this every time against the Layout line's lane order: if the start event's lane isn't at the top, or the work keeps climbing back up the page, move lanes with update_lane and its index (0 is the top). When the order already follows the work, leave it. Outside pools stay where they are.
What polishing never does
- Never add, remove, rename, retype or reconnect steps, change lanes' membership, or add notes. Those change the process; ask first if you think they would help, and say why.
- Never use write_diagram to polish: rewriting puts every hand-moved step back and risks changing the process.
- Don't touch spacing when the user asked only for a tidy up, or tidy up when they asked only for spacing, except for "polish" requests.
Finish with one or two sentences in plain words: what you changed ("I made the spacing roomier both ways and put 3 moved steps back in place") and the next step ("Say 'more' for even more room, or undo to go back"). Don't list the process back.BPMN domains
Reference processes for common business areas: the usual roles, trigger, happy path, decisions, exceptions, controls and KPIs. The AI adapts them to what you tell it about your organization.
Change management (ITIL) reference
Getting an IT change from request to production safely: assessment, approval, scheduling, implementation and review.
Lanes: Change requester, Change manager, Change advisory board (CAB), Implementation team, Service owner.
Trigger: `start Change requested`.
Happy path:
1. Submit request for change (Requester, `user`).
2. Assess impact and risk (Change manager); classifying as standard, normal or emergency is often a `rule` task.
3. Approve change (CAB for normal changes, see the approval topic).
4. Schedule change in the change calendar (Change manager).
5. Implement change (Implementation team).
6. Verify change (Service owner).
7. Review and close change (Change manager), ending in "Change closed".
Decisions: Change type (standard: pre-approved, skip the CAB; normal: CAB; emergency: emergency CAB)? Approved? Verification passed?
Exceptions:
- Rejected or sent back for more information: notify the requester, or loop back to the request.
- Implementation fails or verification fails: an error boundary event on the implementation leads to "Roll back change", then the review, ending in "Change rolled back".
- Implementation window missed: a timer on the scheduled wait reschedules.
Controls: separation between implementer and approver, a backout plan before approval, a freeze calendar.
KPIs: change success rate, emergency change ratio, incidents caused by changes, lead time for changes.Customer support reference
Handling a support ticket from first contact to a confirmed resolution, with escalation to specialists and engineering.
Lanes: Customer, Support agent (L1), Specialist (L2), Product or engineering.
Trigger: `start:message Ticket received` (email, chat, web form).
Happy path:
1. Triage ticket (Support agent): category, priority, customer tier.
2. Search knowledge base (Support agent).
3. Provide solution (Support agent, `send`).
4. Wait for the customer's confirmation, ending in "Ticket resolved".
Decisions: Known issue? Needs a specialist? Bug confirmed? Customer confirms?
Exceptions:
- Needs a specialist: escalate to L2, which may need engineering.
- Bug confirmed: create an engineering issue (`send`), wait for the fix (`catch:message Fix released`), then reply to the customer.
- Customer silent: an event-based gateway between the reply and a timer (for example P7D) auto-closes with a notice.
- Customer reopens: loop back to triage through a merge gateway.
- First-response SLA: a non-interrupting timer on triage alerts the team lead.
KPIs: first response time, resolution time, CSAT, first contact resolution, backlog age.Employee onboarding reference
From an accepted offer to a productive new hire: records, equipment, access, first week and check-ins.
Lanes: HR, Hiring manager, IT, Facilities, New hire.
Trigger: `start:message Offer accepted`.
Happy path:
1. Create employee record (HR, `user` in the HR system).
2. In parallel: prepare equipment and accounts (IT), prepare workspace (Facilities), plan the first week (Hiring manager). Join all three.
3. Welcome new hire (Hiring manager, `manual`).
4. Complete compliance training (New hire, `user`).
5. Hold 30-day check-in (Hiring manager), ending in "Onboarding complete".
Decisions: Remote or on-site (skip the workspace, ship equipment instead)? Does the role need privileged access (an extra approval)?
Exceptions:
- Background check fails or the start date falls through: end "Offer withdrawn", and cancel the parallel preparation with `end:terminate`.
- Equipment not ready a few days before the start date: a timer boundary event escalates to the IT lead.
- Training not completed by its deadline: a reminder, then an escalation to the manager.
Controls: right-to-work verification before day one, access granted on least privilege, signed policies.
KPIs: day-one readiness, time to productivity, 90-day retention, new hire satisfaction.Incident management (ITIL) reference
Restoring service after an unplanned interruption: logging, triage, diagnosis, resolution and closure.
Lanes: User, Service desk (L1), Support group (L2 or L3), Incident manager.
Trigger: `start:message Incident reported` (or a monitoring alert, also a message start).
Happy path:
1. Log incident (Service desk, `user`).
2. Categorize and prioritize (Service desk); priority from impact and urgency, often a `rule` task.
3. Investigate and diagnose (Service desk first, then the support group).
4. Apply fix or workaround (Support group).
5. Confirm resolution with the user (Service desk, `send`, then wait).
6. Close incident, ending in "Incident closed".
Decisions: Major incident? Resolved at first line? User confirms the fix?
Exceptions:
- Major incident: switch to the major incident procedure, a `call` activity owned by the Incident manager.
- Resolution SLA at risk: a timer boundary on the investigation escalates to the next support level.
- User doesn't respond after resolution: a timer on the confirmation wait auto-closes the incident.
- User rejects the fix: reopen and loop back to investigation through a merge gateway.
Controls: priority matrix, SLA targets per priority, a problem record for recurring incidents.
KPIs: mean time to resolve (MTTR), first contact resolution, SLA compliance, reopen rate.Insurance claims reference
Property and casualty claims from first notice of loss to settlement: registration, coverage, assessment, fraud screening and payment.
Lanes: Policyholder (message partner), Claims intake, Claims adjuster, Special investigations unit (SIU), Finance.
Trigger: `start:message Claim submitted` (first notice of loss).
Happy path:
1. Register claim (Claims intake, `user`).
2. Verify coverage (Claims intake; `service` against the policy system).
3. Screen for fraud indicators (`rule` or a scoring `service`).
4. Assess damage (Claims adjuster, `manual` when on site).
5. Calculate settlement (Claims adjuster).
6. Approve settlement (Claims adjuster, or a senior adjuster above their authority limit).
7. Pay claim (Finance, `service`), ending in "Claim paid".
Decisions: Covered? Fraud suspected? Above authority limit? Repair or replace?
Exceptions:
- Not covered: send a denial letter with the reasons ("Claim denied").
- Fraud suspected: refer to SIU (`call`); it may end in "Claim denied" or return to assessment.
- Missing information: request it and wait with a timer.
- Policyholder disputes the settlement: an appeal loop back to assessment through a merge gateway.
Controls: authority limits per adjuster level, reserve setting at registration, payment approval separate from calculation.
KPIs: claim cycle time, loss adjustment expense, leakage, customer satisfaction, reopen rate.KYC customer onboarding reference
Opening an account for a new customer at a bank or regulated financial firm: identity verification, sanctions and AML screening, risk rating and account setup.
Lanes: Applicant (message partner), Onboarding operations, Compliance (KYC and AML), Relationship manager (for business customers), Core banking (system).
Trigger: `start:message Application received`.
Happy path:
1. Check application completeness (Onboarding).
2. Verify identity (`service` for document and biometric checks).
3. Screen against sanctions and PEP lists (`service`).
4. Assess customer risk (`rule`: low, medium, high).
5. Open account (`service` in core banking).
6. Send welcome pack (`send`), ending in "Account opened".
Decisions: Application complete? Identity verified? Screening hit? Risk rating (standard due diligence or enhanced due diligence)?
Exceptions:
- Missing documents: request them and wait with an event-based gateway; close the application if nothing arrives within the deadline ("Application lapsed").
- Possible sanctions or PEP match: manual review in Compliance; a true match ends in "Application declined", and a report to the regulator if required (`send`).
- High risk: enhanced due diligence (source of funds, senior approval) before opening.
- Business customers: identify the ultimate beneficial owners, often a `call` activity.
Controls: four-eyes approval for high-risk customers, an audit trail of checks, periodic review scheduling once the account is open.
KPIs: time to onboard, application drop-off rate, false-positive screening rate, share of applications needing manual review.Loan origination reference
From a loan application to funds disbursed: completeness, credit and risk assessment, decision, offer and disbursement.
Lanes: Applicant (message partner), Loan officer, Underwriting, Credit committee (above a threshold), Operations.
Trigger: `start:message Application received`.
Happy path:
1. Check application completeness (Loan officer).
2. Run KYC and AML checks (a `call` activity, see kyc-onboarding).
3. Pull credit report (`service`).
4. Assess risk (`rule`): automatic approval, manual underwriting or decline.
5. Underwrite loan (Underwriting) when the rule says manual.
6. Prepare and send offer (Loan officer, `send`).
7. Wait for acceptance (event-based gateway: acceptance message or offer expiry timer).
8. Disburse funds (Operations, `service`), ending in "Loan disbursed".
Decisions: Complete? Risk band? Above committee threshold? Offer accepted before expiry?
Exceptions:
- Missing documents: request and wait, with a timer to lapse the application.
- Declined: send an adverse action notice with reasons where regulation requires it ("Application declined").
- Applicant withdraws: a message boundary event on underwriting ("Application withdrawn").
- Offer expires: "Offer expired".
Controls: lending authority limits, committee approval for large exposures, KYC and AML before the decision, affordability checks.
KPIs: time to decision, time to fund, approval rate, pull-through rate.Month-end close reference
Closing the books each month: cut-off, accruals, reconciliations, review and reporting.
Lanes: General ledger accounting, Accounts payable, Accounts receivable, Financial controller, CFO or finance director.
Trigger: `start:timer(R/P1M) Month ended`.
Happy path:
1. Cut off subledgers (AP and AR, in parallel): post the remaining invoices and receipts.
2. Post accruals and prepayments (General ledger, `user`).
3. Run depreciation and allocations (General ledger, `service`).
4. Reconcile balance sheet accounts (General ledger): bank, intercompany, suspense.
5. Review reconciliations and journals (Financial controller).
6. Run trial balance and variance analysis.
7. Prepare management reports, approve them (CFO), and lock the period, ending in "Period closed".
Decisions: Reconciliation differences within tolerance? Variances explained? Adjustments needed?
Exceptions:
- Unreconciled difference: investigate and post an adjusting journal, then reconcile again (rework loop).
- Close deadline at risk: an interrupting timer on the review (for example working day 5) escalates to the controller.
- Late invoices after cut-off: accrue them rather than reopening the period.
Controls: journal approval above a threshold, preparer and reviewer separation, sign-off on reconciliations.
KPIs: days to close, number of post-close adjustments, reconciliations completed on time.
Modeling note: the subledger cut-offs and many reconciliations run in parallel. Fork with `and`, join with `and`, and keep each branch to one or two activities so the diagram stays at one level.Order to cash reference
From a customer order to cash collected: order entry, credit, fulfilment, invoicing and collection.
Lanes: Customer (often only a message partner), Sales or order desk, Credit control, Warehouse, Accounts receivable.
Trigger: `start:message Order received`.
Happy path:
1. Validate order (Sales): customer, prices, terms.
2. Check credit (Credit control, `service` when automated against a limit).
3. Reserve stock (Warehouse, `service`).
4. Pick and pack order (Warehouse, `manual`).
5. Ship order (Warehouse) and send invoice (Accounts receivable), often in parallel after picking.
6. Receive payment (Accounts receivable, `receive` or a message catch).
7. Apply payment (`service`), ending in "Order paid".
Decisions: Credit OK? Stock available (ship in full, ship partially, backorder)? Payment received by the due date?
Exceptions:
- Credit hold: a manual review in Credit control; release, or cancel the order ("Order cancelled").
- Out of stock: backorder and notify the customer, or ship partially.
- Payment overdue: a timer on the payment wait starts dunning (reminder, second reminder, collections).
- Cancellation by the customer before shipping: a message boundary event on fulfilment.
Controls: credit limits, pricing approval for discounts above a threshold, segregation between order entry and credit release.
KPIs: order cycle time, on-time in-full delivery, days sales outstanding (DSO), perfect order rate.Patient referral reference
A referral from a primary care provider to a specialist: triage, insurance authorization, scheduling and the feedback loop.
Lanes: Referring provider, Referral coordinator, Specialist clinic (triage clinician), Payer (message partner), Patient.
Trigger: `start:message Referral received`.
Happy path:
1. Register referral (Referral coordinator, `user` in the scheduling system).
2. Triage referral (Triage clinician): urgency and the right service.
3. Check prior authorization requirement (`rule`).
4. Schedule appointment (Referral coordinator) and notify the patient (`send`).
5. See patient (Specialist clinic, `manual`).
6. Send consultation report to the referring provider (`send`), ending in "Referral completed".
Decisions: Referral complete and appropriate? Urgency (urgent, routine)? Prior authorization needed and approved?
Exceptions:
- Incomplete or inappropriate referral: return it to the referring provider with the reason ("Referral returned").
- Prior authorization: request it from the payer and wait (event-based gateway: approval, denial, or a timer to chase).
- Patient doesn't respond or doesn't attend: reminders, then rebook once, then discharge back to the referrer.
- Urgent cases: a timer on scheduling (for example P2D for suspected cancer pathways) escalates to the clinic lead.
Controls: clinical triage by a qualified clinician, waiting-time targets by urgency, consent and privacy rules on sharing records.
KPIs: referral-to-appointment time, did-not-attend rate, share of urgent referrals seen within target, referral return rate.Permit application reference
A public sector permit or licence (building, business, event): intake, completeness, review, public consultation where required, decision and issue.
Lanes: Applicant (message partner), Intake clerk, Case officer, Specialist reviewers (planning, fire, environment), Decision authority, Finance (fees).
Trigger: `start:message Application submitted`.
Happy path:
1. Check completeness and fee payment (Intake clerk).
2. Assign case officer.
3. Review application against regulations (Case officer); specialist reviews run in parallel when needed.
4. Run public consultation when required (a timer for the statutory period, for example P21D).
5. Decide application (Decision authority, or delegated to the case officer).
6. Issue permit (`send`), ending in "Permit issued".
Decisions: Complete? Fee paid? Which specialist reviews apply (an inclusive gateway)? Consultation required? Approve, approve with conditions, or refuse?
Exceptions:
- Incomplete: request the missing information; the statutory clock pauses, and the application lapses after a deadline.
- Objections during consultation: assess them, possibly a hearing.
- Refused: send the decision with reasons and appeal rights ("Application refused").
- Statutory decision deadline: a non-interrupting timer on the review alerts the manager before it is missed.
Controls: statutory deadlines, conflict-of-interest checks for decision makers, a public register of decisions.
KPIs: share of decisions within the statutory deadline, average processing time, appeal rate, appeals upheld.Procure to pay reference
From a business need to a paid supplier: requisition, approval, purchase order, receipt, invoice matching and payment.
Lanes: Requester, Approver (budget owner), Procurement, Supplier (message partner), Warehouse or receiving, Accounts payable.
Trigger: `start Need identified`.
Happy path:
1. Create purchase requisition (Requester, `user`).
2. Approve requisition (Approver, `user`), see the approval topic.
3. Select supplier (Procurement): a preferred supplier, or request quotes.
4. Create purchase order and send it to the supplier (Procurement, `send`).
5. Receive goods (Warehouse, `manual` goods receipt).
6. Receive invoice (Accounts payable, `receive`).
7. Match PO, goods receipt and invoice (Accounts payable, `service` three-way match).
8. Approve payment, then pay supplier (`service` payment run), ending in "Supplier paid".
Decisions: Within budget? Preferred supplier available (or run a quote)? Three-way match OK?
Exceptions:
- Requisition rejected: notify the requester ("Requisition rejected").
- Match discrepancy: resolve with the supplier or the requester, then match again (rework loop).
- Partial or late delivery: a timer on the delivery wait to chase the supplier.
- Supplier can't deliver: re-source through Procurement.
Controls: approval limits, segregation of duties (whoever raises the PO doesn't approve payment), the three-way match, a vendor master check for new suppliers.
KPIs: requisition-to-PO cycle time, spend under management, invoice exception rate, on-time payment, early-payment discounts captured.Recruitment reference
From an approved vacancy to a signed offer: requisition, sourcing, screening, interviews and offer.
Lanes: Hiring manager, HR or talent acquisition, Interview panel, Candidate (message partner), Finance (for unbudgeted roles).
Trigger: `start Vacancy identified`.
Happy path:
1. Create job requisition (Hiring manager).
2. Approve headcount (Finance or HR, see the approval topic).
3. Publish job posting (HR, `service` to job boards).
4. Screen applications (HR).
5. Interview candidates (Interview panel); usually a `sub` or `call` when there are several rounds.
6. Select candidate (Hiring manager).
7. Run background checks (HR, `service` or an external provider).
8. Send offer (HR, `send`), then wait for the answer, ending in "Offer accepted".
Decisions: Role budgeted? Enough qualified candidates? Candidate selected? Background check clear? Offer accepted?
Exceptions:
- No suitable candidates: re-advertise or use an agency (loop back to sourcing).
- Offer declined or no answer within the deadline: an event-based gateway between the acceptance message and a timer; go back to the shortlist or reopen the search.
- Background check fails: withdraw the offer ("Offer withdrawn").
Controls: headcount approval, structured interviews and scorecards, equal-opportunity record keeping.
KPIs: time to hire, time to fill, offer acceptance rate, quality of hire.
Hand-off: "Offer accepted" is the trigger of employee onboarding; suggest it as a separate diagram.Returns and refunds reference
Retail and e-commerce returns: authorization, shipping back, inspection, and refund, exchange or rejection.
Lanes: Customer, Customer service, Warehouse or returns center, Finance.
Trigger: `start:message Return requested`.
Happy path:
1. Check return eligibility (Customer service; a `rule` task for the policy window and condition).
2. Issue return authorization and label (Customer service, `send`).
3. Wait for the parcel (`catch:message Parcel received`, with a timer for returns never sent).
4. Inspect returned item (Warehouse, `manual`).
5. Restock or dispose item (Warehouse).
6. Issue refund (Finance, `service` to the original payment method), ending in "Refund issued".
Decisions: Within the return window? Refund or exchange? Item condition acceptable (full refund, partial refund, reject)?
Exceptions:
- Not eligible: notify the customer ("Return declined").
- Parcel not received within, say, 30 days: close the authorization ("Return expired").
- Damaged or used item: partial refund or send back to the customer.
- Exchange: create a replacement order, a `call` into order to cash.
Controls: fraud checks for serial returners, refund approval above a threshold, refunds only to the original payment method.
KPIs: return rate, refund cycle time, recovery value of returned stock, customer satisfaction.Sequence diagrams
For sequence diagrams: the sequence code syntax and the drawing style the app follows, and reference interactions for common flows. The AI adapts a reference to the systems you name.
Sequence code syntax (what write_diagram takes and get_diagram returns)
title <text> the diagram's name
autonumber [<start> [<step>]] number the messages 1, 2, 3, or from start by step
participant <name> [as <alias>] declare a column; the other kinds draw UML's shapes
actor <name> / database <name> a person; a data store
queue <name> a queue or topic; also collections, boundary, control and entity
box <label> ... end box a labelled box round the participants declared inside it
participant <name> #blue a colour after a participant's declaration, or after a box's quoted label (box "Team" #blue); a palette name or #RRGGBB
<from>-[#red]><to>: <text> a coloured message: the colour inside the arrow after its first dash (-[#red]-> a reply, -[#red]>> async)
note over <a> #green: <text> a coloured note; alt#green <condition> colours a fragment (any kind)
<from>-><to>: <text> a call: solid line, filled head; the caller waits for an answer
<from>--><to>: <text> a reply to an earlier call: dashed line
<from>->><to>: <text> an async message: solid line, open head; nobody waits
<from>-><to> ++: <text> the message activates the receiver (starts its bar)
<from>--><to> --: <text> the message ends the sender's bar
<from><-><to>: <text> a message both ways: a head at each end
<to><--<from>: <text> written right to left (<-, <--, <<-): the same message as <from>--><to>; get_diagram writes it left to right
<from>->(2)<to>: <text> the message takes time to arrive: its line slants down 2 steps (1 to 20)
<from>->x <to>: <text> the message fails: a cross at its end; ->o <to> is lost on the way
[-><to>: <text> / <from>->]: <text> a message from outside the diagram / out of it
<from>-><to> **: <text> the message creates the receiver, whose head is drawn level with it
destroy <name> end a lifeline in a cross
activate <name> / deactivate <name> start or end a bar on a line of its own
note over <a>[, <b>]: <text> a note over one or more participants; also note left of / note right of <a>
note over <a> a note of several lines, closed by "end note"
alt <condition> / else <condition> / end branches, one taken; par <label> / and <label> / end runs them together
opt <condition> ... end happens only when the condition holds
loop <condition> ... end repeats; also break and group, each with one branch
strict <label> ... end UML's other operators, drawn like group with their word on the tab: seq, strict, neg, ignore, consider, assert, region
critical <label> / option <label> / end work that can't be interrupted, then its other outcomes
ref over <a>[, <b>]: <text> a frame for an interaction drawn in another diagram
== <text> == a divider between phases
...<text>... time passes: a gap in the lifelines
// <text> a comment on a line of its own; /* ... */ too
Participants are created by the first line that names them, left to right in that order. Declare them at the top to fix the order, set a kind, or give a long name a short alias.
Names with spaces or symbols go in quotes: "Users DB"->API: Query. In message and note text, \n is a line break.
Message, note and ref text can be styled: **bold**, *italic*, `code` and ~~struck~~; pasted PlantUML tags such as <color:red>, <b> and <u> are drawn too (<size> and the like are dropped). Use it sparingly, when the user asks or a word needs stress.
Indent the lines inside a fragment by two spaces.
Code from sequencediagram.org and PlantUML reads as it is: participantgroup is a box, box/abox/rbox/state over are notes, A->*B and create B create B, A-xB fails, thread is and; their settings lines, space, icons and styling are read past. A whole Mermaid or PlantUML file can be passed as it is.
get_diagram prints every element's id. Keep those ids when you rewrite a diagram, so the user's comments stay on their elements.
Example
title Sign in with Google
actor User
participant App
participant Google
database Users DB as DB
User->App: Continue with Google
activate App
App->Google: Authorization request
Google-->App: Authorization code
App->Google: Exchange code for tokens
Google-->App: ID token
alt invited email
App->DB: Find or create user
DB-->App: User
App-->User: Signed in
else not invited
App-->User: Not invited yet
end
deactivate AppSequence diagram style
- One interaction per diagram, named for what it achieves ("Sign in with Google", "Checkout payment").
- Participants left to right in the order the interaction reaches them; the one who starts it first. People are actors, data stores are databases, queues and topics are queues. A box round participants marks a boundary the reader needs, such as a third party.
- Messages say what travels, in a few words: an action for a call ("Create payment"), a result for a reply ("Payment confirmed", "404"). Replies go back to the caller with -->.
- Async messages (->>) for events and queues: the sender doesn't wait.
- Frames: alt for one branch of several, opt for maybe, loop for repetition (say the limit: "up to 5 times"), par for work at the same time, break to leave early, critical for work that can't be interrupted, group to label a part.
- Activation bars for who is busy while waiting, usually the service handling the request: "A->B ++" on the call and "B-->A --" on its answer.
- Notes for timeouts, security rules and other facts the arrows can't carry; dividers to split phases.
- One level of detail, picked from the request: an overview of about 3-6 participants and up to 15 messages, the happy path and the failure that matters; or a detailed diagram of up to 8 participants and 30 messages with every case stated. An overview has at most three fragments; an exchange stays as one message with its retries and timing in its text, and the exchanges with a party off the overview fold into a ref that says what it covers, or into its own diagram.API request and response reference
A client calling a service that reads or writes data, the shape most interactions build on.
Participants: the caller (actor User or participant Web app), the API (or a gateway in front of it), the service that does the work if it is separate, and the data store (database).
Happy path:
actor User
participant Web app
participant API
database Orders DB as DB
User->Web app: Open order history
Web app->API ++: GET /orders
API->DB: Query orders for user
DB-->API: Orders
API-->Web app --: 200 OK, orders
Web app-->User: Show orders
Failure paths worth drawing, as alt branches after the call:
- Not signed in or token expired: "401 Unauthorized", and the app sends the user to sign in.
- Not found or not allowed: "404" or "403", and what the app shows.
- Service or database down: "503", with a retry or an error message.
- Validation failed on a write: "422" with the field errors.
Add a cache in front of the store as its own participant (see "cache-aside"), and a gateway only when it does work the reader cares about (auth, rate limits).Cache-aside reference
A service that checks a cache before the database and fills it on a miss.
Participants: Client, API, Cache (participant), Database (database).
participant Client
participant API
participant Cache
database Products DB as DB
Client->API ++: GET /products/42
API->Cache: Get product:42
alt cache hit
Cache-->API: Product
else cache miss
Cache-->API: Nothing
API->DB: Read product 42
DB-->API: Product
API->>Cache: Set product:42, TTL 10 min
end
API-->Client --: 200 OK, product
On a write, the API updates the database and then deletes or overwrites the cache key; draw that as its own diagram or a second phase after a divider. A note can carry the TTL or the invalidation rule.OAuth and OpenID Connect sign-in reference
Signing a user in with an identity provider (Google, Microsoft, Okta) using the authorization code flow with PKCE.
Participants: actor User, participant App (the browser app or its backend), participant the identity provider, and the app's user store (database) when accounts are created or looked up.
actor User
participant App
participant Identity provider as IdP
database Users DB as DB
User->App ++: Sign in with Google
App-->User: Redirect to the provider
User->IdP: Sign in and allow access
IdP-->App: Authorization code
App->IdP: Exchange code for tokens
IdP-->App: ID token and access token
App->DB: Find or create user by email
DB-->App: User
App-->User --: Signed in
note over App, IdP: PKCE and state checked on every request
Failure paths worth drawing:
- The user cancels or denies access: the provider returns an error instead of a code, and the app shows the sign-in page again.
- State or PKCE check fails: the app rejects the callback.
- The account isn't allowed (not invited, wrong domain): an alt after the user lookup.
- Token refresh later on is its own interaction; don't add it to sign-in.Webhook delivery with retries reference
A provider notifying a subscriber's endpoint about an event, retrying until it is acknowledged.
Participants: the provider's event source (participant), its delivery worker or queue (participant), the subscriber's endpoint (participant), and the subscriber's store (database) when the endpoint records the event.
participant Billing
participant Webhook worker as Worker
participant Merchant endpoint as Endpoint
database Merchant DB as DB
Billing->>Worker: invoice.paid event
loop up to 5 attempts, backing off
Worker->Endpoint ++: POST event, signed
alt delivered
Endpoint->DB: Store event if new
DB-->Endpoint: Stored
Endpoint-->Worker --: 200 OK
else endpoint error or timeout
Endpoint-->Worker: 5xx or no answer
end
end
note over Worker, Endpoint: The endpoint checks the signature and ignores events it has seen
Draw the attempts with loop and say the limit in its condition. After the last failed attempt, a break can show the event going to a dead-letter queue or the subscriber being alerted. The provider-to-worker hop is async (->>): the event source doesn't wait.Queue-based async work reference
A service that accepts a request, hands the work to a queue, and lets a worker finish it later.
Participants: Client, API, Queue (participant), Worker, and what the worker writes to or notifies.
actor User
participant API
participant Jobs queue as Queue
participant Worker
database Reports DB as DB
User->API ++: Export report
API->>Queue: Enqueue export job
API-->User --: 202 Accepted, job id
Queue->>Worker: Export job
Worker->DB: Read report rows
DB-->Worker: Rows
Worker->>User: Email download link
Use ->> for every hop where the sender doesn't wait: enqueueing, delivery to the worker, and notifications. The API answers right away (202) instead of waiting for the work. Failure paths: a loop for retries on the worker, and a break to a dead-letter queue after the last one. If the client polls for the result, draw the poll as a loop of calls with a condition such as "until the job is done".Card payment with 3-D Secure reference
A checkout taking a card payment through a payment provider, with a bank challenge when the card needs one.
Participants: actor Shopper, participant Shop (the store's backend), participant the payment provider, participant Bank (the card issuer's 3-D Secure service).
autonumber
actor Shopper
participant Shop
participant Payments
participant Bank
Shopper->Shop: Pay for order
Shop->Payments ++: Create payment
Payments->Bank: Authorize card
alt challenge required
Bank-->Payments: 3-D Secure challenge
Payments-->Shop: Redirect to challenge
Shop-->Shopper: Show bank page
Shopper->Bank: Approve payment
Bank-->Payments: Authorized
else no challenge
Bank-->Payments: Authorized
end
Payments-->Shop --: Payment confirmed
Shop-->Shopper: Order placed
Payments->>Shop: payment.succeeded webhook
Failure paths worth drawing: card declined or challenge failed (an alt branch with "Payment declined" back to the shopper), and the shopper abandoning the challenge (a break). The webhook is async and is what the shop should trust to fulfil the order; a note can say so.ER diagrams
For ER diagrams: the schema code syntax and the modeling style the app follows, and reference schemas for common kinds of system. The AI adapts a reference to what you store and the names you use.
Schema code syntax (DBML; what write_diagram takes and get_diagram returns)
Project <name> { the diagram's name, database and note (optional)
database_type: 'PostgreSQL' PostgreSQL, MySQL, SQL Server, SQLite or Oracle: sets the types you write
Note: 'What this schema is for'
}
Table <name> [headercolor: #3498DB] { a table; schema.name outside the default schema; "as <alias>" before the settings
<column> <type> [<settings>] one column per line
Note: 'What a row is'
indexes {
(a, b) [pk] a composite primary key
email [unique] a unique index; (a, b) [unique] across columns
created_at a plain index; [name: 'ix_name', type: btree]
}
checks {
`end_date > start_date` [name: 'dates'] a rule every row must pass
}
}
Column settings, comma separated: pk, increment, unique, not null, default: <value>, check: `price >= 0`, note: '...', ref: > other.id
default: 0 / true / 'draft' / `now()` a value, or an expression in backticks
ref: > users.id this column points at users.id: many to one
ref: - users.id one to one; ref: <> tags.id many to many (better a junction table)
Ref: orders.customer_id > customers.id [delete: cascade, update: no action]
a relationship on a line of its own; name it with Ref name: ...
Ref: order_items.(order_id, line) > orders.(id, line)
composite keys
Enum <name> { a type with fixed values; columns use it by name
pending
paid [note: 'Money received']
}
TableGroup <name> [color: #27AE60] { a frame round related tables
orders
order_items
}
TablePartial timestamps { columns several tables share, written once
created_at timestamp [not null]
}
Table posts {
id int [pk]
~timestamps takes the partial's columns in here; change them in the partial
}
Records posts(id, title) { sample rows: kept with the table, not drawn; leave them as they are
1, 'Hello'
}
Note <name> { a note of its own on the canvas
'Orders are never deleted, only cancelled.'
}
A Note's text can be styled: **bold**, *italic*, `code` and ~~struck~~; use it sparingly, when the user asks or a word needs stress.
Colours (headercolor on a Table, color on a TableGroup, a Ref or a Note) are the user's choice: keep them, and set one only when asked, or when you copy a diagram or picture that uses them (the nearest of Red #E74C3C, Orange #E67E22, Yellow #F1C40F, Green #27AE60, Blue #3498DB, Purple #8E44AD, Pink #E84393, Grey #7F8C8D, on the matching element). An Enum can't carry one in the code: set it with edit_diagram's color.
// <text> a comment on a line of its own
Names with spaces or symbols go in double quotes: "order items". Text goes in single quotes.
Columns are nullable unless marked not null; primary key columns are never null.
get_diagram prints every element's id. Keep those ids when you rewrite a diagram, so the user's comments stay on their elements.
Example
Project shop {
database_type: 'PostgreSQL'
}
Enum order_status {
pending
paid
shipped
}
Table customers {
id integer [pk, increment]
email varchar(255) [unique, not null]
name varchar(120) [not null]
created_at timestamp [not null, default: `now()`]
}
Table orders {
id integer [pk, increment]
customer_id integer [not null, ref: > customers.id]
status order_status [not null, default: 'pending']
total decimal(10,2) [not null]
created_at timestamp [not null, default: `now()`]
}ER diagram style
- One schema per diagram, named for the system it serves ("Online store", "Team workspace").
- Plural snake_case table names, snake_case columns, <thing>_id for foreign keys.
- A primary key on every table; composite keys for junction tables.
- Foreign keys with the type of the key they point at; not null when the row can't exist without its parent.
- Enums for fixed states, lookup tables for lists that change.
- Constraints that protect the data: unique emails and slugs, not null on required fields, sensible defaults.
- Money as decimal, times as timestamp, flags as boolean with a default.
- Indexes on columns searched or joined often.
- Table groups for areas of the system once the schema passes about eight tables.
- One level of detail, picked from the request: an overview of about 6-10 tables with keys and the columns that define each, the main entities and how they relate; or a detailed schema of up to 25 tables with every column, constraint and index. The tables the work produces (trips, payments, orders) stay; a log, history or line table folds into a note on its parent that says what it holds, and a catalogue goes before them.Online store schema reference
Customers, a catalog with variants, carts, orders and payments.
Decisions that matter:
- An order copies what it needs at the time: unit_price on order_items and the shipping address id, so later price or address edits don't rewrite history.
- Sellable things are product_variants (size, colour) with their own sku and price; products group them.
- Payments are their own table: one order can have a failed attempt, then a captured one, then a refund.
- Money as decimal(10,2), or integer cents named *_cents. Never float.
Enum order_status {
pending
paid
shipped
cancelled
}
Table customers {
id integer [pk, increment]
email varchar(255) [unique, not null]
name varchar(120) [not null]
created_at timestamp [not null, default: `now()`]
}
Table products {
id integer [pk, increment]
name varchar(255) [not null]
slug varchar(255) [unique, not null]
}
Table product_variants {
id integer [pk, increment]
product_id integer [not null, ref: > products.id]
sku varchar(64) [unique, not null]
price decimal(10,2) [not null]
stock integer [not null, default: 0]
}
Table orders {
id integer [pk, increment]
customer_id integer [not null, ref: > customers.id]
status order_status [not null, default: 'pending']
total decimal(10,2) [not null]
placed_at timestamp [not null, default: `now()`]
}
Table order_items {
id integer [pk, increment]
order_id integer [not null, ref: > orders.id]
variant_id integer [not null, ref: > product_variants.id]
quantity integer [not null]
unit_price decimal(10,2) [not null]
}
Table payments {
id integer [pk, increment]
order_id integer [not null, ref: > orders.id]
provider_ref varchar(255) [unique, not null]
amount decimal(10,2) [not null]
status varchar(20) [not null]
}
Often missed: addresses as their own table (customers have several), categories as a self-reference (parent_id) or a junction product_categories, carts and cart_items for a basket that outlives a session, shipments when one order ships in parts, an index on orders.customer_id.Multi-tenant SaaS schema reference
Accounts (workspaces, organisations or teams) that own everything, people who belong to several, roles and invites.
Decisions that matter:
- Every tenant-owned table carries the tenant's id (team_id, org_id), not null, even when it could be reached through a parent: queries and access checks filter on it directly.
- People and tenants are many-to-many: a memberships junction with the role, and a composite primary key (user_id, team_id).
- Invites are their own table: an email that isn't a user yet, who invited them, and when it expires.
- Plans and billing hang off the tenant, not the user.
Enum member_role {
owner
admin
member
}
Table users {
id integer [pk, increment]
email varchar(255) [unique, not null]
name varchar(120)
created_at timestamp [not null, default: `now()`]
}
Table teams {
id integer [pk, increment]
name varchar(120) [not null]
slug varchar(60) [unique, not null]
created_at timestamp [not null, default: `now()`]
}
Table memberships {
user_id integer [not null, ref: > users.id]
team_id integer [not null, ref: > teams.id]
role member_role [not null, default: 'member']
indexes {
(user_id, team_id) [pk]
}
}
Table invites {
id integer [pk, increment]
team_id integer [not null, ref: > teams.id]
email varchar(255) [not null]
role member_role [not null, default: 'member']
invited_by integer [not null, ref: > users.id]
expires_at timestamp [not null]
}
Table projects {
id integer [pk, increment]
team_id integer [not null, ref: > teams.id]
name varchar(255) [not null]
created_by integer [not null, ref: > users.id]
}
Often missed: a unique index on (team_id, email) for invites, subscriptions with plan and status on the tenant, an api_keys table owned by the tenant, audit events (see "history-schema").Booking and scheduling schema reference
Clients booking a time slot for a service with a provider (staff, room or resource).
Decisions that matter:
- A booking stores starts_at and ends_at (or a duration copied from the service at booking time), so changing a service doesn't move past bookings.
- Double booking is prevented by a unique index on (staff_id, starts_at), or an exclusion constraint where the database has one.
- Availability is its own table: weekly opening hours per provider, with exceptions for days off.
- Cancellation is a status with cancelled_at, not a deleted row.
Enum booking_status {
booked
completed
cancelled
no_show
}
Table clients {
id integer [pk, increment]
name varchar(120) [not null]
email varchar(255) [unique, not null]
}
Table staff {
id integer [pk, increment]
name varchar(120) [not null]
active boolean [not null, default: true]
}
Table services {
id integer [pk, increment]
name varchar(120) [not null]
minutes integer [not null]
price decimal(10,2) [not null]
}
Table bookings {
id integer [pk, increment]
client_id integer [not null, ref: > clients.id]
staff_id integer [not null, ref: > staff.id]
service_id integer [not null, ref: > services.id]
starts_at timestamp [not null]
ends_at timestamp [not null]
status booking_status [not null, default: 'booked']
cancelled_at timestamp
indexes {
(staff_id, starts_at) [unique]
}
}
Table availability {
id integer [pk, increment]
staff_id integer [not null, ref: > staff.id]
weekday smallint [not null]
opens time [not null]
closes time [not null]
}
Often missed: which services each provider offers (a junction staff_services), time zones (store timestamps in UTC, the location's zone on the location), payments or deposits per booking, reminders sent.Invoicing and billing schema reference
Customers billed with invoices made of line items, paid by one or more payments.
Decisions that matter:
- An invoice has a human number, unique, separate from its id, and a status (draft, sent, paid, void).
- Line items copy description, quantity and unit price; the invoice's totals are stored once it is sent, so they never change.
- Payments and invoices can be many-to-many when one payment settles several invoices: a payment_allocations junction with the amount applied.
- Taxes are per line (tax_rate), and amounts are decimal(12,2) with a currency char(3).
Enum invoice_status {
draft
sent
paid
void
}
Table customers {
id integer [pk, increment]
name varchar(255) [not null]
billing_email varchar(255) [not null]
}
Table invoices {
id integer [pk, increment]
customer_id integer [not null, ref: > customers.id]
number varchar(30) [unique, not null]
status invoice_status [not null, default: 'draft']
currency char(3) [not null]
issued_at date
due_at date
total decimal(12,2) [not null, default: 0]
}
Table invoice_lines {
id integer [pk, increment]
invoice_id integer [not null, ref: > invoices.id]
description varchar(255) [not null]
quantity decimal(10,2) [not null]
unit_price decimal(12,2) [not null]
tax_rate decimal(5,2) [not null, default: 0]
}
Table payments {
id integer [pk, increment]
customer_id integer [not null, ref: > customers.id]
amount decimal(12,2) [not null]
received_at timestamp [not null]
method varchar(30) [not null]
}
Table payment_allocations {
payment_id integer [not null, ref: > payments.id]
invoice_id integer [not null, ref: > invoices.id]
amount decimal(12,2) [not null]
indexes {
(payment_id, invoice_id) [pk]
}
}
Often missed: credit notes as negative invoices or their own table, products or price lists the lines come from, subscriptions that generate invoices, an index on invoices.due_at for overdue reports.Content and publishing schema reference
Authors writing posts or articles, with comments, tags and categories.
Decisions that matter:
- A post has a unique slug for its URL, a status (draft, published, archived) and published_at, which stays empty until it is published.
- Tags are many-to-many: a post_tags junction with a composite primary key. Categories are usually one per post (category_id) or a tree (parent_id).
- Comments belong to a post and, for threads, to a parent comment; guests' comments carry a name and email instead of a user.
Enum post_status {
draft
published
archived
}
Table authors {
id integer [pk, increment]
email varchar(255) [unique, not null]
name varchar(120) [not null]
}
Table posts {
id integer [pk, increment]
author_id integer [not null, ref: > authors.id]
title varchar(255) [not null]
slug varchar(255) [unique, not null]
body text [not null]
status post_status [not null, default: 'draft']
published_at timestamp
}
Table comments {
id integer [pk, increment]
post_id integer [not null, ref: > posts.id]
parent_id integer [ref: > comments.id]
name varchar(120) [not null]
body text [not null]
created_at timestamp [not null, default: `now()`]
}
Table tags {
id integer [pk, increment]
name varchar(60) [unique, not null]
}
Table post_tags {
post_id integer [not null, ref: > posts.id]
tag_id integer [not null, ref: > tags.id]
indexes {
(post_id, tag_id) [pk]
}
}
Often missed: media or attachments as their own table, revisions when edits need a history (see "history-schema"), an index on (status, published_at) for the listing page.History, soft delete and audit reference
Keeping what changed and who changed it, without losing the current row.
Choose by what the user needs:
- Soft delete: deleted_at timestamp (nullable) on the table; queries skip rows that have one. Unique indexes then need the database's partial index, so mention it in a Note.
- Who and when: created_at, updated_at and, when it matters, created_by and updated_by referencing users. Add them where the user asked, not everywhere.
- Full history of one table: a <table>_versions table with the same columns plus version integer, changed_at and changed_by, and a composite key (<table>_id, version).
- An audit log across tables: one audit_events table with actor, action, table name, row id and a jsonb of the change. It points at rows by value, not by foreign key, so it survives deletes.
Table audit_events {
id bigint [pk, increment]
actor_id integer [ref: > users.id]
action varchar(20) [not null]
table_name varchar(60) [not null]
row_id varchar(60) [not null]
changes jsonb
at timestamp [not null, default: `now()`]
indexes {
(table_name, row_id)
}
}
Don't add history the user didn't ask for: it doubles the tables to read.Flowcharts
For flowcharts: the Mermaid flowchart syntax and the drawing style the app follows, and patterns for common flows. The AI adapts a pattern to your steps and names.
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
---
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])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.Pattern: approval flow (adapt names and thresholds to the user's)
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])
Notes: each decision has a labelled way out per answer; incomplete requests loop back to the start; both outcomes end at one close.Pattern: 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])
Notes: 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.Pattern: retry loop with a limit
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])
Notes: 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.