← 返回 Skills 市场
zrxparley

AHA Mermaid Diagram

作者 Aha.Gare · GitHub ↗ · v1.1.0 · MIT-0
cross-platform ✓ 安全检测通过
105
总下载
0
收藏
0
当前安装
2
版本数
在 OpenClaw 中安装
/install aha-mermaid-diagram
功能描述
Render Mermaid.js class, flowchart, sequence, and ER diagrams in HTML with live preview, dark theme, and error handling for clean visualization.
使用说明 (SKILL.md)

\x3Cskill> 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] \x3C/skill>

Aha Mermaid Diagram Expert

Professional Mermaid.js diagrams for software architecture, domain modeling, and system visualization.

Installation

CDN (HTML)

\x3Cscript type="module">
  import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
  mermaid.initialize({ startOnLoad: true });
\x3C/script>
\x3Cpre class="mermaid">
  flowchart LR
    A --> B
\x3C/pre>

CLI Export

npm install -g @mermaid-js/mermaid-cli
mmdc -i input.mmd -o output.png -w 1920 -H 1080

Core Syntax

All Mermaid diagrams:

diagramType
  definition content

Key principles:

  • First line declares type: classDiagram, sequenceDiagram, flowchart, erDiagram, C4Context, stateDiagram, gantt
  • Use %% for comments
  • Line breaks improve readability
  • Unknown words break diagrams; invalid parameters fail silently
  • Avoid {} in comments

Diagram Type Selection

Type Use For Best Practice
Class Diagram Domain modeling, OOP design, entity relationships Show attributes + methods
Sequence Diagram API flows, auth flows, component interactions Use activations, autonumber
Flowchart Processes, algorithms, decision trees, user journeys Keep \x3C15 nodes per diagram
ERD Database schemas, table relationships UPPERCASE entity names
C4 Diagrams System context, containers, components, architecture 4 levels: Context→Container→Component→Code
State Diagram State machines, lifecycle states Use choice nodes for transitions
Git Graphs Branching strategies Show merges clearly
Gantt Charts Project timelines, scheduling Group by category

Class Diagram (Domain Model)

classDiagram
    %% Relationships: --, *--, o--, \x3C|--, \x3C.., \x3C|..
    Customer "1" --> "0..*" Order : places
    Order "1" *-- "1..*" LineItem : contains
    LineItem "1" --> "1" Product : references
    
    class Customer {
        +UUID id
        +String email
        +String name
        +placeOrder() Order
        +getOrderHistory()
    }
    
    class Order {
        +UUID id
        +DateTime orderDate
        +OrderStatus status
        +calculateTotal() Decimal
        +ship()
    }
    
    class OrderStatus {
        \x3C\x3Cenumeration>>
        PENDING
        PAID
        SHIPPED
        DELIVERED
    }

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)
  • \x3C|-- Inheritance ("is-a")
  • \x3C.. Dependency (parameter/local variable)
  • \x3C|.. Implementation (interface)

Sequence Diagram (API Flow)

sequenceDiagram
    autonumber
    actor User
    participant Frontend
    participant API
    participant Database
    
    User->>+Frontend: Enter credentials
    Frontend->>+API: POST /auth/login
    
    API->>+Database: Query user
    Database-->>-API: User record
    
    alt Valid credentials
        API->>API: Generate JWT
        API-->>-Frontend: 200 OK + JWT
        Frontend-->>-User: Redirect to dashboard
    else Invalid
        API-->>-Frontend: 401 Unauthorized
        Frontend-->>User: Show error
    end

Message types: ->> solid request, -->> dotted response, -) async

Structures: alt/else/end, opt, par/and/end, loop, break

Tips: Use activations (+/-), autonumber, descriptive notes

Flowchart (Process/Decision)

flowchart TD
    Start([Start]) --> Input[User enters data]
    Input --> Validate{Valid?}
    Validate -->|No| Error[Show error]
    Error --> Input
    Validate -->|Yes| Process[Process data]
    Process --> Save[(Save to DB)]
    Save --> End([Complete])
    
    style Start fill:#90EE90
    style End fill:#90EE90
    style Save fill:#FFD700

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/flag

Connections: --> arrow, --- open, -.-> dotted, ==> thick

ERD (Database Schema)

erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ LINE_ITEM : contains
    PRODUCT ||--o{ LINE_ITEM : "ordered in"
    
    CUSTOMER {
        uuid id PK
        varchar email UK "NOT NULL"
        varchar name "NOT NULL"
        timestamp created_at
    }
    
    ORDER {
        uuid id PK
        uuid customer_id FK "NOT NULL"
        decimal total
        varchar status
    }

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)

C4 Architecture Diagrams

C4Context
    title System Context - E-Commerce Platform
    
    Person(customer, "Customer", "Shops online")
    Person(admin, "Admin", "Manages catalog")
    
    System(ecommerce, "E-Commerce", "Online shopping platform")
    
    System_Ext(payment, "Payment Gateway", "Processes payments")
    System_Ext(email, "Email Service", "Sends notifications")
    
    Rel(customer, ecommerce, "Browses, orders")
    Rel(admin, ecommerce, "Manages products")
    Rel(ecommerce, payment, "Processes via", "HTTPS/REST")
    Rel(ecommerce, email, "Sends via", "SMTP")

