๐งพ Accounts Context¶
Last updated: 2025-10-09 (Europe/Paris)
The Accounts context owns identity, access control, and organizational structure across RawDigs. It ensures users, labels, and collaborators can authenticate, join organizations, and receive the right capabilities elsewhere in the platform.
๐ฏ Purpose¶
- Provide secure authentication (email/password, 2FA), session management, and profile data.
- Model organizations (labels, collectives, teams) and connect members with scoped roles.
- Coordinate authorization via Spatie Laravel-Permission using organization-aware teams.
- Surface account-level metadata (handles, avatar, locale, billing country) for other contexts.
๐งฉ Core Models¶
| Model | Description |
|---|---|
User |
Primary identity; stores credentials, profile, and notification preferences. |
Organization |
Represents a label/collective; source of team-scoped permissions. |
Membership |
Joins a user to an organization with a role and status. |
Invitation |
Tracks pending or revoked organization invitations. |
Related enums and traits live in app/Contexts/Accounts/ and app/Shared/.
Detailed schema reference: Models & Database Diagram
๐ Authorization Model¶
- Spatie Permission runs in team mode, keyed to
organization_id. - Middleware (e.g.,
SetActiveOrganization) resolves the current organization and sets the Spatie team context before gate checks. - Roles (
owner,admin,manager,artist,viewer) aggregate granular permissions such asrelease.publish,member.manage, andpayout.configure. - Artist access policies consult this context for organization fallback when artist membership is missing.
See docs/contexts/auth/roles-permissions.md for the full matrix.
๐ Key Flows¶
- Registration & Sign-In
- User creates an account, verifies email, optionally enables 2FA.
- Context emits
UserRegistereddomain event for downstream onboarding. - Organization Creation
- User creates an organization, becoming
owner. - Service assigns default roles, seeds branding/profile placeholders.
- Invitations & Membership
- Owners/admins invite collaborators; invitees accept to become members.
- Membership status transitions:
pending โ active โ removed. - Role Changes
- Org managers adjust roles; event
MembershipRoleChangednotifies dependent contexts. - Artist Roster Management
- Members with
artist.manage(typically owners/admins/managers) can create new artists in the Creators context on behalf of the label. - When a label member creates an artist, the artist record stores
organization_idand the label member becomes the initialArtistMember(roleowneroradmin). - Future collaborators can be invited either through organization memberships or direct artist invitations.
๐ Integrations with Other Contexts¶
- Creators: Provides organization roster data and fallback access rules for artist management.
- Catalog & Commerce: Supplies organization/team context for creating releases and processing orders under the right account.
- Payouts: Shares ownership and payout settings, including billing addresses and tax country.
- Governance: Seeds co-op member records and tracks organization classes for voting eligibility.
Domain events ensure these interactions remain decoupled.
๐ Technical Notes¶
- Source code for Accounts lives under
app/Contexts/Accounts/(Models, Http, Policies, Contracts, Repositories, etc.). - Context registers
AccountsServiceProviderbinding contracts (repositories, invitation service) and loading routes. - Repositories implement interfaces under
Contracts/to allow swapping storage or extracting to packages later. - Tests live under
tests/Contexts/Accounts/mirroring production namespace. - Audit trails leverage Laravel model events, pushing structured logs to the Analytics context.
๐ฃ Roadmap Highlights¶
- Expand authentication to support social/OAuth sign-in.
- Add delegated access tokens for third-party integrations.
- Introduce organization-level billing profiles and invoicing hooks.
- Enhance audit logging with immutable event streams for governance review.
References¶
docs/rawdigs-contexts.mdโ High-level context map.docs/features/features-overview.mdโ Product pillars and MVP scope.docs/contexts/accounts/models.mdโ Database schema for users, organizations, memberships.docs/contexts/accounts/entity-diagram.mdโ High-level relationships across Accounts and neighboring contexts.docs/contexts/auth/roles-permissions.mdโ Detailed access model.docs/contexts/media/index.mdโ Media handling conventions shared across contexts.docs/commands/context-make.mdโ CLI scaffolding for adding new Accounts resources.