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

complex_examples.md

384 lines · skills/markdown-mermaid-writing/references/diagrams/complex_examples.md at 5f2bc03

Open on GitHub
1<!-- Source: https://github.com/SuperiorByteWorks-LLC/agent-project | License: Apache-2.0 | Author: Clayton Young / Superior Byte Works, LLC (Boreal Bytes) -->
2
3# Composing Complex Diagram Sets
4
5> **Back to [Style Guide](../mermaid_style_guide.md)** — This file covers how to combine multiple diagram types to document complex systems comprehensively.
6
7**Purpose:** A single diagram captures a single perspective. Real documentation often needs multiple diagram types working together — an overview flowchart linked to a detailed sequence diagram, an ER schema paired with a state machine showing entity lifecycle, a Gantt timeline complemented by architecture before/after views. This file teaches you when and how to compose diagrams for maximum clarity.
8
9---

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

Composing Complex Diagram Sets

Back to Style Guide — This file covers how to combine multiple diagram types to document complex systems comprehensively.

Purpose: A single diagram captures a single perspective. Real documentation often needs multiple diagram types working together — an overview flowchart linked to a detailed sequence diagram, an ER schema paired with a state machine showing entity lifecycle, a Gantt timeline complemented by architecture before/after views. This file teaches you when and how to compose diagrams for maximum clarity.


Raw lines 1 to 10
11## When to Compose Multiple Diagrams
13| What you're documenting | Diagram combination | Why it works |
14| ------------------------ | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
15| Full system architecture | C4 Context + Architecture + Sequence (key flows) | Context for stakeholders, infrastructure for ops, sequences for developers |
16| API design documentation | ER (data model) + Sequence (request flows) + State (entity lifecycle) | Schema for the database team, interactions for backend, states for business logic |
17| Feature specification | Flowchart (happy path) + Sequence (service interactions) + User Journey (UX) | Process for PM, implementation for engineers, experience for design |
18| Migration project | Gantt (timeline) + Architecture (before/after) + Flowchart (migration process) | Schedule for leadership, topology for infra, steps for the migration team |
19| Onboarding documentation | User Journey + Flowchart (setup steps) + Sequence (first API call) | Experience map for product, checklist for new hires, technical walkthrough for devs |
20| Incident response | State (alert lifecycle) + Sequence (escalation flow) + Flowchart (decision tree) | Status tracking for on-call, communication for management, triage for responders |
22---

When to Compose Multiple Diagrams

What you're documentingDiagram combinationWhy it works
Full system architectureC4 Context + Architecture + Sequence (key flows)Context for stakeholders, infrastructure for ops, sequences for developers
API design documentationER (data model) + Sequence (request flows) + State (entity lifecycle)Schema for the database team, interactions for backend, states for business logic
Feature specificationFlowchart (happy path) + Sequence (service interactions) + User Journey (UX)Process for PM, implementation for engineers, experience for design
Migration projectGantt (timeline) + Architecture (before/after) + Flowchart (migration process)Schedule for leadership, topology for infra, steps for the migration team
Onboarding documentationUser Journey + Flowchart (setup steps) + Sequence (first API call)Experience map for product, checklist for new hires, technical walkthrough for devs
Incident responseState (alert lifecycle) + Sequence (escalation flow) + Flowchart (decision tree)Status tracking for on-call, communication for management, triage for responders

Raw lines 11 to 23
24## Pattern 1: Overview + Detail
26**When to use:** You need both the big picture AND the specifics. Leadership sees the overview; engineers drill into the detail.
28The overview diagram shows high-level phases or components. One or more detail diagrams zoom into specific phases showing the internal interactions.

Pattern 1: Overview + Detail

When to use: You need both the big picture AND the specifics. Leadership sees the overview; engineers drill into the detail.

The overview diagram shows high-level phases or components. One or more detail diagrams zoom into specific phases showing the internal interactions.

