Skip to content

Complete Guide to Diagrams in Markdown: Mermaid, Graphviz & Markmap (2025)

Master technical visualization with diagrams in Markdown. Learn Mermaid, Graphviz, DOT, and Markmap with practical examples for flowcharts, sequence diagrams, ER diagrams, and more.

Complete Guide to Diagrams in Markdown: Mermaid, Graphviz & Markmap (2025)

Ever tried explaining a complex system architecture in pure text? It's painful. That's why diagrams exist—they turn walls of text into something you can actually understand at a glance.

The problem is, most diagramming tools make you choose: use a visual editor and lose version control, or write diagram code and... well, write a lot of code.

MD Editor supports four text-based diagram formats that work right in Markdown: Mermaid.js, Graphviz, DOT, and Markmap. Write diagrams as code, see them render in real-time, and commit everything to Git alongside your documentation.

This guide shows you how to use each one, with examples you can copy and modify.

Table of Contents

Why Use Diagrams in Markdown?

Before diving into the specifics, let's understand why embedding diagrams in markdown is powerful:

  • Version Control: Diagrams are stored as text, making them easy to track in Git
  • Collaboration: Team members can review and edit diagrams just like code
  • Consistency: Diagrams use the same syntax everywhere, no proprietary formats
  • Automation: Diagrams automatically render in exports (HTML, PDF, DOCX)
  • No External Tools: Create professional diagrams without leaving your markdown editor

Mermaid: Versatile Diagrams for Every Need

Mermaid.js is the most versatile option, supporting multiple diagram types from a single syntax.

Flowcharts

Perfect for decision trees and process flows:

flowchart TD
    A[Start] --> B{Is it working?}
    B -->|Yes| C[Great!]
    B -->|No| D[Debug]
    D --> E[Fix the bug]
    E --> B
    C --> F[Deploy]

Mermaid flowchart example showing a debugging decision tree with start, decision points, and deploy steps

Sequence Diagrams

Ideal for API interactions and system communication:

sequenceDiagram
    participant User
    participant Frontend
    participant API
    participant Database

    User->>Frontend: Submit form
    Frontend->>API: POST /api/users
    API->>Database: INSERT user
    Database-->>API: User created
    API-->>Frontend: 201 Created
    Frontend-->>User: Success message

Mermaid sequence diagram showing API interaction flow between user, frontend, API, and database layers

Gantt Charts

Great for project timelines and scheduling:

gantt
    title Project Development Timeline
    dateFormat  YYYY-MM-DD
    section Planning
    Requirements gathering    :2024-01-01, 14d
    System design            :2024-01-08, 10d
    section Development
    Frontend development     :2024-01-15, 30d
    Backend development      :2024-01-20, 35d
    section Testing
    Integration testing      :2024-02-20, 10d
    User acceptance testing  :2024-02-25, 7d

Mermaid Gantt chart showing project development timeline with planning, development, and testing phases

State Diagrams

Perfect for modeling application states and transitions:

stateDiagram-v2
    [*] --> Idle
    Idle --> Loading: User clicks
    Loading --> Success: Data loaded
    Loading --> Error: Request failed
    Success --> Idle: Reset
    Error --> Idle: Retry
    Success --> [*]

Mermaid state diagram illustrating application state transitions from idle to loading, success, or error states

Entity Relationship Diagrams

Essential for database design:

