Skip to content
Lower pricing Individual licenses are now $49/year for Studio, $25 for Core — See pricing →

Entity Relationship Diagram

Last updated:

Mermaid Studio provides full language support for Entity Relationship (ER) diagrams inside IntelliJ IDEA and other JetBrains IDEs, for designing and maintaining your data models alongside the code that uses them. ER diagrams document database structures and the relationships between tables.

Syntax highlighting integrates directly with IntelliJ’s color scheme system, so diagram colors always match your editor theme.

ER diagram syntax highlighting in Armada Dark theme

The summary below shows the IDE support Mermaid Studio ships for ER diagrams, grouped by capability.

IDE feature supportSelect a feature for its description.
Editing
Code Intelligence
Validation
Refactoring
Navigation & Docs
Appearance
Visual Editing

A set of context-aware live templates scaffolds the entity blocks and relationship statements that ER diagrams use day-to-day. Type a short abbreviation, accept it from the completion popup, and tab through the template variables.

Individual abbreviations can be toggled under Settings > Tools > Mermaid Studio > Live Templates in the ER Diagram group. See Live Templates for the cross-cutting mechanics (triggering, contextual visibility, configuration).

The ent template scaffolds an entity with an attribute block; enta adds a display-name alias in brackets.

AbbreviationExpansion
entEntity with an attribute block
entaEntity with a display-name alias (NAME["Label"] { ... })

The rel template expands the cardinality as a picker variable, so you choose the shape on insert. The remaining templates each hard-code one cardinality for when you already know the relationship you want.

AbbreviationExpansion
relRelationship with a cardinality picker
rel1mOne-to-many, identifying (||--o{)
rel1mnOne-to-many, non-identifying (||..o{)
rel11One-to-one (||--||)
relmmMany-to-many (}o--o{)
rel01mZero-or-one to many (|o--o{)
rel1pmOne to one-or-more (||--|{)

The sub template scaffolds a subgraph block with its end line, so you only fill in the id and the entities it groups.

AbbreviationExpansion
subSubgraph block (subgraph ID ... end)

On Mermaid.js 11.17.0 or later, you can group entities into named blocks with subgraph id [Title] ... end, nest blocks inside each other, and set a direction inside a block to lay out its entities independently of the rest of the diagram. A subgraph id works as a relationship endpoint and as a class or style target, so you can connect a whole group or style it in one statement.

Mermaid Studio treats a subgraph like any other declaration. Press Enter after an unclosed subgraph header and the editor inserts the matching end. Rename refactoring on a subgraph id updates every relationship, class, and style that references it, and Find Usages lists them. Click a cluster in the preview to jump to the subgraph’s declaration in the editor. Inspections flag an entity that shares its identifier with a subgraph, which Mermaid.js does not render, and a subgraph nested inside itself, each with a rename quick-fix.

The structure view shows the diagram as Mermaid.js renders it: each entity appears once, under the subgraph that places it.

ER diagram with nested Sales and Catalog subgraphs in the editor and preview, and the Structure tool window listing each entity and relationship under the subgraph that contains it

Relationship cardinality:

  • || - Exactly one
  • o| - Zero or one
  • }| - One or more
  • o{ - Zero or more

Common patterns:

  • ||--o{ - One to many (optional)
  • ||--|{ - One to many (required)
  • }o--o{ - Many to many

Entity attributes:

erDiagram
USER {
int id PK
string email UK
int role_id FK
string name
}

Attribute modifiers: PK (primary key), FK (foreign key), UK (unique key)

Subgraphs (Mermaid.js 11.17.0+), grouping entities into a titled block that a relationship can target as a whole:

erDiagram
subgraph billing [Billing]
direction LR
INVOICE ||--|{ LINE_ITEM : contains
end
USER ||--o{ billing : owns

For the complete syntax reference, see the Mermaid.js ER Diagram documentation.