Overview
Sequence diagrams in Sirena represent interactions between participants over time. They show how processes operate with one another and in what order, making them ideal for documenting system interactions, API calls, and message flows.
Sequence diagrams are useful for:
-
Documenting API interactions and request/response flows
-
Visualizing authentication and authorization processes
-
Mapping multi-system communication patterns
-
Showing temporal relationships between components
-
Illustrating concurrent and asynchronous operations
Syntax specification
Diagram declaration
Sequence diagrams are declared using the sequenceDiagram keyword:
sequenceDiagram
<diagram-content>
Participants
Participants can be declared explicitly or implicitly:
sequenceDiagram
participant Alice
participant Bob
Alice->>Bob: Hello
Messages
Messages connect participants and represent communication:
| Syntax | Style | Description |
|---|---|---|
|
Solid arrow |
Synchronous message with arrowhead |
|
Dotted arrow |
Response or return message |
|
Solid line |
Async message without arrowhead |
|
Dotted line |
Async response without arrowhead |
|
Solid with cross |
Message with cross ending |
|
Dotted with cross |
Response with cross ending |
|
Solid with open arrow |
Async message with open arrow |
|
Dotted with open arrow |
Async response with open arrow |
|
Bidirectional solid |
Bidirectional synchronous message |
|
Bidirectional dotted |
Bidirectional async message |
Activation
Activation boxes show when a participant is actively processing:
sequenceDiagram
Alice->>+Bob: Request
Bob-->>-Alice: Response
The + symbol activates a participant, and - deactivates it.
Explicit activation syntax:
sequenceDiagram
Alice->>Bob: Request
activate Bob
Bob-->>Alice: Response
deactivate Bob
Notes
Notes provide additional context and can be positioned relative to participants:
Note left of Alice: Left note
Note right of Bob: Right note
Note over Alice: Note over one participant
Note over Alice,Bob: Note spanning participants
Conditional blocks
Alt (alternative paths)
The alt block represents conditional execution:
alt Condition description
Alice->>Bob: Message if true
else Another condition
Alice->>Bob: Message if second condition
else
Alice->>Bob: Default message
end
Opt (optional)
The opt block represents optional execution:
opt Optional condition
Alice->>Bob: Optional message
end
Par (parallel)
The par block represents parallel execution:
par Parallel task 1
Alice->>Bob: Message 1
and Parallel task 2
Alice->>Charlie: Message 2
end
Examples
Basic sequence diagram
sequenceDiagram
Alice->>Bob: Hello Bob
Bob-->>Alice: Hello Alice
This creates a simple sequence diagram with two participants exchanging messages.
Sequence with activation
sequenceDiagram
participant User
participant WebApp
participant API
participant Database
User->>+WebApp: Request Product Page
WebApp->>+API: GET /api/product/123
API->>+Database: SELECT * FROM products WHERE id=123
Database-->>-API: Product Data
API-->>-WebApp: JSON Response
WebApp-->>-User: Render Product Page
This example demonstrates:
-
Multiple participants
-
Activation boxes showing processing time
-
Nested activations
-
Request-response patterns
Loop and conditional example
sequenceDiagram
participant User
participant System
participant Database
User->>+System: Login Request
loop Retry up to 3 times
System->>+Database: Verify Credentials
Database-->>-System: Result
alt Valid Credentials
System-->>User: Success
else Invalid Credentials
System-->>User: Error
end
end
System-->>-User: Final Response
This shows:
-
Loop blocks for repeated actions
-
Alt/else blocks for conditional logic
-
Nested control structures
Notes and documentation
sequenceDiagram
participant User
participant Cache
participant API
Note over User,API: First request - cache miss
User->>+Cache: Check Cache
Cache-->>-User: Cache Miss
User->>+API: GET /data
API-->>-User: Data Response
User->>+Cache: Store in Cache
Cache-->>-User: Cached
Note right of Cache: Data now cached
Note over User,API: Second request - cache hit
User->>+Cache: Check Cache
Cache-->>-User: Cache Hit (Fast)
This demonstrates:
-
Notes over multiple participants
-
Notes to the left/right of participants
-
Using notes to explain flow sections
Participant boxes
sequenceDiagram
box "Frontend"
participant User
participant WebApp
end
box "Backend Services"
participant API
participant Database
end
User->>WebApp: Click Button
WebApp->>API: API Request
API->>Database: Query
Database-->>API: Result
API-->>WebApp: Response
WebApp-->>User: Update UI
This shows:
-
Grouping related participants in boxes
-
Visual organization of system layers
-
Clear separation of concerns
Parallel execution
sequenceDiagram
participant User
participant App
participant Service1
participant Service2
User->>App: Request Data
par Fetch User Profile
App->>Service1: Get Profile
Service1-->>App: Profile Data
and Fetch User Posts
App->>Service2: Get Posts
Service2-->>App: Posts Data
end
App-->>User: Combined Response
This demonstrates:
-
Parallel execution using
parblocks -
Multiple concurrent operations
-
Joining results after parallel execution
Comprehensive example with multiple features
sequenceDiagram
autonumber
actor User
participant WebApp
participant API
participant Database
participant Cache
User->>+WebApp: Request Product Page
WebApp->>+Cache: Check Cache
Cache-->>-WebApp: Cache Miss
WebApp->>+API: GET /api/product/123
API->>+Database: SELECT * FROM products WHERE id=123
Database-->>-API: Product Data
API-->>-WebApp: JSON Response
WebApp->>+Cache: Store in Cache
Cache-->>-WebApp: Cached
WebApp-->>-User: Render Product Page
Note over User,Cache: Subsequent request will hit cache
User->>+WebApp: Refresh Page
WebApp->>+Cache: Check Cache
Cache-->>-WebApp: Cache Hit
WebApp-->>-User: Render Product Page (Fast)
This comprehensive example includes:
-
Sequence numbers with
autonumber -
Actor notation for human users
-
Activation boxes
-
Notes explaining behavior
-
Caching pattern
-
Multiple system interactions
Features
Participant declaration
Participants can be declared in any order:
sequenceDiagram
participant Alice
participant Bob
participant Charlie
Or defined implicitly when first used:
sequenceDiagram
Alice->>Bob: Hello
Bob->>Charlie: Hi Charlie
Special characters in names
Participants can have spaces and special characters when quoted:
sequenceDiagram
participant "User Service"
participant "Payment API"
"User Service"->>"Payment API": Process payment
Message text
Messages support long text that will be wrapped:
sequenceDiagram
Alice->>Bob: Extremely long message text that will be wrapped automatically to fit within the diagram boundaries
Limitations
Best practices
Keep participants minimal
Limit the number of participants to maintain readability:
%% Good - 4 participants
sequenceDiagram
User->>API->>Database->>Cache
%% Less readable - too many
sequenceDiagram
A->>B->>C->>D->>E->>F->>G->>H
Use meaningful names
Choose descriptive participant names:
%% Good
sequenceDiagram
participant UserService
participant PaymentGateway
%% Less clear
sequenceDiagram
participant A
participant B
Group related interactions
Use boxes to group related participants:
sequenceDiagram
box "Frontend"
participant UI
participant WebApp
end
box "Backend"
participant API
participant DB
end