Mermaid

Generate flowcharts, sequence diagrams, and 20+ other diagram types from markdown-like text

Library
npm
v12.1.0
90,595 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
93 /100 Excellent
Development Activity 100
Maintenance 96
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
89 /100 Excellent
Architecture 90
Code Quality 88
Innovation 85
Learning Curve 92

Mermaid is a JavaScript-based diagramming and charting library that renders complex diagrams from simple, markdown-inspired text definitions instead of drag-and-drop tools. It ships as an importable library with a mermaid.initialize() / mermaid.run() API that scans a page for .mermaid blocks and renders them to SVG in the browser, and it natively powers Mermaid code fences on GitHub, GitLab, and many documentation and note-taking tools.

Because diagrams are plain text, they live alongside code in version control, get reviewed in diffs, and never go stale the way exported images do. The library supports over 20 diagram types (flowcharts, sequence, class, state, ER, Gantt, Git graphs, mindmaps, timelines, and more), pluggable rendering layouts, theming, and a sandboxed/sanitized rendering mode for embedding user-authored diagrams safely.

What You Get

  • A single mermaid npm package exposing initialize(), run(), and render() APIs for parsing and rendering diagram text to SVG in the browser or a headless DOM
  • 20+ built-in diagram types (flowchart, sequence, class, state, ER, Gantt, pie, Git graph, mindmap, timeline, sankey, C4, requirement, quadrant, packet, and more)
  • Pluggable layout engines, including the default dagre-based layout and optional ELK and tidy-tree layout packages
  • Built-in sanitization via DOMPurify plus a sandboxed iframe rendering mode for safely embedding untrusted diagram text
  • Theming support (default, dark, forest, neutral, base) with per-diagram style configuration
  • Native rendering support already wired into GitHub, GitLab, Notion, and dozens of other markdown-aware tools that recognize ```mermaid code fences

Common Use Cases

  • Embedding architecture and flow diagrams directly in README files and technical documentation so they render on GitHub without external image tooling
  • Generating sequence and state diagrams from text inside internal wikis, static site generators, or documentation-as-code pipelines
  • Building an in-app diagram editor or live preview feature (as the Mermaid Live Editor does) using the mermaid library’s parse/render API
  • Visualizing Git branching history, Gantt project timelines, or entity-relationship schemas as part of automated reporting or CI-generated docs

Under The Hood

Architecture - Mermaid’s public entry point (src/mermaid.ts) wraps an internal mermaidAPI that drives a pipeline of detect → parse → render. detectType() (in diagram-api/detectType.ts) inspects the leading tokens of the input text to pick a diagram type, Diagram.fromText() lazily loads that diagram’s registered definition via loadDiagram.ts/diagram-orchestration.ts if it isn’t already registered, then hands the text to a per-diagram-type parser (Jison-generated grammars for legacy diagrams, or the newer Langium-based @mermaid-js/parser package for others) which populates a diagram-specific in-memory database (e.g. flowDb.ts). The populated db is passed to rendering-util/render.ts, which delegates to pluggable layout algorithms (the default dagre-based layout, plus optional ELK and tidy-tree packages) to compute positions before painting SVG via D3. Each of the 20+ diagram types under src/diagrams/* is a self-contained module (parser + db + renderer + styles), registered through a common DiagramDefinition interface, which is what lets new diagram types be added without touching the core orchestration code.

Tech Stack - The library is TypeScript-first, built with Vite/Rollup, and its runtime dependencies reveal a layered rendering stack: D3 (d3, d3-sankey) for SVG manipulation and data-driven layout, dagre-d3-es for default graph layout, cytoscape plus cytoscape-cose-bilkent/cytoscape-fcose for force-directed diagrams, roughjs for the hand-drawn sketch theme, katex for math rendering inside diagrams, dompurify and @braintree/sanitize-url for output sanitization, marked for markdown-in-labels support, and the sibling @mermaid-js/parser package for Langium-based grammars. It’s organized as a pnpm workspace monorepo (packages/mermaid, packages/parser, packages/mermaid-layout-elk, etc.), so the core library composes cleanly with optional layout and parser plugins that ship as separate npm packages.

Code Quality - The mermaid package has extensive automated test coverage: 149+ .spec.ts/.spec.js files sit alongside their implementation files (e.g. mermaidAPI.spec.ts, config.spec.ts, flowDb.spec.ts), plus a separate Cypress suite (cypress/) for visual/integration testing and Applitools/Argos-powered visual regression testing in CI. TypeScript strict typing, ESLint, and Prettier are enforced repo-wide, and error handling is explicit — Diagram.fromText() throws a typed UnknownDiagramError for unrecognized diagram types rather than failing silently, and the public run() API exposes a suppressErrors option so consumers can opt into graceful degradation instead of having it forced on them.

API Design - The public surface is deliberately small: mermaid.initialize(config) to configure once, mermaid.run() to auto-render all .mermaid elements on a page, and lower-level mermaid.parse()/mermaid.render() for programmatic use in custom editors or SSR pipelines. Getting started requires no build step beyond import mermaid from 'mermaid' (or a CDN script tag) and a text string — there’s no scaffolding, no required project structure, and sensible defaults handle theme and layout selection automatically, which is a large part of why it has been adopted natively by GitHub, GitLab, and dozens of other markdown-aware tools.

Used by 86 apps in this directory

TypeScript
99%
Other

NocoBase

Low Code Platforms · No Code Platforms

24,512

Open-source AI + no-code platform that lets coding agents and people collaborate to build business systems fast on proven infrastructure.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
TypeScript 99%
Updated today
TypeScript
89%
GPL 3.0

NoteGen

AI Assistants · Knowledge Management · Note Taking

12,877

Capture anything first, then let AI transform your scattered records into polished, structured Markdown notes with RAG-powered knowledge retrieval.

View details
87
Repo Health
74
Technical
67
Dependency
Built with
TypeScript 89%
Updated today
TypeScript
95%
MIT

OmniRoute

AI Agents

74,725

A free, open-source AI gateway connecting Claude Code, Codex, Cursor, Cline, and Copilot to 237 AI providers (90+ free) through one endpoint, with automatic fallback and token-compression to stretch free-tier limits further.

View details
86
Repo Health
70
Technical
70
Dependency
Built with
TypeScript 95%
Updated today
TypeScript
96%
Apache 2.0

OneUptime

Monitoring

7,719

The complete open-source observability platform that replaces PagerDuty, Datadog, Sentry, and StatusPage with a single self-hostable system.

View details
91
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 96%
Updated today
Go
66%
Apache 2.0

open-code-review

Developer Tools · Devops

45,444

The AI code review agent born at Alibaba's scale — combining deterministic engineering with LLM intelligence for precise, token-efficient reviews.

View details
83
Repo Health
83
Technical
79
Dependency
Built with
Go 66%
JavaScript 13%
TypeScript 11%
Updated today
TypeScript
97%
GPL 3.0

OpenKnowledge

Code Editors · Knowledge Management · Note Taking

4,485

A beautiful, local-first markdown IDE that turns any git repo into a live collaborative workspace for humans and AI coding agents like Claude, Codex, and OpenCode.

View details
79
Repo Health
89
Technical
64
Dependency
Built with
TypeScript 97%
Updated today
Python
37%
Other

Open WebUI

AI Agents · AI Assistants

154,169

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
92
Repo Health
75
Technical
66
Dependency
Built with
Python 37%
Svelte 34%
JavaScript 21%
Updated yesterday
TypeScript
90%
MIT

OpenClaw

AI Agents · AI Assistants

391,553

An open-source AI assistant that runs on your own hardware and meets you in Discord, Slack, WhatsApp, iMessage, Telegram, and 20+ other channels, with native apps for every major platform.

View details
88
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 90%
Updated today
Rust
86%
Apache 2.0

OpenShell

AI Agents · Developer Tools

15,629

The safe, private runtime that lets autonomous AI agents operate in sandboxed environments governed by declarative YAML policies — blocking data exfiltration, credential leaks, and unauthorized network activity before they happen.

View details
86
Repo Health
81
Technical
68
Dependency
Built with
Rust 86%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers