Skill Tracer
Skills › Scientific Agent Skills › markdown-mermaid-writing › er.md

er.md

229 lines · skills/markdown-mermaid-writing/references/diagrams/er.md at 5f2bc03

Open on GitHub
1<!-- Source: https://github.com/SuperiorByteWorks-LLC/agent-project | License: Apache-2.0 | Author: Clayton Young / Superior Byte Works, LLC (Boreal Bytes) -->
2
3# Entity Relationship (ER) Diagram
4
5> **Back to [Style Guide](../mermaid_style_guide.md)** — Read the style guide first for emoji, color, and accessibility rules.
6
7**Syntax keyword:** `erDiagram`
8**Best for:** Database schemas, data models, entity relationships, API data structures
9**When NOT to use:** Class hierarchies with methods (use [Class](class.md)), process flows (use [Flowchart](flowchart.md))
11---

<!-- Source: https://github.com/SuperiorByteWorks-LLC/agent-project | License: Apache-2.0 | Author: Clayton Young / Superior Byte Works, LLC (Boreal Bytes) -->

Entity Relationship (ER) Diagram

Back to Style Guide — Read the style guide first for emoji, color, and accessibility rules.

Syntax keyword: erDiagram Best for: Database schemas, data models, entity relationships, API data structures When NOT to use: Class hierarchies with methods (use Class), process flows (use Flowchart)


Raw lines 1 to 12
13## Exemplar Diagram
15```mermaid
16erDiagram
17 accTitle: Project Management Data Model
18 accDescr: Entity relationships for a project management system showing teams, projects, tasks, members, and comments with cardinality
20 TEAM ||..o{ PROJECT : "owns"
21 PROJECT ||..o{ TASK : "contains"
22 TASK ||..o{ COMMENT : "has"
23 TEAM ||..o{ MEMBER : "includes"
24 MEMBER ||..o{ TASK : "assigned to"
25 MEMBER ||..o{ COMMENT : "writes"
27 TEAM {
28 uuid id PK "🔑 Primary key"
29 string name "👥 Team name"
30 string department "🏢 Department"
31 }
33 PROJECT {
34 uuid id PK "🔑 Primary key"
35 uuid team_id FK "🔗 Team reference"
36 string title "📋 Project title"
37 string status "📊 Current status"
38 date deadline "⏰ Due date"
39 }
41 TASK {
42 uuid id PK "🔑 Primary key"
43 uuid project_id FK "🔗 Project reference"
44 uuid assignee_id FK "👤 Assigned member"
45 string title "📝 Task title"
46 string priority "⚠️ Priority level"
47 string status "📊 Current status"
48 }
50 MEMBER {
51 uuid id PK "🔑 Primary key"
52 uuid team_id FK "🔗 Team reference"
53 string name "👤 Full name"
54 string email "📧 Email address"
55 string role "🏷️ Job role"
56 }
58 COMMENT {
59 uuid id PK "🔑 Primary key"
60 uuid task_id FK "🔗 Task reference"
61 uuid author_id FK "👤 Author reference"
62 text body "📝 Comment text"
63 timestamp created_at "⏰ Created time"
64 }
65```
67---

Exemplar Diagram

