Skill Tracer
Skills › Scientific Agent Skills › markdown-mermaid-writing › sequence.md

sequence.md

182 lines · skills/markdown-mermaid-writing/references/diagrams/sequence.md at 5f2bc03

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1<!-- Source: https://github.com/SuperiorByteWorks-LLC/agent-project | License: Apache-2.0 | Author: Clayton Young / Superior Byte Works, LLC (Boreal Bytes) -->
2
3# Sequence Diagram
4
5> **Back to [Style Guide](../mermaid_style_guide.md)** — Read the style guide first for emoji, color, and accessibility rules.
6
7**Syntax keyword:** `sequenceDiagram`
8**Best for:** API interactions, temporal flows, multi-actor communication, request/response patterns
9**When NOT to use:** Simple linear processes (use [Flowchart](flowchart.md)), static relationships (use [Class](class.md) or [ER](er.md))
11---

<!-- Source: https://github.com/SuperiorByteWorks-LLC/agent-project | License: Apache-2.0 | Author: Clayton Young / Superior Byte Works, LLC (Boreal Bytes) -->

Sequence Diagram

Back to Style Guide — Read the style guide first for emoji, color, and accessibility rules.

Syntax keyword: sequenceDiagram Best for: API interactions, temporal flows, multi-actor communication, request/response patterns When NOT to use: Simple linear processes (use Flowchart), static relationships (use Class or ER)


Raw lines 1 to 12
13## Exemplar Diagram
15This is an illustrative interaction sketch, not a complete OAuth/OIDC implementation
16or a provider endpoint contract. Fill in protocol checks from the chosen provider.
18```mermaid
19sequenceDiagram
20 accTitle: OAuth 2.0 Authorization Code Flow
21 accDescr: Step-by-step OAuth flow between user browser, app server, and identity provider showing the token exchange and error path
23 participant U as 👤 User Browser
24 participant A as 🖥️ App Server
25 participant I as 🔐 Identity Provider
27 U->>A: Click Sign in
28 A-->>U: Redirect to IdP
30 U->>I: Enter credentials
31 I->>I: 🔍 Validate credentials
33 alt ✅ Valid credentials
34 I-->>U: Redirect with auth code
35 U->>A: Send auth code
36 A->>I: Exchange code for token
37 I-->>A: 🔐 Access token (optional refresh token)
38 A-->>U: ✅ Set session cookie
39 Note over U,A: 🔒 User is now authenticated
40 else ❌ Invalid credentials
41 I-->>U: ⚠️ Show error message
42 end
43```
45---

Exemplar Diagram

This is an illustrative interaction sketch, not a complete OAuth/OIDC implementation or a provider endpoint contract. Fill in protocol checks from the chosen provider.

sequenceDiagram
    accTitle: OAuth 2.0 Authorization Code Flow
    accDescr: Step-by-step OAuth flow between user browser, app server, and identity provider showing the token exchange and error path

    participant U as 👤 User Browser
    participant A as 🖥️ App Server
    participant I as 🔐 Identity Provider

    U->>A: Click Sign in
    A-->>U: Redirect to IdP

    U->>I: Enter credentials
    I->>I: 🔍 Validate credentials

    alt ✅ Valid credentials
        I-->>U: Redirect with auth code
        U->>A: Send auth code
        A->>I: Exchange code for token
        I-->>A: 🔐 Access token (optional refresh token)
        A-->>U: ✅ Set session cookie
        Note over U,A: 🔒 User is now authenticated
    else ❌ Invalid credentials
        I-->>U: ⚠️ Show error message
    end

Raw lines 13 to 46
47## Tips
49- Limit to **4–5 participants** — more becomes unreadable
50- Solid arrows (`->>`) for requests, dashed (`-->>`) for responses; open arrows (`-)`) can denote asynchronous messages
51- Use `alt/else/end` for conditional branches
52- Use `Note over X,Y:` for contextual annotations with emoji
53- Use `par/end` for parallel operations
54- Use `loop/end` for repeated interactions
55- Emoji in **message text** works great for status clarity (✅, ❌, ⚠️, 🔐)