Levels: C4Context → C4Container → C4Component → Class diagrams

Elements: Person, System, System_Ext, SystemDb, SystemQueue, Container, ContainerDb, ContainerQueue, Component

Advanced Configuration

Theme Variables

mermaid.initialize({
  theme: 'dark',
  themeVariables: {
    primaryColor: '#3b82f6',
    primaryTextColor: '#f1f5f9',
    primaryBorderColor: '#8b5cf6',
    lineColor: '#06b6d4',
    background: '#111827',
    mainBkg: '#1e293b'
  }
});

Available themes: default, forest, dark, neutral, base

Layout Options

// Dagre (default) - balanced layout
// ELK - better for complex diagrams
mermaid.initialize({
  layout: 'elk',
  elk: {
    mergeEdges: true,
    nodePlacementStrategy: 'BRANDES_KOEPF'
  }
});

Look Options

mermaid.initialize({
  look: 'classic'   // Traditional
  // or
  look: 'handDrawn' // Sketch-like
});

HTML Rendering Config

mermaid.initialize({
  startOnLoad: false,
  maxTextSize: 99999,
  fontSize: 14,
  securityLevel: 'loose'
});

Styling

Node Styling

flowchart LR
    A[Start]:::success
    B[Process]:::warning
    C[End]:::error
    
    classDef success fill:#90EE90,stroke:#333,stroke-width:2px
    classDef warning fill:#FFD700,stroke:#333
    classDef error fill:#FF6B6B,stroke:#333

Link Styling

flowchart LR
    A --> B --> C
    linkStyle 0 stroke:#ff6b6b,stroke-width:4px
    linkStyle 1 stroke:#4ecdc4,stroke-width:2px

Subgraph Styling

flowchart TB
    subgraph Frontend
        A[Web] & B[Mobile]
    end
    
    subgraph Backend
        C[API] & D[DB]
    end
    
    A & B --> C --> D
    
    style Frontend fill:#e3f2fd,stroke:#2196f3,stroke-width:2px

Interactive Features

Click Events & Links

flowchart LR
    A[GitHub] --> B[Documentation]
    click A "https://github.com" "Go to GitHub"
    click B "https://mermaid.js.org" "View Docs"

Tooltips

flowchart LR
    A[Service A] -.->|REST API| B[Service B]
    linkStyle 0 stroke:#06b6d4,stroke-dasharray:5

Export Options

Method Command
Live Editor https://mermaid.live
CLI PNG mmdc -i diagram.mmd -o output.png
CLI SVG mmdc -i diagram.mmd -o output.svg
Custom Size mmdc -i input.mmd -o output.png -w 1920 -H 1080
Dark BG mmdc -i input.mmd -o output.svg -b "#111827"

HTML Template

\x3C!DOCTYPE html>
\x3Chtml lang="zh-CN">
\x3Chead>
  \x3Cmeta charset="UTF-8">
  \x3Cmeta name="viewport" content="width=device-width, initial-scale=1.0">
  \x3Ctitle>Mermaid Diagram\x3C/title>
  \x3Cstyle>
    body { margin: 0; background: #111827; }
    .mermaid { display: flex; justify-content: center; padding: 20px; }
    .mermaid svg { max-width: 100%; height: auto; }
  \x3C/style>
\x3C/head>
\x3Cbody>
  \x3Cdiv class="mermaid">
flowchart LR
    A[Start] --> B[Process] --> C[End]
  \x3C/div>
  
  \x3Cscript 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'
      }
    });
  \x3C/script>
\x3C/body>
\x3C/html>

Best Practices

  1. Start simple — begin with core entities, add details incrementally
  2. Use meaningful names — clear labels make diagrams self-documenting
  3. Comment extensively — use %% comments to explain complex relationships
  4. Keep focused — one diagram per concept; split large diagrams
  5. Version control — store .mmd files alongside code
  6. Add context — include titles and notes to explain purpose
  7. Iterate — refine diagrams as understanding evolves

Common Pitfalls

Error Cause Solution
Nodes undefined Chinese class names Use English identifiers
No diagram type Syntax error Validate in mermaid.live
Diagram too small Missing config Set useMaxWidth: false
Mermaid not defined Load order Use waitForMermaid()
Lines crossing Complex layout Use ELK layout
Truncated text Too many nodes Split into multiple diagrams

NEVER Do

  1. NEVER create diagrams with >15 nodes — unreadable; split into focused views
  2. NEVER leave arrows unlabeled — every connection should explain the relationship
  3. NEVER create diagrams without a title — context-free diagrams are useless
  4. NEVER use diagrams as sole documentation — pair with prose explaining the "why"
  5. NEVER let diagrams go stale — update when architecture changes
  6. NEVER use Mermaid for data visualization — it's for architecture, not charts

