How a loan payment changes net worth
In this example, a Rp1,000,000 payment includes Rp800,000 in principal and Rp200,000 in interest.
- Cash
- −Rp1,000,000
- Remaining debt
- −Rp800,000
- Net worth
- −Rp200,000
| Starting position | Liquid assets + investment principal − remaining liabilities |
|---|---|
| Monthly step | Cash += scheduled income + coupons − recurring expenses − full liability payment |
| Liability split | Full payment reduces cash; principal portion reduces liability separately from interest |
| Local persistence | Versioned JSON with atomic write replacement and secondary recovery snapshot |
| Automated coverage | XCTest suites across projections, reference dates, corruption recovery, and dummy mode |
| Pinned source commit | 358b5d3f |
Why balances and history stay separate
Most personal finance apps treat transaction logs as the single ledger for account balances. The moment you forget to log a cash purchase or a bank transfer fee, your displayed balance drifts away from what sits in your bank account.
I built Worthly solo in SwiftUI to answer three everyday questions without linking bank feeds: what I hold, what I owe, and whether my current cash flow reaches a target net worth. First-run onboarding walks from an empty file through an initial account, liability, optional investment, and first entry across four tabs (Overview, Assets, History, and Planning) with consistent IDR formatting.
Account balances stay decoupled from transaction history. Balances are an explicit snapshot you update directly; History records cash movements on its own timeline, so an incomplete log never corrupts your real account total.
Month-by-month planning math
PlanningProjection.swift advances month by month from the saved snapshot:
- Starting net worth:
liquid assets + investment principal − remaining liabilities. - Monthly cash update: Adds scheduled income and active fixed investment coupons after the reference date, then subtracts recurring expenses and full liability payments.
- Principal and interest split: The full payment leaves cash, while only the principal portion reduces remaining liabilities. That prevents principal repayment from being double-counted as a drop in net worth.
- Goal comparison: Reports projected ending net worth, the gap or surplus against the target, and the extra monthly savings needed when behind schedule.
Atomic JSON saves and fallback recovery
FinancePersistence.swift writes a versioned JSON snapshot using atomic file replacement alongside a secondary backup copy:
- If the primary file is truncated or fails decoding, the loader falls back to the secondary backup automatically.
- If both copies are unreadable, the app opens a recovery screen and preserves the damaged files on disk until the user chooses to reset.
- Legacy snapshots without a schema-version key still decode cleanly.
- Turning on sample data stashes the live snapshot first and restores it cleanly when sample mode ends.
Tests and current limits
WorthlyTests covers the accounting and persistence rules in XCTest: principal/interest separation, recurring dates, investment coupons, reference-date cutoffs, balance/history independence, corrupt-primary fallback, and legacy decoding.
Everything described here maps to commit 358b5d3f. Projections run strictly on user-entered assumptions and leave out taxes, inflation, market swings, compounding, and irregular spending. Worthly stays local with zero cloud sync or bank integration; broader VoiceOver and physical-device usability testing are still open.