A multi-vendor healthcare marketplace where patients book lab tests, doctor consultations and health insurance in one app — with AI report summaries, a per-marker health dashboard, and a single signed ledger that pays every vendor.
A global test catalogue with per-lab pricing and home-collection fees, lab-owned packages, slot capacity, an eight-state order lifecycle from placed to completed, and offline walk-in bookings that live alongside platform orders in the same tables.
When a lab uploads a PDF or image, Gemini extracts every numeric marker with its reference range, then a second prompt writes a plain-language summary with highlights and specialist suggestions constrained to an eleven-item whitelist. Every AI path degrades to a rule-based fallback so an upload never blocks.
Per-marker sparklines built from every report in order, a deterministic health score over markers with reference bounds, doctors nearby re-ranked by suggested specialty, revocable share links for reports, and reminder emails that fire when a re-test is due.
Labs, doctors and insurers share a single append-only wallet table. Earnings credit on completion, platform fees, ad spend and commissions debit, and a balance is simply the sum. Vendors can buy sponsored listings wallet-first with Razorpay covering the remainder.
Four independent checkout-and-verify flows recompute every price from the database, verify the Razorpay signature with a constant-time HMAC compare, short-circuit on already-terminal records, and flip state inside a transaction. Coupon double-redemption is blocked by a unique index.
Separate dashboards for labs, doctors and insurers covering bookings, slots or plans, coupons, a phone-linked patient CRM, promotions, wallet and analytics. Admin approves vendors, plan commissions and profile change requests, and runs platform-wide analytics and coupons.
A single Next.js 15 App Router codebase: every page is a thin re-export of a view component, and all business logic sits in route handlers under /api/v1 plus a lib layer of thirty modules. PostgreSQL through Prisma is the only source of truth; Redis and Gemini are optional subsystems that the app runs fine without.
Two-stage Docker build on node:20-slim, standalone Next output, runs as a non-root user.
Labs earn on order completion, doctors on consultations, insurers on policy commissions, and all three spend on platform fees and ads. A balance column per vendor drifts the moment two code paths disagree, and payouts need an audit trail.
A single append-only WalletEntry table with signed integer paise, an owner discriminator, and a structured ref_id per event such as order:{id} or fee:{labId}:{period}. Balance is the sum of entries. Adding doctors later kept the original lab ref_id format unchanged so existing idempotency held.
A vendor coupon reduces what the vendor is paid, but an admin coupon must not. Getting this wrong either shorts the vendor or overpays them, and the maths differs for orders, consults and policies.
Coupon lookup prefers vendor-owned codes, and admin codes mark the order as platform-borne with the amount stored in platform_discount. Every payout path then credits gross: total plus platform discount for labs, fee plus discount for doctors, amount plus discount minus commission for insurers. Payable is floored at one rupee.
Verification is driven by the client callback, so a replayed or forged callback, a double click, or a modified price in the request body all had to be harmless.
Each verify route re-fetches the record, asserts ownership and that the stored provider order id matches, verifies the HMAC with a constant-time compare, returns early if the record is already terminal, flips state in a transaction, and records the coupon redemption behind a unique index that swallows duplicates. Prices are always recomputed server-side.
Gemini output is free text in a medical context. It can invent specialties, return malformed JSON, or time out, and none of that may block a lab from uploading a report or a patient from reading it.
JSON response mode plus a guarded parse, array checks on every field, specialty suggestions filtered against a whitelist, and a rule-based fallback summary on any failure. Only AI-generated results are cached so a fallback is retried next time. The profile-level summary is keyed by a hash of the analyte snapshot so it regenerates only on real change.
Labs and doctors still see walk-in patients who never signed up. They needed a CRM that works offline yet reconciles when that patient later books online, without counting manual bookings as platform revenue.
A VendorPatient table unique on vendor and phone. Manual orders carry a null user id and a MANUAL source; platform bookings upsert into the same book by phone, so identities merge silently. Every wallet, fee and GMV query filters to PLATFORM source.