🧊 Accounts Context — Models & Database Diagram¶
Last updated: 2025-10-09 (Europe/Paris)
This reference captures the core tables, relationships, and fields that power identity and organization management inside the Accounts context. Use it when designing migrations, factories, or API contracts.
🗺️ Entity Relationship Diagram¶
%%{init: {'themeVariables': {'fontSize': '15px'}, 'class': {'useMaxWidth': true}}}%%
classDiagram
direction LR
class User {
+UUID id
+string name
+string email (unique)
+timestamp email_verified_at
+string password
+string avatar_path (nullable)
+string locale = "en"
+boolean two_factor_enabled
+json preferences (nullable)
+timestamps
}
class Organization {
+UUID id
+string name
+string slug (unique)
+string handle (unique)
+text description (nullable)
+string country_code (nullable)
+json branding (nullable)
+UUID owner_id
+timestamps
}
class Membership {
+UUID id
+UUID user_id
+UUID organization_id
+string role (enum)
+string status (enum)
+json permissions (nullable)
+timestamp joined_at (nullable)
+timestamps
}
class Invitation {
+UUID id
+UUID organization_id
+UUID inviter_id
+string email
+string role
+string status (enum)
+string token (unique)
+timestamp expires_at
+timestamps
}
User "1" -- "many" Membership : enrolls
Organization "1" -- "many" Membership : contains
User "1" -- "many" Invitation : sends
Organization "1" -- "many" Invitation : issues
🧱 Domain Models in Scope¶
| Model | Stored in | Description |
|---|---|---|
App\Contexts\Accounts\Models\User |
users |
Core identity for every person interacting with RawDigs. |
App\Contexts\Accounts\Models\Organization* |
organizations |
Label/collective entity providing a shared workspace. |
App\Contexts\Accounts\Models\Membership* |
memberships |
Junction between users and organizations with role metadata. |
App\Contexts\Accounts\Models\Invitation* |
invitations |
Records pending org invitations before a membership exists. |
* Planned models that will live under the same namespace as the Accounts context evolves.
📋 Table Details¶
users¶
The users table stores the canonical identity that underpins every guard (web, token, Filament).
| Column | Type | Notes |
|---|---|---|
id |
UUID | Primary key (uses HasUuid). |
name |
string | Display name shown across the app. |
email |
string | Unique, indexed; verified via email_verified_at. |
password |
string | Hashed via Laravel Hash facade. |
avatar_path |
string (nullable) | Reference managed by Spatie Media Library (e.g., collection avatar); actual files live in the shared media table. |
locale |
string | Defaults to en; drives UI translation. |
two_factor_enabled |
boolean | Mirrors Fortify/Sanctum 2FA state. |
preferences |
JSON | Structured settings (notification opt-ins, UI flags). |
timestamps |
— | Laravel managed. |
organizations¶
The organizations table represents labels, collectives, or teams that coordinate creators, catalog assets, and payouts.
| Column | Type | Notes |
|---|---|---|
id |
UUID | Primary key. |
name |
string | Public-facing label name. |
slug |
string | URL-safe identifier; unique. |
handle |
string | Short code for mentions or search. |
description |
text (nullable) | Rich bio/mission. |
country_code |
string (nullable) | ISO code for compliance, VAT. |
branding |
JSON (nullable) | Theme colors, logos, featured imagery. |
owner_id |
UUID | FK to users.id, initial owner membership. |
timestamps |
— | Laravel managed. |
memberships¶
memberships link users to organizations, capturing the team-scoped role that Spatie synchronises.
| Column | Type | Notes |
|---|---|---|
id |
UUID | Primary key. |
user_id |
UUID | FK to users. |
organization_id |
UUID | FK to organizations. |
role |
string | Enumerated roles aligning with Spatie roles (e.g., owner, admin, manager, artist, viewer). Roles such as artist.manage empower label members to create artists in the Creators context. |
status |
string | pending, active, or removed. |
permissions |
JSON (nullable) | Per-member overrides or temporary grants. |
joined_at |
timestamp (nullable) | Captures acceptance timestamp. |
timestamps |
— | Audit creation/updates. |
invitations¶
The invitations table tracks open invites so non-members can accept and become organization members.
| Column | Type | Notes |
|---|---|---|
id |
UUID | Primary key. |
organization_id |
UUID | FK to organizations. |
inviter_id |
UUID | FK to users (sender). |
email |
string | Recipient address (allows non-users). |
role |
string | Proposed role once accepted. |
status |
string | Lifecycle: pending, accepted, declined, revoked. |
token |
string | Signed token for acceptance link. |
expires_at |
timestamp | Invitation expiry for security. |
timestamps |
— | Record keeping. |
🧪 Migration Notes¶
- All primary keys are UUIDs; use Laravel
uuidhelper or UuidGenerator trait. - Add composite unique constraint on
memberships(user_id,organization_id) to prevent duplicates. - Index
status/roleonmembershipsfor frequent queries (roster filtering). - Ensure
organization_idandinviter_idcascades are configured to revoke invites when entities are deleted. - Use soft deletes only if audit requirements demand; otherwise capture removal events via
status.
Related Docs¶
docs/contexts/auth/roles-permissions.md— Permission matrix tied to roles.docs/contexts/auth/models.md— How Spatie roles/permissions tables connect to Accounts entities.docs/contexts/accounts/index.md— Context overview and integration notes.docs/contexts/auth/flows/web-session.md— Session login flow that relies on Accounts entities.