name: aha-mermaid-diagram model: fast version: 1.1.0 description: > Create professional software diagrams using Mermaid syntax. Expert in all diagram types: Class, Sequence, Flowchart, ERD, C4 Architecture, State, Git Graphs, Gantt Charts. Includes HTML rendering, theming, styling, and interactive features. Triggers: diagram, visualize, model, architecture, flow, domain model, ERD, sequence. tags: [diagrams, mermaid, visualization, architecture, documentation, modeling, class-diagram, flowchart, sequence-diagram]
Professional Mermaid.js diagrams for software architecture, domain modeling, and system visualization.
html
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
<pre class="mermaid">
flowchart LR
A --> B
</pre>
bash
npm install -g @mermaid-js/mermaid-cli
mmdc -i input.mmd -o output.png -w 1920 -H 1080
All Mermaid diagrams:
text
diagramType
definition content
Key principles:
classDiagram, sequenceDiagram, flowchart, erDiagram, C4Context, stateDiagram, gantt%% for comments{} in commentsTypeUse ForBest PracticeClass DiagramDomain modeling, OOP design, entity relationshipsShow attributes + methodsSequence DiagramAPI flows, auth flows, component interactionsUse activations, autonumberFlowchartProcesses, algorithms, decision trees, user journeysKeep <15 nodes per diagramERDDatabase schemas, table relationshipsUPPERCASE entity namesC4 DiagramsSystem context, containers, components, architecture4 levels: Context→Container→Component→CodeState DiagramState machines, lifecycle statesUse choice nodes for transitionsGit GraphsBranching strategiesShow merges clearlyGantt ChartsProject timelines, schedulingGroup by category
Rendering diagram...
Visibility modifiers: + public, - private, # protected, ~ package
Relationships:
-- Association (loose relationship)*-- Composition (strong ownership, child dies with parent)o-- Aggregation (weak ownership, child can exist alone)<|-- Inheritance ("is-a")<.. Dependency (parameter/local variable)<|.. Implementation (interface)Rendering diagram...
Message types: ->> solid request, -->> dotted response, -) async
Structures: alt/else/end, opt, par/and/end, loop, break
Tips: Use activations ( +/ -), autonumber, descriptive notes
Rendering diagram...
Directions: TD/TB (top-down), BT (bottom-up), LR (left-right), RL (right-left)
Node shapes:
[Text] Rectangle([Text]) Stadium/pill[[Text]] Subroutine[(Text)] Cylinder (database)((Text)) Circle{Text} Rhombus (decision){{Text}} Hexagon[/Text/] Parallelogram (IO)[>Text] Asymmetric/flagConnections: --> arrow, --- open, -.-> dotted, ==> thick
Rendering diagram...
Cardinality: || exactly one, |o zero or one, }{ one or many, }o zero or many
Constraints: PK (primary key), FK (foreign key), UK (unique), NN (not null)
Rendering diagram...
Levels: C4Context → C4Container → C4Component → Class diagrams
Elements: Person, System, System_Ext, SystemDb, SystemQueue, Container, ContainerDb, ContainerQueue, Component
javascript
mermaid.initialize({
theme: 'dark',
themeVariables: {
primaryColor: '#3b82f6',
primaryTextColor: '#f1f5f9',
primaryBorderColor: '#8b5cf6',
lineColor: '#06b6d4',
background: '#111827',
mainBkg: '#1e293b'
}
});
Available themes: default, forest, dark, neutral, base
javascript
// Dagre (default) - balanced layout
// ELK - better for complex diagrams
mermaid.initialize({
layout: 'elk',
elk: {
mergeEdges: true,
nodePlacementStrategy: 'BRANDES_KOEPF'
}
});
javascript
mermaid.initialize({
look: 'classic' // Traditional
// or
look: 'handDrawn' // Sketch-like
});
javascript
mermaid.initialize({
startOnLoad: false,
maxTextSize: 99999,
fontSize: 14,
securityLevel: 'loose'
});
Rendering diagram...
Rendering diagram...
Rendering diagram...
Rendering diagram...
Rendering diagram...
MethodCommandLive Editorhttps://mermaid.liveCLI PNGmmdc -i diagram.mmd -o output.pngCLI SVGmmdc -i diagram.mmd -o output.svgCustom Sizemmdc -i input.mmd -o output.png -w 1920 -H 1080Dark BGmmdc -i input.mmd -o output.svg -b "#111827"
html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mermaid Diagram</title>
<style>
body { margin: 0; background: #111827; }
.mermaid { display: flex; justify-content: center; padding: 20px; }
.mermaid svg { max-width: 100%; height: auto; }
</style>
</head>
<body>
<div class="mermaid">
flowchart LR
A[Start] --> B[Process] --> C[End]
</div>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
mermaid.initialize({
startOnLoad: true,
theme: 'dark',
themeVariables: {
primaryColor: '#3b82f6',
background: '#111827',
mainBkg: '#1e293b',
fontSize: '14px'
}
});
</script>
</body>
</html>
%% comments to explain complex relationships.mmd files alongside codeErrorCauseSolutionNodes undefinedChinese class namesUse English identifiersNo diagram typeSyntax errorValidate in mermaid.liveDiagram too smallMissing configSet useMaxWidth: false``Mermaid not definedLoad orderUse waitForMermaid()Lines crossingComplex layoutUse ELK layoutTruncated textToo many nodesSplit into multiple diagrams
Rendering diagram...
Rendering diagram...
Rendering diagram...