Tips

  • Limit to 4–5 participants — more becomes unreadable
  • Solid arrows (->>) for requests, dashed (-->>) for responses; open arrows (-)) can denote asynchronous messages
  • Use alt/else/end for conditional branches
  • Use Note over X,Y: for contextual annotations with emoji
  • Use par/end for parallel operations
  • Use loop/end for repeated interactions
  • Emoji in message text works great for status clarity (✅, ❌, ⚠️, 🔐)
Raw lines 47 to 56
57## Common Patterns
59**Parallel calls:**
61```
62par 📥 Fetch user
63 A->>B: GET /user
64and 📥 Fetch orders
65 A->>C: GET /orders
66end
67```
69**Loops:**
71```
72loop ⏰ Every 30 seconds
73 A->>B: Health check
74 B-->>A: ✅ 200 OK
75end
76```
78---

Common Patterns

Parallel calls:

par 📥 Fetch user
    A->>B: GET /user
and 📥 Fetch orders
    A->>C: GET /orders
end

Loops:

loop ⏰ Every 30 seconds
    A->>B: Health check
    B-->>A: ✅ 200 OK
end

Raw lines 57 to 79
80## Template
82```mermaid
83sequenceDiagram
84 accTitle: Your Title Here
85 accDescr: Describe the interaction between participants and what the sequence demonstrates
87 participant A as 👤 Actor
88 participant B as 🖥️ System
89 participant C as 💾 Database
91 A->>B: 📤 Request action
92 B->>C: 🔍 Query data
93 C-->>B: 📥 Return results
94 B-->>A: ✅ Deliver response
95```
97---

Template

sequenceDiagram
    accTitle: Your Title Here
    accDescr: Describe the interaction between participants and what the sequence demonstrates

    participant A as 👤 Actor
    participant B as 🖥️ System
    participant C as 💾 Database

    A->>B: 📤 Request action
    B->>C: 🔍 Query data
    C-->>B: 📥 Return results
    B-->>A: ✅ Deliver response

Raw lines 80 to 98
99## Complex Example
101A microservices checkout flow with 6 participants grouped in `box` regions. Shows parallel calls, conditional branching, retry logic, and contextual notes — the full toolkit for complex sequences.
103```mermaid
104sequenceDiagram
105 accTitle: Microservices Checkout Flow
106 accDescr: Multi-service checkout sequence showing parallel inventory and payment processing, error recovery with retries, and async notification dispatch across client, gateway, and backend service layers
108 box rgb(237,233,254) 🌐 Client Layer
109 participant browser as 👤 Browser
110 end
112 box rgb(219,234,254) 🖥️ API Layer
113 participant gw as 🌐 API Gateway
114 participant order as 📋 Order Service
115 end
117 box rgb(220,252,231) ⚙️ Backend Services
118 participant inventory as 📦 Inventory
119 participant payment as 💰 Payment
120 participant notify as 📤 Notifications
121 end
123 browser->>gw: 🛒 Submit checkout
124 gw->>gw: 🔐 Validate JWT token
125 gw->>order: 📋 Create order
127 Note over order: 📊 Order status: PENDING
129 par ⚡ Parallel validation
130 order->>inventory: 📦 Reserve items
131 inventory-->>order: ✅ Items reserved
132 and
133 order->>payment: 💰 Authorize card
134 payment-->>order: ✅ Payment authorized
135 end
137 alt ✅ Both succeeded
138 order->>payment: 💰 Capture payment
139 payment-->>order: ✅ Payment captured
140 order->>inventory: 📦 Confirm reservation
142 Note over order: 📊 Order status: CONFIRMED
144 par 📤 Async notifications
145 order-)notify: 📧 Send confirmation email
146 and
147 order-)notify: 📱 Send push notification
148 end
150 order-->>gw: ✅ Order confirmed
151 gw-->>browser: ✅ Show confirmation page
153 else ❌ Inventory unavailable
154 order->>payment: 🔄 Void authorization
155 order-->>gw: ⚠️ Items out of stock
156 gw-->>browser: ⚠️ Show stock error
158 else ❌ Payment declined
159 order->>inventory: 🔄 Release reservation
161 loop 🔄 Retry up to 2 times
162 order->>payment: 💰 Retry authorization
163 payment-->>order: ❌ Still declined
164 end
166 order-->>gw: ❌ Payment failed
167 gw-->>browser: ❌ Show payment error
168 end
169```

