Appearance
Organization Data Models
Multi-tenant organization system models managed by Better Auth's organization plugin.
Overview
Organizations provide multi-tenant workspace functionality, allowing users to belong to multiple organizations with different roles. All organization data is managed through Better Auth's organization plugin integrated with AdonisJS and PostgreSQL.
Models
Organization
Multi-tenant workspaces that group users and events. Events are currently organization-owned; additional organization-owned resource types remain planned.
Fields:
id- UUID primary keyowner_id- Stored user reference maintained by Jubiloop's organization hooks. It is separate from Better Auth's membership role used for organization authorization.name- Organization display nameslug- URL-safe identifier (unique)logo- Optional logo URLmetadata- Optional serialized custom data stored in a text columncreated_at- Creation timestamp
Indexes:
- Primary key on
id - Index on
owner_idfor owner lookups - Unique index on
slugfor URL routing
Member
Organization membership records with role-based access.
Fields:
id- Membership record IDuser_id- Reference to Userorganization_id- Reference to Organizationrole- Role within organization (owner,admin,member)created_at- When user joined organization
Roles:
owner- Better Auth membership role with full organization-management permissionsadmin- Administrative permissionsmember- Standard member permissions
Indexes:
- Primary key on
id - Unique constraint on
(user_id, organization_id)for membership lookups - Index on
organization_idfor listing members
Team
Sub-groups within organizations for grouping members.
Fields:
id- Team IDorganization_id- Parent organizationname- Team namecreated_at- Creation timestampupdated_at- Last modification timestamp
Indexes:
- Primary key on
id - Index on
organization_idfor listing teams - Composite unique index on
(organization_id, name)
TeamMember
Team membership is a separate many-to-many link. A user may belong to more than one team without changing their organization membership record.
Indexes and constraints:
- Primary key on
id - Unique constraint on
(team_id, user_id) - Indexes on
team_idanduser_id
Invitation
Pending organization invitations with expiry.
Fields:
id- Invitation IDorganization_id- Target organizationteam_id- Optional team ID for team-specific invitationsemail- Invitee email addressrole- Role to assign upon acceptanceinviter_id- User ID of the inviterstatus- Better Auth invitation statusexpires_at- When invitation expirescreated_at- When the invitation record was created
Indexes:
- Primary key on
id - Index on
organization_idfor listing invitations - Index on
emailfor user invitation lookups - Index on
statusfor filtering by status - Index on
expires_atfor expiring invitations
Relationships
Key Relationships:
- User → Organization (stored
owner_idreference, one-to-many) - User → Member (user can be member of many organizations)
- Organization → Member (organization has many members)
- Organization → Team (organization contains teams)
- User → TeamMember → Team (users can join multiple teams)
- Organization → Invitation (organization can send invitations)
- Organization → Event (organization owns current event records)
Persistence Constraints
- Organization slugs are unique.
(user_id, organization_id)is unique, so a user has at most one membership per organization.(organization_id, name)is unique for teams.(team_id, user_id)is unique for team memberships.- Foreign keys cascade membership, team, and invitation cleanup where defined by the migrations.
Runtime limits, owner protection, and role behavior belong to the organization backend guide.
See Also
- Authentication Data Models — User, Session, Account schemas
- Auth API Reference — Organization management endpoints
- Organizations Feature Backend — Implementation patterns
For actual migration files, see apps/server/database/migrations/