Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

A loan is not an expense: modelling debt in a personal finance app

Most personal finance apps model one thing: money leaving. That assumption quietly breaks half the ledger. If you have ever built or used an expense tracker, you have hit this. You lend a friend money. What is it? It is

Most personal finance apps model one thing: money leaving. That assumption quietly breaks half the ledger.

If you have ever built or used an expense tracker, you have hit this. You lend a friend money. What is it? It is not an expense - the money is coming back. It is not a transfer between your own accounts. It is not income. Most apps make you pick one of those three, and whichever you pick makes your reports wrong.

Why the standard schema fails

The typical minimal transaction model looks like this:

Transaction {
  id, date, amount, category, note
  type: INCOME | EXPENSE
}

Everything is forced into a binary. A loan given out has to masquerade as an expense, so your spending total inflates and your net worth silently drops by an amount you still own. A repayment received has to masquerade as income, so your earnings look better than they were.

Neither entry is wrong on its own. Together they produce a ledger that balances and still misrepresents reality.

What the model actually needs

A loan is not a transaction. It is an obligation with a lifecycle, and transactions attach to it:

Loan {
  id
  direction: LENT | BORROWED
  counterparty
  principal
  currency
  opened_at
  status: OPEN | SETTLED | WRITTEN_OFF
}

Repayment {
  id, loan_id, date, amount, note
}

That shape answers the questions people actually ask, none of which the flat model can answer:

  • How much is outstanding on this loan right now?
  • How much am I owed in total, across everyone?
  • Has this person paid anything back since August?
  • What is my position if every open loan settles?

Four edge cases that decide your schema

1. Partial and irregular repayment

Informal loans are not amortised. Someone pays back whatever they have, whenever they have it. Any model that assumes a schedule will not survive contact with real lending between friends.

2. Direction can reverse

You lend someone money, they lend you some later, and the net position flips. If direction is immutable on the loan, that is two loans. If you try to net them automatically, you will produce a number neither party recognises.

3. Multi-currency

Lend in one currency, get repaid in another, and now you need a rate - and a decision about which rate. The honest options are: store both amounts as entered and do not convert, or store a rate per repayment. Converting silently at today's rate produces a balance that changes when nobody paid anything.

4. Write-offs

Some loans are never repaid. The status needs to distinguish settled from written off, because they mean opposite things in a report even though both close the loan.

Why receipts matter more than you expect

The feature request that keeps coming up for informal lending is not analytics. It is a shareable record.

Informal loans run on memory, and memory diverges. A dated PDF showing principal and every repayment resolves a conversation that otherwise turns into two people being sincerely certain of different numbers. That makes export a core feature rather than a nice-to-have.

Offline-first is not optional here

Expense logging has a brutal decay curve: a transaction not recorded within a minute or two is often never recorded. If the app needs a connection to accept an entry, you lose entries - and for a ledger, a missing entry is worse than an imprecise one.

Local-first storage with optional backup sidesteps the whole problem. It also avoids holding other people's financial details on a server, which is a liability you do not want for a solo-maintained app.

Summary

Concern Flat transaction model Loan as an entity
Outstanding balance Manual arithmetic Derived
Total owed to you Impossible One query
Spending reports Inflated by lending Accurate
Partial repayment Unrelated rows Attached to the loan
Shareable record None Generated from the loan

If you are building anything that touches money people lend each other, model the obligation before you model the transaction. Retrofitting it later means migrating every historical row and guessing at intent.

I applied this in IncomeMap, an iOS expense tracker with a loan and debt manager, offline logging and PDF receipts. Interested in how others have modelled write-offs - it is the case I am least happy with.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.