Skip to content

System Architecture

Overview of the Keshless Accounting System structure and component interactions.

Core Principles

PrincipleDescription
ACID ComplianceAll operations use PostgreSQL transactions
ImmutabilityPosted ledger entries cannot be modified
Double-EntryEvery transaction creates balanced debit/credit pairs

Architecture Layers

┌─────────────────────────────────────────────────────┐
│              Application Layer                       │
│  (Wallet Controllers, Payment APIs, Transactions)   │
└─────────────────────────┬───────────────────────────┘

┌─────────────────────────────────────────────────────┐
│                  Service Layer                       │
│  Ledger | Templates | Posting | Balance Verify      │
│  Trial Balance | Statement | Chart of Accounts      │
└─────────────────────────┬───────────────────────────┘

┌─────────────────────────────────────────────────────┐
│                    Data Layer                        │
│  JournalEntry | LedgerEntry | ChartOfAccounts       │
│  AccountBalance | Reconciliation | AuditLog         │
└─────────────────────────┬───────────────────────────┘

┌─────────────────────────────────────────────────────┐
│              PostgreSQL Database                     │
└─────────────────────────────────────────────────────┘

Data Models

ChartOfAccounts

Hierarchical account structure.

FieldDescription
codeUnique account code (e.g., "1110")
nameAccount name
typeASSET, LIABILITY, EQUITY, REVENUE, EXPENSE
normalBalanceDEBIT or CREDIT
currencyE (Emalageni)

Account Ranges:

  • 1000-1999: Assets
  • 2000-2999: Liabilities
  • 3000-3999: Equity
  • 4000-4999: Revenue
  • 5000-5999: Expenses

JournalEntry

Groups related ledger entries for a single transaction.

FieldDescription
journalIdUnique ID (JE-XXXXXX)
statusPENDING, POSTED, REVERSED, CANCELLED
totalAmountTransaction amount
walletTransactionIdLink to source transaction
reversalOfIf reversing another entry

LedgerEntry

Individual debit or credit records.

FieldDescription
entryIdUnique ID (LE-XXXXXX)
journalIdParent journal
accountCodeChart of Accounts reference
typeDEBIT or CREDIT
amountEntry amount
entityIdUser/Vendor reference
statusPENDING, POSTED, REVERSED

Immutability: Once status = POSTED, entry cannot be modified.

AccountBalance

Denormalized cache for fast balance queries.

FieldDescription
accountCodeAccount reference
balanceCurrent balance
versionOptimistic locking
lastReconciledAtLast reconciliation

AuditLog

Tamper-proof audit trail with SHA-256 hash chaining.

FieldDescription
eventTypeJOURNAL_CREATED, ENTRY_POSTED, etc.
changesBefore/after state
previousHashHash of previous entry
currentHashSHA-256 hash of this entry

Hash Chain: Any tampering breaks the chain and is immediately detectable.


Services

ledgerService

Core journal and ledger operations.

MethodDescription
createJournalEntry()Create journal with entries
reverseJournalEntry()Create reversing entry
getJournalById()Retrieve journal

transactionTemplatesService

Pre-built double-entry transaction patterns.

TemplateDescription
getUserTransferTemplate()P2P transfers
getUserPaymentTemplate()User → Vendor
getUserTopupTemplate()Wallet topups
getUserWithdrawalTemplate()Cash withdrawals
getUserRefundTemplate()Refunds
getManualAdjustmentTemplate()Admin corrections

postingService

Pending → posted workflow management.

MethodDescription
postEntry()Manually post entry
cancelEntry()Cancel pending entry
autoPostPendingEntries()Auto-post old entries
reviewEntry()Approve/reject flagged

balanceVerificationService

Reconciliation and balance verification.

MethodDescription
verifyUserBalance()Check user wallet vs ledger
verifyAllUserBalances()Reconcile all users
fixDiscrepancy()Auto-fix balance issues

Job Scheduling

dailyReconciliation

Runs at 2 AM daily.

Tasks:

  1. Auto-post pending entries > 30 minutes old
  2. Verify all user/vendor balances
  3. Generate trial balance
  4. Create reconciliation record
  5. Alert on discrepancies

Performance Features

FeatureBenefit
Balance CachingFast queries via AccountBalance
Optimistic LockingPrevents race conditions
Indexed QueriesCritical indexes on all models

Security Features

FeatureProtection
ImmutabilityPosted entries locked at DB level
Hash ChainingTamper detection via SHA-256
Audit TrailEvery action logged
Transaction IsolationPostgreSQL ACID compliance
Optimistic LockingConcurrent update protection

Internal use only - Keshless Payment Platform