Unsaved
Ready
Loading Monaco Editor...
Preview
Styling
ER Diagram
All Database Design templates

SaaS Multi-Tenant Schema — Mermaid ER Diagram

ER diagram for a multi-tenant SaaS application with organizations, members, roles, and subscription billing.

What this diagram shows

This Mermaid ER diagram isolates tenant data on ORGANIZATION. An organization has many memberships, many projects, and exactly one subscription. A user has many memberships, so the same person can belong to several orgs with a role stored on MEMBERSHIP, not on USER. Projects contain tasks. A task is assigned to a user. The subscription generates invoices and stores the Stripe subscription id plus current_period_end.

Use it when you are deciding where tenant_id lives. Here the org id is on membership, project, and subscription. Tasks reach the org through the project. That is a deliberate gap: a task query must join PROJECT to know the tenant. If you want every table to carry org_id for row-level security, add the column; the diagram currently trusts the project foreign key.

The organization-to-subscription relationship is one-to-one. Plan is denormalized onto both ORGANIZATION and SUBSCRIPTION. Treat the subscription row as the billing source and the org plan as a cache, or you will update one and not the other.

Mermaid syntax in this template

Relationship lines name the verb. Identifying-style markers (||--|{) mean at least one child. Optional children use o{.

  • ORGANIZATION ||--|{ MEMBERSHIP : has

    An organization has one or more memberships. A brand-new org with zero users does not fit this marker; use o{ if the org can exist empty.

  • ORGANIZATION ||--|| SUBSCRIPTION : billed via

    Exactly one subscription. The label is quoted in the source because it is two words.

  • TASK }o--|| USER : assigned to

    Many tasks can point at one user. The template does not draw an unassigned state; assignee_id is a normal FK.

  • string role

    Role is a string on MEMBERSHIP (owner, admin, member). It is not a separate ROLE table. See the RBAC class diagram if you need permissions as entities.

Variations and ways to customize it

Put org_id on every tenant table

Row-level security is easier when TASK and INVOICE store org_id themselves. Add the column and a relationship to ORGANIZATION even if the project or subscription already implies it.

ORGANIZATION ||--o{ TASK : scopes
TASK {
    uuid id PK
    uuid org_id FK
    uuid project_id FK
}

Allow several subscriptions

One org to one subscription blocks add-ons. Change the marker to one-to-many and add a product column on SUBSCRIPTION so the base plan and an add-on are different rows.

ORGANIZATION ||--o{ SUBSCRIPTION : "billed via"

Invite before the membership exists

MEMBERSHIP is only people who have joined. Add INVITE with email, org_id, and role, and convert it to a membership when the user accepts. Do not overload joined_at for pending invites.

Diagram type

ER Diagram

Tags

SaaSmulti-tenantorganizationssubscriptionsbilling
Open in Editor

Frequently asked questions

Where is the tenant key in this ER diagram?

ORGANIZATION.id. MEMBERSHIP, PROJECT, and SUBSCRIPTION store org_id. TASK stores project_id and assignee_id only, so the tenant is reached through PROJECT.

Can one user be in multiple organizations?

Yes. USER ||--|{ MEMBERSHIP and the role sits on the membership row. Email stays unique on USER. Do not put role on USER or the second org overwrites the first.

Why do both the org and the subscription have a plan column?

The template denormalizes plan onto ORGANIZATION and SUBSCRIPTION. Billing truth should be the subscription, including stripe_sub_id and current_period_end. Drop the org column if you do not want a cache.

How do I model a free org with no invoice?

Invoices are one-or-more from the subscription (||--|{). A free org that never invoices should use o{ so zero invoices is valid. The one-to-one subscription can stay if every org still has a subscription row with plan=free.

Related templates and guides

All Database Design templates