erDiagram
    accTitle: Project Management Data Model
    accDescr: Entity relationships for a project management system showing teams, projects, tasks, members, and comments with cardinality

    TEAM ||..o{ PROJECT : "owns"
    PROJECT ||..o{ TASK : "contains"
    TASK ||..o{ COMMENT : "has"
    TEAM ||..o{ MEMBER : "includes"
    MEMBER ||..o{ TASK : "assigned to"
    MEMBER ||..o{ COMMENT : "writes"

    TEAM {
        uuid id PK "🔑 Primary key"
        string name "👥 Team name"
        string department "🏢 Department"
    }

    PROJECT {
        uuid id PK "🔑 Primary key"
        uuid team_id FK "🔗 Team reference"
        string title "📋 Project title"
        string status "📊 Current status"
        date deadline "⏰ Due date"
    }

    TASK {
        uuid id PK "🔑 Primary key"
        uuid project_id FK "🔗 Project reference"
        uuid assignee_id FK "👤 Assigned member"
        string title "📝 Task title"
        string priority "⚠️ Priority level"
        string status "📊 Current status"
    }

    MEMBER {
        uuid id PK "🔑 Primary key"
        uuid team_id FK "🔗 Team reference"
        string name "👤 Full name"
        string email "📧 Email address"
        string role "🏷️ Job role"
    }

    COMMENT {
        uuid id PK "🔑 Primary key"
        uuid task_id FK "🔗 Task reference"
        uuid author_id FK "👤 Author reference"
        text body "📝 Comment text"
        timestamp created_at "⏰ Created time"
    }

Raw lines 13 to 68
69## Tips
71- Include data types, `PK`/`FK` annotations, and **comment strings** with emoji for context
72- Use clear verb-phrase relationship labels: `"owns"`, `"contains"`, `"assigned to"`
73- Cardinality notation:
74 - `||--o{` exactly one to zero-or-more
75 - `||--|{` exactly one to one-or-more
76 - `||--||` exactly one at each end
77 - `}o--o{` zero-or-more at both ends
78 - Read the pair of endpoint markers together: `o|`/`|o` is zero-or-one; `||` is exactly one.
79 - Solid `--` means identifying, dashed `..` non-identifying. Choose from the actual key constraint; Mermaid does not enforce a database schema.
80- Limit to **5–7 entities** per diagram — split large schemas by domain
81- Entity names: `UPPER_CASE` (SQL convention)
83---

Tips

  • Include data types, PK/FK annotations, and comment strings with emoji for context
  • Use clear verb-phrase relationship labels: "owns", "contains", "assigned to"
  • Cardinality notation:
  • ||--o{ exactly one to zero-or-more
  • ||--|{ exactly one to one-or-more
  • ||--|| exactly one at each end
  • }o--o{ zero-or-more at both ends
  • Read the pair of endpoint markers together: o|/|o is zero-or-one; || is exactly one.
  • Solid -- means identifying, dashed .. non-identifying. Choose from the actual key constraint; Mermaid does not enforce a database schema.
  • Limit to 5–7 entities per diagram — split large schemas by domain
  • Entity names: UPPER_CASE (SQL convention)

Raw lines 69 to 84
85## Template
87```mermaid
88erDiagram
89 accTitle: Your Title Here
90 accDescr: Describe the data model and key relationships between entities
92 ENTITY_A ||..o{ ENTITY_B : "has many"
93 ENTITY_B ||..|| ENTITY_C : "belongs to"
95 ENTITY_A {
96 uuid id PK "🔑 Primary key"
97 string name "📝 Display name"
98 }
100 ENTITY_B {
101 uuid id PK "🔑 Primary key"
102 uuid entity_a_id FK "🔗 Reference"
103 string value "📊 Value field"
104 }
105```
107---

Template

erDiagram
    accTitle: Your Title Here
    accDescr: Describe the data model and key relationships between entities

    ENTITY_A ||..o{ ENTITY_B : "has many"
    ENTITY_B ||..|| ENTITY_C : "belongs to"

    ENTITY_A {
        uuid id PK "🔑 Primary key"
        string name "📝 Display name"
    }

    ENTITY_B {
        uuid id PK "🔑 Primary key"
        uuid entity_a_id FK "🔗 Reference"
        string value "📊 Value field"
    }

Raw lines 85 to 108
109## Complex Example
111A multi-tenant SaaS platform schema with 10 entities spanning three domains — identity & access, billing & subscriptions, and audit & security. Relationships show the full cardinality picture from tenant isolation through user permissions to invoice generation.
113```mermaid
114erDiagram
115 accTitle: SaaS Multi-Tenant Platform Schema
116 accDescr: Ten-entity data model for a multi-tenant SaaS platform covering identity management, role-based access, subscription billing, and audit logging with full cardinality relationships
118 TENANT ||..o{ ORGANIZATION : "contains"
119 ORGANIZATION ||..o{ USER : "employs"
120 ORGANIZATION ||..|| SUBSCRIPTION : "holds"
121 USER }o..o{ ROLE : "assigned"
122 ROLE ||..o{ PERMISSION : "grants"
123 SUBSCRIPTION }o..|| PLAN : "subscribes to"
124 SUBSCRIPTION ||..o{ INVOICE : "generates"
125 USER ||..o{ AUDIT_LOG : "produces"
126 TENANT ||..o{ AUDIT_LOG : "scoped to"
127 USER ||..o{ API_KEY : "owns"
129 TENANT {
130 uuid id PK "🔑 Primary key"
131 string name "🏢 Tenant name"
132 string subdomain "🌐 Unique subdomain"
133 string tier "🏷️ Service tier"
134 boolean active "✅ Active status"
135 timestamp created_at "⏰ Created time"
136 }
138 ORGANIZATION {
139 uuid id PK "🔑 Primary key"
140 uuid tenant_id FK "🔗 Tenant reference"
141 string name "👥 Org name"
142 string billing_email "📧 Billing contact"
143 int seat_count "📊 Licensed seats"
144 }
146 USER {
147 uuid id PK "🔑 Primary key"
148 uuid org_id FK "🔗 Organization reference"
149 string email "📧 Login email"
150 string display_name "👤 Display name"
151 string status "📊 Account status"
152 timestamp last_login "⏰ Last active"
153 }
155 ROLE {
156 uuid id PK "🔑 Primary key"
157 uuid tenant_id FK "🔗 Tenant scope"
158 string name "🏷️ Role name"
159 string description "📝 Role purpose"
160 boolean system_role "🔒 Built-in flag"
161 }
163 PERMISSION {
164 uuid id PK "🔑 Primary key"
165 uuid role_id FK "🔗 Role reference"
166 string resource "🎯 Target resource"
167 string action "⚙️ Allowed action"
168 string scope "🔒 Permission scope"
169 }
171 PLAN {
172 uuid id PK "🔑 Primary key"
173 string name "🏷️ Plan name"
174 int price_cents "💰 Monthly price"
175 int seat_limit "👥 Max seats"
176 jsonb features "📋 Feature flags"
177 boolean active "✅ Available flag"
178 }
180 SUBSCRIPTION {
181 uuid id PK "🔑 Primary key"
182 uuid org_id FK "🔗 Organization reference"
183 uuid plan_id FK "🔗 Plan reference"
184 string status "📊 Sub status"
185 date current_period_start "📅 Period start"
186 date current_period_end "📅 Period end"
187 }
189 INVOICE {
190 uuid id PK "🔑 Primary key"
191 uuid subscription_id FK "🔗 Subscription reference"
192 int amount_cents "💰 Total amount"
193 string currency "💱 Currency code"
194 string status "📊 Payment status"
195 timestamp issued_at "⏰ Issue date"
196 }
198 AUDIT_LOG {
199 uuid id PK "🔑 Primary key"
200 uuid tenant_id FK "🔗 Tenant scope"
201 uuid user_id FK "👤 Acting user"
202 string action "⚙️ Action performed"
203 string resource_type "🎯 Target type"
204 uuid resource_id "🔗 Target ID"
205 jsonb metadata "📋 Event details"
206 timestamp created_at "⏰ Event time"
207 }
209 API_KEY {
210 uuid id PK "🔑 Primary key"
211 uuid user_id FK "👤 Owner"
212 string prefix "🏷️ Key prefix"
213 string hash "🔐 Hashed secret"
214 string name "📝 Key name"
215 timestamp expires_at "⏰ Expiration"
216 boolean revoked "❌ Revoked flag"
217 }
218```

Complex Example

A multi-tenant SaaS platform schema with 10 entities spanning three domains — identity & access, billing & subscriptions, and audit & security. Relationships show the full cardinality picture from tenant isolation through user permissions to invoice generation.

erDiagram
    accTitle: SaaS Multi-Tenant Platform Schema
    accDescr: Ten-entity data model for a multi-tenant SaaS platform covering identity management, role-based access, subscription billing, and audit logging with full cardinality relationships

    TENANT ||..o{ ORGANIZATION : "contains"
    ORGANIZATION ||..o{ USER : "employs"
    ORGANIZATION ||..|| SUBSCRIPTION : "holds"
    USER }o..o{ ROLE : "assigned"
    ROLE ||..o{ PERMISSION : "grants"
    SUBSCRIPTION }o..|| PLAN : "subscribes to"
    SUBSCRIPTION ||..o{ INVOICE : "generates"
    USER ||..o{ AUDIT_LOG : "produces"
    TENANT ||..o{ AUDIT_LOG : "scoped to"
    USER ||..o{ API_KEY : "owns"

    TENANT {
        uuid id PK "🔑 Primary key"
        string name "🏢 Tenant name"
        string subdomain "🌐 Unique subdomain"
        string tier "🏷️ Service tier"
        boolean active "✅ Active status"
        timestamp created_at "⏰ Created time"
    }

    ORGANIZATION {
        uuid id PK "🔑 Primary key"
        uuid tenant_id FK "🔗 Tenant reference"
        string name "👥 Org name"
        string billing_email "📧 Billing contact"
        int seat_count "📊 Licensed seats"
    }

    USER {
        uuid id PK "🔑 Primary key"
        uuid org_id FK "🔗 Organization reference"
        string email "📧 Login email"
        string display_name "👤 Display name"
        string status "📊 Account status"
        timestamp last_login "⏰ Last active"
    }

    ROLE {
        uuid id PK "🔑 Primary key"
        uuid tenant_id FK "🔗 Tenant scope"
        string name "🏷️ Role name"
        string description "📝 Role purpose"
        boolean system_role "🔒 Built-in flag"
    }

    PERMISSION {
        uuid id PK "🔑 Primary key"
        uuid role_id FK "🔗 Role reference"
        string resource "🎯 Target resource"
        string action "⚙️ Allowed action"
        string scope "🔒 Permission scope"
    }

    PLAN {
        uuid id PK "🔑 Primary key"
        string name "🏷️ Plan name"
        int price_cents "💰 Monthly price"
        int seat_limit "👥 Max seats"
        jsonb features "📋 Feature flags"
        boolean active "✅ Available flag"
    }

    SUBSCRIPTION {
        uuid id PK "🔑 Primary key"
        uuid org_id FK "🔗 Organization reference"
        uuid plan_id FK "🔗 Plan reference"
        string status "📊 Sub status"
        date current_period_start "📅 Period start"
        date current_period_end "📅 Period end"
    }

    INVOICE {
        uuid id PK "🔑 Primary key"
        uuid subscription_id FK "🔗 Subscription reference"
        int amount_cents "💰 Total amount"
        string currency "💱 Currency code"
        string status "📊 Payment status"
        timestamp issued_at "⏰ Issue date"
    }

    AUDIT_LOG {
        uuid id PK "🔑 Primary key"
        uuid tenant_id FK "🔗 Tenant scope"
        uuid user_id FK "👤 Acting user"
        string action "⚙️ Action performed"
        string resource_type "🎯 Target type"
        uuid resource_id "🔗 Target ID"
        jsonb metadata "📋 Event details"
        timestamp created_at "⏰ Event time"
    }

    API_KEY {
        uuid id PK "🔑 Primary key"
        uuid user_id FK "👤 Owner"
        string prefix "🏷️ Key prefix"
        string hash "🔐 Hashed secret"
        string name "📝 Key name"
        timestamp expires_at "⏰ Expiration"
        boolean revoked "❌ Revoked flag"
    }
Raw lines 109 to 219
220### Why this works
222- **10 entities organized by domain** — identity (Tenant, Organization, User, Role, Permission), billing (Plan, Subscription, Invoice), and security (Audit Log, API Key). The relationship lines naturally cluster related entities together.
223- **Full cardinality tells the business rules** — `||..||` (one-to-one, non-identifying) for Organization-Subscription means one subscription per org. `}o..o{` (many-to-many) for User-Role means flexible RBAC. Each relationship symbol encodes a constraint.
224- **Every field has type, annotation, and purpose** — PK/FK as documented key roles, emoji comments for human scanning. Confirm uniqueness, nullability, join tables, and identifying relationships before implementing a migration.

Why this works

  • 10 entities organized by domain — identity (Tenant, Organization, User, Role, Permission), billing (Plan, Subscription, Invoice), and security (Audit Log, API Key). The relationship lines naturally cluster related entities together.
  • Full cardinality tells the business rules — ||..|| (one-to-one, non-identifying) for Organization-Subscription means one subscription per org. }o..o{ (many-to-many) for User-Role means flexible RBAC. Each relationship symbol encodes a constraint.
  • Every field has type, annotation, and purpose — PK/FK as documented key roles, emoji comments for human scanning. Confirm uniqueness, nullability, join tables, and identifying relationships before implementing a migration.
Raw lines 220 to 226
227## Verified reference
229Syntax examples reviewed against [official Mermaid documentation](https://mermaid.js.org/syntax/entityRelationshipDiagram.html) and rendered with Mermaid 12.0.0 (2026-10-01). Check the destination version; appearance and accessibility are not guaranteed by a successful parse.

Verified reference

Syntax examples reviewed against official Mermaid documentation and rendered with Mermaid 12.0.0 (2026-10-01). Check the destination version; appearance and accessibility are not guaranteed by a successful parse.

Raw lines 227 to 229