Skip to content

Core Module (Auth, Users, KYC)

Overview

The Core Module is the foundational module of the IWM Platform, responsible for identity management, authentication, authorization, and KYC (Know Your Customer) verification. All other modules depend on Core for user identity and access control.

Responsibilities

  • User registration and account management
  • Authentication (email/password, OAuth providers)
  • Two-factor authentication (2FA)
  • Session management (JWT tokens)
  • KYC verification workflow
  • Role-based access control (RBAC)
  • Password security and account protection

Domain Entities

User

The central identity entity representing a platform user.

FieldTypeDescription
idUUIDPrimary identifier
emailVARCHAR(255)Unique email address
phoneVARCHAR(20)Optional phone number (unique)
password_hashVARCHAR(255)Bcrypt hashed password
statusENUMAccount status
email_verified_atTIMESTAMPEmail verification timestamp
phone_verified_atTIMESTAMPPhone verification timestamp
last_login_atTIMESTAMPLast successful login
created_atTIMESTAMPAccount creation time
updated_atTIMESTAMPLast modification time

UserProfile

Extended user information for personalization and compliance.

FieldTypeDescription
idUUIDPrimary identifier
user_idUUIDReference to User
first_nameVARCHAR(100)Legal first name
last_nameVARCHAR(100)Legal last name
middle_nameVARCHAR(100)Middle name (patronymic)
date_of_birthDATEBirth date for KYC
avatar_urlVARCHAR(500)Profile image URL
languageVARCHAR(10)Preferred language code
timezoneVARCHAR(50)User timezone

Session

Active user sessions for authentication state.

FieldTypeDescription
idUUIDSession identifier
user_idUUIDReference to User
refresh_token_hashVARCHAR(255)Hashed refresh token
device_fingerprintVARCHAR(255)Device identification
ip_addressINETClient IP address
user_agentTEXTBrowser/client info
expires_atTIMESTAMPSession expiration
revoked_atTIMESTAMPManual revocation time

KycVerification

KYC verification process state and data.

FieldTypeDescription
idUUIDVerification identifier
user_idUUIDReference to User
statusENUMVerification status
levelENUMVerification level achieved
personal_infoJSONBEncrypted personal data
submitted_atTIMESTAMPSubmission time
reviewed_atTIMESTAMPReview completion time
reviewed_byUUIDAdmin who reviewed
rejection_reasonTEXTReason if rejected
expires_atTIMESTAMPVerification expiry

KycDocument

Documents uploaded for KYC verification.

FieldTypeDescription
idUUIDDocument identifier
verification_idUUIDReference to KycVerification
document_typeENUMType of document
file_keyVARCHAR(500)S3/storage key
file_nameVARCHAR(255)Original filename
mime_typeVARCHAR(100)File MIME type
statusENUMDocument status
ocr_dataJSONBExtracted OCR data
rejection_reasonTEXTReason if rejected

User Lifecycle States

Users progress through defined states during their lifecycle:

Status Definitions

StatusDescriptionAllowed Actions
PENDING_VERIFICATIONAccount created, awaiting email verificationResend verification, view limited content
ACTIVEFully verified and operational accountAll platform features
SUSPENDEDTemporarily restricted due to policy violationView only, submit appeal
BANNEDPermanently banned from platformNone

Authentication Methods

Email/Password Authentication

Primary authentication method using email and password:

  1. Registration: User provides email and password
  2. Password Hashing: bcrypt with cost factor 12
  3. Email Verification: Unique token sent via email
  4. Login: Email + password verification
  5. Session Creation: JWT access token + refresh token issued

OAuth Providers

Supported social login providers:

ProviderTypeIdentifier
GoogleGOOGLEprovider_user_id from Google
FacebookFACEBOOKprovider_user_id from Facebook
AppleAPPLEprovider_user_id from Apple ID
TelegramTELEGRAMprovider_user_id from Telegram

OAuth Flow:

  1. User initiates OAuth with provider
  2. Provider redirects with authorization code
  3. Backend exchanges code for tokens
  4. User profile fetched from provider
  5. Account linked or created
  6. Platform session issued

Two-Factor Authentication (2FA)

TOTP (Time-based One-Time Password)

Primary 2FA method using authenticator apps:

Configuration:

  • Algorithm: SHA-1
  • Digits: 6
  • Period: 30 seconds
  • Secret: 32 bytes, base32 encoded

SMS Backup

