Mermaid Flowchart
Mermaid flowcharts are perfect for visualizing processes, algorithms, and decision trees. They're text-based, version-control friendly, and render beautifully.
Use Case
Use flowcharts when you need to:
- Document algorithms or processes
- Show decision logic
- Map out workflows
- Visualize state transitions
Code
1```mermaid
2graph TD
3 A[Start] --> B{Decision?}
4 B -->|Yes| C[Action 1]
5 B -->|No| D[Action 2]
6 C --> E[End]
7 D --> E
8```
Result:
Explanation
graph TD- Top-down flowchart (useLRfor left-right,BTfor bottom-top)[]- Rectangle node{}- Diamond (decision) node()- Rounded rectangle-->- Arrow-->|text|- Arrow with label
Examples
Example 1: Research Process
1```mermaid
2graph TD
3 A[Research Question] --> B{Literature<br/>Review Done?}
4 B -->|No| C[Read Papers]
5 C --> B
6 B -->|Yes| D[Form Hypothesis]
7 D --> E[Design Experiment]
8 E --> F[Run Experiment]
9 F --> G{Results<br/>Significant?}
10 G -->|Yes| H[Document Findings]
11 G -->|No| I[Refine Approach]
12 I --> E
13 H --> J[Publish]
14```
Result:
Example 2: Algorithm Flow
1```mermaid
2graph LR
3 A[Input Data] --> B[Preprocess]
4 B --> C[Feature Extraction]
5 C --> D[Model Training]
6 D --> E[Validation]
7 E --> F{Accuracy > 95%?}
8 F -->|No| G[Tune Hyperparameters]
9 G --> D
10 F -->|Yes| H[Deploy Model]
11```
Result:
Example 3: Node Shapes
1```mermaid
2graph TD
3 A[Rectangle] --> B(Rounded)
4 B --> C([Stadium])
5 C --> D[[Subroutine]]
6 D --> E[(Database)]
7 E --> F((Circle))
8 F --> G>Asymmetric]
9 G --> H{Diamond}
10 H --> I{{Hexagon}}
11```
Result:
Notes
- Use
<br/>for line breaks in node text - Keep node IDs simple (A, B, C or descriptive names)
- Use subgraphs for grouping related nodes
- Test complex diagrams at https://mermaid.live/
Gotchas/Warnings
- ⚠️ Special characters: Avoid quotes in node text, use
#quot;if needed - ⚠️ Spacing: Extra spaces in node IDs can cause issues
- ⚠️ Circular references: Be careful with loops, they can make diagrams hard to read
- ⚠️ Complexity: Very large flowcharts become hard to maintain - consider breaking them up
Related Snippets
- Architecture Diagrams (C4 Model)
Create system architecture diagrams using C4 model with Mermaid - Chart.js Bar Chart
Create bar charts for data visualization - Graphviz DOT Diagrams
Create complex graph layouts with Graphviz DOT language - KaTeX Math Examples and Tips
Comprehensive guide to KaTeX math notation with examples and tips - Mermaid Arbitrary Graphs
Create arbitrary graphs and networks with Mermaid - Mermaid Block Diagrams
Create block diagrams for system architecture with Mermaid - Mermaid Charts (Pie, Bar, Line)
Create pie charts, bar charts, and line charts with Mermaid - Mermaid Class Diagrams (UML)
Create UML class diagrams with Mermaid - Mermaid Entity Relationship Diagrams
Create Entity Relationship Diagrams (ERD) with Mermaid - Mermaid Gantt Chart
Create Gantt charts for project timelines and scheduling - Mermaid Git Diagrams
Create Git branch and commit diagrams with Mermaid - Mermaid Kanban Boards
Create Kanban boards for project management with Mermaid - Mermaid Mindmaps
Create mindmaps for brainstorming and organizing ideas with Mermaid - Mermaid Packet Diagrams
Create packet diagrams for network protocols with Mermaid - Mermaid Quadrant Charts
Create quadrant charts for prioritization with Mermaid - Mermaid Radar Charts
Create radar charts for multi-dimensional comparisons with Mermaid - Mermaid Requirement Diagrams
Create requirement diagrams for system requirements with Mermaid - Mermaid Sankey Diagrams
Create Sankey diagrams for flow visualization with Mermaid - Mermaid Sequence Diagram
Create sequence diagrams for interactions and API flows - Mermaid State Diagrams
Create state diagrams and state machines with Mermaid - Mermaid Timeline Diagrams
Create timeline diagrams for chronological events with Mermaid - Mermaid Treemap Diagrams
Create treemap diagrams for hierarchical data visualization with Mermaid - Mermaid User Journey Diagrams
Create user journey maps with Mermaid - Mermaid ZenUML Diagrams
Create ZenUML sequence diagrams with Mermaid - P5.js Interactive Visualizations
Create interactive visualizations and animations with P5.js