Sequence
A sequence diagram shows who talks to whom, in what order: one lifeline per participant, one arrow per message, top to bottom.
sequence login "Sign in" [numbered] {
actor user "Customer" [purple]
participant web, api, db
user -> web: open /login
web -> api: POST /login
api -> db: find user
db --> api: row
note api: compares the **bcrypt** hash
--- session ---
api --> web: 200 + cookie
web -> web: store token
}Syntax
sequence id "Title" [numbered] {
participant api "API" [blue] // declare to set label, colour or order
actor user "Customer" // rounded, for people
participant web, db // order only
user -> web: message // solid
web --> user: reply // dashed
web ..> db: async // dotted
web => api: important // thick
api -> db: write [amber] // a colour tints one message
db --> api: rows [width: 2, head: open] // edge props style one message
api -> api: self call
note api: text over one participant
note web, db: text across several
--- section ---
}Participants appear in order of first use unless declared. numbered puts a number in front of every message. A colour in brackets at the end of a message or note colours it: a -> b: retry [red], note api: slow [amber], or a -> b: [red] without text. Messages take the edge props width, style: solid | dashed | dotted (or dashed, dotted), thick and head: arrow | open | none next to the colour: a -> b: audit [red, dotted, head: open]. Message text takes the inline markup: **bold**, *muted*, `code` and style spans like {red, bold | text} (text).
The header styles the lifelines: lifeline: <colour> and lifeline-style: dashed | dotted | solid (dashed by default). edge-color and edge-width set the ink of every message.
To make room, nudge a part in the layout block or drag its handle in the visual editor. A participant name widens the gap to its left; m3, note1 and d1 (the third message, first note, first --- divider) add space above that row:
layout {
login:api 40
login:m3 24
}Examples
OAuth sign-in
theme: pastel
sequence oauth "Sign in with GitHub" [numbered] {
actor user "User" [purple]
participant app "App"
participant gh "GitHub" [slate]
user -> app: click sign in
app --> user: redirect to GitHub
user -> gh: authorize the app
gh --> app: callback with a code
app -> gh: exchange the code
gh --> app: access token
note app: stores the token **encrypted**
--- later ---
app -> gh: GET /user [blue]
gh --> app: profile
}Background job
Dotted lifelines, async messages and a self call.
theme: midnight
sequence job "Resize an upload" [lifeline-style: dotted] {
participant api "API" [blue]
participant q "Queue" [amber]
participant w "Worker" [green]
api ..> q: enqueue resize
q ..> w: deliver
w -> w: resize to 3 sizes
w -> api: done [dotted, head: open]
w => q: ack
note q, w: retried 3 times on failure [amber]
}Next to the architecture
The graph shows the parts, the panel the conversation between them:
title: Checkout
web "Web" [blue] -> api "API" [blue] -> psp "Payments" [green]
sequence pay "Pay" {
participant web, api, psp
web -> api: POST /checkout
api -> psp: charge 49 €
psp --> api: ok
api --> web: receipt
}