Sequence Diagrams

A sequence diagram is who says what to whom, in order down the page. It starts with sequence and its title.

sequence Paying at the till
actor Customer
participant Till
participant bank: Bank of Example
database Ledger
Customer -> Till: Scan the items
Till -> bank: Ask to pay 12.50
bank -> Ledger: Hold the amount
Ledger --> bank: Held
if Card accepted
  bank --> Till: Approved
  Till --> Customer: Receipt
else Card declined
  bank --> Till: Declined
  Till --> Customer: Try another card
note over Till, bank: Card details never stay on the till

The text above: a customer, a till, a bank and a ledger, the calls between them with their bars, and an if and an else in one frame

Settings

Setting Also Value
numbers numbered, numbering, autonumber on numbers the messages; off by default. autonumber on a line of its own is the same.
activations activation, bars off leaves out the bars; on by default
mirror footer, heads below off leaves out the participants' heads at the foot; on by default

Participants

Participants are columns, in the order they are first named - in a message, or declared at the top:

Line Draws
participant Till a box
actor Customer (also person) a person
database Ledger a cylinder

A declaration can give a long name a short one to write messages with, either way round: participant bank: Bank of Example, or participant Bank of Example as bank. A colour in brackets after the name colours the participant's head: actor Customer [orange].

Messages

From -> To: what is said is a message, and messages go down the page in the order they are written.

Arrow Is
->, ->> a call: a solid line with a filled head
-->, -->>, ..> a reply: a dashed line with an open head
<-, <-- the same, pointing back at the first name

A call that is answered has a bar on its receiver, from the call to the reply back; a call that never is draws none. A message to oneself - Ann -> Ann: Think - is a loop on its own column. A colour or a role in brackets after the words colours the message: Till --> Customer: Declined [bad].

Blocks

Lines indented under a block's word are drawn in a frame named by that word, with the words after it as its condition:

Word Also For
loop something repeated
if alt a choice; else, at the same indentation after its lines, adds another case
opt optional something that may happen
par parallel things that happen at once; and adds another strand
critical something that must happen whole
break what happens instead of the rest
region any other stretch to frame
sequence A month of banking
numbers: on
actor Ann
participant Bank of Example as Bank
Ann -> Bank: Log in
Bank --> Ann: Welcome
== Every month ==
loop Until the account is closed
  Bank -> Ann: Statement
  Ann --> Bank: Read
par
  Ann -> Bank: Pay the rent
and
  Ann -> Bank: Save a little
note right of Ann: Busy month
Ann -> Ann: Plan next month

The text above: numbered messages, a divider, a loop, a par with two strands, a note and a message to oneself

An else or an and that does not follow its if or its par is said. A message with lines indented under it is warned of - only a block holds lines - and its lines are read as messages.

Notes and dividers

Line Draws
note over A: text a note over A
note over A, C: text a note spanning A to C
note left of A: text a note left of A
note right of A: text a note right of A
== Later that day == a divider across every column