Sequence code reference

The complete sequence code syntax, exactly as the assistant and connected AI apps get it.

This is the reference the in-app assistant has in its instructions when you work on a sequence diagram, and connected AI apps get from lookup_guidance with the topic sequence-code. For a walk-through, see Sequence code.

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

The reference ends with this example.

Sequence code
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 App

On this page