The backend for Nirbhor, a shared flat management app for bachelor housing, live on Google Play.
Node.js, Express and PostgreSQL (Prisma), with 128 automated tests across unit, integration and edge-case suites.
Twelve modules, each documented in doc/api_modules: auth, flat, member, meal, wallet and payment, expense, task, complaint, notification, audit log, monthly summary and feedback.
The parts worth reading:
- Meal cost is a pool, not a price. Members collect meal points per shift, the flat collects grocery spending, and the cost per point only exists when the month closes. See
src/services/meal.service.jsand the monthly summary service. - Rounding adds up. Shares are floored and the remainder is assigned deliberately, so the parts always equal the whole. Covered in
tests/unit/rounding.test.js. - A settlement lock at the edge. While a member's exit settlement is pending,
src/middlewares/settlementLock.jsanswers423 Lockedto anything that would change their balance, so no new endpoint can forget the rule. - Money moves inside transactions. Wallet debits, transaction rows and the audit entry are written in one Prisma transaction.
- Daily rollover on time.
src/jobs/rollover.job.jscloses each flat's day in its own timezone, even if nobody opens the app.
src/
├── routes/ one router per module
├── controllers/ HTTP layer
├── services/ business rules
├── repositories/ database access (Prisma)
├── middlewares/ auth, roles, flat membership, settlement lock, validation, errors
├── validators/ express-validator schemas
├── jobs/ rollover sweep
└── utils/ JWT, OTP, rounding, timezone, FCM and storage helpers
prisma/ schema and migrations (29 models)
tests/ unit, integration, edge-cases
scripts/manual/ ad hoc API walkthroughs against a local server
npm install
cp .env.example .env # fill in the secrets, see comments in the file
npx prisma migrate deploy
npm run dev # http://localhost:3000You need a PostgreSQL database. Firebase Admin (push notifications), Gmail OAuth (emails) and Supabase (file storage) are optional for local work, but the features that use them will not run without credentials.
npm run test:unit
npm run test:integration # needs a running server and database
npm run test:edgeIssues and pull requests are welcome. See CONTRIBUTING.md.
MIT © Md. Zayed Oyshik