Skip to content

Domain Model

Schemas in @nx/core/src/models/schemas/identity/ (and shared public/configuration/). Numeric/text columns follow IGNIS conventions.

1. Full ERD

2. Common Columns

Every entity adds these via generateCommonColumnDefs():

ColumnType
idtext (PK, Snowflake)
createdAt / modifiedAttimestamptz
createdBy / modifiedBytext
deletedAttimestamptz (soft-delete)
metadatajsonb
statustext (when using …WithStatusDefs)

3. Entities

3.1 User

PropertyValue
TableUser
Soft-deleteyes
FieldTypeRequiredDescription
usernametextDisplay username (also stored as identifier)
statustextACTIVATED / DEACTIVATED / LOCKED
lastLoginAttimestamptzUpdated by signIn

3.2 UserIdentifier

FieldTypeRequiredDescription
userIdtextFK
identifiertextThe login value (email, phone, username, etc.)
schemetextUSERNAME / EMAIL / PHONE_NUMBER / USER_NUMBER / NX_AUTH
verifiedbooleanDefault false; set to true after OTP confirmation

Unique constraint: partial unique on (scheme, identifier) WHERE deletedAt IS NULL — a value is unique per scheme.

3.3 UserCredential

FieldTypeRequiredDescription
userIdtextFK
schemetextBASIC (password) / TWO_FA / OAUTH / OAUTH2
credentialtextHashed via Bun.password (or external token for OAUTH)

3.4 UserProfile

FieldTypeRequiredDescription
userIdtextFK (1:1)
firstName / lastNametext
birthdaytimestamptz
localetexten / vi (drives mail/SMS template selection)

3.5 UserConfiguration

Per-user feature flags / settings as kv pairs in jsonb.

3.6 Role

FieldTypeRequiredDescription
identifiertextUnique slug (SUPER_ADMIN, etc.)
namei18n jsonbDisplay
descriptioni18n jsonb
priorityintRange 101–499 for custom; system roles use 500–1000
typetextSYSTEM / CUSTOM / UNKNOWN
statustextACTIVATED / DEACTIVATED

System roles (immutable, seeded): SUPER_ADMIN(1000), ADMIN(500), OPERATOR(600), OWNER(500), CASHIER(110), EMPLOYEE(100), CUSTOMER(10), GUEST(1).

3.7 Permission

FieldTypeRequiredDescription
codetext<Resource>.<action> (e.g. User.create)
resourcetextAuthorization subject
actiontextfind / create / updateById / deleteById / domain action
name / descriptioni18n jsonb

3.8 PolicyDefinition (RBAC edge)

FieldTypeRequiredDescription
varianttextGROUP (subject ↔ subject) / PERMISSION (role ↔ permission)
subjectTypetextUser / Role / Permission
subjectIdtextFK target
targetTypetextRole / Permission / User / Organizer / Merchant
targetIdtextFK target
scopetextSYSTEM / ORGANIZER / MERCHANT (PolicyDomains)

Common edges:

Edge typeVariantSubjectTarget
User → RoleGROUPUserRole
User → OrganizerGROUPUserOrganizer
User → MerchantGROUPUserMerchant
Role → PermissionPERMISSIONRolePermission

3.9 Customer

User extension with sales-context fields (managed in identity but read by sale).

FieldTypeRequiredDescription
userIdtextoptional FK (some customers are guests, no User)
nametextDisplay
phone / emailtextContact
merchantIdtextOwner
pointBalancedecimal(15,4)Loyalty points (default 0; written by sale)

3.10 Employee

FieldTypeRequiredDescription
userIdtextFK to User
merchantIdtextEmployer (or organizerId)
organizerIdtextAlternative employer
positiontextJob title
statustextACTIVATED / DEACTIVATED

3.11 Configuration (shared)

FieldTypeRequiredDescription
codetextUnique per (group, principalId, principalType, environment) partial
grouptextINTEGRATION / MAIL / SMS / OTP / etc.
principalType / principalIdtextWhen per-merchant (e.g., SMS provider per merchant)
environmenttextDEVELOPMENT / PRODUCTION
tValuetextJSON value (encrypted for credentials)
dataTypetextTEXT / JSON / BOOLEAN
credentialtextEncrypted (AES-256-GCM via CryptoUtility); hidden from CRUD reads

Identity reads mail/SMS/OTP configs from this table; payment writes encrypted provider credentials.

4. Status Enums

4.1 UserIdentifierSchemes

ValueDescription
USERNAMEDisplay username
EMAILEmail address
PHONE_NUMBERE.164 phone
USER_NUMBERInternal numeric id
NX_AUTHNX-Auth federation

4.2 UserCredentialSchemes

ValueUse
BASICPassword (Bun.password hash)
TWO_FASecond factor token (placeholder)
OAUTHOAuth1 federation (declared, no provider)
OAUTH2OAuth2 federation (declared, no provider)

4.3 RoleTypes

ValueCode
SYSTEMseeded, immutable
CUSTOMmerchant-defined
UNKNOWNfallback

4.4 PolicyDomains (scope field)

ValueUse
SYSTEMglobal edges
ORGANIZERscoped to an organizer
MERCHANTscoped to a merchant

4.5 OTP namespaces

NamespaceUse
verify-emailRegister email
verify-phoneRegister phone
forgot-passwordPassword reset
phone-authPhone-only sign-in (when applicable)
add-phone / add-emailLink to authenticated account

4.6 OTP defaults

SettingValue
CODE_LENGTH6
EXPIRY5–15 min depending on flow
MAX_ATTEMPTS5
LOCKOUT10–15 min
RESEND_COOLDOWN60s
MAX_RESENDS_PER_DAY5

5. Cross-entity Invariants

InvariantEnforcement
UserIdentifier(scheme, value) is unique system-wide (per scheme)Partial unique index
UserCredential.scheme=BASIC is hashed (never plaintext)AuthenticationService.signUp + changePassword always hash
Role.priority is unique within typeService validation in RoleService
System roles (type=SYSTEM) cannot be deleted/modified except via migrationService guard
PolicyDefinition cycles (User → Role → User) are forbiddenService-level acyclicity check
OTP daily quota per (namespace, identifierValue)Redis counter {ns}:daily:{value}
JWT payload always includes userId, roles, organizers, merchantsAuthenticationService.generateToken

6. Soft-delete Behavior

EntitySoft-deleteNotes
All identity entitiesdeletedAt marker; reads default IS NULL
ConfigurationBut seeded rows are typically restored on migration re-run

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