Technical Design Specification

Wallet Module
WALLET
Version1.0
SystemHR Management System
ModuleWALLET - Electronic Wallet
Databasewallet_db
Date2026-08-05
AuthorNam Nguyen
StatusDraft

Table of Contents

1. Introduction

1.1 Purpose

This document provides the technical design specification for the Wallet module. It describes the system architecture, service design, data models, and integration patterns required to implement the electronic wallet functionality.

1.2 Scope

The Wallet module implements electronic wallet operations including balance management, deposits, withdrawals, transfers, and payments for recruitment services. It integrates with the AUTH module for user authentication and the RECR module for service payments.

1.3 Design Decisions

DecisionRationaleRequirement
Use PostgreSQL for wallet dataACID compliance required for financial transactionsNFR-007
PIN-based transaction authorizationBalance security without full auth flowNFR-005
Optimistic locking for balance updatesPrevent race conditions in concurrent transactionsNFR-003
Separate payout request workflowAdmin approval required for withdrawalsFR-015
RabbitMQ for inter-service communicationAsynchronous event-driven architectureNFR-001

2. Architecture

2.1 System Architecture

The Wallet module follows a service-oriented architecture with clear separation of concerns:

ComponentResponsibilityTechnology
Wallet APIREST API endpoints for wallet operationsNestJS
Wallet ServiceBusiness logic for wallet managementNestJS Service
Transaction ServiceTransaction processing and audit trailNestJS Service
Payment ServicePayment order managementNestJS Service
Payment Gateway AdapterIntegration with external PGNestJS Module
Message ProducerEvent publishing to RabbitMQamqplib
DatabasePersistent storage for wallet dataPostgreSQL + Drizzle ORM

2.2 Component Diagram

Component Diagram
Figure 1: Wallet Component Diagram

3. Technical Design

3.1 Wallet Management Service

AspectDesign
ResolvesFR-001, FR-002, FR-003
ClassWalletService
DependenciesDrizzle ORM, AuthGuard, MessageProducer

Methods:

MethodDescriptionReturns
createWallet(userId)Creates wallet for new userWallet
getBalance(userId)Returns wallet balance and statusWalletBalance
setPin(userId, pin)Hashes and stores wallet PINvoid
verifyPin(userId, pin)Verifies wallet PINboolean
freezeWallet(walletId)Freezes wallet for admin actionWallet

3.2 Transaction Service

AspectDesign
ResolvesFR-004, FR-009, FR-010
ClassTransactionService

Methods:

MethodDescriptionReturns
createTransaction(data)Creates transaction record with balance snapshotTransaction
getTransactions(walletId, filters)Returns paginated transaction historyPaginatedResult
getTransactionById(id)Returns single transaction detailsTransaction

3.3 Payment Service

AspectDesign
ResolvesFR-011, FR-012, FR-013
ClassPaymentService

Methods:

MethodDescriptionReturns
createPaymentOrder(data)Creates payment order for servicePaymentOrder
processPayment(orderId, pin)Processes payment from wallet balancePaymentResult
processRefund(orderId)Processes refund to walletRefundResult

3.4 Withdrawal Service

AspectDesign
ResolvesFR-007, FR-015
ClassWithdrawalService

Methods:

MethodDescriptionReturns
createPayoutRequest(data)Creates withdrawal requestPayoutRequest
approvePayout(requestId, adminId)Approves withdrawal requestPayoutRequest
rejectPayout(requestId, adminId, reason)Rejects withdrawal requestPayoutRequest
processPayout(requestId)Processes approved payout to bankPayoutResult

3.5 Transfer Service

AspectDesign
ResolvesFR-008
ClassTransferService

Methods:

MethodDescriptionReturns
transfer(senderId, recipientId, amount)Transfers funds between walletsTransferResult

3.6 Payment Gateway Integration

AspectDesign
ResolvesFR-006
ClassPaymentGatewayAdapter

Methods:

MethodDescriptionReturns
initiatePayment(data)Creates payment session with PGPaymentSession
verifyPayment(transactionId)Verifies payment status with PGPaymentStatus
processWebhook(payload)Handles PG webhook callbackWebhookResult

4. Data Design

4.1 Database Schema

ERD Diagram
Figure 2: Wallet Database Schema

5. Integration Design

5.1 Sequence Diagram

Sequence Diagram
Figure 3: Wallet Integration Flow

6. Security Design

Security MeasureImplementationRequirement
AuthenticationJWT token validation via AUTH serviceNFR-005
AuthorizationRole-based access control (User, Admin)NFR-005
PIN Securitybcrypt hashing, 6-digit formatNFR-005
Data EncryptionAES-256 for sensitive fields (account numbers)NFR-006
Audit TrailComplete transaction history with timestampsNFR-007

7. Requirements Traceability

SRS Requirement TDS Section Component DB Table
FR-001: Create Wallet3.1WalletServicewallet_wallets
FR-002: View Balance3.1WalletServicewallet_wallets
FR-003: Set PIN3.1WalletServicewallet_wallets
FR-004: Transaction History3.2TransactionServicewallet_transactions
FR-005: Payment Methods3.3PaymentServicewallet_payment_methods
FR-006: Deposit Funds3.6PaymentGatewayAdapterwallet_transactions
FR-007: Withdrawal3.4WithdrawalServicewallet_payout_requests
FR-008: Transfer3.5TransferServicewallet_transactions
FR-011: Pay Job Posting3.3PaymentServicewallet_payment_orders
FR-015: Admin Approval3.4WithdrawalServicewallet_payout_requests