Healthcare · Mental health
Real-time EEG data pipeline for clinical therapy sessions
NestJS backend with dual databases (MongoDB + PostgreSQL), MQTT ingestion for live EEG sensor data, and multi-role clinical workflows.
Domain: Healthcare / Mental Health / Neuroscience Engagement: Client project (backend ownership, embedded with client's in-house team) Team Size: Backend-focused
A mental health startup was building a neurofeedback therapy platform that required processing real-time EEG (electroencephalogram) brain data during therapy sessions. The client had an in-house team handling frontend and product and brought us on to own the backend end-to-end.
The surface requirements looked familiar — patient management, scheduling, reports — but the real engineering problem sat underneath:
Off-the-shelf healthcare platforms couldn't handle the real-time EEG pipeline or the specialized neurofeedback workflow, and none of them could be extended to without forking.
A full backend for the therapy management platform: real-time brain data ingestion, session lifecycle, clinical reporting, and multi-role access — delivered while the client's in-house team owned frontend and product.
| Role | Capabilities |
|---|---|
| Patient | View sessions, reports, progress |
| Doctor | Manage patients, run sessions, write reports |
| Admin | Clinic management, staff oversight |
| Finance | Billing, payment tracking |
Clinical observations evolve: each therapy protocol defines its own set of notes, measurements, and scoring fields, and protocols change over time. Forcing that into a rigid relational schema would guarantee either painful migrations every protocol update or a dumping-ground JSON column that loses all query ergonomics. Patient–doctor–clinic–billing data, on the other hand, is classically relational — every useful query joins across those entities, and referential integrity is non-negotiable (you do not want a patient record orphaned from a clinic).
The decision: MongoDB for clinical / session / protocol data (schema flexibility with Mongoose validation at the edges), PostgreSQL via TypeORM for the relational core (identity, assignments, billing, audit). Each write path is owned by exactly one store; cross-store operations go through an application-level coordinator that is transactional where it must be and idempotent everywhere else. The boundary is explicit in the code structure so no engineer has to guess which database a given entity lives in.
EEG data is not a batch upload problem. Samples arrive continuously during a session, must be bound to the correct session + patient + device, and cannot be silently dropped — a gap in data is a gap in a clinical record.
Sessions move through scheduled → in-progress → ingesting → completed → reported, with transitions gated by clear preconditions (a session cannot be in-progress without a bound device; cannot be reported without persisted samples). State lives in PostgreSQL; stream data lives in MongoDB; the state machine is the single place that guarantees they stay consistent.
Every identity-scoped entity carries a clinicId. ORM-layer query interceptors inject the current session's clinic scope into every read so "forgot the where clause" isn't a privilege-escalation bug. The same scope gates Mongo queries for session and EEG data. UI-level gating exists for ergonomics; security is enforced at the API and data layers so a compromised frontend cannot cross clinic boundaries.
Report generation, email delivery, and progress-aggregate recomputation all run as Bull jobs. Each carries an idempotency key; retries use exponential backoff; failed jobs surface through the error-tracking pipeline. Reports are versioned — regenerating a report produces a new immutable version rather than overwriting — because clinical decisions may reference a specific report snapshot and history cannot be rewritten.
Four roles (Patient, Doctor, Admin, Finance) are enforced through API-layer guards that resolve role + clinic scope from the validated JWT. The same role claims drive audit-log attribution so every clinical mutation is traceable to a specific actor.
Owning the backend while the client owned frontend and product meant contract discipline was the project's most important tool. API schemas were defined first, reviewed jointly, and treated as the source of truth — their frontend consumed them directly, and breaking changes surfaced as build failures on their side within minutes. Code review cut across both teams; incidents were triaged together. The pattern let a small backend team operate as a reliable seam in a larger product organization rather than a black box.
| Layer | Technology |
|---|---|
| Backend | NestJS 8, TypeScript 4.3 |
| Clinical / session store | MongoDB (Mongoose) |
| Identity / billing / relational store | PostgreSQL (TypeORM) |
| Queue | Bull (Redis-backed) |
| Real-Time | MQTT (TLS) for EEG sensor data |
| Storage | AWS S3 (per-clinic path scoping, signed URLs) |
| AWS SES | |
| Monitoring | Sentry + structured logs with correlation IDs |
| Auth | JWT with refresh rotation, API-layer role + clinic guards |
We owned the backend for a real-time clinical data product — MQTT-based EEG ingestion, a deliberately bicameral data model, state-machine-driven sessions, multi-clinic isolation, and audit-grade reporting — while working alongside the client's in-house frontend and product teams. This is the kind of engagement where getting the boundaries right, both between systems and between teams, determines whether the product scales past its first five clinics or collapses under them. It scaled.
More recent work
Healthcare · Patient management
A six-app healthcare ecosystem — the product our client took to Shark Tank
Patient app, resident web, staff portal, admin dashboard, shared SDK, and an AI emergency dispatcher — all sharing a single backend with role-isolated access. Built for a healthcare startup that was later featured on Shark Tank with the product we delivered.
Read the case study
Transportation · Smart city
Multi-modal routing and cashless ticketing for public transit
Proprietary IP we built and productised — launched on the App Store and Play Store. 150+ APIs, dynamic fare engine, real-time vehicle tracking, ONDC-certified, and a voice AI for 250+ metro stations.
Read the case study
Tell us what you're trying to build. Discovery calls this week, scope within 3 business days.