Sequence diagrams for Choreo.
Sequence diagrams show how participants interact with each other over time.
Unlike most other Choreo modules, this module is heavily skewed toward
Mermaid's native sequenceDiagram syntax — GraphViz has no native
sequence-diagram concept, so the DOT renderer is provided as a best-effort
timeline-style fallback.
Supported features
- Participants and Actors (external roles)
- Synchronous, asynchronous, return, and self messages
- Activation boxes (
activate/deactivate) - Notes (
over,left,rightof a participant, orbetweentwo) - Loops and fragments (
loop,opt,alt/else,par,break,critical)
Example
iex> alias Choreo.Sequence
iex> Sequence.new()
...> |> Sequence.add_actor(:user, label: "User")
...> |> Sequence.add_participant(:api, label: "API")
...> |> Sequence.add_participant(:db, label: "Database")
...> |> Sequence.message(:user, :api, label: "GET /accounts")
...> |> Sequence.activate(:api)
...> |> Sequence.message(:api, :db, label: "SELECT * FROM accounts")
...> |> Sequence.return(:db, :api, label: "rows")
...> |> Sequence.deactivate(:api)
...> |> Sequence.return(:api, :user, label: "200 OK")
...> |> Sequence.to_mermaid()
...> |> String.split("\n")
...> |> Enum.take(4)
["sequenceDiagram", " actor User", " participant API", " participant Database"]
Summary
Functions
Emits an activate event for the given participant.
Adds an actor (external person or system) to the diagram.
Adds a participant to the diagram.
Adds an asynchronous message.
Emits a deactivate event for the given participant.
Ends the most recently started fragment.
Returns all ordered events in the diagram.
Starts a fragment (loop, opt, alt, par, break, critical).
Adds a message from from to to.
Returns messages in chronological order.
Creates a new empty sequence diagram.
Adds a note to the diagram.
Returns metadata for a participant.
Returns all participants/actors in the diagram.
Adds a return message.
Adds a self-message on the given participant.
Renders the diagram as a DOT graph (best-effort timeline view).
Renders the diagram as a Mermaid sequence diagram.
Types
@type event_type() :: :message | :activation | :note | :fragment
@type fragment_kind() :: :loop | :opt | :alt | :else | :par | :break | :critical
@type message_type() :: :sync | :async | :return | :self
Functions
Emits an activate event for the given participant.
Adds an actor (external person or system) to the diagram.
Options
:label- display name (defaults toMacro.camelize/1of the id):description- longer description (used by analysis, not rendered)
Adds a participant to the diagram.
Options
:label- display name:description- longer description
Adds an asynchronous message.
Emits a deactivate event for the given participant.
Ends the most recently started fragment.
Returns all ordered events in the diagram.
@spec fragment(t(), fragment_kind(), String.t() | nil) :: t()
Starts a fragment (loop, opt, alt, par, break, critical).
Examples
seq
|> Sequence.fragment(:loop, "for each item")
|> Sequence.message(:a, :b, label: "process")
|> Sequence.end_fragment()
seq
|> Sequence.fragment(:alt, "x > 0")
|> Sequence.message(:a, :b, label: "positive")
|> Sequence.fragment(:else, "otherwise")
|> Sequence.message(:a, :b, label: "negative")
|> Sequence.end_fragment()
Adds a message from from to to.
Options
:label- message label:type-:sync(default),:async,:return, or:self
A self-message is automatically detected when from == to.
Returns messages in chronological order.
@spec new() :: t()
Creates a new empty sequence diagram.
@spec note(t(), note_position(), String.t()) :: t()
Adds a note to the diagram.
position can be:
{:over, :alice}{:left, :alice}{:right, :alice}{:between, :alice, :bob}
Returns metadata for a participant.
Returns all participants/actors in the diagram.
Adds a return message.
Adds a self-message on the given participant.
Renders the diagram as a DOT graph (best-effort timeline view).
Renders the diagram as a Mermaid sequence diagram.