Complex Example

A microservices checkout flow with 6 participants grouped in box regions. Shows parallel calls, conditional branching, retry logic, and contextual notes — the full toolkit for complex sequences.

sequenceDiagram
    accTitle: Microservices Checkout Flow
    accDescr: Multi-service checkout sequence showing parallel inventory and payment processing, error recovery with retries, and async notification dispatch across client, gateway, and backend service layers

    box rgb(237,233,254) 🌐 Client Layer
        participant browser as 👤 Browser
    end

    box rgb(219,234,254) 🖥️ API Layer
        participant gw as 🌐 API Gateway
        participant order as 📋 Order Service
    end

    box rgb(220,252,231) ⚙️ Backend Services
        participant inventory as 📦 Inventory
        participant payment as 💰 Payment
        participant notify as 📤 Notifications
    end

    browser->>gw: 🛒 Submit checkout
    gw->>gw: 🔐 Validate JWT token
    gw->>order: 📋 Create order

    Note over order: 📊 Order status: PENDING

    par ⚡ Parallel validation
        order->>inventory: 📦 Reserve items
        inventory-->>order: ✅ Items reserved
    and
        order->>payment: 💰 Authorize card
        payment-->>order: ✅ Payment authorized
    end

    alt ✅ Both succeeded
        order->>payment: 💰 Capture payment
        payment-->>order: ✅ Payment captured
        order->>inventory: 📦 Confirm reservation

        Note over order: 📊 Order status: CONFIRMED

        par 📤 Async notifications
            order-)notify: 📧 Send confirmation email
        and
            order-)notify: 📱 Send push notification
        end

        order-->>gw: ✅ Order confirmed
        gw-->>browser: ✅ Show confirmation page

    else ❌ Inventory unavailable
        order->>payment: 🔄 Void authorization
        order-->>gw: ⚠️ Items out of stock
        gw-->>browser: ⚠️ Show stock error

    else ❌ Payment declined
        order->>inventory: 🔄 Release reservation

        loop 🔄 Retry up to 2 times
            order->>payment: 💰 Retry authorization
            payment-->>order: ❌ Still declined
        end

        order-->>gw: ❌ Payment failed
        gw-->>browser: ❌ Show payment error
    end
Raw lines 99 to 170
Starts an agent dispatch :106
171### Why this works
173- **`box` grouping** clusters participants by architectural layer — readers instantly see which services are client-facing vs backend
174- **`par` blocks** show parallel inventory + payment checks happening simultaneously, as an illustrative concurrency pattern; actual consistency and compensation rules must be specified
175- **Nested `alt`/`else`** covers the happy path AND two distinct failure modes, each with proper cleanup (void auth, release reservation)
176- **`loop` for retry logic** shows the payment retry pattern without cluttering the happy path
177- **Emoji in messages** makes scanning fast — 📦 for inventory, 💰 for payment, ✅/❌ for outcomes

Why this works

  • **box grouping** clusters participants by architectural layer — readers instantly see which services are client-facing vs backend
  • **par blocks** show parallel inventory + payment checks happening simultaneously, as an illustrative concurrency pattern; actual consistency and compensation rules must be specified
  • **Nested alt/else** covers the happy path AND two distinct failure modes, each with proper cleanup (void auth, release reservation)
  • **loop for retry logic** shows the payment retry pattern without cluttering the happy path
  • Emoji in messages makes scanning fast — 📦 for inventory, 💰 for payment, ✅/❌ for outcomes
Raw lines 171 to 179
180## Verified reference
182Syntax examples reviewed against [official Mermaid documentation](https://mermaid.js.org/syntax/sequenceDiagram.html) and rendered with Mermaid 12.0.0 (2026-10-01). Check the destination version; appearance and accessibility are not guaranteed by a successful parse.

Verified reference

Syntax examples reviewed against official Mermaid documentation and rendered with Mermaid 12.0.0 (2026-10-01). Check the destination version; appearance and accessibility are not guaranteed by a successful parse.

Raw lines 180 to 182