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.
| What you're documenting | Diagram combination | Why it works |
|---|---|---|
| Full system architecture | C4 Context + Architecture + Sequence (key flows) | Context for stakeholders, infrastructure for ops, sequences for developers |
| API design documentation | ER (data model) + Sequence (request flows) + State (entity lifecycle) | Schema for the database team, interactions for backend, states for business logic |
| Feature specification | Flowchart (happy path) + Sequence (service interactions) + User Journey (UX) | Process for PM, implementation for engineers, experience for design |
| Migration project | Gantt (timeline) + Architecture (before/after) + Flowchart (migration process) | Schedule for leadership, topology for infra, steps for the migration team |
| Onboarding documentation | User Journey + Flowchart (setup steps) + Sequence (first API call) | Experience map for product, checklist for new hires, technical walkthrough for devs |
| Incident response | State (alert lifecycle) + Sequence (escalation flow) + Flowchart (decision tree) | Status tracking for on-call, communication for management, triage for responders |
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.
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.
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
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.
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 secret_hash "๐ Encrypted secret"
boolean verified "โ
Setup complete"
timestamp registered_at "โฐ Registered"
}
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
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
When to use: Migration documentation where stakeholders need to see the current state, the target state, and understand the transformation.
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
โ ๏ธ Problem: Single database is the bottleneck. Monolith can't scale horizontally. Deploy = full restart.
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
โ Result: Each service scales independently. Database-per-service eliminates the shared bottleneck. Async messaging decouples service dependencies.
flowchart TB so the structural transformation is visually obvious. The monolith is 4 nodes; the target is 11 nodes with subgraphs.When composing diagrams in a real document, follow these practices:
| Practice | Example |
|---|---|
| Use headers as anchors | See [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 naming | Same entity = same name in every diagram (User Service, not "User Svc" in one and "Users API" in another) |
| Adjacent placement | Keep related diagrams in consecutive sections, not scattered across the document |
| Bridging prose | One sentence between diagrams explaining how they connect: "The sequence below zooms into the Deploy phase from the pipeline above" |
| Audience labels | Mark sections: "### Data Model โ for database team" so readers skip to their view |
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