Fragments and notes

Write fragments, notes, refs, dividers and delays in sequence code.

Fragments frame messages that happen only in some cases, or more than once. Notes, refs, dividers and delays add what the arrows can't say.

Fragments

alt card accepted
  Payments-->Shop: Payment confirmed
else card declined
  Payments-->Shop: Declined
end

par
  Shop->>Email: Send receipt
and
  Shop->>Warehouse: Pick order
end

loop up to 3 times
  Worker->Receiver: POST /webhooks
end

A fragment starts with its kind and an optional condition, and closes with end. See Fragments for what each kind means.

The kinds are alt, opt, loop, par, break, critical and group. UML's other operators are seq, strict, neg, ignore, consider, assert and region. These have one branch and a label: consider login, logout. sequencediagram.org's expandable+ and expandable- read as group.

How branches start:

  • In an alt, each branch after the first starts with else and its condition.
  • In a par, each branch after the first starts with and, or sequencediagram.org's thread.
  • In a critical, each other outcome starts with option and its condition.
  • The other kinds have one branch.

Fragments can sit inside other fragments.

Notes

note over App: Token cached for 5 minutes
note over App, Auth server: PKCE checked on every request
note left of User: On a phone
note right of Receiver
  Signed with HMAC-SHA256
  Replays rejected after 5 minutes
end note
  • note over takes one participant, or several separated by commas, and spans them.
  • note left of and note right of take one participant.
  • For a note of several lines, leave out the colon, write the lines below, and close them with end note. \n in a note's text also starts a new line.

Some other tools' words are notes too. These are sequencediagram.org's box, abox, rbox and state, and PlantUML's hnote and rnote, followed by over, left of or right of: box over API: validates cart. One of several lines closes with its own word, such as end box.

Refs

ref over Shop, Payments: Take payment
ref over Shop
  Notify customer
  by email and SMS
end ref

A ref is a frame that stands for an interaction drawn in another diagram. It goes over one participant, or spans several separated by commas.

For text of several lines, leave out the colon and close the lines with end ref.

Dividers and delays

== Delivery ==
...2 days later...
...

A divider is a label between two ==, across the whole diagram. Use one to split a long interaction into phases.

A delay is ..., with optional text and another ... after it. It shows that time passes: the lifelines turn dotted for a row.

On this page