AgentSkillsCN

mermaid-diagrams

在 Markdown 中生成 Mermaid 图表。触发点包括:图表、统计图、可视化、流程图, 序列图、架构图、ER 图、状态机、甘特图、思维导图, C4、类图、Git 图。 适用场景:当用户希望以可视化方式呈现代码、系统、流程、数据结构, 数据库架构、工作流或 API 流程时,可主动建议生成相关图表。 在讲解复杂系统时,更应积极主动地为用户提供直观的视觉化表达。

SKILL.md
--- frontmatter
name: mermaid-diagrams
description: |
  Generate Mermaid diagrams in markdown. Triggers on: diagrams, charts, visualizations, flowcharts,
  sequence diagrams, architecture diagrams, ER diagrams, state machines, Gantt charts, mindmaps,
  C4, class diagrams, git graphs.

  Use when: user asks for visual representations of code, systems, processes, data structures,
  database schemas, workflows, or API flows. Proactively suggest diagrams when explaining
  complex systems.

Mermaid Diagrams

Generate diagrams in markdown that render in GitHub, GitLab, VS Code, Obsidian, Notion.

Quick Start

markdown
```mermaid
flowchart LR
    A[Start] --> B{Decision}
    B -->|Yes| C[Action]
    B -->|No| D[End]
```

Quick Decision Tree

code
What to visualize?
├─ Process, algorithm, decision flow    → flowchart
├─ API calls, service interactions      → sequenceDiagram
├─ Database tables, relationships       → erDiagram
├─ OOP, type hierarchy, domain model    → classDiagram
├─ State machine, lifecycle             → stateDiagram-v2
├─ System architecture, services        → flowchart + subgraphs (or C4Context)
├─ Project timeline, sprints            → gantt
├─ User experience, pain points         → journey
├─ Git branches                         → gitGraph
├─ Data distribution                    → pie
└─ Priority matrix                      → quadrantChart

Diagram Types

TypeDeclarationBest For
Flowchartflowchart LR/TBProcesses, decisions, data flow
SequencesequenceDiagramAPI flows, service calls
ERerDiagramDatabase schemas
ClassclassDiagramTypes, domain models
StatestateDiagram-v2State machines
GanttganttProject timelines
JourneyjourneyUser experience
C4C4ContextSystem architecture
GitgitGraphBranch visualization

Common Patterns

System Architecture

mermaid
flowchart LR
    subgraph Client
        Browser & Mobile
    end
    subgraph Services
        API --> Auth & Core
    end
    subgraph Data
        DB[(PostgreSQL)]
    end
    Client --> API
    Core --> DB

API Request Flow

mermaid
sequenceDiagram
    autonumber
    Client->>+API: POST /orders
    API->>Auth: Validate
    Auth-->>API: OK
    API->>+DB: Insert
    DB-->>-API: ID
    API-->>-Client: 201 Created

Database Schema

mermaid
erDiagram
    USER ||--o{ ORDER : places
    ORDER ||--|{ LINE_ITEM : contains
    USER { uuid id PK; string email UK }
    ORDER { uuid id PK; uuid user_id FK }

State Machine

mermaid
stateDiagram-v2
    [*] --> Draft
    Draft --> Submitted : submit()
    Submitted --> Approved : approve()
    Submitted --> Rejected : reject()
    Approved --> [*]

Syntax Quick Reference

Flowchart Nodes

code
[Rectangle]  (Rounded)  {Diamond}  [(Database)]  [[Subroutine]]
((Circle))   >Asymmetric]   {{Hexagon}}

Flowchart Edges

code
A --> B       # Arrow
A --- B       # Line
A -.-> B      # Dotted arrow
A ==> B       # Thick arrow
A -->|text| B # Labeled

Sequence Arrows

code
->>   # Solid arrow (request)
-->>  # Dotted arrow (response)
-x    # X end (async)
-)    # Open arrow

ER Cardinality

code
||--||   # One to one
||--o{   # One to many
}o--o{   # Many to many

Best Practices

  1. Choose the right type — Use decision tree above
  2. Keep focused — One concept per diagram
  3. Use meaningful labels — Not just A, B, C
  4. Direction mattersLR for flows, TB for hierarchies
  5. Group with subgraphs — Organize related nodes

Reference Documentation

FilePurpose
references/FLOWCHARTS.mdNodes, edges, subgraphs, styling
references/SEQUENCE.mdParticipants, messages, activation
references/CLASS-ER.mdClasses, ER diagrams, relationships
references/STATE-JOURNEY.mdStates, user journeys
references/DATA-CHARTS.mdGantt, Pie, Timeline, Quadrant
references/ARCHITECTURE.mdC4, Block, Kanban
references/CHEATSHEET.mdAll syntax quick reference

Resources