DEV Community

Cover image for Lend Again Architecture: Reactivating a Settled Debt Without Duplicating History
DEVANSHU PATIL
DEVANSHU PATIL

Posted on

Lend Again Architecture: Reactivating a Settled Debt Without Duplicating History

Lend Again Architecture: Reactivating a Settled Debt Without Duplicating History

Human relationships are rarely transactional; they are cyclical.

Consider what happens with a close friend or family member:

  • In January, you lend Rahul Rs. 1,500 for a weekend road trip.
  • By March, Rahul has repaid the Rs. 1,500 across two installments. The debt is fully resolved and moves into your settled archive.
  • In July, Rahul's car breaks down and he asks to borrow Rs. 3,000 until payday.

What should happen inside your personal finance application when a settled contact borrows money again?

In poorly designed apps, you are faced with broken workflows:

  • Some apps force you to create a duplicate contact: "Rahul (2)" or "Rahul July".
  • Other apps allow you to add money to the old record, but doing so mutates the historical entity—blending his previous repayments into the new loan and destroying the audit trail of the January loan!

In FinLedger, handling recurring debt cycles was engineered from the ground up through the "Lend Again" Architecture (LendingRepository.kt, commit af5ad95).

Here is how FinLedger preserves independent loan cycles across multi-year personal relationships.

The Pitfalls of Mutating Settled Records

flowchart TD
    subgraph MutatingDisaster["The Flawed Mutation Anti-Pattern"]
        Settled["January Loan: Rs. 1,500
        Repayments: Rs. 1,500
        Status: SETTLED"] --> BorrowAgain["July: Rahul borrows Rs. 3,000"]

        BorrowAgain --> NaiveAdd["Naive Implementation:
        Directly mutates existing record:
        Original Amount = 1,500 + 3,000 = Rs. 4,500"]

        NaiveAdd --> Confusion["Historical Corruption:
        1. January disbursement date overwritten!
        2. Previous repayments look like partial payments on the 4.5k loan!
        3. Impossible to prove that the January loan was ever settled."]
    end

When an app merges a new loan into an old record, you lose chronological truth.

If a disagreement arises a year later, you can no longer prove when each loan occurred, which bank accounts funded them, or how long each cycle took to settle.

The Multi-Cycle Domain Model (LendingPersonSummary)

To solve this, FinLedger enforces a strict hierarchy: A Person is a container of independent, immutable Loan Agreements:

flowchart TD
    subgraph MultiCycleHierarchy["FinLedger Multi-Cycle Architecture"]
        Person["Person: Rahul Patil (UUID: p-1092)"]

        Person --> Cycle1["Cycle 1 (Jan 2026):
        - Loan ID: loan-01
        - Principal: Rs. 1,500.00
        - Status: SETTLED (100% Repaid)
        - Repayments: [Rs. 500 on Feb 1, Rs. 1,000 on Mar 15]"]

        Person --> Cycle2["Cycle 2 (Jul 2026 - Active):
        - Loan ID: loan-02
        - Principal: Rs. 3,000.00
        - Status: OUTSTANDING (0% Repaid)
        - Repayments: []"]

        Cycle1 --> Engine["LendingPersonSummary Domain Engine"]
        Cycle2 --> Engine

        Engine --> ReactiveState["Computed Person State:
        - Total Lifetime Lent: Rs. 4,500.00
        - Total Lifetime Repaid: Rs. 1,500.00
        - Active Outstanding: Rs. 3,000.00
        - isFullySettled: FALSE -> Moves back to Active Tab!"]
    end

1. Cycle Independence

Each loan agreement is an independent SQLite entity (LendingEntity) with its own:

  • Unique id (UUIDv4).
  • Immutable disbursement timestamp and principal amount.
  • Dedicated list of partial repayments (LendingRepaymentEntity).
  • Independent status: OUTSTANDING, PARTIALLY_PAID, or SETTLED.

When Rahul borrows Rs. 3,000 in July, the January loan entity is never touched. Its records, timestamps, and repayment linkages remain permanently frozen and settled.

2. Automatic Tab Reactivation

When Rahul had zero outstanding balance, his person summary flagged isFullySettled = true, displaying him under Past Records.

The moment you tap "Lend Again" and disburse the Rs. 3,000:

  1. A new LendingRecord (loan-02) is committed to the database.
  2. The domain engine recalculates LendingPersonSummary.fromRecords.
  3. Because lentOutstanding is now greater than zero (Rs. 3,000.00), isFullySettled evaluates to false.
  4. Rahul's card is automatically reactivated and moved back into the Active Records dashboard.

The Jetpack Compose Presentation: Chronological Timeline

In the UI, tapping Rahul's card opens a clean, chronologically partitioned timeline:

  • Section 1: Active Loan (Cycle 2)
    • Prominently displays the Rs. 3,000 outstanding balance.
    • Shows due dates, action buttons to record partial repayments, and linked bank accounts.
  • Section 2: Settled History (Cycle 1)
    • Displays a collapsed accordion labeled "Settled on 15-Mar-2026 (Rs. 1,500)".
    • Expanding the accordion reveals the exact payment dates and companion bank deposits for the earlier loan.

The user enjoys the best of both worlds: zero clutter for today's active tasks, combined with an immutable historical archive.

Key Takeaway

Financial tracking software must accommodate the continuous, cyclical nature of human relationships.

By decoupling individual loan agreements from the persistent person entity, FinLedger's "Lend Again" architecture allows you to track new loans with old friends effortlessly—without ever rewriting or corrupting the past.


FinLedger is a privacy-first, offline-first personal finance application for Android that models bank accounts, credit cards, and cash without double-counting.

Explore FinLedger on Google Play: https://play.google.com/store/apps/details?id=com.devanshufinance.app

Top comments (0)