erDiagram
    USER ||--o{ ARTICLE : writes
    USER ||--o{ COMMENT : posts
    ARTICLE ||--o{ COMMENT : has
    USER {
        string id PK
        string email
        string name
        datetime created_at
    }
    ARTICLE {
        string id PK
        string user_id FK
        string title
        text content
        datetime published_at
    }
    COMMENT {
        string id PK
        string user_id FK
        string article_id FK
        text content
        datetime created_at
    }

Mermaid entity relationship diagram showing database schema with USER, ARTICLE, and COMMENT tables and their relationships

Graphviz & DOT: Powerful Graph Layouts

Graphviz excels at creating complex graph structures with sophisticated automatic layouts.

Directed Graphs

Perfect for dependency trees and network topologies:

digraph Architecture {
    rankdir=TB;
    node [shape=box, style=rounded];

    Frontend [label="React Frontend"];
    API [label="REST API"];
    Cache [label="Redis Cache"];
    DB [label="PostgreSQL"];
    Queue [label="Message Queue"];
    Worker [label="Background Worker"];

    Frontend -> API [label="HTTPS"];
    API -> Cache [label="Read/Write"];
    API -> DB [label="SQL"];
    API -> Queue [label="Enqueue"];
    Queue -> Worker [label="Process"];
    Worker -> DB [label="Update"];
}

Undirected Graphs

Great for network relationships and clustering:

graph Network {
    layout=neato;
    node [shape=circle];

    A -- B [label="10ms"];
    A -- C [label="15ms"];
    B -- C [label="8ms"];
    B -- D [label="12ms"];
    C -- D [label="7ms"];
    C -- E [label="20ms"];
    D -- E [label="9ms"];

    A [label="Server A"];
    B [label="Server B"];
    C [label="Server C"];
    D [label="Server D"];
    E [label="Server E"];
}

Hierarchical Structures

Ideal for organization charts and file systems:

digraph OrgChart {
    node [shape=box, style="rounded,filled", fillcolor=lightblue];

    CEO [label="CEO"];
    CTO [label="CTO"];
    CFO [label="CFO"];
    VP_Eng [label="VP Engineering"];
    VP_Product [label="VP Product"];
    Team_Lead_1 [label="Team Lead 1"];
    Team_Lead_2 [label="Team Lead 2"];

    CEO -> CTO;
    CEO -> CFO;
    CTO -> VP_Eng;
    CTO -> VP_Product;
    VP_Eng -> Team_Lead_1;
    VP_Eng -> Team_Lead_2;
}

Cluster Diagrams

Perfect for microservices architecture:

digraph Microservices {
    compound=true;
    rankdir=LR;

    subgraph cluster_frontend {
        label="Frontend Cluster";
        style=filled;
        color=lightgrey;
        WebApp [label="Web App"];
        MobileApp [label="Mobile App"];
    }

    subgraph cluster_backend {
        label="Backend Services";
        style=filled;
        color=lightblue;
        AuthService [label="Auth Service"];
        UserService [label="User Service"];
        OrderService [label="Order Service"];
    }

    subgraph cluster_data {
        label="Data Layer";
        style=filled;
        color=lightyellow;
        UserDB [label="User DB"];
        OrderDB [label="Order DB"];
    }

    WebApp -> AuthService;
    MobileApp -> AuthService;
    AuthService -> UserService;
    UserService -> UserDB;
    OrderService -> OrderDB;
}

Markmap: Interactive Mind Maps

Markmap transforms markdown lists into beautiful, hierarchical mind maps.

Knowledge Organization

# Technical Documentation Guide

## Planning
- Define audience
- Set objectives
- Outline structure
- Gather resources

## Writing
- Introduction
  - Purpose
  - Scope
  - Prerequisites
- Main Content
  - Step-by-step guides
  - Code examples
  - Best practices
- Conclusion
  - Summary
  - Next steps
  - Resources

## Review
- Technical accuracy
- Clarity and readability
- Code testing
- Peer review

## Publishing
- Export formats
  - HTML
  - PDF
  - Markdown
- Distribution
  - Documentation site
  - GitHub repository
  - Internal wiki

Feature Planning

# Application Features

## User Management
- Authentication
  - Email/Password
  - OAuth (Google, GitHub)
  - 2FA
- User Profiles
  - Personal information
  - Preferences
  - Avatar upload
- Permissions
  - Role-based access
  - Custom permissions
  - Team management

## Content Management
- Editor
  - Markdown support
  - Real-time preview
  - Auto-save
- Organization
  - Folders
  - Tags
  - Search
- Collaboration
  - Sharing
  - Comments
  - Version history

## Export & Publishing
- Formats
  - HTML
  - PDF
  - DOCX
- Publishing
  - Medium
  - Dev.to
  - GitHub

Learning Path

# Full-Stack Development Path

## Frontend
- HTML/CSS
  - Semantic HTML
  - Responsive design
  - CSS Grid & Flexbox
- JavaScript
  - ES6+ features
  - Async programming
  - DOM manipulation
- React
  - Components
  - Hooks
  - State management
  - Next.js

## Backend
- Node.js
  - Express.js
  - API design
  - Authentication
- Databases
  - SQL (PostgreSQL)
  - NoSQL (MongoDB)
  - ORMs
- DevOps
  - Docker
  - CI/CD
  - Cloud platforms

How to Use Diagrams in MD Editor

Using diagrams in MD Editor is simple:

  1. Create a code block with the diagram type as the language
  2. Write your diagram code using the syntax for that type
  3. The diagram renders automatically in the preview
  4. Export to any format (HTML, PDF, DOCX) and diagrams are included as images

Example Syntax

For Mermaid:

```mermaid
graph TD
    A --> B
```

For Graphviz:

```graphviz
digraph G {
    A -> B
}
```

For DOT:

```dot
graph G {
    A -- B
}
```

For Markmap:

```markmap
# Root
## Branch 1
## Branch 2
```

Best Practices

Choose the Right Tool

  • Mermaid: Best for standard diagrams (flowcharts, sequence, Gantt)
  • Graphviz/DOT: Best for complex graphs and custom layouts
  • Markmap: Best for hierarchical information and mind maps

Keep Diagrams Readable

  • Limit nodes to avoid clutter
  • Use meaningful labels
  • Add colors to group related elements
  • Include legends when necessary

Maintain Consistency

  • Use the same diagram type for similar visualizations
  • Follow naming conventions
  • Document complex diagrams with comments

Version Control Tips

  • Keep diagrams in separate code blocks
  • Add descriptive comments
  • Break complex diagrams into smaller ones
  • Use meaningful commit messages when updating diagrams

Export Behavior

When you export your document from MD Editor:

  • HTML Export: Diagrams are rendered as embedded PNG images with base64 encoding
  • PDF Export: Diagrams appear as high-resolution images
  • DOCX Export: Diagrams are included as inline images
  • Markdown Export: Original diagram code is preserved for portability

All diagrams are automatically rendered during export, ensuring your documentation looks professional regardless of the output format.

Frequently Asked Questions

What is the best tool for creating diagrams in Markdown?

Mermaid.js is the most popular and versatile tool for creating diagrams in Markdown. It supports flowcharts, sequence diagrams, Gantt charts, state diagrams, ER diagrams, and more—all using simple text syntax. For complex graph layouts, Graphviz/DOT excels, while Markmap is perfect for mind maps and hierarchical information.

How do I add a flowchart to my Markdown document?

To add a flowchart in Markdown, create a code block with mermaid as the language and use Mermaid's flowchart syntax. For example:

```mermaid
flowchart TD
    A[Start] --> B[Process]
    B --> C[End]
```

MD Editor will automatically render this as a visual flowchart.

Can I export Markdown diagrams to PDF or Word?

Yes! When you export your Markdown document from MD Editor to PDF, HTML, or DOCX formats, all diagrams are automatically rendered as high-quality images and embedded in the output file. The original text-based diagram code is preserved when exporting to Markdown.

What's the difference between Mermaid and Graphviz?

Mermaid is easier to learn and covers common diagram types (flowcharts, sequence, Gantt, ER diagrams) with simple syntax. Graphviz/DOT offers more control over complex graph layouts and is better for intricate network diagrams, dependency trees, and custom node positioning. Use Mermaid for standard diagrams and Graphviz for advanced graph visualizations.

Do I need to install anything to use diagrams in MD Editor?

No installation required! MD Editor has built-in support for Mermaid, Graphviz, DOT, and Markmap. Simply write your diagram code in a code block with the appropriate language identifier, and it renders automatically in the preview. Start using it immediately at app.mdedit.ai/scratchpad.

Can I create database diagrams in Markdown?

Yes! Mermaid's Entity Relationship Diagram (ERD) syntax is perfect for database schema visualization. You can define tables, fields, data types, primary keys, foreign keys, and relationships using simple text, making it ideal for database documentation that lives alongside your code.

Are Markdown diagrams compatible with GitHub and other platforms?

Yes! Mermaid diagrams are widely supported on GitHub, GitLab, Notion, and many other platforms. Graphviz and Markmap may require additional rendering tools on some platforms, but MD Editor ensures all diagrams export correctly to standard formats (PDF, HTML, DOCX) that work everywhere.

How do I create a sequence diagram for API documentation?

Use Mermaid's sequence diagram syntax to document API interactions. Define participants (user, frontend, API, database) and use arrows (->> for requests, -->> for responses) to show the message flow. See the Sequence Diagrams section above for a complete example.

Can I style my Mermaid diagrams with custom colors?

Yes! Mermaid supports custom styling using CSS-like syntax. You can add colors, shapes, and styles directly in your diagram code. For example:

```mermaid
graph TD
    A[Start] --> B[Process]
    style A fill:#90EE90
    style B fill:#FFD700
```

What are the best use cases for Markmap diagrams?

Markmap excels at visualizing hierarchical information, knowledge organization, learning paths, feature planning, documentation outlines, and brainstorming sessions. It automatically converts nested Markdown lists into interactive, collapsible mind maps—perfect for high-level overviews and knowledge bases.

Related Articles

Wrapping Up

Text-based diagrams aren't just a nice-to-have—they solve real problems. Your diagrams live in Git. Your team can review them in PRs. They don't break when you upgrade your diagramming software.

Mermaid covers 80% of what most people need. Graphviz handles the complex graph layouts. Markmap is great for mind maps. And they all work directly in MD Editor without plugins or extra setup.

Pick whichever format fits your use case and start writing. The syntax takes a few minutes to learn, but once it clicks, you'll wonder how you ever managed without it.