Raw lines 24 to 29
30### Overview — Release Pipeline
32```mermaid
33flowchart LR
34 accTitle: Release Pipeline Overview
35 accDescr: High-level four-phase release pipeline from code commit through build, staging, and production deployment
37 subgraph source ["📥 Source"]
38 commit[📝 Code commit] --> pr_review[🔍 PR review]
39 end
41 subgraph build ["🔧 Build"]
42 compile[⚙️ Compile] --> test[🧪 Test suite]
43 test --> scan[🔐 Security scan]
44 end
46 subgraph staging ["🚀 Staging"]
47 deploy_stg[☁️ Deploy staging] --> smoke[🧪 Smoke tests]
48 smoke --> approval{👤 Approved?}
49 end
51 subgraph production ["✅ Production"]
52 canary[🚀 Canary 5%] --> rollout[🚀 Full rollout]
53 rollout --> monitor[📊 Monitor metrics]
54 end
56 source --> build
57 build --> staging
58 approval -->|Yes| production
59 approval -->|No| source
61 classDef phase_start fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a5f
62 classDef phase_test fill:#fef9c3,stroke:#ca8a04,stroke-width:2px,color:#713f12
63 classDef phase_deploy fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#14532d
65 class commit,pr_review,compile phase_start
66 class test,scan,smoke,approval phase_test
67 class deploy_stg,canary,rollout,monitor phase_deploy
68```
70_The production deployment phase involves multiple service interactions. See the detail sequence below for the canary rollout process._

Overview — Release Pipeline

flowchart LR
    accTitle: Release Pipeline Overview
    accDescr: High-level four-phase release pipeline from code commit through build, staging, and production deployment

    subgraph source ["📥 Source"]
        commit[📝 Code commit] --> pr_review[🔍 PR review]
    end

    subgraph build ["🔧 Build"]
        compile[⚙️ Compile] --> test[🧪 Test suite]
        test --> scan[🔐 Security scan]
    end

    subgraph staging ["🚀 Staging"]
        deploy_stg[☁️ Deploy staging] --> smoke[🧪 Smoke tests]
        smoke --> approval{👤 Approved?}
    end

    subgraph production ["✅ Production"]
        canary[🚀 Canary 5%] --> rollout[🚀 Full rollout]
        rollout --> monitor[📊 Monitor metrics]
    end

    source --> build
    build --> staging
    approval -->|Yes| production
    approval -->|No| source

    classDef phase_start fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a5f
    classDef phase_test fill:#fef9c3,stroke:#ca8a04,stroke-width:2px,color:#713f12
    classDef phase_deploy fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#14532d

    class commit,pr_review,compile phase_start
    class test,scan,smoke,approval phase_test
    class deploy_stg,canary,rollout,monitor phase_deploy

The production deployment phase involves multiple service interactions. See the detail sequence below for the canary rollout process.

Raw lines 30 to 71
72### Detail — Canary Deployment Sequence
74```mermaid
75sequenceDiagram
76 accTitle: Canary Deployment Service Interactions
77 accDescr: Detailed sequence showing how the CI server orchestrates a canary deployment through the container registry, Kubernetes cluster, and monitoring stack with automated rollback on failure
79 participant ci as ⚙️ CI Server
80 participant registry as 📦 Container Registry
81 participant k8s as ☁️ Kubernetes
82 participant monitor as 📊 Monitoring
83 participant oncall as 👤 On-Call Engineer
85 ci->>registry: 📤 Push tagged image
86 registry-->>ci: ✅ Image stored
88 ci->>k8s: 🚀 Deploy canary (5% traffic)
89 k8s-->>ci: ✅ Canary pods running
91 ci->>monitor: 📊 Start canary analysis
92 Note over monitor: ⏰ Observe for 15 minutes
94 loop 📊 Every 60 seconds
95 monitor->>k8s: 🔍 Query error rate
96 k8s-->>monitor: 📊 Metrics response
97 end
99 alt ✅ Error rate below threshold
100 monitor-->>ci: ✅ Canary healthy
101 ci->>k8s: 🚀 Promote to 100%
102 k8s-->>ci: ✅ Full rollout complete
103 ci->>monitor: 📊 Continue monitoring
104 else ❌ Error rate above threshold
105 monitor-->>ci: ❌ Canary failing
106 ci->>k8s: 🔄 Rollback to previous
107 k8s-->>ci: ✅ Rollback complete
108 ci->>oncall: ⚠️ Alert: canary failed
109 Note over oncall: 📋 Investigate root cause
110 end
111```

