Skip to content

๐Ÿงพ 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 as release.publish, member.manage, and payout.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

  1. Registration & Sign-In
  2. User creates an account, verifies email, optionally enables 2FA.
  3. Context emits UserRegistered domain event for downstream onboarding.
  4. Organization Creation
  5. User creates an organization, becoming owner.
  6. Service assigns default roles, seeds branding/profile placeholders.
  7. Invitations & Membership
  8. Owners/admins invite collaborators; invitees accept to become members.
  9. Membership status transitions: pending โ†’ active โ†’ removed.
  10. Role Changes
  11. Org managers adjust roles; event MembershipRoleChanged notifies dependent contexts.
  12. Artist Roster Management
  13. Members with artist.manage (typically owners/admins/managers) can create new artists in the Creators context on behalf of the label.
  14. When a label member creates an artist, the artist record stores organization_id and the label member becomes the initial ArtistMember (role owner or admin).
  15. 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 AccountsServiceProvider binding 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.