Diagrams: examples and installation
Convert Mermaid or JSON into ASCII and box-drawing diagrams for chat, terminal and web. Render flowcharts, sequences and more with the library or CLI.
LangGraph agent
◜───────────◝
│ __start__ │
◟───────────◞
│
│
╭───▼───╮
┌────────▶ agent │
│ ╰───────╯
│ │ ╎
│ │ ╎ __end__
│ ┌─────┘ └╌╌╌╌╌┐
│ │ ╎
│ ╭───▼───╮ ◜────▼────◝
└─│ tools │ │ __end__ │
╰───────╯ ◟─────────◞
Mermaid / JSON source
%%{init: {'flowchart': {'curve': 'linear'}}}%%
graph TD;
__start__([__start__]):::first
agent(agent)
tools(tools)
__end__([__end__]):::last
__start__ --> agent;
agent --> tools;
agent -. __end__ .-> __end__;
tools --> agent;
classDef default fill:#f2f0ff,line-height:1.2
classDef first fill-opacity:0
classDef last fill:#bfb6fc
flowchart
Order intake·◜────────────◝··············
· │ Cart ready │ ·
· ◟────────────◞ ·
· │ ·
· └┐ ·
· │ ·
· ╭──────▼──────╮ ·
· │ ◆ In stock? │ ·
· ╰─────────────╯ ·
· no ╎ │ yes ·
· ┌╌╌╌╌╌╌╌╌╌┘ └────────┐ ·
· ╎ │ ·
· ┌─────▼─────┐ ┌───────▼───────┐ ·
· │ Wait list │ │ Reserve items │ ·
· └───────────┘ └───────────────┘ ·
· ╎ ║ ·
········╎····················║··········
╎ ║
╎ ║
╎ Order fulfilment·║··········
╎ · ║ ·
┌──────▼───────┐ · ┌──────▼───────┐ ·
│ Notify buyer │ · │ Take payment │ ·
└──────────────┘ · └──────────────┘ ·
· │ ·
· │ ·
· │ ·
· ┌─────▼──────┐ ·
· │ Pack order │ ·
· └────────────┘ ·
· │ ·
· │ ·
· │ ·
· ◜────▼─────◝ ·
· │ Dispatch │ ·
· ◟──────────◞ ·
· ╎ ·
·········╎··········
╎
╎
┌──────▼───────┐
│ Send receipt │
└──────────────┘
Mermaid / JSON source
flowchart TB
subgraph intake[Order intake]
cart([Cart ready]) --> stock{In stock?}
stock -->|yes| reserve[Reserve items]
stock -.->|no| wait[Wait list]
end
subgraph fulfil[Order fulfilment]
charge[Take payment]
charge --> pack[Pack order]
pack --> ship([Dispatch])
end
reserve ==> charge
wait -.-> notify[Notify buyer]
ship -.-> receipt[Send receipt]
graph
············Quality gate··············
· · ┌───────┐ ┌────────┐ ┌─────────┐
· ┌───────┐ · ┌─▶ Stage │════════▶ Canary │────────▶ Promote │
· │ Audit │╌╌╌╌┐ · │ └───────┘ └────────┘ └─────────┘
· └───────┘ ╎ · │
· ╎ · │
· ╎ · │
· ╎ · │ pass
· ╎ ╭──────────────╮ · │
· ┌──────┐ └╌▶ │─────┘
· │ Lint │────┐ │ ◆ All green? │ ·
· └──────┘ ├──▶ │────┐
· │ ╰──────────────╯ · │
· │ · │ fail
· │ · │
· │ · │
· ┌────────────┐ │ · │
· │ Unit tests │─┘ · │ ┌────────┐ ┌────────────────┐
· └────────────┘ · └─▶ Repair │╌╌╌╌▶ Failure report │
· · └────────┘ └────────────────┘
······································
Mermaid / JSON source
graph LR
subgraph checks[Quality gate]
lint[Lint] --> gate{All green?}
unit[Unit tests] --> gate
audit[Audit] -.-> gate
end
gate -->|pass| stage[Stage]
gate -->|fail| repair[Repair]
stage ==> canary[Canary]
canary --> promote[Promote]
repair -.-> report[Failure report]
stateDiagram
●
│
│
│
╭───▼───╮
│ Draft │
╰───────╯
│
│
│ submit
········Payment·│···············
· │ ·
· ▼ ·
· ● ·
· │ ·
· │ ·
· │ ·
· ╭──────────▼──────────╮ ·
· │ Authorize │ ·
· │ Note: Key per order │ ·
· ╰─────────────────────╯ ·
· │ ·
· response │ ·
· │ ·
· ╭─▼─╮ ·
· │ ◆ │ ·
· ╰─┬─╯ ·
· refused │ approved ·
· ┌────────┴──────┐ ·
· │ │ ·
· ╭────▼─────╮ ╭────▼─────╮ ·
· │ Declined │ │ Captured │ ·
· ╰──────────╯ ╰──────────╯ ·
· │ │ ·
· └───────┐ ┌─────┘ ·
· │ │ ·
· └┬┘ ·
· ▼ ·
· ◉ ·
· │ ·
················│···············
paid │
│
╭────▼────╮
│ Packing │
╰─────────╯
│
dispatch │
│
╭────▼────╮
│ Shipped │
╰─────────╯
│
│
│
▼
◉ Mermaid / JSON source
stateDiagram-v2
[*] --> Draft
Draft --> Payment: submit
state Payment {
[*] --> Authorize
Authorize --> Check: response
state Check <<choice>>
Check --> Captured: approved
Check --> Declined: refused
Captured --> [*]
Declined --> [*]
}
note right of Authorize: Key per order
Payment --> Packing: paid
Packing --> Shipped: dispatch
Shipped --> [*]
sequenceDiagram
Place an order
o
Buyer API Stock Bank
│ │ │ │
│ 1. Submit cart │ │ │
├───────────────────────────────────▶│ │ │
│ │ │ │
│ │ 2. Reserve items │ │
│ ├─────────────────────────────▶│ │
│ │ │ │
│ │ 3. Hold confirmed │ │
│ │◀╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌┤ │
│ │ │ │
│ ┌──────────────────────────────┴────────────────┐
│ │ note One key per order │
│ └──────────────────────────────┬────────────────┘
│ │ 4. Authorize payment │ │
│ ├──────────────────────────────┼───────────────▶│
│ │ │ │
┌─ alt approved ────────────────────────┼──────────────────────────────┼────────────────┼──┐
│ │ │ 5. Payment token │ │ │
│ │ │◀╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌┼╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ┤ │
│ │ │ │ │ │
│ │ ┌─ loop each parcel ─────────────┼─┐ │ │
│ │ │ │ 6. Queue shipment │ │ │ │
│ │ │ ├─────────────────────────────▶│ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ 7. Tracking code │ │ │ │
│ │ │ │◀╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌┤ │ │ │
│ │ └─┼──────────────────────────────┼─┘ │ │
│ │ │ │ │ │
│ │ 8. Order accepted │ │ │ │
│ │◀╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌┤ │ │ │
│ │ │ │ │ │
├╌ else declined ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌│╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌│╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌│╌╌┤
│ │ │ 9. Card declined │ │ │
│ │ │◀╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌┼╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ┤ │
│ │ │ │ │ │
│ │ 10. Choose another card │ │ │ │
│ │◀╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌ ╌┤ │ │ │
└──┼────────────────────────────────────┼──────────────────────────────┼────────────────┼──┘
│ │ │ │
Mermaid / JSON source
sequenceDiagram
title Place an order
autonumber
actor Buyer
participant API
participant Stock
participant Bank
Buyer->>+API: Submit cart
API->>+Stock: Reserve items
Stock-->>-API: Hold confirmed
Note over API,Bank: One key per order
API->>+Bank: Authorize payment
alt approved
Bank-->>-API: Payment token
loop each parcel
API->>Stock: Queue shipment
Stock-->>API: Tracking code
end
API-->>Buyer: Order accepted
else declined
Bank-->>API: Card declined
API-->>Buyer: Choose another card
end
deactivate API
classDiagram
┌────────────────┐
│ Account │
├────────────────┤
┌╌╌╌╌╌│ +String email │
╎ ├────────────────┤
╎ │ +signIn() bool │
╎ └──────△─────────┘
╎ │
╎ └─────────┐
╎ │
╎ ┌─────────────────┐
╎ │ Buyer │
╎ ├─────────────────┤
╎ │ +String address │
╎ ├─────────────────┤
╎ │ +checkout() │
╎ └───────◇─────────┘
╎ │ │
╎ stores │ │ [1] places [*]
╎ ┌─────────┘ └─────────┐
╎ │ │
╎ ┌───────────────────┐ ┌──────▼──────┐
╎ │ Card │ │ Order │
audits ╎ ├───────────────────┤ ├─────────────┤
╎ │ -String token │ ┌╌│ +int number │
╎ ├───────────────────┤ ╎ ├─────────────┤
╎ │ +authorize() bool │ ╎ │ +submit() │
╎ └───────────────────┘ ╎ └─────◆───────┘
╎ ╎ ╎ │
╎ ╎ ╎ │ [1] contains [*]
╎ ╎ ╎ └─────────┐
╎ ╎ ╎ │
╎ ╎ ╎ ┌───────────────────┐
╎ ╎ ╎ │ Line │
╎ ╎ ╎ ├───────────────────┤
╎ ╎ ╎ │ +int quantity │
╎ ╎ ╎ ├───────────────────┤
╎ ╎ charges ╎ │ +subtotal() Money │
╎ ╎ ╎ └───────────────────┘
╎ ╎ ╎ │
╎ └┐ ┌╌╌╌╌╌╌╌┘ │
╎ ╎ ╎ │
╎ ┌────────△───▼──────┐ │
╎ │ Payment │ refunds │
└╌╌╌│ <<interface>> │──────────────────┘
├───────────────────┤
│ +authorize() bool │
└───────────────────┘
Mermaid / JSON source
classDiagram
direction TB
class Account {
+String email
+signIn() bool
}
class Buyer {
+String address
+checkout()
}
class Order {
+int number
+submit()
}
class Line {
+int quantity
+subtotal() Money
}
class Payment {
<<interface>>
+authorize() bool
}
class Card {
-String token
+authorize() bool
}
Account <|-- Buyer
Buyer "1" --> "*" Order : places
Order "1" *-- "*" Line : contains
Buyer o-- Card : stores
Card ..|> Payment
Order ..> Payment : charges
Line -- Payment : refunds
Account .. Payment : audits
erDiagram
┌─────────────────┐
│ CUSTOMER │
├─────────────────┤
│ int id PK │
│ string email UK │
│ string name │
└────────┼────────┘
┼
places │
○
┌─────────v──────────┐ ┌───────────────┐
│ ORDER │ │ PRODUCT │
├────────────────────┤ ├───────────────┤
│ int id PK │ │ int id PK │
│ int customer_id FK │ │ string sku UK │
│ date placed │ │ decimal price │
└────────┼─┼─────────┘ └───────┼───────┘
┼ ┼ ┼
│ │ contains │
settles │ └─────────────────────┐ │ appears
○ ┼ ○
┌────────┼────────┐ ┌─────────v─v──────────┐
│ PAYMENT │ │ LINE │
├─────────────────┤ ├──────────────────────┤
│ int id PK │ │ int order_id PK,FK │
│ int order_id FK │ │ int product_id PK,FK │
│ string status │ │ int quantity │
└─────────────────┘ └──────────────────────┘
Mermaid / JSON source
erDiagram
CUSTOMER {
int id PK
string email UK
string name
}
ORDER {
int id PK
int customer_id FK
date placed
}
LINE {
int order_id PK, FK
int product_id PK, FK
int quantity
}
PRODUCT {
int id PK
string sku UK
decimal price
}
PAYMENT {
int id PK
int order_id FK
string status
}
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE : contains
PRODUCT ||--o{ LINE : appears
ORDER ||--o| PAYMENT : settles
mindmap
╭─────────╮
┌────│ Filters │
╭────────╮ │ ╰─────────╯
┌────│ Search ├─┤
│ ╰────────╯ │ ╭─────────╮
│ └────│ Ranking │
╭─────────╮ │ ╰─────────╯
┌──│ Product ├─┤
│ ╰─────────╯ │ ╭────────╮
│ │ ┌──│ Wallet │
│ │ ╭──────────╮ │ ╰────────╯
│ └───│ Checkout ├─┤
│ ╰──────────╯ │ ╭──────────╮
│ └──│ Receipts │
│ ╰──────────╯
│
│ ╭─────────╮
│ ┌──│ Backups │
│ ╭─────────────╮ │ ╰─────────╯
│ ┌─│ Reliability ├─┤
│ │ ╰─────────────╯ │ ╭────────╮
│ │ └──│ Alerts │
◜◠◠◠◠◠◠◠◠◠◠◠◠◠◠◠◝ │ ╭──────────╮ │ ╰────────╯
│ Portal launch ├─┼─│ Platform ├─┤
◟◡◡◡◡◡◡◡◡◡◡◡◡◡◡◡◞ │ ╰──────────╯ │ ╭───────╮
│ │ ┌────│ Roles │
│ │ ╭──────────╮ │ ╰───────╯
│ └───│ Security ├─┤
│ ╰──────────╯ │ ╭───────╮
│ └────│ Audit │
│ ╰───────╯
│
│ ╭──────╮
│ ┌──│ Tour │
│ ╭────────────╮ │ ╰──────╯
│ ┌───│ Onboarding ├─┤
│ │ ╰────────────╯ │ ╭────────╮
│ │ └──│ Emails │
│ ╭────────╮ │ ╰────────╯
└──│ Growth ├─┤
╰────────╯ │ ╭─────────╮
│ ┌───│ Funnels │
│ ╭───────────╮ │ ╰─────────╯
└───│ Analytics ├─┤
╰───────────╯ │ ╭─────────╮
└───│ Cohorts │
╰─────────╯
Mermaid / JSON source
mindmap
root((Portal launch))
Product
Search
Filters
Ranking
Checkout
Wallet
Receipts
Platform
Reliability
Backups
Alerts
Security
Roles
Audit
Growth
Onboarding
Tour
Emails
Analytics
Funnels
Cohorts
gitGraph
* Portal baseline (tag: v1.0)
├─┬─╮
│ * │ Search index
│ │ │
│ * │ Rank results (search)
│ │ * Payment keys
│ │ │
│ │ * Receipt emails (checkout)
* │ │ 4634a00 (cherry-pick: Payment keys)
│ │ │
├─╯ │
* │ Ship search (merge)
│ │
├───╯
* Ship checkout (merge)
│
* Portal release (main, HIGHLIGHT, tag: v1.1) Mermaid / JSON source
gitGraph TB:
commit id: "Portal baseline" tag: "v1.0"
branch search
commit id: "Search index"
commit id: "Rank results"
checkout main
branch "checkout"
commit id: "Payment keys"
commit id: "Receipt emails"
checkout main
cherry-pick id: "Payment keys"
merge search id: "Ship search"
merge "checkout" id: "Ship checkout"
commit id: "Portal release" tag: "v1.1" type: HIGHLIGHT
block
┌─────────┐ ┌────────────┐
│ Web app │─┐ ┌───────────│ Mobile app │
└─────────┘ │ │ └────────────┘
│ │
│ │
│ │
│ │
·······│·│··········Gateway····················
· │ │ ·
· ┌────▼─▼────┐ ┌──────┐ ┌────────────┐ · ┌────────┐
· │ Order API │ │ Auth │ │ Rate limit │ · ┌─────────│ Worker │
· └───────────┘ └──────┘ └────────────┘ · │ └────────┘
· │ │ · │ │
·······│·│····································· │ │
│ │ │ │
│ │ │ │
│ └─────────────────────────────────────┐ │ │
│ │ │ │
◜───▼────◝ ┌─────▼─▼─────┐ ◜───▼───◝
│ Orders │ ││ Job queue ││ │ Cache │
◟────────◞ └─────────────┘ ◟───────◞
Mermaid / JSON source
block-beta
columns 3
web["Web app"] space mobile["Mobile app"]
block:Gateway:3
columns 3
auth["Auth"] api["Order API"] quota["Rate limit"]
end
orders[("Orders")] queue[["Job queue"]] cache[("Cache")]
space worker["Worker"] space
web --> api
mobile --> api
api --> orders
api --> queue
worker --> queue
worker --> cache
architecture
·······················[cloud] Commerce························
· ·
· ┌───────────────┐ ┌─────────────────┐
·········[cloud] Edge·········· · ┌─▶ [server] Jobs │───▶ [disk] Receipts │
· · · │ └───────────────┘ └─────────────────┘
┌────────────┐ ┌──────────┐ · · ┌─────────────────┐ │ ·
│ [internet] │───▶ [server] │────┐ │ │─┘ ·
│ Browser │ │ Gateway │ · └─▶ [server] Orders │ ·
└────────────┘ └──────────┘ · · │ │─┐ ·
· · · └─────────────────┘ │ ◜──────────────◝ ·
······························· · └─▶ [db] Records │ ·
· ◟──────────────◞ ·
· ·
·······························································
Mermaid / JSON source
architecture-beta
group edge(cloud)[Edge]
service browser(internet)[Browser] in edge
service gateway(server)[Gateway] in edge
group platform(cloud)[Commerce]
service orders(server)[Orders] in platform
service jobs(server)[Jobs] in platform
service db(database)[Records] in platform
service files(disk)[Receipts] in platform
browser:R --> L:gateway
gateway:R --> L:orders
orders:B --> T:db
orders:R --> L:jobs
jobs:B --> T:files
requirementDiagram
┌───────────────────────┐ ┌───────────────────┐
│ suite │ │ api │
│ <<element>> │ │ <<element>> │
├───────────────────────┤ ├───────────────────┤
│ type: test │ verifies │ type: service │
│ docref: Payment tests │╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┐ │ docref: Order API │
└───────────────────────┘ ╎ └───────────────────┘
╎ ╎ ╎ ╎ ╎
╎ satisfies ╎ ╎ ╎ ╎
╎ ┌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┘ ╎ ╎
verifies ╎ ╎ ╎ satisfies ╎ ╎
╎ ╎ ╎ ┌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┘ ╎ satisfies
╎ ╎ ╎ ╎ └╌╌╌╌╌╌╌╌╌╌╌╌╌╌┐
╎ ╎ ┌────────────▼─▼────────────┐ ╎
┌────────────▼─▼────────────┐ │ receipt │ ┌─────────────▼──────────────┐
│ safe │ │ <<functionalRequirement>> │ │ fast │
│ <<requirement>> │ ├───────────────────────────┤ │ <<performanceRequirement>> │
├───────────────────────────┤ │ id: R3 │ ├────────────────────────────┤
│ id: R1 │ │ text: Email every receipt │ │ id: R2 │
│ text: No duplicate charge │ │ risk: low │ │ text: Checkout under 2s │
│ risk: high │ │ verifymethod: │ │ risk: medium │
│ verifymethod: test │ │ demonstration │ │ verifymethod: analysis │
└───────────────────────────┘ └───────────────────────────┘ └────────────────────────────┘
Mermaid / JSON source
requirementDiagram
requirement safe {
id: R1
text: "No duplicate charge"
risk: high
verifymethod: test
}
performanceRequirement fast {
id: R2
text: "Checkout under 2s"
risk: medium
verifymethod: analysis
}
functionalRequirement receipt {
id: R3
text: "Email every receipt"
risk: low
verifymethod: demonstration
}
element api {
type: "service"
docref: "Order API"
}
element suite {
type: "test"
docref: "Payment tests"
}
api - satisfies -> safe
api - satisfies -> fast
api - satisfies -> receipt
suite - verifies -> safe
suite - verifies -> receipt
C4Context
╭───────────────╮
│ Buyer │
│ [person] │
│ Places orders │
╰───────────────╯
│
│
│
│ Orders
····Commerce·│···········
· │ ·
· ┌───────▼────────┐ ·
· │ Portal │ ·
· │ [system] │ ·
· │ Browse and buy │ ·
· └────────────────┘ ·
· │ │ ·
· │ │ ·
· │ │ ·
· │ │ ·
·Dispatches │ │ Charges·
· ┌─┘ └───────────────────────┐
· │ · │
· ┌───────▼───────┐ · ┌─────────▼──────────┐
· │ Operations │ · │ Bank │
· │ [system] │ · │ [system, external] │
· │ Fulfil orders │ · │ Card payments │
· └───────────────┘ · └────────────────────┘
· │ ·
··········│··············
│
Notifies │
┌┘
│
┌─────────▼──────────┐
│ Mail │
│ [system, external] │
│ Delivery notices │
└────────────────────┘
Mermaid / JSON source
C4Context
Person(buyer, "Buyer", "Places orders")
Enterprise_Boundary(shop, "Commerce") {
System(portal, "Portal", "Browse and buy")
System(ops, "Operations", "Fulfil orders")
}
System_Ext(bank, "Bank", "Card payments")
System_Ext(mail, "Mail", "Delivery notices")
Rel(buyer, portal, "Orders")
Rel(portal, bank, "Charges")
Rel(portal, ops, "Dispatches")
Rel(ops, mail, "Notifies")
C4Container
╭──────────╮
│ Buyer │
│ [person] │
│ Customer │
╰──────────╯
│
│
│
│
Browses │
│
│
·····················Portal·········│············
· │ ·
· ┌─────────▼─────────┐ ·
· │ Web app │ ·
· │ [container] │ ·
· │ React │ ·
· │ Cart and checkout │ ·
· └───────────────────┘ ·
· │ ·
· │ ·
· │ ·
· Submits [HTTPS] │ ·
· │ ·
· │ ·
· │ ·
· ┌───────▼────────┐ ·
· │ Order API │ ·
· │ [container] │ ·
· │ Node │ ·
· │ Order workflow │ ·
· └──────┬─────────┘ ·
· │ │ ·
· Queues │ │ ·
· ┌──────────────────────┤ │ ·
· │ │ │ ·Pays
· │ │ └──────────────────────────┐
· │ Stores [SQL] └┐ · │
· │ │ · │
· ┌─────────▼─────────┐ ◜────────▼─────────◝ · │
· │ Dispatch │ │ Orders │ · ┌─────────▼──────────┐
· │ [container queue] │ │ [container db] │ · │ Bank │
· │ AMQP │ │ Postgres │ · │ [system, external] │
· │ Shipment jobs │ │ Purchase records │ · │ Payments │
· └───────────────────┘ ◟──────────────────◞ · └────────────────────┘
· ·
·················································
Mermaid / JSON source
C4Container
Person(buyer, "Buyer", "Customer")
System_Boundary(shop, "Portal") {
Container(web, "Web app", "React", "Cart and checkout")
Container(api, "Order API", "Node", "Order workflow")
ContainerDb(db, "Orders", "Postgres", "Purchase records")
ContainerQueue(queue, "Dispatch", "AMQP", "Shipment jobs")
}
System_Ext(bank, "Bank", "Payments")
Rel(buyer, web, "Browses")
Rel(web, api, "Submits", "HTTPS")
Rel(api, db, "Stores", "SQL")
Rel(api, queue, "Queues")
Rel(api, bank, "Pays")
C4Component
╭──────────╮
│ Buyer │
│ [person] │
│ Customer │
╰──────────╯
│
│
│
│
│
Submits └┐
│
······Order API·│·········
· │ ·
· ┌──────▼──────┐ ·
· │ Checkout │ ·
· │ [component] │ ·
· │ HTTP │ ·
· │ Accept cart │ ·
· └─────────────┘ ·
· │ ·
· │ ·
· │ ·
· Validates │ ·
· │ ·
· │ ·
· │ ·
· ┌──────▼──────┐ ·
· │ Policy │ ·
· │ [component] │ ·
· │ Rules │ ·
· │ Check order │ ·
· └─────────────┘ ·
· │ │ ·
· │ │ ·
· │ │ ·
· │ │ ·
· Persists │ │ ·Authorizes
· ┌────┘ └─────────────────────────┐
· │ · │
· ┌───────▼───────┐ · │
· │ Repository │ · ┌─────────▼──────────┐
· │ [component] │ · │ Bank │
· │ SQL │ · │ [system, external] │
· │ Save purchase │ · │ Payments │
· └───────────────┘ · └────────────────────┘
· │ ·
··········│···············
│
│
│
Writes │
│
┌┘
│
◜───────▼────────◝
│ Orders │
│ [container db] │
│ Postgres │
◟────────────────◞
Mermaid / JSON source
C4Component
Person(buyer, "Buyer", "Customer")
Container_Boundary(api, "Order API") {
Component(handler, "Checkout", "HTTP", "Accept cart")
Component(policy, "Policy", "Rules", "Check order")
Component(repo, "Repository", "SQL", "Save purchase")
}
ContainerDb(db, "Orders", "Postgres")
System_Ext(bank, "Bank", "Payments")
Rel(buyer, handler, "Submits")
Rel(handler, policy, "Validates")
Rel(policy, repo, "Persists")
Rel(repo, db, "Writes")
Rel(policy, bank, "Authorizes")
C4Deployment
╭──────────╮
│ Buyer │
│ [person] │
│ Customer │
╰──────────╯
│
│
└┐
│ Browses
Production [Cloud]·│···········
· │ ·
· Edge [CDN]·│········· ·
· · │ · ·
· · ┌──────▼──────┐ · ·
· · │ Web app │ · ·
· · │ [container] │ · ·
· · │ React │ · ·
· · └─────────────┘ · ·
· · │ · ·
· ·········│········· ·
· │ ·
· │ ·
· │ ·
· Calls [HTTPS] │ ·
· │ ·
· │ ·
· │ ·
App cluster [Linux]·│········· ·
· · │ · ·
· · ┌──────▼──────┐ · ·
· · │ Order API │ · ·
· · │ [container] │ · ·
· · │ Node │ · ·
· · └─────────────┘ · ·
· · │ │ · ·
· · │ │ · ·
· · │ │ · ·
· · │ │ · ·
· ·Dispatches │ │ · ·Charges
· · ┌──┘ └──────────────────────┐
· · │ · · │
· · ┌──────▼──────┐ · · ┌─────────▼──────────┐
· · │ Worker │ · · │ Bank │
· · │ [container] │ · · │ [system, external] │
· · │ Node │ · · │ Payments │
· · └─────────────┘ · · └────────────────────┘
· · │ · ·
· ·········│············· ·
· │ ·
· │ ·
· Updates │ ·
· │ ·
Data [Managed]·│··········· ·
· · │ · ·
· · ◜───────▼────────◝ · ·
· · │ Orders │ · ·
· · │ [container db] │ · ·
· · │ Postgres │ · ·
· · ◟────────────────◞ · ·
· · · ·
· ······················ ·
· ·
····························
Mermaid / JSON source
C4Deployment
Person(buyer, "Buyer", "Customer")
Deployment_Node(cloud, "Production", "Cloud") {
Deployment_Node(edge, "Edge", "CDN") {
Container(web, "Web app", "React")
}
Deployment_Node(app, "App cluster", "Linux") {
Container(api, "Order API", "Node")
Container(worker, "Worker", "Node")
}
Deployment_Node(data, "Data", "Managed") {
ContainerDb(db, "Orders", "Postgres")
}
}
System_Ext(bank, "Bank", "Payments")
Rel(buyer, web, "Browses")
Rel(web, api, "Calls", "HTTPS")
Rel(api, worker, "Dispatches")
Rel(worker, db, "Updates")
Rel(api, bank, "Charges")
C4Dynamic
╭──────────╮
│ Buyer │
┌──▶ [person] │
│ │ Customer │
│ ╰──────────╯
│ │
│ │
│ │
6: Show receipt │ │
│ │
│ └┐ 1: Submit cart
│ │
··········│·Portal·│·········
· │ │ ·
· │ ┌──────▼──────┐ ·
· │ │ Web app │ ·
· └─│ [container] ◀───┐
· │ React │ · │
· └─────────────┘ · │
· │ · │
· │ · │
· │ · │
· 2: Place order │ · │ 5: Confirm
· │ · │
· │ · │
· │ · │
· ┌──────▼──────┐ · │
· │ Order API │ · │
· │ [container] │───┘
· │ Node │ ·
· └─────────────┘ ·
· │ │ ·
· │ │ ·
· │ │ ·
· │ │ ·
· 4: Save order │ │ ·3: Authorize
· ┌───────┘ └───────────────────────────┐
· │ · │
· ◜───────▼────────◝ · ┌─────────▼──────────┐
· │ Orders │ · │ Bank │
· │ [container db] │ · │ [system, external] │
· │ Postgres │ · │ Payments │
· ◟────────────────◞ · └────────────────────┘
· ·
·····························
Mermaid / JSON source
C4Dynamic
Person(buyer, "Buyer", "Customer")
System_Boundary(shop, "Portal") {
Container(web, "Web app", "React")
Container(api, "Order API", "Node")
ContainerDb(db, "Orders", "Postgres")
}
System_Ext(bank, "Bank", "Payments")
Rel(buyer, web, "Submit cart")
Rel(web, api, "Place order")
Rel(api, bank, "Authorize")
Rel(api, db, "Save order")
Rel(api, web, "Confirm")
Rel(web, buyer, "Show receipt")