Quick Reference

Entity with Methods Template

classDiagram
    class EntityName {
        \x3C\x3CEntity>>
        +type id
        +type field1
        +type field2
        +method1()
        +method2()
    }

Complete Relationship Set

classDiagram
    A -- B : association
    A *-- B : composition
    A o-- B : aggregation
    A \x3C|-- B : inheritance
    A \x3C.. B : dependency
    A \x3C|.. B : implementation
    A "1" --> "0..*" B : multiplicity

Flowchart Complete Shapes

flowchart LR
    A[Rectangle] B([Pill]) C[[Subroutine]]
    D[(Cylinder)] E((Circle)) F{Decision}
    G{{Hexagon}} H[/IO/] I[/Trapezoid\]
安全使用建议
This skill is a doc-style helper for Mermaid diagrams and appears coherent. Before using: (1) If you import Mermaid JS into web pages, prefer official release URLs and pinned versions (avoid implicit latest tags on CDNs). (2) When installing mermaid-cli via npm, confirm the package name/version is official. (3) Be cautious about rendering untrusted .mmd inputs in contexts that execute click handlers or embed external links; untrusted diagrams could include links or behaviors you don't want. Otherwise the skill's instructions and requirements are proportional to its purpose.
功能分析
Type: OpenClaw Skill Name: aha-mermaid-diagram Version: 1.1.0 The 'aha-mermaid-diagram' skill bundle is a comprehensive instructional resource designed to enable an AI agent to generate professional Mermaid.js diagrams. The bundle consists of a main SKILL.md file and several detailed reference files (references/*.md) covering various diagram types like C4, ERD, and Sequence diagrams. The instructions are strictly focused on syntax, styling, and best practices for diagramming. While the documentation mentions the 'securityLevel: loose' configuration for Mermaid (which allows HTML tags in diagrams), it is presented as a standard technical reference rather than an attempt to exploit the agent or the host environment. No evidence of data exfiltration, malicious execution, or harmful prompt injection was found.
能力标签
cryptocan-make-purchasesrequires-oauth-token
能力评估
Purpose & Capability
Name/description (render Mermaid diagrams) match the provided instructions and reference material: HTML+CDN usage, mermaid-cli for exports, and many example diagram types. No unrelated credentials, binaries, or config paths are requested.
Instruction Scope
SKILL.md and references only instruct how to write Mermaid syntax, load Mermaid from a CDN, and optionally use the mermaid-cli to export files; they don't instruct reading arbitrary system files, harvesting environment variables, or sending data to hidden endpoints. Example 'click' links reference public docs/live editors, which is expected for interactive diagrams.
Install Mechanism
This is instruction-only (no install spec). It recommends importing mermaid via jsdelivr CDN and installing @mermaid-js/mermaid-cli from npm — both are standard for this purpose. Loading remote JS from a CDN and installing npm packages are normal but carry the usual supply-chain/trust considerations (verify sources and versions).
Credentials
The skill declares no environment variables, credentials, or config paths. The examples do not attempt to access hidden env vars or secrets.
Persistence & Privilege
The skill does not request permanent presence (always:false) and does not instruct modifying other skills or system-wide agent settings.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install aha-mermaid-diagram
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /aha-mermaid-diagram 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.1.0
**Version 1.1.0 – Expanded diagram coverage & documentation overhaul** - Adds extensive reference docs for advanced features and specific diagram types (class, ER, flowchart, sequence, C4). - Skill documentation (SKILL.md) fully reorganized with practical examples, formatting tips, and syntax guidance for all major Mermaid diagram types. - Triggers, description, and tags now cover broader use-cases: not just class/flowchart, but also sequence, ERD, C4, Gantt, git graphs, and more. - Provides new guidance for rendering, theming, layout, and interactive features in Mermaid diagrams. - Example-rich and best practices for modeling, architecture, and visual documentation.
v1.0.0
Mermaid Diagram Skill 1.0.0 – Initial Release - Provides detailed integration guide for Mermaid.js diagram rendering in HTML pages. - Covers live preview, dark theme configuration, and robust error handling strategies. - Includes ready-to-use rendering and loading code patterns for maximum reliability. - Offers troubleshooting for common Mermaid errors and best practices for class diagram structure. - Supports UI toggle between diagram preview and code view.
元数据
Slug aha-mermaid-diagram
版本 1.1.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 2
常见问题

AHA Mermaid Diagram 是什么?

Render Mermaid.js class, flowchart, sequence, and ER diagrams in HTML with live preview, dark theme, and error handling for clean visualization. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 105 次。

如何安装 AHA Mermaid Diagram?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install aha-mermaid-diagram」即可一键安装,无需额外配置。

AHA Mermaid Diagram 是免费的吗?

是的,AHA Mermaid Diagram 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

AHA Mermaid Diagram 支持哪些平台?

AHA Mermaid Diagram 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 AHA Mermaid Diagram?

由 Aha.Gare(@zrxparley)开发并维护,当前版本 v1.1.0。

💬 留言讨论