ALL PROJECTS/DDF — DOCTOR DIET FAMILY

Overview

DDF (Doctor Diet Family) is a full-stack healthcare SaaS platform that connects families with qualified diet doctors for ongoing, subscription-based nutrition care. A single family head manages an account for the whole household — themselves plus dependent members — discovering doctors, subscribing to plans, and giving each member their own diet plans, chat thread, and video consultations. The product ships as three client surfaces backed by one API: a React web application (which also hosts the admin console) and two Flutter mobile apps, one for patients and one for doctors, published for iOS and Android.

Walkthrough

A short product walkthrough of DDF — Doctor Diet Family.

Problem

Continuous nutrition care is inherently multi-party and stateful: a doctor curates reusable meal templates, assigns them to individual patients, and follows adherence over time; patients log meals, hydration and wellness daily; both sides message and hold video calls; and money flows in from families and out to doctors — all under strict quotas and medical-data privacy. The engineering problem was to model that lifecycle precisely across web and mobile while keeping payments idempotent, protected health information (PHI) private, real-time chat and calls reliable, and the whole system able to serve a few thousand users on modest managed infrastructure. It also had to bill customers in their own currency without putting slow third-party calls on the checkout path.

System Design

How It Works

01/04
01

Subscription & Payment

A family head subscribes to a doctor's plan through Stripe Checkout, with payment confirmation converging idempotently and the doctor gating activation.

  1. 1Family head calls POST /subscriptions/create/; a guard chain validates the plan, profile completeness and the three-doctor cap, then prices the plan server-side in the caller's detected currency
  2. 2Backend opens a Stripe Checkout session with the subscription id bound as client_reference_id and metadata at session and payment-intent level, returning the checkout URL
  3. 3Payment confirms through three converging paths — signed webhook, authenticated status poll, and unauthenticated confirm — all funnelling into one idempotent activator guarded by a global ProcessedStripeEvent ledger
  4. 4A new subscription lands PENDING (payment held, refundable) and notifies the doctor to accept or reject
  5. 5On accept, per-member message and video-call quota trackers are created and the subscription goes ACTIVE; on reject, Stripe issues an automatic refund
02

Video Consultations

Instant and scheduled video calls run on a shared Jitsi/WebRTC room with WebSocket signalling and strict quota enforcement.

  1. 1A caller starts an instant 'ring' (POST /start-now/) or books a scheduled slot (POST /book/), which checks and decrements call quota under a row lock
  2. 2A fresh Jitsi room is created and an INCOMING_CALL / CALL_BOOKED push is sent; the receiver polls /incoming/ and answers or rejects
  3. 3Both participants open the shared Jitsi room; a VideoCallConsumer WebSocket validates participants and relays WebRTC offer/answer/ICE
  4. 4The call ends idempotently to COMPLETED, while a 60-second no-answer ring auto-expires to MISSED and refunds the quota
  5. 5Doctors may also run quota-exempt clinical assessment calls, recording structured per-body-area findings against the session
03

Diet Plan Lifecycle

A doctor builds reusable templates, assigns them as immutable snapshots, and follows patient adherence over time.

  1. 1A doctor builds a reusable DietPlanTemplate from the admin-managed food database, requiring at least one item
  2. 2Assigning a template snapshots its items into a new plan so later template edits never leak into assigned plans, and any prior active plan is deactivated first
  3. 3The patient logs daily meal tracking, hydration and wellness — skipped or partial meals require a reason — upserted per day
  4. 4The backend computes adherence (completion rate, hydration goals, last activity) and raises exception flags such as LOW_MEAL_ADHERENCE or MEAL_LOG_STALE
  5. 5A Celery beat task sends a daily diet-reminder FCM push to every patient with an active plan
04

Doctor Earnings & Payouts

Accepted subscriptions credit a doctor's wallet ledger, hold the funds, then settle to their bank via admin-driven payouts.

  1. 1On subscription acceptance or renewal auto-activation, the doctor's DoctorWallet is credited their configurable share (default 75%) of the gross charge via an idempotent ledger write, normalised to PKR
  2. 2Each earning is held (default 72 hours) as PENDING; a Celery task matures held earnings to AVAILABLE
  3. 3An admin reserves a doctor's available balance into a Payout, snapshotting the doctor's bank details
  4. 4The admin marks the payout paid with a bank reference, or cancels it to return funds to the wallet, through a pluggable provider (manual Stripe now, local bank API stubbed for later)

Key Features

  • Doctor discovery, self-onboarding and admin approval / rejection / suspension with an audit trail
  • Subscription plans with per-member message and video-call quotas, three-doctor family caps and expiry reminders
  • Stripe Checkout with server-side multi-currency pricing, idempotent activation and automatic refunds on doctor rejection
  • Reusable diet-plan templates assigned as immutable per-patient snapshots, with daily meal, hydration and wellness tracking
  • Doctor-facing adherence summaries and history with automatic exception flags (low adherence, stale logs)
  • Instant 'ring' and scheduled Jitsi/WebRTC video calls plus quota-exempt structured clinical assessments
  • Real-time in-app chat with a 24-hour unanswered-message SLA alert and private, signed-URL medical report uploads
  • Doctor earnings wallet with a held-then-available ledger and admin-driven payouts, plus FCM push and in-app notifications

Outcomes

  • Hardened for ~3,000 users: composite indexes on hot paths, N+1 removals proven by query-count tests, cached public reads, and FX lookups moved off the checkout request path
  • PHI kept private end to end — medical reports and IDs stored as private DigitalOcean Spaces objects served only via short-lived signed URLs, tokens in HttpOnly cookies, API docs gated to staff
  • Payments made safe under retries and lost sessions via a global ProcessedStripeEvent ledger plus per-row guards, making activation and refunds idempotent across webhook and client-confirm paths
  • Operable by design: containerised, health-check-gated deploys across four environments via GitLab CI/CD, with Sentry/GlitchTip errors, OpenTelemetry tracing and per-request structured logs

More work

AirAds preview
ADTECH PLATFORM

AirAds

Map-based discovery — the right nearby business, right now

VIEW PROJECT