191 lines
7.1 KiB
Markdown
191 lines
7.1 KiB
Markdown
---
|
||
title: "Flowchart"
|
||
task: ""
|
||
lineage_type: import
|
||
upstream_source: https://github.com/K-Dense-AI/scientific-agent-skills/blob/9c9bd2e9/skills/markdown-mermaid-writing/references/diagrams/flowchart.md
|
||
upstream_sha: 9c9bd2e9
|
||
imported_at: 2026-06-27
|
||
prompt_class: prompt
|
||
upstream_changes: accepted
|
||
author: upstream
|
||
validated: false
|
||
---
|
||
|
||
<!-- Source: https://github.com/SuperiorByteWorks-LLC/agent-project | License: Apache-2.0 | Author: Clayton Young / Superior Byte Works, LLC (Boreal Bytes) -->
|
||
|
||
# Flowchart
|
||
|
||
> **Back to [Style Guide](../mermaid_style_guide.md)** โ Read the style guide first for emoji, color, and accessibility rules.
|
||
|
||
**Syntax keyword:** `flowchart`
|
||
**Best for:** Sequential processes, workflows, decision logic, troubleshooting trees
|
||
**When NOT to use:** Complex timing between actors (use [Sequence](sequence.md)), state machines (use [State](state.md))
|
||
|
||
---
|
||
|
||
## Exemplar Diagram
|
||
|
||
```mermaid
|
||
flowchart TB
|
||
accTitle: Feature Development Lifecycle
|
||
accDescr: End-to-end feature flow from idea through design, build, test, review, and release with a revision loop on failed reviews
|
||
|
||
idea([๐ก Feature idea]) --> spec[๐ Write spec]
|
||
spec --> design[๐จ Design solution]
|
||
design --> build[๐ง Implement]
|
||
build --> test[๐งช Run tests]
|
||
test --> review{๐ Review passed?}
|
||
review -->|Yes| release[๐ Release to prod]
|
||
review -->|No| revise[โ๏ธ Revise code]
|
||
revise --> test
|
||
release --> monitor([๐ Monitor metrics])
|
||
|
||
classDef start fill:#ede9fe,stroke:#7c3aed,stroke-width:2px,color:#3b0764
|
||
classDef process fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a5f
|
||
classDef decision fill:#fef9c3,stroke:#ca8a04,stroke-width:2px,color:#713f12
|
||
classDef success fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#14532d
|
||
|
||
class idea,monitor start
|
||
class spec,design,build,test,revise process
|
||
class review decision
|
||
class release success
|
||
```
|
||
|
||
---
|
||
|
||
## Tips
|
||
|
||
- Use `TB` (top-to-bottom) for processes, `LR` (left-to-right) for pipelines
|
||
- Rounded rectangles `([text])` for start/end, diamonds `{text}` for decisions
|
||
- Max 10 nodes โ split larger flows into "Phase 1" / "Phase 2" diagrams
|
||
- Max 3 decision points per diagram
|
||
- Edge labels should be 1โ4 words: `-->|Yes|`, `-->|All green|`
|
||
- Use `classDef` for **semantic** coloring โ decisions in amber, success in green, actions in blue
|
||
|
||
## Subgraph Pattern
|
||
|
||
When you need grouped stages:
|
||
|
||
```mermaid
|
||
flowchart TB
|
||
accTitle: CI/CD Pipeline Stages
|
||
accDescr: Three-stage pipeline grouping code quality checks, testing, and deployment into distinct phases
|
||
|
||
trigger([โก Push to main])
|
||
|
||
subgraph quality ["๐ Code Quality"]
|
||
lint[๐ Lint code] --> format[โ๏ธ Check formatting]
|
||
end
|
||
|
||
subgraph testing ["๐งช Testing"]
|
||
unit[๐งช Unit tests] --> integration[๐ Integration tests]
|
||
end
|
||
|
||
subgraph deploy ["๐ Deployment"]
|
||
build[๐ฆ Build artifacts] --> ship[โ๏ธ Deploy to staging]
|
||
end
|
||
|
||
trigger --> quality
|
||
quality --> testing
|
||
testing --> deploy
|
||
deploy --> done([โ
Pipeline complete])
|
||
|
||
classDef trigger_style fill:#ede9fe,stroke:#7c3aed,stroke-width:2px,color:#3b0764
|
||
classDef success fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#14532d
|
||
|
||
class trigger trigger_style
|
||
class done success
|
||
```
|
||
|
||
---
|
||
|
||
## Template
|
||
|
||
```mermaid
|
||
flowchart TB
|
||
accTitle: Your Title Here (3-8 words)
|
||
accDescr: One or two sentences explaining what this diagram shows and what insight the reader gains
|
||
|
||
start([๐ Starting point]) --> step1[โ๏ธ First action]
|
||
step1 --> decision{๐ Check condition?}
|
||
decision -->|Yes| step2[โ
Positive path]
|
||
decision -->|No| step3[๐ง Alternative path]
|
||
step2 --> done([๐ Complete])
|
||
step3 --> done
|
||
```
|
||
|
||
---
|
||
|
||
## Complex Example
|
||
|
||
A 20+ node e-commerce order pipeline organized into 5 subgraphs, each representing a processing phase. Subgraphs connect through internal nodes, decision points route orders to exception handling, and color classes distinguish phases at a glance.
|
||
|
||
```mermaid
|
||
flowchart TB
|
||
accTitle: E-Commerce Order Processing Pipeline
|
||
accDescr: Full order lifecycle from intake through fulfillment, shipping, and notification with exception handling paths for payment failures, stockouts, and delivery issues
|
||
|
||
order_in([๐ฅ New order]) --> validate_pay{๐ฐ Payment valid?}
|
||
|
||
subgraph intake ["๐ฅ Order Intake"]
|
||
validate_pay -->|Yes| check_fraud{๐ Fraud check}
|
||
validate_pay -->|No| pay_fail[โ Payment **declined**]
|
||
check_fraud -->|Clear| check_stock{๐ฆ In stock?}
|
||
check_fraud -->|Flagged| manual_review[๐ Manual **review**]
|
||
manual_review --> check_stock
|
||
end
|
||
|
||
subgraph fulfill ["๐ฆ Fulfillment"]
|
||
pick[๐ **Pick** items] --> pack[๐ฆ Pack order]
|
||
pack --> label[๐ท๏ธ Generate **shipping** label]
|
||
end
|
||
|
||
subgraph ship ["๐ Shipping"]
|
||
handoff[๐ Carrier **handoff**] --> transit[๐ In transit]
|
||
transit --> deliver{โ
Delivered?}
|
||
end
|
||
|
||
subgraph notify ["๐ค Notifications"]
|
||
confirm_email[๐ง Order **confirmed**]
|
||
ship_update[๐ง Shipping **update**]
|
||
deliver_email[๐ง Delivery **confirmed**]
|
||
end
|
||
|
||
subgraph exception ["โ ๏ธ Exception Handling"]
|
||
pay_fail --> retry_pay[๐ Retry payment]
|
||
retry_pay --> validate_pay
|
||
out_of_stock[๐ฆ **Backorder** created]
|
||
deliver_fail[๐ **Reattempt** delivery]
|
||
end
|
||
|
||
check_stock -->|Yes| pick
|
||
check_stock -->|No| out_of_stock
|
||
label --> handoff
|
||
deliver -->|Yes| deliver_email
|
||
deliver -->|No| deliver_fail
|
||
deliver_fail --> transit
|
||
|
||
check_stock -->|Yes| confirm_email
|
||
handoff --> ship_update
|
||
deliver_email --> complete([โ
Order **complete**])
|
||
|
||
classDef intake_style fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a5f
|
||
classDef fulfill_style fill:#ede9fe,stroke:#7c3aed,stroke-width:2px,color:#3b0764
|
||
classDef ship_style fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#14532d
|
||
classDef warn_style fill:#fef9c3,stroke:#ca8a04,stroke-width:2px,color:#713f12
|
||
classDef danger_style fill:#fee2e2,stroke:#dc2626,stroke-width:2px,color:#7f1d1d
|
||
|
||
class validate_pay,check_fraud,check_stock,manual_review intake_style
|
||
class pick,pack,label fulfill_style
|
||
class handoff,transit,deliver ship_style
|
||
class confirm_email,ship_update,deliver_email warn_style
|
||
class pay_fail,retry_pay,out_of_stock,deliver_fail danger_style
|
||
```
|
||
|
||
### Why this works
|
||
|
||
- **5 subgraphs map to real business phases** โ intake, fulfillment, shipping, notification, and exceptions are how operations teams actually think about orders
|
||
- **Exception handling is its own subgraph** โ not scattered across phases. Agents and readers can see all failure paths in one place
|
||
- **Color classes reinforce structure** โ blue for intake, purple for fulfillment, green for shipping, amber for notifications, red for exceptions. Even without reading labels, the color pattern tells you which phase you're looking at
|
||
- **Decisions route between subgraphs** โ the diamonds (`{Payment valid?}`, `{In stock?}`, `{Delivered?}`) are the points where flow branches, and each branch leads to a clearly-labeled destination
|