Organization Module Architecture The Organization module provides an interface to retrieve organization and membership data. Since the adoption of Better Auth, all organization and membership mutations (creation, invitation, role updates) are handled exclusively by the Bun backend. The Go backend treats these tables as read-only data sources.

Core Concepts

  • Organizations: Represent business entities or tenants. All data in the platform is siloed by organization_id.
  • Members: Define the relationship between a User and an Organization, including their assigned role within that organization.
  • Plans: Represent subscription tiers (Starter, Pro, Enterprise). Unlike identity data, Plan definitions are managed directly by the Go backend.

Architecture

Source of Truth

  • Organizations & Members: Better Auth (PostgreSQL tables: organizations, members).
  • Plans: Go Backend (PostgreSQL table: plans).

Repository Pattern (Read-Only)

The Go repositories for Organizations and Members are strictly read-only. We use GORM to perform selection queries against the shared PostgreSQL database.

Functional Requirements

1. Organization Retrieval

  • Retrieve organization details by ID or Slug.
  • List all organizations a specific User belongs to.
  • Retrieve organization metadata (logo, settings).

2. Member Management (Query Only)

  • List all members of an organization (with user details joined).
  • Check a user’s role within an organization.
  • Retrieve membership status and join date.

3. Subscription Plans

  • List available subscription plans.
  • Retrieve plan limits (Max Users, Max Products, etc.).
  • Update plan definitions (Administrator only).

Data Models

Organization (organizations table)

FieldTypeDescription
idstringUnique identifier (ULID/UUID)
namestringDisplay name
slugstringURL-friendly identifier
logostringURL to organization logo
created_atdatetimeCreation timestamp

Member (members table)

FieldTypeDescription
idstringUnique membership ID
organization_idstringForeign key to organizations
user_idstringForeign key to users
rolestringAssigned role (owner, admin, member)
created_atdatetimeJoin date

Plan (plans table)

FieldTypeDescription
idstringUnique identifier
namestringPlan name (e.g., Enterprise)
max_usersintLimit on total members
max_productsintLimit on inventory items

Implementation Details

Multi-Tenancy

Most Go services use the OrganizationID from the authenticated context (extracted from the Better Auth JWT) to scope database queries.

Authorization

Roles are defined in the members table. The PermissionService in the Go backend queries this table directly and caches the result in Redis to ensure low-latency authorization checks across all Go modules.