Skip to content
All case studies
12 Jul 2026

Closing the month without an argument

Designing the settlement engine behind Nirbhor: meal pools, wallet transactions, exit settlements and a month close that has to be right to the last taka.

Role
Sole engineer
Timeline
2026
Stack
Node.js, Express, PostgreSQL, Prisma, Firebase

Context

Shared bachelor flats in Bangladesh run on an informal ledger. Rent splits, a cook's salary, groceries bought by whoever was passing the market, and meals counted per person per shift. At the end of the month one member sits with a notebook and works out who owes what.

That person is doing unpaid accounting for their friends, and every disagreement lands on them. Nirbhor exists to take that job away from them.

I built the whole thing: Flutter app, Node.js and Express API, PostgreSQL schema, eleven modules and twenty six business tables.

The problem is not tracking. It is trust.

Any developer can build an expense list. What makes this domain hard is that the output is a number people owe each other, and they have to believe it.

That produces requirements a normal CRUD app does not have:

  • Every figure must be explainable back to the events that produced it.
  • Nothing may silently change after the fact.
  • An arithmetic error of one taka is not rounding noise, it is evidence the system cannot be trusted.
  • The person who benefits from a change must not be the only person who can make it.

The meal pool

The central idea is that a meal has no price until the month ends.

Members accumulate points per shift based on what they said they would eat. The flat accumulates grocery expenses. Only at close does a cost per point exist:

code
cost per point = total approved meal expense / total meal points
member meal cost = member points x cost per point

This is the honest model. Charging a fixed price per meal would mean either overcollecting or running a shortfall, and someone would have to absorb the difference.

It also means the system must be comfortable saying "not yet known" for most of the month, which is a product decision as much as a technical one. The app shows a running projection and labels it as a projection.

Rounding, which is where trust is actually lost

Split 1,000 taka across three members and the naive answer loses a taka or invents one.

code
distributeWithRounding(total, members):
  base      = floor(total / count)
  remainder = total - (base x count)
  everyone gets base
  the manager absorbs the remainder

Floor every share, give the remainder to the flat manager. The parts always sum to the whole, and the rule is stated in the app so nobody discovers it as a surprise. A cent level discrepancy in a system like this is not a rounding artefact to the people using it. It is proof the app is wrong.

The settlement lock

When a member starts leaving, the system calculates what they owe or are owed: their meal cost to date, their refundable fixed contribution, the net.

If they can still add an expense while that calculation is open, the settlement is meaningless.

So a middleware sits in front of every route that could move an exiting member's numbers and returns 423 Locked. Payments stay allowed, because settling up is the whole point of the state they are in.

The important detail is that the lock is enforced in the middleware chain, not inside each service. A rule enforced per service is a rule that the next endpoint forgets.

Transactions and the audit log

Approving a household expense is not one write. It debits every active member's wallet, debits the flat wallet, writes a transaction row per member and writes an audit entry.

All of that is a single prisma.$transaction, and the audit helper takes the transaction client as an argument on purpose. An audit log written outside the transaction can survive a rollback of the thing it claims to describe, which is worse than having no audit log, because now it lies with authority.

The audit log has no write endpoint. Clients can read it. Only the system can append to it.

Month close

Month close is the one job that must not be half done.

  1. Lock the meal pool so no further points can enter it.
  2. Compute cost per point.
  3. Deduct each member's meal cost and write the transaction.
  4. Write a monthly_summaries row per member as a permanent record.
  5. Reset fixed contributions for the following month.
  6. Notify everyone.
  7. Write the audit entry.

Two design points I would defend in any review.

Fixed contributions are deducted at month start, never at close. Deducting them at both would double charge, and deducting only at close would hide the flat's real position all month. Choosing the earlier point means the wallet balance is meaningful on any day, not just on the last one.

A negative balance carries naturally into the next month. No special transaction, no debt object. It is the same number, and it is still negative. Introducing a separate concept for owed money would create two sources of truth for one fact.

Close runs automatically on the last day of the month and can also be triggered by the manager, with a preview endpoint that computes the whole thing and writes nothing. Nobody should have to run an irreversible job to find out what it will do.

Results

Live on Google Play, running real flats through real months.

CONTENT NEEDED: number of flats or members using it, and any feedback worth quoting.

What I would change

Model the wallet as an append only transaction ledger with the balance derived, rather than a stored balance updated alongside transactions. Both are correct while every write is transactional, but a derived balance cannot drift, and in a system whose entire value is trust, "cannot drift" beats "does not currently drift".

Why this project matters to me

It is small enough that I made every decision and large enough that the bad decisions would have shown. Twenty six tables, money moving between members, an irreversible monthly job, and no team to catch me. The habits it forced, transactions around anything that touches money, enforcement at the edge rather than per service, an audit trail that cannot outlive its own transaction, are the ones I bring to work.