Sequence code

Write a sequence diagram as text, one message per line, starting with a first diagram and the rules that matter.

Sequence code is the text form of a sequence diagram. The Sequence code pane beside the canvas shows it, and you can edit it there. The diagram follows when you pause typing.

The assistant and a connected AI app write the same code, so knowing it helps you read what they draft. The app does the layout, so the code only says who takes part and what they send.

A first diagram

Paste this into the Sequence code pane to see it drawn.

Sequence code
title Password reset
actor User
participant App
database Users DB as DB

User->App: Forgot password
App->DB: Find user by email
alt user found
  DB-->App: User
  App->>User: Email reset link
else no such user
  DB-->App: Nothing
end
App-->User: Check your email

Reading it from the top:

  • title Password reset names the diagram.
  • actor, participant and database declare the columns, left to right. as DB gives a long name a short alias for the lines below.
  • Every other line is a message: who sends it, an arrow, who receives it, then a colon and the text.
  • alt and else start the two branches, and end closes the fragment.

The rules that matter

  1. One element per line, top to bottom. The order of the lines is the order of the messages.
  2. Participants are created as lines name them. The first line that mentions a name adds its column, so you don't have to declare anything. Declare participants at the top to fix their order, set their kind, or give them an alias.
  3. A message needs a colon before its text. App->DB: Find user. You can leave the text out: App->DB draws an arrow with no label.
  4. Fragments close with end. The app's style indents the lines inside by two spaces, which makes the code easier to read. The app doesn't need it.
  5. Keywords and names ignore case. ALT works like alt, and app finds the participant called App.

Title and numbering

title Checkout payment
autonumber

title names the diagram. It's the same name you see at the top of the editor.

autonumber, on a line of its own, numbers the messages 1, 2, 3. autonumber 10 starts at 10, and autonumber 10 5 counts 10, 15, 20. autonumber off turns numbering off again.

Comments

// Happy path only for now
Client->API: GET /orders

A line that starts with // is a comment. The app ignores it, and keeps it in the text when the diagram changes. A // later on a line isn't a comment, so a message's text can hold it.

The other tools' comments are comments too, so code pasted from them reads:

  • /* … */ across one or more lines, as sequencediagram.org writes it.
  • PlantUML's ' at the start of a line, and /' … '/.
  • Mermaid's %%.

Ids

Every participant and element has an id, such as Participant_Shop or Message_CreatePayment. Comments, the assistant and connected AI apps refer to elements by id.

When you edit the code, the app keeps each element's id while it still says the same thing. A participant keeps its id by its alias or name. A message keeps it while it has the same sender, receiver and text. So you can reorder lines and add new ones, and comments stay on their elements.

The rest of the code

The sequence code reference has the complete syntax on one page, exactly as the assistant gets it.

On this page