Fallback 2FA method via SMS:

  1. User requests SMS backup
  2. System sends 6-digit code to verified phone
  3. Code valid for 5 minutes
  4. Maximum 3 attempts per code

Session Management

Token Architecture

The platform uses a dual-token system:

Access Token (JWT)

ClaimDescription
subUser ID (UUID)
emailUser email
rolesArray of role codes
iatIssued at timestamp
expExpiration timestamp

Concurrent Sessions

  • Users can have multiple active sessions
  • Each device/browser creates a separate session
  • Sessions tracked with device fingerprint
  • User can view and revoke individual sessions
  • Security: Suspicious activity triggers session review

Session Revocation

Sessions can be revoked:

  • Manually by user (logout, security settings)
  • Automatically on password change
  • Automatically on security incident
  • By admin action

KYC Workflow

Verification Levels

LevelRequirementsUnlocked Features
NONENo verificationView only, limited actions
BASICEmail + phone verifiedBasic purchases, limited investments
STANDARDID document verifiedFull platform access
ENHANCEDAddress proof + selfieHigh-value transactions

KYC Status Flow

Document Types

TypeRequired ForDescription
PASSPORTSTANDARDGovernment-issued passport
ID_CARDSTANDARDNational ID card
DRIVER_LICENSESTANDARDDriver's license with photo
UTILITY_BILLENHANCEDAddress proof (recent)
BANK_STATEMENTENHANCEDFinancial address proof
SELFIEENHANCEDLive selfie with document

Security Features

Password Security

  • Hashing: bcrypt with cost factor 12
  • Requirements: Minimum 8 characters, mixed case, numbers
  • History: Last 5 passwords cannot be reused
  • Expiry: Optional forced rotation (configurable)

Brute-Force Protection

Thresholds:

  • 5 failed attempts: 5-minute delay
  • 10 failed attempts: 15-minute lockout
  • 20 failed attempts: Account locked, email verification required

Rate Limiting

EndpointLimitWindow
POST /auth/login10 requests1 minute
POST /auth/register5 requests1 minute
POST /auth/forgot-password3 requests5 minutes
POST /auth/verify-2fa5 requests1 minute

Events Published

The Core Module publishes the following domain events for inter-module communication:

EventTriggerPayload
UserRegisteredNew user registrationuserId, email, referralCode
UserVerifiedEmail verification completeuserId, email
UserStatusChangedAccount status changeuserId, fromStatus, toStatus, reason
UserProfileUpdatedProfile information changeduserId, changedFields
UserLoggedInSuccessful loginuserId, ipAddress, userAgent
UserLoggedOutUser logoutuserId, sessionId
SessionRevokedSession manually revokeduserId, sessionId, reason
TwoFactorEnabled2FA activateduserId, method
TwoFactorDisabled2FA deactivateduserId, method
KycStatusChangedKYC status transitionuserId, fromStatus, toStatus, level
KycDocumentUploadedDocument uploaded for KYCuserId, verificationId, documentType
KycApprovedKYC verification approveduserId, level, approvedBy
KycRejectedKYC verification rejecteduserId, reason, rejectedBy
PasswordChangedUser changed passworduserId, changedAt
PasswordResetRequestedPassword reset initiateduserId, email

Business Rules and Invariants

User Rules

  1. Email must be unique across all users
  2. Phone number, if provided, must be unique
  3. User cannot be deleted if they have active orders or investments
  4. Status transitions must follow defined state machine
  5. Only ACTIVE users can perform transactions

Session Rules

  1. Access token lifetime: 15 minutes (non-configurable)
  2. Refresh token lifetime: 7 days
  3. Maximum concurrent sessions per user: 10
  4. Session must be revoked on password change
  5. Inactive sessions auto-expire after refresh token expiry

KYC Rules

  1. KYC verification expires after 1 year (for ENHANCED level)
  2. User cannot submit new KYC while previous is UNDER_REVIEW
  3. Rejected KYC allows resubmission after 24 hours
  4. ENHANCED level requires STANDARD level first
  5. KYC data must be encrypted at rest

Integration Points

Provides to Other Modules

InterfaceConsumersPurpose
IUserLookupServiceMLM, Commerce, InvestmentFetch user profile data
IKycStatusServiceInvestment, MLMCheck KYC verification status
IAuthenticationServiceAll modulesValidate tokens, get current user
IRoleServiceAdminCheck user permissions

Consumes from Other Modules

The Core Module is foundational and does not consume services from other business modules.