Skip to content

Architecture

1. System Context (C4 L1)

Identity is the trust root — every JWT in the platform is signed by this service. JWKS at /jw-certs is the public endpoint sister services use to verify signatures.

2. Container View (C4 L2)

3. Component View (C4 L3) — Internal Layering

LayerResponsibility
Routes12 base paths in RestPaths
ControllersAuth gate (JWT / BASIC) + permission
ServicesBusiness logic (auth + RBAC + OTP + user mgmt)
RepositoriesDrizzle queries; identifier-aware lookups
ComponentsMail / SMS / WebSocket
Token serviceJWKSIssuerTokenService from @nx/core (ES256 signer)

4. State Machines

Identity has minimal state-machine surface; most flows are validation chains rather than persistent state machines.

EntityStatesNotes
User.statusACTIVATED / DEACTIVATED / LOCKEDguard for sign-in
UserIdentifier.verifiedfalsetrueverification via OTP/token
Role.typeSYSTEM / CUSTOM / UNKNOWNSYSTEM rows immutable

5. Runtime Scenarios

5.1 Sign-in (BASIC scheme)

5.2 Sign-up

5.3 Email OTP — Verify Email Flow

5.4 JWKS Verification by Sister Service

6. Crosscutting Concerns

ConcernHow this service handles it
Token signingES256 via JWKSIssuerTokenService (from @nx/core); private key from environment / secure config
Token verificationNOT done here — sister services pull JWKS over HTTP and verify locally
Password storageBun.password hashing (argon2-style, internal default)
OTP storageRedis with TTL — hashed code + attempt counter + cooldown + daily quota
i18nMail/SMS templates in EN + VI; user locale selects on send
LoggingIGNIS structured (key: %s); request-id propagated
AuthZCasbin + PolicyDefinition edges; permissions cached in Redis
Soft-deleteSoftDeletableRepositorydeletedAt; identifier uniqueness scoped to deletedAt IS NULL
IDsSnowflake via IdGenerator, worker 1

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.