agentleFS
hugobatistahugobatista/agent-skills/skills/docs/mermaid-syntax/SKILL.md

mermaid-syntax

Skill1 starsChanged 54 days agoMITView on GitHub

Correct Mermaid diagram syntax reference covering all types (flowchart, sequence, class, ERD, state, C4, git, gantt, pie). Emphasizes parser-compatible patterns to avoid rendering errors in GitHub, Obsidian, VS Code, and other tools. Use when creating, visualizing, or documenting software architecture through diagrams.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Subgraphs: use subgraph "Title" — NOT subgraph ID["Title"] (named subgraphs require mermaid ≥10.3)

    line 18
  2. Very specific:

    Diamond nodes: always give an explicit ID — DECISION{"text"} — NOT anonymous {"text"} after -->

    line 19
  3. Distinctive:

    Every diagram starts with a type declaration on the first line:

    line 26
  4. Very specific:

    Use %% for comments. Indentation improves readability but isn't required.

    line 39
  5. Distinctive:

    Always use quoted titles:

    line 73
  6. Very specific:

    Unclosed brackets: every [, (, { needs a matching closing bracket

    line 322

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Mermaid Syntax Reference

Syntax Compatibility Rules

These 5 rules prevent parser errors across common rendering tools (GitHub, Obsidian, VS Code extensions):

  1. Subgraphs: use subgraph "Title" — NOT subgraph ID["Title"] (named subgraphs require mermaid ≥10.3)
  2. Diamond nodes: always give an explicit ID — DECISION{"text"} — NOT anonymous {"text"} after -->
  3. Line breaks: \n works inside ["text"]; avoid \n inside {"text"} — keep diamond labels single-line
  4. Sequence notes: plain text only — no <br/>, <br>, or other HTML tags
  5. Special characters: replace & with and to avoid HTML entity issues

Core Syntax

Every diagram starts with a type declaration on the first line:

flowchart LR
sequenceDiagram
classDiagram
erDiagram
stateDiagram-v2
gitGraph
gantt
pie

Use %% for comments. Indentation improves readability but isn't required.

Flowchart

Node shapes

SyntaxShape
A[text]Rectangle
A(text)Rounded rectangle
A([text])Stadium / pill
A[[text]]Subroutine
A[(text)]Database / cylinder
A((text))Circle
A{text}Rhombus / decision
A{{text}}Hexagon
A>text]Asymmetric / flag
A[/text/]Parallelogram
A[\text\]Parallelogram (reverse)
A[/text\]Trapezoid

Edges

SyntaxType
A --> BArrow
A --- BLink (no arrow)
A -.-> BDotted arrow
A ==> BThick arrow
A -->|label| BLabeled arrow (preferred)
A -- label --> BLabeled arrow (alt)

Subgraphs

Always use quoted titles:

flowchart LR
    subgraph "Group Name"
        A --> B
    end

Example

flowchart TD
    Start([Start]) --> Auth{Authenticated?}
    Auth -->|Yes| Dashboard[Show dashboard]
    Auth -->|No| Login[Show login form]
    Login --> Auth

Sequence Diagram

Participants

sequenceDiagram
    participant A
    participant B as "Display Name"
    actor User

Messages

SyntaxType
->>Synchronous call
-->>Synchronous response
-)Asynchronous call
--)Asynchronous response
-xDelete / loss

Structure blocks

sequenceDiagram
    participant A
    participant B

    alt Condition
        A->>B: branch
    else Other
        A->>B: other branch
    end

    opt Optional
        A->>B: optional
    end

    loop Every N seconds
        A->>B: repeat
    end

    par Parallel
        A->>B: parallel 1
    and
        A->>B: parallel 2
    end

Notes

Plain text only — no HTML tags:

sequenceDiagram
    participant App
    Note over App: Plain text description
    Note right of App: Plain text
    Note left of App: Plain text

Example

sequenceDiagram
    participant App
    participant DB

    App->>DB: Query
    DB-->>App: Result

    alt Found
        App->>App: Process
    else Not found
        App->>App: Handle error
    end

    Note over App: Plain text only

Class Diagram

Class declaration

classDiagram
    class ClassName {
        +publicField
        -privateField
        #protectedField
        +method() returnType
        -method() void
    }

Relationships

SyntaxRelationship
<|--Inheritance
*--Composition
o--Aggregation
-->Association
..|>Realization
..>Dependency
--Link

Multiplicity: "1" --> "*"

Example

classDiagram
    Animal <|-- Duck
    Animal <|-- Fish
    Animal <|-- Zebra
    Animal : +int age
    Animal : +isMammal() bool
    Duck : +beakColor string
    Duck : +swim()

Entity-Relationship Diagram

Cardinality

SymbolMeaning
|oZero or one
||Exactly one
}oZero or more
}|One or more

Example

erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ LINE_ITEM : contains
    PRODUCT ||--o{ LINE_ITEM : includes
    CUSTOMER {
        int id PK
        string name
    }
    ORDER {
        int id PK
        decimal total
    }

State Diagram

stateDiagram-v2
    [*] --> Idle
    Idle --> Processing : start
    Processing --> Completed : finish
    Processing --> Failed : error
    Failed --> Idle : retry
    Completed --> [*]

Composite states:

stateDiagram-v2
    state Active {
        [*] --> Working
        Working --> Waiting
        Waiting --> Working
    }

C4 Diagram

C4Context
    Person(user, "Customer", "Bank customer")
    System(bankingSystem, "Banking System", "Handles accounts")
    System_Ext(mail, "Email System")
    Rel(user, bankingSystem, "Uses")
    Rel(bankingSystem, mail, "Sends emails")

Other levels: C4Container, C4Component, C4Deployment.

Boundaries: System_Boundary(name, "Label") { ... }, Container_Boundary, etc.

Git Graph

gitGraph
    commit
    branch feature
    checkout feature
    commit
    checkout main
    merge feature

Gantt Chart

gantt
    title Project Timeline
    dateFormat YYYY-MM-DD
    section Design
    Research    :2024-01-01, 30d
    Prototype   :2024-01-15, 20d
    section Dev
    Backend     :2024-02-01, 45d
    Frontend    :2024-02-15, 30d

Pie Chart

pie title Distribution
    "Category A" : 45
    "Category B" : 30
    "Category C" : 25

Common Pitfalls

  • Subgraph syntax: subgraph Name["Label"] fails in many renderers — use subgraph "Label" instead
  • Anonymous diamond nodes: -->{"text"} causes parse errors — use --> DECISION{"text"} with an explicit ID
  • HTML in sequence notes: <br/> renders literally — use plain text
  • \n in diamonds: {"line1\nline2"} is not supported — keep text single-line
  • & character: triggers HTML entity issues — write and instead
  • Unclosed brackets: every [, (, { needs a matching closing bracket
  • Unknown words: misspellings break diagrams; validate at https://mermaid.live

Best Practices

  1. Start simple — build up complexity incrementally
  2. Use action-oriented labels — "Process payment" not "Payment"
  3. One concept per diagram — split complex systems into focused views
  4. Validate syntax — test in mermaid.live before committing

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.