Skip to content

Sequence diagram syntax

Sequence diagrams are a type of diagram defined by the Mermaid syntax, often used within tools like Obsidian to visualize interactions between participants over time^[600-developer-tools-obsidian-johnny-ob-037.md]. They are distinct from other graph types like flowcharts or Gantt charts^[600-developer-tools-obsidian-johnny-ob-037.md].

Basic Syntax

The syntax for sequence diagrams involves defining participants (actors or systems) and describing the messages sent between them^[600-developer-tools-obsidian-johnny-ob-037.md].

Arrows and Messages

Different arrow types are used to represent different kinds of interactions:

  • ->>: Represents a solid line with an open arrowhead, typically used for synchronous messages or simple signals^[600-developer-tools-obsidian-johnny-ob-037.md].
    • Example: Alice->>John: Hello John, how are you?
  • -->>: Represents a dashed line with an open arrowhead, often used for return messages or asynchronous responses^[600-developer-tools-obsidian-johnny-ob-037.md].
    • Example: John-->>Alice: Hi Alice, I can hear you!

Activation

Mermaid allows for explicit control over participant "activation" (the focus of control or activity lifespan) by adding specific suffixes to the arrow operators^[600-developer-tools-obsidian-johnny-ob-037.md]:

  • +: Activates the receiver. This adds an activation bar to the participant's lifeline starting at the receipt of the message^[600-developer-tools-obsidian-johnny-ob-037.md].
    • Example: Alice->>+John: Hello John, how are you?
  • -: Deactivates the receiver. This removes the activation bar from the lifeline^[600-developer-tools-obsidian-johnny-ob-037.md].
    • Example: John-->>-Alice: I feel great!

Advanced Features

Loops

The syntax supports logical control structures such as loops^[600-developer-tools-obsidian-johnny-ob-037.md]. A loop block encloses messages that are to be repeated^[600-developer-tools-obsidian-johnny-ob-037.md].

  • Syntax:
    loop [Label]
      [Messages]
    end
    
  • Example:
    loop Healthcheck
        John->>John: Fight against hypochondria
    end
    

Notes

Annotations can be added to the diagram to provide context or comments regarding specific participants or timeframes^[600-developer-tools-obsidian-johnny-ob-037.md].

  • Syntax: Note [right/left of] [Participant]: [Text]
  • Example: Note right of John: Rational thoughts!

Code Example

The following is a complete example combining participants, activation, and notes^[600-developer-tools-obsidian-johnny-ob-037.md]:

sequenceDiagram
Alice->>+John: Hello John, how are you?
Alice->>+John: John, can you hear me?
John-->>-Alice: Hi Alice, I can hear you!
John-->>-Alice: I feel great!
  • [[Mermaid]]
  • [[Obsidian]]

Sources

^[600-developer-tools-obsidian-johnny-ob-037.md]