Flowcharts are one of the oldest and most widely used forms of technical documentation. First formalized in the 1920s by industrial engineers Frank and Lillian Gilbreth, flowcharts were originally used to map manufacturing processes. By the 1940s, computer scientists Herman Goldstine and John von Neumann adapted them to document program logic, and flowcharts became a foundational tool in software engineering.
A century later, flowcharts remain indispensable. They document business logic, onboarding workflows, CI/CD pipelines, error-handling paths, and decision trees. But despite their simplicity, poorly constructed flowcharts can confuse rather than clarify. This article covers the principles that separate an effective flowchart from a tangled mess, with practical Mermaid.js examples you can use immediately.
When to Use a Flowchart
Flowcharts excel at showing sequential processes with decision points. Reach for a flowchart when you need to document:
- Business logic and rules engines. "If the user is premium and the order exceeds $100, apply a 15% discount" is much clearer as a decision tree than as nested if-else prose.
- Onboarding and setup procedures. Step-by-step processes where each step depends on the previous one.
- Error handling paths. Showing how your application responds to different failure modes.
- Approval workflows. Multi-stage processes with human decision points.
If your goal is to show communication between components over time, a sequence diagram is a better fit. If you want to show the overall structure of a system, an architecture diagram is more appropriate.
Choosing a Layout Direction
Mermaid supports four layout directions, and choosing the right one makes a surprising difference in readability.
| Direction | Code | Best For |
|---|---|---|
| Top to Bottom | flowchart TD |
Sequential processes, decision trees, most general-purpose flows |
| Left to Right | flowchart LR |
Data pipelines, timelines, horizontal workflows |
| Bottom to Top | flowchart BT |
Build-up processes, dependency chains leading to a goal |
| Right to Left | flowchart RL |
Rarely used; helpful for RTL language contexts |
Top-to-bottom is the safest default because most people read downward. Left-to-right works well for pipeline-style flows where you want to emphasize the transformation of data across stages.
Node Naming Conventions
Every node in a Mermaid flowchart has an ID and an optional display label. Establishing clear conventions for both improves readability and makes diagrams easier to maintain.
- Use short, descriptive IDs. IDs like
validateInputorsendEmailare self-documenting. Avoid generic names likestep1orA. - Use labels for human-readable text. The display label can contain spaces and punctuation:
validateInput[Validate User Input]. - Use diamond shapes for decisions. Mermaid uses curly braces for diamond nodes:
{Is Valid?}. Reserve these exclusively for yes/no or branching conditions. - Use rounded rectangles for start/end. The parenthesis syntax
(Start)creates a rounded rectangle, a widely recognized convention for terminal states.
Color Coding for Clarity
Color can dramatically improve the scannability of a flowchart. Mermaid supports custom styles on individual nodes and entire classes of nodes. Use color purposefully rather than decoratively.
A practical color scheme might assign green to success paths, red to error states, blue to processing steps, and yellow to decision points. The key is consistency: once you establish a color meaning, apply it uniformly throughout the diagram and document the convention for your team.
MermaidSplitting Complex Flows
One of the most common flowchart mistakes is cramming an entire complex process into a single diagram. If your flowchart has more than 12 to 15 nodes, readers will struggle to follow it. Instead, split the flow into multiple diagrams connected by reference points.
Use subgraphs in Mermaid to group related steps visually. Each subgraph acts like a named container, making it clear which steps belong to which phase of the process.
MermaidMermaid Syntax Tips
Here are a few syntax details that trip up newcomers.
- Arrow labels go between dashes. Use
-- label -->for labeled connections. The label text sits between the double dashes. - Dotted and thick arrows. Use
-.->for dotted lines and==>for thick arrows. These help distinguish primary flows from secondary or optional paths. - Links can chain.
A --> B --> Cis equivalent to writing two separate connections on different lines. - Use click events for interactive docs.
click nodeId "https://url"turns a node into a hyperlink, which is powerful for internal documentation wikis.
Build Your Flowchart Now
Copy any of the examples above and paste them into the SimpleMermaid editor to see them render instantly.
Open the Editor