Overview
The User module in the Go backend has been refactored to be a read-only repository that queries the Better Auth PostgreSQL tables directly. This module no longer handles user creation, password management, or profile updates; these responsibilities have been moved to the Better Auth service running on the Bun monolith. The Go backend serves as a consumer of identity data, providing enriched user information to other microservices and modules within the Go ecosystem.Data Model (Consumer View)
The User entity maps directly to theusers (Better Auth core) and members (Better Auth organization) tables.
User Entity
- ID: Unique Identifier (nanoid generated by Better Auth)
- Email: Unique email address
- EmailVerified: Boolean status from Better Auth
- Name: User’s full name
- Image: URL to profile image
- IsAnonymous: Boolean flag for guest users
- Role: Platform-level role (
user,admin,superadmin) from the Better Auth admin plugin - Status Fields:
Banned: Boolean statusBanReason: Optional reason for account suspensionBanExpires: Timestamp for temporary bans
- Enriched Context:
OrganizationID: The active organization ID (frommemberstable)OrgRole: The user’s role in the organization (owner,admin,staff,viewer)ManagerID: Optional reporting manager ID (frommemberscustom field)DepartmentID: Optional department ID
Functional Requirements
1. Retrieve User Details
- Input: User ID or Email.
- Logic:
- Performs a direct query against the
userstable in PostgreSQL. - Joins with the
memberstable to inject organization context if available.
- Performs a direct query against the
- Output: Enriched User object.
2. Search Users by Organization
- Input: Organization ID.
- Logic: Join
membersanduserstables to list all users belonging to a specific organization. - Output: List of User objects with their organization roles.
3. Identity Verification (Stateless)
- Note: The User module provides the infrastructure to map JWT claims (from
Authorizationheader) to local domain entities. No database lookup is performed for signature verification; only for supplemental data enrichment.
Architecture: Single Source of Truth
The User module adheres to a “Query-Only” pattern in the Go backend:- No Data Duplication: The Go backend does not maintain a local
userstable. It queries theuserstable managed by Bun/Better Auth. - No NATS Synchronization: Synchronization logic has been eliminated in favor of direct database queries, ensuring absolute consistency and zero lag.
- Write Forwarding: All write operations (creating users, changing passwords, assigning roles) must be addressed to the Better Auth HTTP API on the Bun backend.
API Endpoints (Read-Only)
| Endpoint | Method | Description |
|---|---|---|
/api/v1/users/:id | GET | Retrieve user details by ID |
/api/v1/users/email/:email | GET | Retrieve user details by email address |
Deprecated Endpoints
The following endpoints have been DELETED from the Go backend and moved to Bun:POST /users(UsePOST /api/auth/admin/create-useron Bun)PATCH /users/:id(UsePOST /api/auth/admin/set-roleon Bun)DELETE /users/:id(UsePOST /api/auth/admin/remove-useron Bun)