# Configurable Multi-Tenant LMS — Domain-Driven Design (DDD) *System Architecture & Bounded Context Specifications* --- ## 1. Domain Map & Ubiquitous Language To support hundreds of lenders dynamically, all domain concepts are bounded and read from configuration metadata rather than code-defined defaults. ### Ubiquitous Language Definitions * **Lender (Tenant)**: The owner of the lending products. Identified by `lender_id`. * **Product**: A financial model offered by a Lender (e.g. "Personal Loan - Tier 1 Salaried"). * **Product Configuration**: The metadata that defines rules, workflows, fees, and engines for a Product. * **Amortization Schedule (RPS)**: The collection of repayment installments (Principal + Interest + Charges) mapped over time. * **Allocation Sequence**: The priority order in which received payments are distributed across outstanding balances (e.g. Interest -> Principal -> Charges). * **Charge Entry**: An individual fee applied to a loan (e.g. Processing Fee, Cheque Bounce Fee, Restructure Fee). * **NPA (Non-Performing Asset)**: A loan state determined by consecutive days past due (DPD) exceeding a product-specific threshold. --- ## 2. Bounded Contexts ``` ┌────────────────────────────────────────────────────────────────────────┐ │ Multi-Tenant LMS Bounded Contexts │ ├────────────────────────────────────────────────────────────────────────┤ │ ┌────────────────────────┐ ┌────────────────────────────┐ │ │ │ Configuration Context │ │ Loan Context │ │ │ │ - Lenders & Products ├───────────►│ - Amortization Schedules │ │ │ │ - Dynamic Rule Sets │ │ - Loan Accounts & States │ │ │ └───────────┬────────────┘ └─────────────┬──────────────┘ │ │ │ │ │ │ ▼ ▼ │ │ ┌────────────────────────┐ ┌────────────────────────────┐ │ │ │ Repayment & Allocation │ │ Charge Context │ │ │ │ - IPC/PIC Allocation │◄───────────┤ - Fixed/Percentage Fees │ │ │ │ - Payment Receipts │ │ - Penalties & Grace Days │ │ │ └───────────┬────────────┘ └─────────────┬──────────────┘ │ │ │ │ │ │ ▼ ▼ │ │ ┌────────────────────────┐ ┌────────────────────────────┐ │ │ │ Settlement Context │ │ NPA Context │ │ │ │ - Foreclosures │◄───────────┤ - DPD Tracking │ │ │ │ - Maker-Checker Entry │ │ - Bucket Classification │ │ │ └────────────────────────┘ └────────────────────────────┘ │ └────────────────────────────────────────────────────────────────────────┘ ``` ### Context Details #### A. Configuration Context (Central Source of Truth) * **Aggregate Roots**: `Lender`, `Product`, `ProductConfiguration`. * **Entities & Value Objects**: `ChargeMaster`, `AllocationPriority`, `DisbursementScheduleConfig`, `InterestConfig`. * **Responsibilities**: Defines the parameters governing calculation methods, allocation hierarchies, fee matrices, and state transition workflows. * **Temporal Rules**: Enforces version control using `version`, `effective_from`, and `effective_to`. #### B. Loan Context * **Aggregate Roots**: `Loan`. * **Entities & Value Objects**: `RepaymentSchedule` (Installment), `AmortizationParameters`. * **Responsibilities**: Generates schedules on disbursement, computes due dates, and manages loan status transitions (e.g. active -> foreclosure_pending -> closed). #### C. Repayment & Allocation Context * **Aggregate Roots**: `Payment`. * **Entities & Value Objects**: `PaymentAllocation`, `AllocationSequence`. * **Responsibilities**: Records receipts from payment gateways (Razorpay, Paytm) and dynamically splits funds across interest, principal, and penalties according to the configured rule (IPC, PIC, etc.). #### D. Charge Context * **Aggregate Roots**: `ChargeEntry`. * **Entities & Value Objects**: `PenaltyRule`, `WaiverEntry`. * **Responsibilities**: Calculates and applies charges (Fixed / Percentage) on triggers (NACH bounce, cheque bounce, restructuring) and manages grace periods. #### E. Settlement & Foreclosure Context * **Aggregate Roots**: `SettlementEntry`. * **Entities & Value Objects**: `ForeclosureCalculation`, `MakerCheckerApproval`. * **Responsibilities**: Computes total outstanding, applies foreclosure penalties, and enforces checker approvals before closing accounts. #### F. NPA Context * **Aggregate Roots**: `NPAClassification`. * **Entities & Value Objects**: `DPDBucket`. * **Responsibilities**: Evaluates loan portfolios daily, tracks DPD counts, and transitions loans to NPA status when thresholds are breached.