Detail — Canary Deployment Sequence

sequenceDiagram
    accTitle: Canary Deployment Service Interactions
    accDescr: Detailed sequence showing how the CI server orchestrates a canary deployment through the container registry, Kubernetes cluster, and monitoring stack with automated rollback on failure

    participant ci as ⚙️ CI Server
    participant registry as 📦 Container Registry
    participant k8s as ☁️ Kubernetes
    participant monitor as 📊 Monitoring
    participant oncall as 👤 On-Call Engineer

    ci->>registry: 📤 Push tagged image
    registry-->>ci: ✅ Image stored

    ci->>k8s: 🚀 Deploy canary (5% traffic)
    k8s-->>ci: ✅ Canary pods running

    ci->>monitor: 📊 Start canary analysis
    Note over monitor: ⏰ Observe for 15 minutes

    loop 📊 Every 60 seconds
        monitor->>k8s: 🔍 Query error rate
        k8s-->>monitor: 📊 Metrics response
    end

    alt ✅ Error rate below threshold
        monitor-->>ci: ✅ Canary healthy
        ci->>k8s: 🚀 Promote to 100%
        k8s-->>ci: ✅ Full rollout complete
        ci->>monitor: 📊 Continue monitoring
    else ❌ Error rate above threshold
        monitor-->>ci: ❌ Canary failing
        ci->>k8s: 🔄 Rollback to previous
        k8s-->>ci: ✅ Rollback complete
        ci->>oncall: ⚠️ Alert: canary failed
        Note over oncall: 📋 Investigate root cause
    end
Raw lines 72 to 112
113### How these connect
115- The **overview flowchart** shows the full pipeline with subgraph-to-subgraph connections — leadership reads this to understand the release process
116- The **detail sequence** zooms into "Canary 5% → Full rollout" from the Production subgraph, showing the actual service interactions an engineer would debug
117- **Naming is consistent** — "Canary" and "Monitor metrics" appear in both diagrams, creating a clear bridge between overview and detail
119---

How these connect

  • The overview flowchart shows the full pipeline with subgraph-to-subgraph connections — leadership reads this to understand the release process
  • The detail sequence zooms into "Canary 5% → Full rollout" from the Production subgraph, showing the actual service interactions an engineer would debug
  • Naming is consistent — "Canary" and "Monitor metrics" appear in both diagrams, creating a clear bridge between overview and detail

Raw lines 113 to 120
121## Pattern 2: Multi-Perspective Documentation
123**When to use:** The same system needs to be documented for different audiences — database teams, backend engineers, and product managers each need a different view of the same feature.
125This example documents a **User Authentication** feature from three perspectives.

Pattern 2: Multi-Perspective Documentation

When to use: The same system needs to be documented for different audiences — database teams, backend engineers, and product managers each need a different view of the same feature.

This example documents a User Authentication feature from three perspectives.

