Mastering Flowcharts: A Complete Guide to Mermaid Flow Diagrams
Learn how to create professional flowcharts with Mermaid.js syntax, from basic decision trees to complex process flows with conditional logic and multiple paths.
Master the art of diagram creation with our comprehensive tutorials, practical examples, and expert tips. From basic flowcharts to advanced AI-powered diagrams, learn everything you need to know.
Learn how to create professional flowcharts with Mermaid.js syntax, from basic decision trees to complex process flows with conditional logic and multiple paths.
Step-by-step guide to creating sequence diagrams that clearly show how different parts of your system interact over time, including actors, lifelines, and messages.
Discover how to use Mermaid Gantt charts to plan, track, and communicate project timelines effectively with dependencies, milestones, and resource allocation.
Comprehensive tutorial on creating class diagrams to represent object-oriented software designs, including classes, interfaces, inheritance, and relationships.
Learn to create state diagrams that show how systems change from one state to another based on events, conditions, and transitions in your application flow.
Create compelling pie charts and other data visualizations using Mermaid's powerful charting capabilities for reports, dashboards, and presentations.
Explore how artificial intelligence is revolutionizing diagram creation with smart suggestions, automated layouts, and intelligent diagram completion features.
Discover the power of real-time diagram editing and how it transforms team collaboration, feedback loops, and productivity in diagram creation workflows.
Explore advanced diagram types including entity-relationship diagrams, mind maps, journey diagrams, git graphs, C4 architecture, and other specialized visualizations.
Learn about all the ways to export your Mermaid diagrams and integrate them into your workflows, documentation, presentations, and development processes.
Start creating beautiful Mermaid diagrams with our free online editor. No registration required!
Learn how to create professional flowcharts with Mermaid.js syntax, from basic decision trees to complex process flows with conditional logic and multiple paths.
Flowcharts are visual representations of processes, workflows, or systems. They use standardized symbols to show the sequence of steps, decisions, and outcomes in a process. Mermaid.js makes creating beautiful, interactive flowcharts simple with its text-based syntax.
Here's the basic structure for creating a flowchart in Mermaid:
graph TD
A[Start] --> B{Decision Point}
B -->|Yes| C[Process 1]
B -->|No| D[Process 2]
C --> E[End]
D --> E
Mermaid supports advanced features like subgraphs, styling, and complex conditional flows:
graph TD
subgraph "User Authentication"
A[Start] --> B[Enter Credentials]
B --> C{Valid Credentials?}
C -->|Yes| D[Grant Access]
C -->|No| E[Show Error]
E --> B
end
D --> F[Welcome Page]
Head over to the Mermaid Canvas editor and paste this flowchart code to see it in action:
graph TD
A[User Login] --> B{Valid User?}
B -->|Yes| C[Dashboard]
B -->|No| D[Error Message]
D --> A
Step-by-step guide to creating sequence diagrams that clearly show how different parts of your system interact over time, including actors, lifelines, and messages.
Sequence diagrams are a type of interaction diagram that shows how objects interact with each other over time. They are particularly useful for understanding the flow of messages between different components of a system.
The basic syntax for sequence diagrams in Mermaid is straightforward:
sequenceDiagram
participant User
participant System
participant Database
User->>System: Login Request
System->>Database: Validate Credentials
Database-->>System: User Data
System-->>User: Login Success
Mermaid supports different types of messages:
Sequence diagrams can include notes, loops, and complex interactions:
sequenceDiagram
participant User
participant API
participant Cache
participant Database
User->>API: GET /users
API->>Cache: Check Cache
Cache-->>API: Cache Miss
API->>Database: SELECT * FROM users
Database-->>API: User Data
API->>Cache: Store in Cache
API-->>User: User List
Note over User,Database: This shows a typical
API call with caching
Copy this sequence diagram to Mermaid Canvas to explore how system components interact:
sequenceDiagram
participant Alice
participant Bob
Alice->>Bob: Hello Bob, how are you?
Bob-->>Alice: I am good thanks!
Discover how to use Mermaid Gantt charts to plan, track, and communicate project timelines effectively with dependencies, milestones, and resource allocation.
Gantt charts are project management tools that provide a visual timeline of project tasks, showing when each task should start and finish. They help teams understand project schedules, dependencies, and progress at a glance.
Mermaid makes creating Gantt charts simple with its text-based syntax:
gantt
title Project Timeline
dateFormat YYYY-MM-DD
section Planning
Define requirements :done, req1, 2025-01-01, 2025-01-05
Create wireframes :done, wire1, 2025-01-06, 2025-01-10
section Development
Frontend development :active, front1, 2025-01-11, 2025-01-25
Backend development :back1, after front1, 2025-01-20, 2025-01-30
section Testing
QA testing :test1, after back1, 2025-02-01, 2025-02-05
You can indicate task status and add visual styling:
Gantt charts support complex project structures:
gantt
title Software Development Lifecycle
dateFormat YYYY-MM-DD
section Research
Market research :done, research1, 2025-01-01, 2025-01-07
User interviews :done, research2, 2025-01-08, 2025-01-14
section Design
UI/UX Design :done, design1, 2025-01-15, 2025-01-28
Technical Design :active, design2, 2025-01-29, 2025-02-11
section Development
Frontend Dev :front1, after design2, 2025-02-12, 2025-03-01
Backend Dev :back1, after design2, 2025-02-15, 2025-03-05
API Integration :api1, after front1, 2025-03-02, 2025-03-08
section Testing
Unit Testing :test1, after back1, 2025-03-06, 2025-03-12
Integration Testing :test2, after api1, 2025-03-09, 2025-03-15
User Acceptance :uat1, after test2, 2025-03-16, 2025-03-20
section Deployment
Production Deploy :milestone, deploy1, 2025-03-21, 2025-03-21
Use this template in Mermaid Canvas to plan your next project:
gantt
title My Project Timeline
dateFormat YYYY-MM-DD
section Planning
Requirements :done, req, 2025-01-01, 2025-01-05
section Execution
Development :active, dev, 2025-01-06, 2025-01-20
Testing :test, after dev, 2025-01-21, 2025-01-25
Comprehensive tutorial on creating class diagrams to represent object-oriented software designs, including classes, interfaces, inheritance, and relationships.
Class diagrams are a type of UML (Unified Modeling Language) diagram that shows the structure of a system by displaying classes, their attributes, operations, and relationships between classes. They are fundamental to object-oriented design.
In Mermaid, you define classes with their properties and methods:
classDiagram
class Animal {
+String name
+int age
+makeSound()
+eat()
}
class Dog {
+String breed
+bark()
+fetch()
}
class Cat {
+String color
+meow()
+purr()
}
Animal <|-- Dog
Animal <|-- Cat
Class diagrams show different types of relationships:
Mermaid supports interfaces, abstract classes, and complex relationships:
classDiagram
class Shape {
<<interface>>
+calculateArea()
+calculatePerimeter()
}
class Circle {
-double radius
+calculateArea()
+calculatePerimeter()
}
class Rectangle {
-double width
-double height
+calculateArea()
+calculatePerimeter()
}
class DrawingApp {
+List~Shape~ shapes
+addShape()
+removeShape()
}
Shape <|.. Circle
Shape <|.. Rectangle
DrawingApp *-- Shape
Class diagrams are excellent for illustrating common design patterns:
classDiagram
class Subject {
+attach(Observer)
+detach(Observer)
+notify()
}
class ConcreteSubject {
-List~Observer~ observers
+attach(Observer)
+detach(Observer)
+notify()
}
class Observer {
<<interface>>
+update()
}
class ConcreteObserver {
+update()
}
Subject <|-- ConcreteSubject
Observer <|.. ConcreteObserver
ConcreteSubject --> Observer
Try this simple class diagram in Mermaid Canvas:
classDiagram
class Car {
+String model
+start()
+stop()
}
class Engine {
+ignite()
+shutdown()
}
Car *-- Engine
Learn to create state diagrams that show how systems change from one state to another based on events, conditions, and transitions in your application flow.
State diagrams (also called state machines or statecharts) show how a system behaves differently in different states. They are particularly useful for modeling reactive systems, user interfaces, and complex business processes.
Mermaid state diagrams use a simple syntax to define states and transitions:
stateDiagram-v2
[*] --> Idle
Idle --> Running : start
Running --> Idle : stop
Running --> Error : error
Error --> Idle : reset
Error --> [*] : terminate
State diagrams can model complex behaviors with concurrent states and history:
stateDiagram-v2
[*] --> Authentication
state Authentication as Auth {
[*] --> Login
Login --> Verifying : submit
Verifying --> Authenticated : success
Verifying --> Login : failure
Authenticated --> [*]
}
Authentication --> Dashboard : authenticated
Dashboard --> Authentication : logout
state Dashboard as Dash {
[*] --> Home
Home --> Profile : view_profile
Home --> Settings : view_settings
Profile --> Home : back
Settings --> Home : back
}
You can add conditions and actions to transitions:
stateDiagram-v2
[*] --> Pending
Pending --> Approved : approve[amount < 1000]
Pending --> Review : approve[amount >= 1000]
Pending --> Rejected : reject
Review --> Approved : manager_approve
Review --> Rejected : manager_reject
Approved --> [*] : process/payment
Rejected --> [*] : notify/reject
State diagrams are excellent for modeling user interface flows:
stateDiagram-v2
[*] --> Loading
Loading --> Empty : no_data
Loading --> Error : network_error
Loading --> Ready : data_loaded
Ready --> Loading : refresh
Ready --> Editing : edit_item
Editing --> Ready : save
Editing --> Ready : cancel
Error --> Loading : retry
Empty --> Loading : create_first
Model your app's user flow with this state diagram in Mermaid Canvas:
stateDiagram-v2
[*] --> Login
Login --> Dashboard : authenticate
Dashboard --> Profile : click_profile
Dashboard --> Settings : click_settings
Profile --> Dashboard : back
Settings --> Dashboard : back
Dashboard --> Login : logout
Create compelling pie charts and other data visualizations using Mermaid's powerful charting capabilities for reports, dashboards, and presentations.
Mermaid supports various chart types for data visualization:
Pie charts are simple to create and show data as proportional slices:
pie title Browser Usage Statistics
"Chrome" : 65.5
"Firefox" : 15.2
"Safari" : 10.3
"Edge" : 6.8
"Other" : 2.2
You can customize pie charts with different styles and data formats:
pie title Monthly Revenue Breakdown
"Product Sales" : 45.2
"Services" : 32.8
"Subscriptions" : 15.6
"Licensing" : 6.4
Mermaid also supports XY charts for more complex visualizations:
xychart-beta
title "Sales Revenue"
x-axis [jan, feb, mar, apr, may, jun]
y-axis "Revenue (in $)" 4000 --> 11000
bar [5000, 6000, 7500, 8200, 9500, 10500]
line [5000, 6000, 7500, 8200, 9500, 10500]
Quadrant charts are useful for plotting data in four categories:
quadrantChart
title Reach and engagement of campaigns
x-axis Low Reach --> High Reach
y-axis Low Engagement --> High Engagement
quadrant-1 We should expand
quadrant-2 Need to promote
quadrant-3 Re-evaluate
quadrant-4 May be improved
Campaign A: [0.3, 0.6]
Campaign B: [0.45, 0.23]
Campaign C: [0.57, 0.69]
Campaign D: [0.78, 0.34]
Campaign E: [0.40, 0.34]
Campaign F: [0.35, 0.78]
Create this pie chart in Mermaid Canvas to visualize your data:
pie title Team Distribution
"Developers" : 40
"Designers" : 25
"Managers" : 20
"QA" : 15
Explore how artificial intelligence is revolutionizing diagram creation with smart suggestions, automated layouts, and intelligent diagram completion features.
Artificial Intelligence is transforming how we create and work with diagrams. From intelligent layout algorithms to natural language processing for diagram generation, AI is making visual documentation more accessible and efficient than ever before.
AI-powered layout engines can automatically arrange diagram elements for optimal readability and visual flow. These algorithms consider factors like:
One of the most exciting developments is the ability to generate diagrams from natural language descriptions:
// Instead of writing complex syntax, you might soon be able to write:
"Create a flowchart showing user login process with email validation and error handling"
// And get a complete diagram automatically
AI can provide contextual suggestions while you create diagrams:
AI can enhance existing diagrams by:
AI can generate complete diagram templates based on common use cases:
AI can analyze codebases and automatically generate diagrams:
// From code like this:
class UserService {
login(credentials) {
// validate credentials
// create session
// return user data
}
}
// AI could generate:
sequenceDiagram
User->>UserService: login(credentials)
UserService->>Database: validateCredentials()
Database-->>UserService: validationResult
UserService->>SessionManager: createSession()
UserService-->>User: loginResponse
As AI technology advances, we can expect:
As AI becomes more integrated into diagramming tools, it's important to consider:
Try the latest AI features in Mermaid Canvas. Our intelligent suggestions and automated layouts help you create better diagrams faster.
Discover the power of real-time diagram editing and how it transforms team collaboration, feedback loops, and productivity in diagram creation workflows.
Real-time collaboration in diagramming tools allows multiple team members to work on the same diagram simultaneously, seeing each other's changes as they happen. This eliminates version conflicts and speeds up the diagram creation process.
Effective real-time collaboration includes several key features:
See who's currently viewing or editing the diagram:
Track who made what changes:
Built-in communication features:
Use collaborative diagramming for creative brainstorming:
Streamline the review process:
Create living documentation:
Handle conflicting changes gracefully:
Ensure smooth collaboration experience:
Try creating diagrams with colleagues using Mermaid Canvas. Share your diagrams and collaborate in real-time for better team productivity.
Explore advanced diagram types including entity-relationship diagrams, mind maps, journey diagrams, git graphs, C4 architecture, and other specialized visualizations.
While flowcharts and sequence diagrams are essential, Mermaid offers a rich ecosystem of specialized diagram types for specific use cases and industries. These advanced diagrams help visualize complex systems, processes, and relationships.
ER diagrams are crucial for database design and data modeling:
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE-ITEM : contains
CUSTOMER {
string name
string custNumber
string sector
}
ORDER {
int orderNumber
string deliveryAddress
}
LINE-ITEM {
string productCode
int quantity
float pricePerUnit
}
Mind maps are excellent for brainstorming, organizing thoughts, and visualizing hierarchical information:
mindmap
root((Mermaid Canvas))
Features
Diagrams
Flowchart
Sequence
Gantt
AI
Generation
Suggestions
Auto-layout
Benefits
Free
Real-time
Export
Collaboration
User journey diagrams map out the complete experience of a user interacting with a product or service:
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 3: Me
Visualize Git branching strategies and commit history:
gitgraph
commit id: "Initial commit"
branch develop
checkout develop
commit id: "Add feature A"
branch feature-b
checkout feature-b
commit id: "Add feature B"
checkout develop
merge feature-b
checkout main
merge develop
C4 diagrams provide multiple levels of architectural detail:
C4Context
title System Context diagram for Internet Banking System
Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.")
Person(customerB, "Banking Customer B", "A customer of the bank, with personal bank accounts.")
Person_Ext(customerC, "Banking Customer C", "A customer of the bank, with personal bank accounts.")
System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")
System_Ext(email_system, "E-mail system", "The internal Microsoft Exchange e-mail system.")
System_Ext(mainframe, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")
Rel(customerA, SystemAA, "Uses")
Rel(SystemAA, email_system, "Sends e-mails", "SMTP")
Rel(SystemAA, mainframe, "Uses")
Sankey diagrams show flow volumes between processes:
sankey-beta
%% source,target,value
Electricity grid,Over generation / storage,0.21
Electricity grid,Heating and cooling,0.15
Electricity grid,Industry,0.25
Electricity grid,Losses,0.10
Electricity grid,Transportation,0.15
Electricity grid,Residential and commercial,0.14
Timeline diagrams visualize events and milestones over time:
timeline
title Mermaid Canvas Development
2024 : Version 1.0 Released
: Core diagram types implemented
2025 : AI features added
: Real-time collaboration launched
: Advanced diagram types released
Network packet diagrams visualize data flow in network communications:
packet-beta
title HTTP Request Packet
0-15: "GET"
16-31: "HTTP/1.1"
32-47: "Host: example.com"
48-63: "User-Agent: Browser/1.0"
Block diagrams show high-level system architectures:
block-beta
columns 3
a["Input"] b["Process"] c["Output"]
d["Data"] e["Logic"] f["Result"]
a --> b
b --> c
d --> e
e --> f
Selecting the appropriate diagram type depends on your communication goals:
Try these advanced diagram types in Mermaid Canvas. Each diagram type serves specific visualization needs and can greatly enhance your communication.
Learn about all the ways to export your Mermaid diagrams and integrate them into your workflows, documentation, presentations, and development processes.
Mermaid Canvas provides multiple export options to ensure your diagrams work wherever you need them:
High-quality raster images perfect for:
Scalable vector graphics ideal for:
Vector-based PDFs suitable for:
Seamlessly integrate Mermaid diagrams into your existing workflows:
Automate diagram generation and export through APIs:
// REST API Example
POST /api/diagrams/render
Content-Type: application/json
{
"diagram": "graph TD\\n A-->B\\n B-->C",
"format": "png",
"theme": "default"
}
// Response
{
"success": true,
"data": {
"url": "https://api.mermaidcanvas.app/diagrams/abc123.png",
"expires": "2025-10-10T10:00:00Z"
}
}
Set up automated workflows for diagram generation:
Embed interactive diagrams in your applications:
<div class="mermaid">
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Action 1]
B -->|No| D[Action 2]
</div>
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
<script>mermaid.initialize({startOnLoad:true});</script>
// React Example
import { Mermaid } from 'react-mermaid';
const MyDiagram = () => (
<Mermaid
chart={`graph TD
A --> B
B --> C`}
/>
);
Keep your diagrams in sync with your code:
Streamline team collaboration with integrated tools:
Ensure your diagrams meet security and compliance requirements:
Export your first diagram and see how easy it is to integrate Mermaid Canvas into your workflow. Start with a simple PNG export and explore premium formats as your needs grow.