Mermaid — Generate Diagrams from Text Like Markdown
Mermaid is a JavaScript-based diagramming tool that renders Markdown-inspired text definitions to create diagrams and visualizations. Flowcharts, sequence diagrams, Gantt charts, class diagrams, ER diagrams, and more — all from plain text. Natively supported in GitHub Markdown.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install 90331916-3649-11f1-9bc6-00163e2b0d79 --target codex先 dry-run 确认安装计划,再运行此命令。
What it is
Mermaid is a JavaScript-based diagramming tool that renders Markdown-inspired text definitions into diagrams and visualizations. It supports flowcharts, sequence diagrams, Gantt charts, class diagrams, ER diagrams, state diagrams, and more, all from plain text.
Mermaid is natively supported in GitHub Markdown, GitLab, Notion, Obsidian, and Docusaurus. It lets developers create documentation diagrams without Figma, draw.io, or any visual editor. Written in TypeScript with an MIT license.
How it saves time or tokens
Mermaid eliminates the context switch between writing documentation and creating diagrams. Instead of opening a separate tool, exporting images, and embedding them, you write diagram definitions inline with your documentation. Changes to diagrams are version-controlled alongside code. AI agents can generate and modify Mermaid diagrams as text, which is far more efficient than manipulating image files. The CLI tool renders diagrams to SVG or PNG for contexts that do not support live rendering.
How to use
- Write Mermaid diagrams directly in GitHub Markdown:
flowchart TD
A[User visits site] --> B{Logged in?}
B -->|Yes| C[Dashboard]
B -->|No| D[Login page]
D --> E[Enter credentials]
E --> B
- Use the CLI for rendering to files:
npm i -g @mermaid-js/mermaid-cli
mmdc -i input.mmd -o output.svg -t dark
mmdc -i input.mmd -o output.png -w 1200
- Embed in HTML for web applications:
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true, theme: 'dark' });
</script>
<pre class="mermaid">
sequenceDiagram
Client->>API: POST /login
API->>DB: SELECT user
DB-->>API: user record
API-->>Client: JWT token
</pre>
Example
An entity-relationship diagram for a project management system:
erDiagram
USER ||--o{ PROJECT : owns
PROJECT ||--|{ TASK : contains
TASK }o--|| USER : assigned_to
PROJECT ||--o{ MEMBER : has
USER ||--o{ MEMBER : participates
Related on TokRepo
- Documentation tools — More documentation and diagramming tools on TokRepo.
- Coding tools — Browse developer tools for AI-assisted workflows.
Common pitfalls
- Complex diagrams with many nodes and edges become unreadable. Break large diagrams into multiple smaller ones focused on specific subsystems.
- Not all Mermaid diagram types are supported in every platform. GitHub supports flowcharts, sequence, class, state, ER, Gantt, pie, and git graphs, but some newer types may lag.
- Using Mermaid's live editor for collaboration does not save state. Export diagram definitions to your repository for version control.
常见问题
Mermaid supports flowcharts (TD, LR, RL, BT), sequence diagrams, class diagrams, state diagrams, entity-relationship diagrams, Gantt charts, pie charts, git graphs, user journey maps, mindmaps, and timeline diagrams.
Yes. GitHub natively renders Mermaid code blocks in Markdown files including READMEs, issues, pull request descriptions, and wiki pages. Wrap your diagram in a mermaid-tagged code fence.
Yes. Since Mermaid diagrams are plain text, AI agents can generate, modify, and version them like any other code. This is more efficient than generating or editing image files.
Use the Mermaid CLI tool: npm i -g @mermaid-js/mermaid-cli, then mmdc -i input.mmd -o output.svg. The CLI supports SVG, PNG, and PDF output with configurable themes and dimensions.
Yes. Mermaid is open source under the MIT license. It is free for personal, commercial, and open-source use. The live editor at mermaid.live is also free.
引用来源 (3)
- Mermaid GitHub— Mermaid is a JavaScript diagramming tool with 87K+ stars
- GitHub Blog— GitHub native Mermaid rendering support
- Mermaid Documentation— Mermaid live editor and documentation
讨论
相关资产
Kroki — Unified API for Generating Diagrams from Text
A free, open-source service that generates diagrams from textual descriptions. Kroki supports over 25 diagram types including Mermaid, PlantUML, D2, GraphViz, BPMN, Excalidraw, and more through a single HTTP API.
D2 — Declarative Diagram Scripting Language
A modern diagram scripting language that turns text into diagrams, offering a readable syntax for architecture, flow, and sequence diagrams rendered from code.
CotEditor — Lightweight Plain-Text Editor for macOS
A native macOS text editor built with Swift and Cocoa that offers syntax highlighting for 50+ languages, powerful find-and-replace with regex, and a fast, distraction-free editing experience.
OOP Architect — Self-Updating UML in CLAUDE.md
Generate and maintain Mermaid UML diagrams inside CLAUDE.md as you code; verified 105★ and installs as a Claude Code skill via marketplace or git clone.