Raw lines 121 to 126
127### Data Model — for database team
129```mermaid
130erDiagram
131 accTitle: Authentication Data Model
132 accDescr: Five-entity schema for user authentication covering users, sessions, refresh tokens, login attempts, and MFA devices with cardinality relationships
134 USER ||..o{ SESSION : "has"
135 USER ||..o{ REFRESH_TOKEN : "owns"
136 USER ||..o{ LOGIN_ATTEMPT : "produces"
137 USER ||..o{ MFA_DEVICE : "registers"
138 SESSION ||..|| REFRESH_TOKEN : "paired with"
140 USER {
141 uuid id PK "🔑 Primary key"
142 string email "📧 Unique login"
143 string password_hash "🔐 Bcrypt hash"
144 boolean mfa_enabled "🔒 MFA flag"
145 timestamp last_login "⏰ Last active"
146 }
148 SESSION {
149 uuid id PK "🔑 Primary key"
150 uuid user_id FK "👤 Session owner"
151 string ip_address "🌐 Client IP"
152 string user_agent "📋 Browser info"
153 timestamp expires_at "⏰ Expiration"
154 }
156 REFRESH_TOKEN {
157 uuid id PK "🔑 Primary key"
158 uuid user_id FK "👤 Token owner"
159 uuid session_id FK "🔗 Paired session"
160 string token_hash "🔐 Hashed token"
161 boolean revoked "❌ Revoked flag"
162 timestamp expires_at "⏰ Expiration"
163 }
165 LOGIN_ATTEMPT {
166 uuid id PK "🔑 Primary key"
167 uuid user_id FK "👤 Attempting user"
168 string ip_address "🌐 Source IP"
169 boolean success "✅ Outcome"
170 string failure_reason "⚠️ Why failed"
171 timestamp attempted_at "⏰ Attempt time"
172 }
174 MFA_DEVICE {
175 uuid id PK "🔑 Primary key"
176 uuid user_id FK "👤 Device owner"
177 string device_type "📱 TOTP or WebAuthn"
178 string credential_reference "🔐 Credential storage reference"
179 boolean verified "✅ Setup complete"
180 timestamp registered_at "⏰ Registered"
181 }
182```

Data Model — for database team

