Case study · September 2026 — now
LIVESmartCura
A telehealth platform where the vitals, the consult, the prescription and the delivery are one record — with an AI layer that is not allowed to diagnose.
- REST operations
- 251
- OpenAPI schemas
- 421
- Migrations
- 64
- Automated checks
- 368
Role · Sole engineer — API, contracts, portal, apps, firmware
smartcura.appContext
Remote care arrives as four disconnected products. A video call happens in one app, a wearable writes vitals into a vendor dashboard nobody opens, the prescription is a PDF in a chat thread, and the pharmacy delivery is a phone call. The doctor consults on top of a record that is missing half the evidence.
SmartCura is one platform for that loop: an ESP32 monitor and Health Connect feed vitals into a care record, doctors consult and prescribe against it, pharmacy orders dispatch to drivers with live tracking, and an emergency path ties patients back to staff. Four Flutter surfaces and a Next.js portal sit on one NestJS API.
The problem
Four clients, one contract
Patient, doctor, driver and admin surfaces consume the same clinical record. Without a shared contract, each client invents its own idea of an appointment, and the API drifts until the portal is the only thing that still works.
Vitals need provenance, not just numbers
A heart rate from a prototype sensor and a heart rate synced from Health Connect are not the same fact. If the record cannot tell them apart, every later summary is built on sand.
AI in healthcare fails by being helpful
A model that suggests a diagnosis or a dose is the fastest way to harm someone. The interesting engineering problem is capping what the model is allowed to produce, not making it sound better.
Constraints
- One engineer, and coursework running in parallel
- Synthetic data only — the platform is a prototype, not a medical device
- A single VPS is the whole reliability boundary, documented as such
- No clinical write path for the AI: no diagnosis, no medication change
- Every route must be documented before it can be mounted
Decisions
The choices that carried most of the system. Each one lists the alternative that was on the table and the bill that came with the choice.
OpenAPI 3.1 and AsyncAPI are the source of truth; TypeScript and Dart clients are generated from them.
- Not this
- Hand-written clients per app, with the contract written afterwards as documentation.
- Why
- Four clients against one clinical record is exactly the case where hand-written clients drift. A CI test fails the build if a mounted route is missing from the contract, so the contract cannot quietly become fiction.
- The cost
- 251 operations and 421 schemas have to be maintained as code before any client work starts, and a contract change is a four-client change by default.
A transactional outbox with a lease-claiming worker for push, email, AI and notifications.
- Not this
- Writing to the database and calling FCM, SMTP or the model provider in the same request.
- Why
- Dual writes fail in the gap between the two systems, and the failure is invisible: the appointment exists, the patient was never told. The outbox makes the intent durable first, then retries it with leases, backoff and a dead-letter replay path.
- The cost
- A second process to run and monitor, plus every side effect now has to be idempotent, because at-least-once delivery is the guarantee.
The AI layer returns structured artifacts — summary, trend, symptom — every one flagged non-diagnostic and carrying its sources.
- Not this
- A free-text health assistant that answers whatever the patient asks.
- Why
- A bounded artifact can be validated, reviewed and rendered with a disclaimer. Its inputs are assembled server-side from vitals with provenance, conditions, medications and risk scores, so the model summarises evidence rather than guessing at it.
- The cost
- The product feels narrower than a chatbot, and every new question type is a schema change, a prompt change and a review note.
One VPS behind Traefik: API, worker, PostgreSQL, Redis, MQTT broker, LiveKit and ClamAV on one host.
- Not this
- Managed services and a container platform, sized for a load that does not exist yet.
- Why
- At prototype scale, operational surface is the scarce resource. One host is a boundary that can be written down honestly, backed up and restored in a rehearsal, instead of six vendors each with their own failure mode.
- The cost
- No horizontal scaling and one blast radius: the video, the database and the virus scanner share a disk and a reboot.
How it is put together
- Surfaces
- Three Flutter apps (patient, doctor, driver) and a Next.js 15 portal with 68 wired pages, all on generated clients.
- Identity
- Firebase Auth on the clients, exchanged for a __Host- session cookie; opaque tokens stored as hashes, CSRF derived per session.
- API
- One NestJS 11 process serving REST and Socket.IO, with an RBAC policy matrix scoped by organisation and site.
- Worker
- A separate process claims outbox rows with leases, retries and dead-letter replay for push, email, AI generation and notifications.
- Data
- PostgreSQL 18 — 73 tables from 64 migrations — plus Redis for rate limits and ClamAV scanning before uploads reach private R2 storage.
- Devices
- ESP32 with MAX30102, DS18B20 and an OLED provisions over BLE, publishes MQTT-over-WebSocket, and lands in PostgreSQL with UCUM units, range checks, dedupe and a ten-minute replay window.
What broke, and what it taught
A case study that only lists wins is a sales page. These are the defects the audit found in my own system, how each surfaced, and what fixing it takes.
Defect
The patient-app workflow marks its steps continue-on-error, so a green badge can sit above a failing build.
Found by
While writing this page: the README admits the badge is best-effort, and the workflow confirms it.
Fix
Either make the steps blocking or remove the badge. A status that cannot fail is decoration, and decoration on a CI page is a lie with good typography.
Defect
Payments are a deterministic stub while the portal exposes payouts and earnings.
Found by
The status table in the README, cross-checked against the finance screens.
Fix
Label the money surfaces as simulated in the UI until a real provider is wired. A stub that looks settled is worse than a disabled button.
Defect
Four contention and race scenarios from the NFR plan have never been executed.
Found by
The measured-versus-target report: three k6 baseline scenarios ran live, the four hard ones did not.
Fix
Run them against staging with two drivers claiming one order and two devices replaying the same sample, then publish the numbers including the failures.
Defect
The prototype sensor is not clinically accurate, and the data model cannot fix that.
Found by
Firmware notes and the disclaimer.
Fix
Provenance is recorded per reading, so a consumer can tell a prototype device from Health Connect. Accuracy stays a hardware problem and is stated, not hidden.
Evidence
- Public repository: 32 test files across TypeScript and Dart, 9 GitHub Actions workflows
- 368 checks run without a database, including a route-contract test, CSRF coverage and PHI-redaction tests
- 251 REST operations and 421 schemas generated into both clients
- Three k6 baseline scenarios executed against the live deployment: 100% success at 60 iterations/min, p95 under 21 ms
- Sixteen product screenshots in the repository, all synthetic data
Checked 30 November 2026. Repository public: github.com/ashrafulislamse/smartcura. The live demo runs on synthetic data only.