Bank8:Lending - README
Lending as a product line: loan products with versioned, simulatable amortization templates, origination, disbursement, repayment with rule-driven allocation, daily accrual, delinquency and collections, restructure, and write-off - every money movement posted through Bank8:Ledger, never bookkeeping balances of its own.
Summary
Bank8:Lending is a Rust service owning the lending schema in the bank8
vertical database. A loan is a contract plus a ledger.accounts row
(tside = 'ASSET'); Lending owns what is owed, when, and what happens
when it is not paid, while the ledger owns the position. Disbursement,
repayment, fees, accrual, and write-off are all ledger posting batches
submitted through the public posting API.
Motivation
A core ledger can hold a loan-shaped account, but a bank needs the lending business: an application funnel, a contract with a term and a schedule, an arrears process, and a way to write a loan off. Those are state machines and rules, not balances.
Two design choices carry the service:
- Amortization is data. A repayment schedule comes from a versioned, simulatable template, so a new interest method or day-count convention is a product operation rather than an engineering release, and the bank can preview a schedule before a customer sees one.
- Lending never touches balances. Every movement re-enters the ledger's posting pipeline, so loan money obeys exactly the same invariants as any other transfer - balanced, idempotent, audited, tenant-isolated, and visible to the book of account for free.
Architecture & High-Level Design
Key Traits and Data Structures
LoanProduct/LoanProductVersion- the product definition (term bounds, interest method, day-count, allocation order, fees). A loan pins its opening version.ScheduleTemplate/ScheduleTemplateVersion- a versioned, simulatable amortization definition; preview writes nothing.LoanApplication- origination state machine, draft to decision.Loan- the contract: ledger account binding, commitment, disbursed principal, term, status, schedule revision.LoanSchedule/LoanSchedulePeriod- the revisioned repayment plan with per-period principal/interest/fee split and paid state.LoanTransaction- a movement with itsledger_posting_idand idempotency key.Allocation- how a repayment split across penalty, fee, interest, and principal - persisted so the split is explainable afterwards.DelinquencyState/DelinquencyAction- ageing state and pause.
Rationale, Trade-offs, and Alternatives
- Data-driven amortization. A compiled-in set of amortization methods becomes a change request the moment the bank invents product fourteen. Versioned, simulatable templates keep the type space open and keep existing loans on their opening terms.
- Posting, not bookkeeping. Lending could hold its own loan balances and reconcile later; it does not, because a parallel balance is a second source of truth. Posting to the ledger makes every loan movement auditable through the same journal as everything else and gives Accounting and Risk the data for free.
- Guards before money. Every transition (open, disburse, repay, restructure, write off) is guarded by its state machine and audited before a posting is built, so an invalid transition fails closed rather than creating a compensating mess.
- Compensating reversal on partial failure. If the ledger accepts a movement and the local commit then fails, Lending issues a reversing posting and alerts - it never leaves the contract and the position disagreeing.
See DESIGN.md for the wire-level detail (including the normative
posting mapping) and BUSINESS.md for the business capabilities.
Architecture & Design: bank8:lending and its underlying concepts were designed by Hamid Jahanzad.