Model entities and relationships with entity-relationship diagrams.
ERD (entity-relationship diagram) views focus on data: entities, their fields, and how they relate. They complement the Objects diagram when the question is about the data model rather than runtime structure.
What an ERD shows
- Entities and their fields (attributes).
- Relationships between entities with crow’s-foot cardinality.
- Primary, foreign, and unique keys where you define them on attributes.
- Optional column-level anchors on relationships (iomodel extension — see below).
ERDs are attached to objects as artifacts. The diagram source is Mermaid erDiagram text — the same grammar used by Mermaid Entity Relationship Diagrams, which is documented as compatible with PlantUML ER notation, with Mermaid’s own extension for relationship labels after :.
Diagram source format
Every ERD artifact starts with the erDiagram header, then entity blocks and relationship lines. A minimal example:
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : containsCompatible with Mermaid and PlantUML
You can paste or author diagrams that follow the public Mermaid ER grammar. Studio parses them with the same JISON-based ER parser Mermaid uses (mermaid-ast), so standard constructs work as in the Mermaid docs:
| Construct | Syntax (summary) | Notes |
|---|---|---|
| Entities | ENTITY_NAME or ENTITY["Display alias"] | Singular names are conventional. Unicode and quoted names with spaces are allowed. |
| Attributes | Block after the entity: ENTITY { type name PK FK UK "comment" } | type and name follow Mermaid rules; * on a name can mark a primary key instead of PK. |
| Relationships | FROM cardinality TO : label | One statement per edge; label is mandatory when any part of the relationship is present. |
| Cardinality | Crow’s foot between entities, e.g. ||, o{, }|, o| | Same markers and aliases as Mermaid (zero or more, 1+, only one, …). |
| Identifying vs non-identifying | -- (solid) vs .. (dashed) between cardinality markers | Identifying: child cannot exist without parent; non-identifying: optional association. |
| Direction | direction TB / LR / BT / RL | Accepted in source; layout in the visual canvas uses ELK separately. |
| Comments | %% line comment | Line comments in the source editor. |
| Styling | classDef, class, style | Mermaid styling directives parse in source; the visual editor does not expose style editing yet. |
Relationship lines read like Mermaid’s template:
<first-entity> <card-left>--<card-right> <second-entity> : <relationship-label>Example with attributes and keys:
erDiagram
CUSTOMER {
uuid id PK
string name
string email UK
}
ORDER {
uuid id PK
uuid customer_id FK
}
CUSTOMER ||--o{ ORDER : placesCardinality on the left of -- applies to the first entity; cardinality on the right applies to the second. The label describes the relationship from the first entity’s perspective (as in Mermaid).
iomodel extensions
Standard Mermaid ER diagrams relate entities only; they do not say which columns implement a foreign key. iomodel extends the relationship label with an optional @ref clause so the visual editor can attach edges to specific attributes and keep them in sync when you rename entities or columns.
Three label shapes are supported (everything after :):
- Display label only — plain text, same as Mermaid. No column anchors.
@refonly — machine-readable column mapping (case of@refis ignored).- Display label and
@ref— human text, then|(spaces required on both sides of|), then@ref.
After @ref, use Entity.attribute -> Entity.attribute. The parser matches entity names on the left and right of -> to the relationship’s from and to entities and sets fromAttribute / toAttribute. There is no guess from column names such as customer_id; anchors come only from an explicit @ref in the label.
In the visual editor, connecting handles on attribute rows creates or updates the @ref segment. Renaming an entity or attribute rewrites @ref text in the source so it stays consistent.
Tooltips and `@ref`
Edge tooltips show the display part of the label only. A label that is only @ref does not show a tooltip. The @ref block is for the model and editor, not for end-user-facing text on the diagram.
Source and visual editing
The ERD artifact editor matches other diagram artifacts:
- Source — edit raw
erDiagramtext. - Split — source and canvas side by side; both stay in sync.
- Visual — drag entities, edit attributes, and draw relationships on a React Flow canvas backed by the same document.
Parsing and serialization round-trip through the shared @iomodel/erd package. Editing in the visual view re-emits source in a canonical layout (consistent indentation, entities before relations). Inline %% comments and hand-tuned formatting inside blocks may not survive visual edits — prefer source-only mode when you need to keep exact formatting.
Import existing Mermaid or PlantUML-style ER snippets by pasting into source mode. Add @ref on relationships where you need precise FK column wiring in the visual editor.
When to use a data view
- Designing or documenting a persistence model.
- Communicating entity relationships to engineers.
- Reviewing keys, cardinality, and which columns implement each FK.
Attaching an ERD
Add the artifact
Attach an ERD artifact to the relevant object (for example a data store or service).
Define entities
Describe entities, fields, and relationships in erDiagram source, or build them in the visual editor.
Embed in specs
Reference the artifact from a specification page so docs and data design stay together.
Keep ERDs scoped to a bounded area (one service or domain). A single diagram of every table is rarely readable.
Last updated on