MBS Mobile API
Backend Developer · Mercan Brilliant Schools
Overview
A NestJS service that reuses the school's existing database, JWT secret and session store while adding guardian and student self-service. It owns the newer relational side of the platform — guardians, devices, activation codes, fees, payments and receipts — through Prisma, and runs REST plus a raw WebSocket chat transport designed for multiple PM2 instances.
What I did
- 01Built the PIN auth lifecycle: activation code, PIN setup, login, new-device OTP, refresh rotation, logout and device revocation.
- 02Added Prisma migrations for guardians, devices, activation codes, fees, payments and receipts.
- 03Built the fees and payments API, with server-calculated totals in kobo and Paystack webhook handling.
- 04Added a 10-minute reconciliation job that re-checks PENDING payments older than 5 minutes.
- 05Built offline-first chat on REST + WebSocket with an incremental sync endpoint, Redis pub/sub and presence.
- 06Added admin endpoints for issuing activation codes, unlocking accounts and revoking devices.
- 07Added rate limiting, health checks and development diagnostics.
Key features
- Guardian PIN onboarding with Argon2-hashed PINs and activation codes
- New-device OTP verification and trusted-device management
- Fees, payments, virtual accounts and receipts
- Paystack webhook verification and payment reconciliation
- Result checker and attendance notifications
- Offline-first chat sync for mobile clients
- Health and diagnostics endpoints
Bugs fixed & failure modes handled
A client could have submitted its own payment amount.
FixThe server calculates every total; the app only sends the invoice/reference, and amounts are stored as integer kobo.
Duplicate Paystack events could mark a payment successful twice.
FixEvents are signature-verified, re-verified with Paystack by reference, and duplicate deliveries return { received: true, duplicate: true }.
A missed webhook left a payment PENDING forever.
FixA scheduled reconciliation job re-checks PENDING payments older than five minutes every ten minutes.
Refresh tokens sitting in plaintext would widen a database leak.
FixOnly SHA-256 hashes of refresh tokens are stored; device secrets are hashed too.
A stolen PIN alone could sign in from a new device.
FixNew devices must pass an OTP challenge; ICT can also lock the account or revoke every device.
Chat sync could duplicate messages after a reconnect.
FixClients keep a SQLite outbox and sync incrementally from a cursor instead of re-sending the whole conversation.
Integrations
- Paystack payments and webhooks
- Infobip OTP / SMS
- Redis pub/sub and presence
- PostgreSQL via Prisma
- MongoDB school database
- Raw WebSocket chat transport
- PM2 multi-instance deployment
Engineering highlights
- PINs use Argon2; refresh tokens and device secrets are stored only as hashes.
- Payment correctness is enforced server-side, not in the mobile client.
- The chat transport is built for more than one API instance.
Tools used
- NestJS
- TypeScript
- Prisma
- PostgreSQL
- MongoDB
- Redis
- WebSocket
- Argon2
- JWT
- Paystack
- Infobip
- PM2
- Vitest
Tools & access needed
- Node.js 24+ and npm
- PostgreSQL and MongoDB
- Redis for pub/sub, presence and multi-instance chat
- Paystack test/live keys and a webhook tunnel (for example ngrok) locally
- Infobip credentials for OTP/SMS
- The school's existing JWT secret and session store
Gave guardians a secure self-service path into the school without opening up the internal staff portal.
