2.1 Introduction to Flowcharts in Mermaid
A flowchart represents a process using:
Edges (connections between steps)
Direction (layout orientation)
In Mermaid, flowcharts are defined using structured text. The syntax is minimal and declarative.
Every flowchart begins with:
You may also see:
Both are valid. For clarity and maintainability, flowchart is recommended.
2.2 Direction: Controlling Layout
Direction determines how the diagram is rendered.
Example: Top-to-Down Layout
Example: Left-to-Right Layout
Direction affects layout only — not logical structure.
2.3 Nodes: Defining Steps
A node is defined using:
Example:
A, B → internal identifiers
[Login Page] → visible label
The identifier must be unique within the diagram.
2.4 Connecting Nodes
Connections are created using arrow syntax.
Example:
Undirected Link
Example:
2.5 Chaining Connections
You can write multiple connections in one line:
This reduces redundancy and improves readability.
2.6 Adding Labels to Connections
Connections can carry decision labels.
Syntax:
Example:
This is critical for representing decision branches.
2.7 Common Node Shapes (Basic Level)
Shape is controlled using bracket style.
Example:
At this stage, focus on understanding structure rather than visual styling.
2.8 Decision Flow Example
Practical example: Authentication workflow.
Key observations:
{} creates a decision node.
Labeled edges define branching logic.
2.9 Minimal Valid Flowchart
The smallest valid flowchart:
Mermaid automatically creates nodes for A and B.
However, using labeled nodes is recommended for clarity.
Use comments to document logic.
Example:
Comments are ignored during rendering.
2.11 Refactoring Example (Hands-On)
Start with a simple architecture:
Now extend it:
Refactored version:
Observe how small text edits produce structural evolution.
2.12 Common Beginner Errors
Missing direction keyword
Incorrect arrow syntax (-> instead of -->)
Forgetting brackets for labels
Incorrect:
Correct:
2.13 Practice Exercise
Create a checkout flow with:
Failure path with retry loop
Requirements:
At least one decision node
Logical direction (choose TD or LR)
2.14 Key Takeaways
Basic flowchart syntax in Mermaid relies on:
These primitives form the foundation for:
Large-scale system modeling
Master these fundamentals before moving to more complex flowchart constructs.