Role-Based Access Control — Mermaid Class Diagram
Class diagram for an RBAC system with users, roles, permissions, and resource-level access policies.
What this diagram shows
This Mermaid class diagram is role-based access control with conditions. A user has many roles and can answer hasPermission(resource, action). A role has many permissions. A permission names a resource and an action and can carry conditions. A condition checks a field, an operator, and a value against a context. Separately, AccessControl holds policies. A policy has an effect, resources, actions, and conditions, and evaluates a request. The two stacks meet because AccessControl evaluates a user.
Use it when a boolean role check is not enough and you need to show attribute conditions (owner-only, same organization) next to the role. The template draws both a permission model and a policy model. That is useful in a design discussion and dangerous in an implementation if you build both and they disagree. Pick the permission path (user to role to permission) or the policy path (AccessControl to policy) before you generate tables.
Relationships are associations with multiplicities. User 1 to many Role, Role 1 to many Permission. The dashed arrow is AccessControl depending on User.
Mermaid syntax in this template
classDiagram multiplicities use quoted numbers on the association. Methods list parameter types and a return type. There is no interface in this template; every box is a concrete class.
User "1" --> "*" Role : hasQuoted multiplicities. The arrow points at Role. The label has is the association name.
+hasPermission(resource: string, action: string) booleanThe method that callers actually use. The body is not in the diagram. The class structure is the contract.
+evaluate(context: Context) booleanCondition.evaluate and Policy.evaluate share a verb and take different inputs. Rename one if that collision confuses the review.
AccessControl ..> User : evaluatesA dependency, not ownership. The control object does not store every user.
Variations and ways to customize it
Collapse policies into permissions
If you will not ship a second evaluator, delete Policy and AccessControl and hang conditions only on Permission. The user to role to permission chain is enough for classic RBAC.
User "1" --> "*" Role : has
Role "1" --> "*" Permission : grants
Permission "1" --> "*" Condition : "limited by"Add an organization scope
A global role list cannot express tenant admins. Put organizationId on the assignment, which means a join class between User and Role instead of a direct association.
class Assignment {
+string userId
+string roleId
+string organizationId
}
User "1" --> "*" Assignment
Assignment "*" --> "1" RoleShow allow and deny effects
Policy.effect is a string. Constrain it in the diagram with a note or an enumeration class so deny is a real value, not a comment.
class Effect {
<<enumeration>>
allow
deny
}
Policy --> EffectDiagram type
Class DiagramTags
Frequently asked questions
Is this RBAC diagram roles or policies?
Both. Users have roles, roles grant permissions, and permissions have conditions. AccessControl also holds policies with an effect. Use one of those chains in the implementation. The diagram is the comparison, not a single schema.
Where would an organization admin live?
Not in this drawing. Role has no scope. Add an assignment class with user, role, and organization id. A role named admin without that column is global.
What does Condition.check compare?
A field, an operator, and a value against a context object. That is how a permission becomes owner-only or same-tenant. Permission.evaluate calls those conditions. The context type is referenced and not drawn.
How is this different from the multi-tenant ER diagram?
The ER template stores a role string on MEMBERSHIP. This class diagram breaks role into permissions and conditions. Use the ER diagram for tables. Use this one when the check itself is the design question.
Related templates and guides
All Database Design templatesObserver Design Pattern
Class diagram showing the Observer pattern with EventEmitter, subscribers, and typed event handling.
SaaS Multi-Tenant Schema
ER diagram for a multi-tenant SaaS application with organizations, members, roles, and subscription billing.
SaaS Platform Schema (Modern Auth)
ER diagram for a modern SaaS platform with external auth provider integration, team workspaces, role-based access, and usage-based billing.
Mermaid class diagram syntax
Multiplicities and dependency arrows used for roles and policies.
Getting started with Mermaid
When to use a class diagram instead of an ER diagram for the same access model.