Skip to content

About

Backend for Nirbhor, a shared flat management app: Node.js, Express, PostgreSQL (Prisma), 128 tests

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

nirbhor-api

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.

What it handles

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.js and 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.js answers 423 Locked to 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.js closes each flat's day in its own timezone, even if nobody opens the app.

Layout

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

Running it locally

npm install
cp .env.example .env        # fill in the secrets, see comments in the file
npx prisma migrate deploy
npm run dev                 # http://localhost:3000

You 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.

Tests

npm run test:unit
npm run test:integration    # needs a running server and database
npm run test:edge

Contributing

Issues and pull requests are welcome. See CONTRIBUTING.md.

License

MIT © Md. Zayed Oyshik

About

Backend for Nirbhor, a shared flat management app: Node.js, Express, PostgreSQL (Prisma), 128 tests

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages