// 01 The Core Problem: Rigid Category Traps
At the end of the month, people check their banking app and see that a substantial sum disappeared — but they cannot pinpoint where. Most existing expense apps force users into rigid, predefined categories ("Food", "Bills", "Shopping"). If you want to track "Specialty Coffee Roasters", "Track Day Expenses", or "Server Hosting", you're forced to lump them into vague catch-all buckets.
The Solution: SpendSense was engineered to adapt to the individual. It empowers users to define custom categorical trees and delivers 1-day, 7-day, 30-day, and 365-day granular spending analytics.
// 02 Architecture Evolution: Migrating from Firebase to Node/MongoDB
SpendSense started as a pure Firebase/Firestore mobile prototype. While Firestore allowed rapid initial prototyping, it quickly fell short when I planned the friend-based group expense splitting feature:
Document-relational schemas, atomic $set and $push operations, custom aggregation pipelines for calculating pairwise net debt balances, and full control over JWT middleware.
NoSQL document security rules made complex bilateral friend approval logic and cross-user balance queries prohibitively convoluted and costly.
I rebuilt the entire backend using an MVC architecture with Express.js, MongoDB via Mongoose, password hashing with bcrypt, and stateless JWT token authentication, deployed on Render.
// 03 Peer Bill Splitting Engine
College students and roommates frequently split grocery trips, dinners, and travel tickets. SpendSense incorporates a Splitwise-like peer ledger:
- Friend Discovery: Send and accept friend requests via user email/handle.
- Even or Custom Split: Split an expense evenly across N participants, or allocate custom rupee amounts per person.
- Net Debt Simplification: Calculates net who-owes-whom across multiple group transactions so friends settle up with minimal cash transfers.
// 04 The Hard Technical Problem: Bilateral State Desync
During early development of the Splitwise feature, sending a friend request from User A to User B showed as "Sent" on User A's client, but User B's notifications often failed to reflect the pending request until an app restart, or worse, accepted requests left User A in a permanently "pending" state.
The Root Cause: The initial database design kept unilateral friend arrays on the User document without transactional locking. If User B accepted while User A was submitting an expense, race conditions caused partial writes.
The Fix:
- Refactored friendships into a dedicated
Friendshiprelational schema with states:PENDING,ACCEPTED, andDECLINED. - Added compound indexing:
{ requester: 1, recipient: 1 }, { unique: true }to prevent duplicate pending invites. - Implemented a synchronized polling/refresh pipeline on the Flutter Provider layer with cached optimistic updates and error rollback.
// 05 REST API Specification
Key REST endpoints engineered and tested with Postman:
// 06 What I Learned & Next Steps
- Backend Rigor: Writing your own REST API with MongoDB and Express is vastly superior for relational data modeling than relying purely on client-side BaaS SDKs when multi-user relations are involved.
- State Decoupling: Provider's clean separation enabled swapping the data repository from Firebase to our custom HTTP API client with zero changes to UI widgets.
- Next Steps: Add camera OCR receipt scanning using on-device text recognition to automatically extract line items into categories.