erDiagram
    accTitle: Authentication Data Model
    accDescr: Five-entity schema for user authentication covering users, sessions, refresh tokens, login attempts, and MFA devices with cardinality relationships

    USER ||..o{ SESSION : "has"
    USER ||..o{ REFRESH_TOKEN : "owns"
    USER ||..o{ LOGIN_ATTEMPT : "produces"
    USER ||..o{ MFA_DEVICE : "registers"
    SESSION ||..|| REFRESH_TOKEN : "paired with"

    USER {
        uuid id PK "🔑 Primary key"
        string email "📧 Unique login"
        string password_hash "🔐 Bcrypt hash"
        boolean mfa_enabled "🔒 MFA flag"
        timestamp last_login "⏰ Last active"
    }

    SESSION {
        uuid id PK "🔑 Primary key"
        uuid user_id FK "👤 Session owner"
        string ip_address "🌐 Client IP"
        string user_agent "📋 Browser info"
        timestamp expires_at "⏰ Expiration"
    }

    REFRESH_TOKEN {
        uuid id PK "🔑 Primary key"
        uuid user_id FK "👤 Token owner"
        uuid session_id FK "🔗 Paired session"
        string token_hash "🔐 Hashed token"
        boolean revoked "❌ Revoked flag"
        timestamp expires_at "⏰ Expiration"
    }

    LOGIN_ATTEMPT {
        uuid id PK "🔑 Primary key"
        uuid user_id FK "👤 Attempting user"
        string ip_address "🌐 Source IP"
        boolean success "✅ Outcome"
        string failure_reason "⚠️ Why failed"
        timestamp attempted_at "⏰ Attempt time"
    }

    MFA_DEVICE {
        uuid id PK "🔑 Primary key"
        uuid user_id FK "👤 Device owner"
        string device_type "📱 TOTP or WebAuthn"
        string credential_reference "🔐 Credential storage reference"
        boolean verified "✅ Setup complete"
        timestamp registered_at "⏰ Registered"
    }
Raw lines 127 to 183
184### Authentication Flow — for backend team
186```mermaid
187sequenceDiagram
188 accTitle: Login Flow with MFA
189 accDescr: Step-by-step authentication sequence showing credential validation, conditional MFA challenge, token issuance, and failure handling between browser, API, auth service, and database
191 participant B as 👤 Browser
192 participant API as 🌐 API Gateway
193 participant Auth as 🔐 Auth Service
194 participant DB as 💾 Database
196 B->>API: 📤 POST /login (email, password)
197 API->>Auth: 🔐 Validate credentials
198 Auth->>DB: 🔍 Fetch user by email
199 DB-->>Auth: 👤 User record
201 Auth->>Auth: 🔐 Verify password hash
203 alt ❌ Invalid password
204 Auth->>DB: 📝 Log failed attempt
205 Auth-->>API: ❌ 401 Unauthorized
206 API-->>B: ❌ Invalid credentials
207 else ✅ Password valid
208 alt 🔒 MFA enabled
209 Auth-->>API: ⚠️ 202 MFA required
210 API-->>B: 📱 Show MFA prompt
212 B->>API: 📤 POST /login/mfa (code)
213 API->>Auth: 🔐 Verify MFA code
214 Auth->>DB: 🔍 Fetch MFA device
215 DB-->>Auth: 📱 Device record
216 Auth->>Auth: 🔐 Validate TOTP
218 alt ❌ Invalid code
219 Auth-->>API: ❌ 401 Invalid code
220 API-->>B: ❌ Try again
221 else ✅ Code valid
222 Auth->>DB: 📝 Create session + tokens
223 Auth-->>API: ✅ 200 + tokens
224 API-->>B: ✅ Set cookies + redirect
225 end
226 else 🔓 No MFA
227 Auth->>DB: 📝 Create session + tokens
228 Auth-->>API: ✅ 200 + tokens
229 API-->>B: ✅ Set cookies + redirect
230 end
231 end
232```

Authentication Flow — for backend team

sequenceDiagram
    accTitle: Login Flow with MFA
    accDescr: Step-by-step authentication sequence showing credential validation, conditional MFA challenge, token issuance, and failure handling between browser, API, auth service, and database

    participant B as 👤 Browser
    participant API as 🌐 API Gateway
    participant Auth as 🔐 Auth Service
    participant DB as 💾 Database

    B->>API: 📤 POST /login (email, password)
    API->>Auth: 🔐 Validate credentials
    Auth->>DB: 🔍 Fetch user by email
    DB-->>Auth: 👤 User record

    Auth->>Auth: 🔐 Verify password hash

    alt ❌ Invalid password
        Auth->>DB: 📝 Log failed attempt
        Auth-->>API: ❌ 401 Unauthorized
        API-->>B: ❌ Invalid credentials
    else ✅ Password valid
        alt 🔒 MFA enabled
            Auth-->>API: ⚠️ 202 MFA required
            API-->>B: 📱 Show MFA prompt

            B->>API: 📤 POST /login/mfa (code)
            API->>Auth: 🔐 Verify MFA code
            Auth->>DB: 🔍 Fetch MFA device
            DB-->>Auth: 📱 Device record
            Auth->>Auth: 🔐 Validate TOTP

            alt ❌ Invalid code
                Auth-->>API: ❌ 401 Invalid code
                API-->>B: ❌ Try again
            else ✅ Code valid
                Auth->>DB: 📝 Create session + tokens
                Auth-->>API: ✅ 200 + tokens
                API-->>B: ✅ Set cookies + redirect
            end
        else 🔓 No MFA
            Auth->>DB: 📝 Create session + tokens
            Auth-->>API: ✅ 200 + tokens
            API-->>B: ✅ Set cookies + redirect
        end
    end
Raw lines 184 to 233
234### Login Experience — for product team
236```mermaid
237journey
238 accTitle: Login Experience Journey Map
239 accDescr: User satisfaction scores across the sign-in experience for password-only users and MFA users showing friction points in the multi-factor flow
241 title 👤 Login Experience
242 section 🔐 Sign In
243 Navigate to login : 4 : User
244 Enter email and password : 3 : User
245 Click sign in button : 4 : User
246 section 📱 MFA Challenge
247 Receive MFA prompt : 3 : MFA User
248 Open authenticator app : 2 : MFA User
249 Enter 6-digit code : 2 : MFA User
250 Handle expired code : 1 : MFA User
251 section ✅ Post-Login
252 Land on dashboard : 5 : User
253 See personalized content : 5 : User
254 Resume previous session : 4 : User
255```

Login Experience — for product team

journey
    accTitle: Login Experience Journey Map
    accDescr: User satisfaction scores across the sign-in experience for password-only users and MFA users showing friction points in the multi-factor flow

    title 👤 Login Experience
    section 🔐 Sign In
        Navigate to login          : 4 : User
        Enter email and password   : 3 : User
        Click sign in button       : 4 : User
    section 📱 MFA Challenge
        Receive MFA prompt         : 3 : MFA User
        Open authenticator app     : 2 : MFA User
        Enter 6-digit code         : 2 : MFA User
        Handle expired code        : 1 : MFA User
    section ✅ Post-Login
        Land on dashboard          : 5 : User
        See personalized content   : 5 : User
        Resume previous session    : 4 : User
Raw lines 234 to 256
257### How these connect
259- **Same entities, different views** — "User", "Session", "MFA Device" appear in the ER diagram as tables, in the sequence as participants/operations, and in the journey as experience touchpoints
260- **Each audience gets actionable information** — the DB team sees candidate fields and cardinality, the backend team sees illustrative request/error flows, and the product team sees hypothetical experience scores; these are not verified implementations or measurements
261- **The journey reveals what the sequence hides** — the sequence diagram shows MFA as a clean conditional branch, but the invented low scores indicate where a real study might look for friction. Gather evidence before making a product decision
263---

How these connect

  • Same entities, different views — "User", "Session", "MFA Device" appear in the ER diagram as tables, in the sequence as participants/operations, and in the journey as experience touchpoints
  • Each audience gets actionable information — the DB team sees candidate fields and cardinality, the backend team sees illustrative request/error flows, and the product team sees hypothetical experience scores; these are not verified implementations or measurements
  • The journey reveals what the sequence hides — the sequence diagram shows MFA as a clean conditional branch, but the invented low scores indicate where a real study might look for friction. Gather evidence before making a product decision

Raw lines 257 to 264
265## Pattern 3: Before/After Architecture
267**When to use:** Migration documentation where stakeholders need to see the current state, the target state, and understand the transformation.

Pattern 3: Before/After Architecture

When to use: Migration documentation where stakeholders need to see the current state, the target state, and understand the transformation.

Raw lines 265 to 268
269### Current State — Monolith
271```mermaid
272flowchart TB
273 accTitle: Current State Monolith Architecture
274 accDescr: Single Rails monolith handling all traffic through one server connected to one database showing the scaling bottleneck
276 client([👤 All traffic]) --> mono[🖥️ Rails Monolith]
277 mono --> db[(💾 Single PostgreSQL)]
278 mono --> jobs[⏰ Background jobs]
279 jobs --> db
281 classDef bottleneck fill:#fee2e2,stroke:#dc2626,stroke-width:2px,color:#7f1d1d
282 classDef neutral fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#1f2937
284 class mono,db bottleneck
285 class client,jobs neutral
286```
288> ⚠️ **Illustrative assumption:** This deployment has a shared database bottleneck and restarts on deployment. These are properties to measure, not inherent facts about monoliths.

Current State — Monolith

flowchart TB
    accTitle: Current State Monolith Architecture
    accDescr: Single Rails monolith handling all traffic through one server connected to one database showing the scaling bottleneck

    client([👤 All traffic]) --> mono[🖥️ Rails Monolith]
    mono --> db[(💾 Single PostgreSQL)]
    mono --> jobs[⏰ Background jobs]
    jobs --> db

    classDef bottleneck fill:#fee2e2,stroke:#dc2626,stroke-width:2px,color:#7f1d1d
    classDef neutral fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#1f2937

    class mono,db bottleneck
    class client,jobs neutral
⚠️ Illustrative assumption: This deployment has a shared database bottleneck and restarts on deployment. These are properties to measure, not inherent facts about monoliths.
Raw lines 269 to 289
290### Target State — Microservices
292```mermaid
293flowchart TB
294 accTitle: Target State Microservices Architecture
295 accDescr: Decomposed microservices architecture with API gateway routing to independent services each with their own data store and a shared message queue for async communication
297 client([👤 All traffic]) --> gw[🌐 API Gateway]
299 subgraph services ["⚙️ Services"]
300 user_svc[👤 User Service]
301 order_svc[📋 Order Service]
302 product_svc[📦 Product Service]
303 end
305 subgraph data ["💾 Data Stores"]
306 user_db[(💾 Users DB)]
307 order_db[(💾 Orders DB)]
308 product_db[(💾 Products DB)]
309 end
311 gw --> user_svc
312 gw --> order_svc
313 gw --> product_svc
315 user_svc --> user_db
316 order_svc --> order_db
317 product_svc --> product_db
319 order_svc --> mq[📥 Message Queue]
320 mq --> user_svc
321 mq --> product_svc
323 classDef gateway fill:#ede9fe,stroke:#7c3aed,stroke-width:2px,color:#3b0764
324 classDef service fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a5f
325 classDef datastore fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#14532d
326 classDef infra fill:#fef9c3,stroke:#ca8a04,stroke-width:2px,color:#713f12
328 class gw gateway
329 class user_svc,order_svc,product_svc service
330 class user_db,order_db,product_db datastore
331 class mq infra
332```
334> ✅ **Proposed outcome:** Independent services and data stores may reduce the measured shared bottleneck. Verify scaling, consistency, operational cost, and failure recovery before claiming improvement.

Target State — Microservices

flowchart TB
    accTitle: Target State Microservices Architecture
    accDescr: Decomposed microservices architecture with API gateway routing to independent services each with their own data store and a shared message queue for async communication

    client([👤 All traffic]) --> gw[🌐 API Gateway]

    subgraph services ["⚙️ Services"]
        user_svc[👤 User Service]
        order_svc[📋 Order Service]
        product_svc[📦 Product Service]
    end

    subgraph data ["💾 Data Stores"]
        user_db[(💾 Users DB)]
        order_db[(💾 Orders DB)]
        product_db[(💾 Products DB)]
    end

    gw --> user_svc
    gw --> order_svc
    gw --> product_svc

    user_svc --> user_db
    order_svc --> order_db
    product_svc --> product_db

    order_svc --> mq[📥 Message Queue]
    mq --> user_svc
    mq --> product_svc

    classDef gateway fill:#ede9fe,stroke:#7c3aed,stroke-width:2px,color:#3b0764
    classDef service fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a5f
    classDef datastore fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#14532d
    classDef infra fill:#fef9c3,stroke:#ca8a04,stroke-width:2px,color:#713f12

    class gw gateway
    class user_svc,order_svc,product_svc service
    class user_db,order_db,product_db datastore
    class mq infra
✅ Proposed outcome: Independent services and data stores may reduce the measured shared bottleneck. Verify scaling, consistency, operational cost, and failure recovery before claiming improvement.
Raw lines 290 to 335
336### How these connect
338- **Same layout, different complexity** — both diagrams use `flowchart TB` so the structural transformation is visually obvious. The monolith is 4 nodes; the target is 11 nodes with subgraphs.
339- **Color tells the story** — the monolith uses red (danger) on the bottleneck components. The target uses blue/green/purple to show healthy, differentiated components.
340- **Prose bridges the diagrams** — the ⚠️ problem callout and ✅ result callout explain _why_ the architecture changes, not just _what_ changed.
342---

How these connect

  • Same layout, different complexity — both diagrams use flowchart TB so the structural transformation is visually obvious. The monolith is 4 nodes; the target is 11 nodes with subgraphs.
  • Color tells the story — the monolith uses red (danger) on the bottleneck components. The target uses blue/green/purple to show healthy, differentiated components.
  • Prose bridges the diagrams — the ⚠️ problem callout and ✅ result callout explain why the architecture changes, not just what changed.

Raw lines 336 to 343
344## Linking Diagrams in Documentation
346When composing diagrams in a real document, follow these practices:
348| Practice | Example |
349| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
350| **Use headers as anchors** | `See [Authentication Flow](#authentication-flow-for-backend-team) for the full login sequence` |
351| **Reference specific nodes** | "The **API Gateway** from the overview connects to the services detailed below" |
352| **Consistent naming** | Same entity = same name in every diagram (User Service, not "User Svc" in one and "Users API" in another) |
353| **Adjacent placement** | Keep related diagrams in consecutive sections, not scattered across the document |
354| **Bridging prose** | One sentence between diagrams explaining how they connect: "The sequence below zooms into the Deploy phase from the pipeline above" |
355| **Audience labels** | Mark sections: "### Data Model — _for database team_" so readers skip to their view |
357---

Linking Diagrams in Documentation

When composing diagrams in a real document, follow these practices:

PracticeExample
Use headers as anchorsSee [Authentication Flow](#authentication-flow-for-backend-team) for the full login sequence
Reference specific nodes"The API Gateway from the overview connects to the services detailed below"
Consistent namingSame entity = same name in every diagram (User Service, not "User Svc" in one and "Users API" in another)
Adjacent placementKeep related diagrams in consecutive sections, not scattered across the document
Bridging proseOne sentence between diagrams explaining how they connect: "The sequence below zooms into the Deploy phase from the pipeline above"
Audience labelsMark sections: "### Data Model — for database team" so readers skip to their view

Raw lines 344 to 358
359## Choosing Your Composition Strategy
361```mermaid
362flowchart TB
363 accTitle: Diagram Composition Decision Tree
364 accDescr: Decision flowchart for choosing between single diagram, overview plus detail, multi-perspective, or before-after composition strategies based on audience and documentation needs
366 start([📋 What are you documenting?]) --> audience{👥 Multiple audiences?}
368 audience -->|Yes| perspectives[📐 Multi-Perspective]
369 audience -->|No| depth{📏 Need both summary and detail?}
371 depth -->|Yes| overview[🔍 Overview + Detail]
372 depth -->|No| change{🔄 Showing a change over time?}
374 change -->|Yes| before_after[⚡ Before / After]
375 change -->|No| single[📊 Single diagram is fine]
377 classDef decision fill:#fef9c3,stroke:#ca8a04,stroke-width:2px,color:#713f12
378 classDef result fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a5f
379 classDef start_style fill:#ede9fe,stroke:#7c3aed,stroke-width:2px,color:#3b0764
381 class audience,depth,change decision
382 class perspectives,overview,before_after,single result
383 class start start_style
384```

Choosing Your Composition Strategy

flowchart TB
    accTitle: Diagram Composition Decision Tree
    accDescr: Decision flowchart for choosing between single diagram, overview plus detail, multi-perspective, or before-after composition strategies based on audience and documentation needs

    start([📋 What are you documenting?]) --> audience{👥 Multiple audiences?}

    audience -->|Yes| perspectives[📐 Multi-Perspective]
    audience -->|No| depth{📏 Need both summary and detail?}

    depth -->|Yes| overview[🔍 Overview + Detail]
    depth -->|No| change{🔄 Showing a change over time?}

    change -->|Yes| before_after[⚡ Before / After]
    change -->|No| single[📊 Single diagram is fine]

    classDef decision fill:#fef9c3,stroke:#ca8a04,stroke-width:2px,color:#713f12
    classDef result fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a5f
    classDef start_style fill:#ede9fe,stroke:#7c3aed,stroke-width:2px,color:#3b0764

    class audience,depth,change decision
    class perspectives,overview,before_after,single result
    class start start_style
Raw lines 359 to 384