Skip to content
G26karthikPublic

About

Setu: district health resource network. Turns WhatsApp stock updates into shortage forecasts and transfer recommendations, and a person approves every transfer. Firebase, Cloud Run, Gemini.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Setu - District Health Resource Network

Track 3: Smart Health · Build with AI: Code for Communities (Hack2Skill × Google Cloud)

Setu turns the WhatsApp stock updates health workers already send into a live district-wide view, forecasting shortages before they happen and recommending exactly which facility should send what to whom. Every transfer requires an explicit human approval; nothing moves automatically.

Live right now

Setu is deployed in two environments. The Vercel deployment is the first version, and the Google Cloud deployment is the second, main / primary version. Both read/write from the same Firestore/Firebase Auth backend (setu-health-net):

Deployment URL Compute Status
Google Cloud (Primary) https://setu-health-net.web.app Firebase Hosting + Cloud Run (Node + Python) Version 2 (Main)
Vercel https://dashboard-five-eta-84.vercel.app Vercel serverless Functions (Node + Python) Version 1

Anonymous visitors to either URL land on a public landing page (3D network visualization, product explainer, "who it's for") — signing in reveals the live, role-scoped dashboard. See docs/DECISIONS.md §15 for the full, verified-live writeup of the Cloud Run migration, including two real integration bugs found and fixed during the move (Cloud Run's service-to-service auth model, Firebase Hosting's Cloud Run invoker grant).

Read this first

  1. PRD.md — problem, users, scope, competitive research, rubric mapping.
  2. ARCHITECTURE.md — system design, data model, tech choices and why.
  3. setu-design.html — the original standalone interactive prototype. Open it directly in a browser; no build step. This is the UI/UX and interaction model the real dashboard (dashboard/) ports faithfully.
  4. docs/DECISIONS.md — every place the real build deviates from ARCHITECTURE.md, and exactly why, kept up to date incrementally as the project grew: RBAC + multi-tenancy (Blocks A/F), offline-first resilience (Block E), the escalation cron + Slack alerting, and the Google Cloud migration (§15) are all logged here with real, verified-live results — not just written-and-assumed.
  5. docs/SETUP.md — step-by-step runbook for manual account setup (Gemini API key, Twilio WhatsApp Sandbox, Vercel/Firebase deploy, Slack alerting, multi-district provisioning) plus local dev and troubleshooting.
  6. HANDOFF.md — data ownership, what "done" means for this project, and the runbook for moving off a personal developer's accounts onto an institutional one.

What's real right now

  • RBAC: three structurally distinct roles (district_approver, facility_reporter, auditor), Firebase Auth + custom claims, firestore.rules enforcing per-district data isolation (verified live via a real cross-district access attempt, not just written — see docs/DECISIONS.md §14).
  • Multi-tenant: two seeded demo districts (district-nalgonda-demo, district-warangal-demo) proving isolation isn't just assumed for a single-district demo.
  • A real Intake Agent: Twilio WhatsApp/SMS webhook → Gemini Flash structured extraction (English/Telugu/Hindi/code-mixed, real accuracy run and logged) → a confirm-back loop → Firestore, with low-confidence extractions flagged for manual review instead of auto-accepted.
  • A real Forecast Agent: fits a regression trend to each facility/item's reported stock history and predicts a stockout date with a confidence score.
  • A real Allocation Agent: solves a per-item transportation problem with PuLP (open-source LP, not an LLM guess), with a deterministic fallback if the bundled solver ever can't run in a given environment.
  • A real Notify Agent + Approve/Reject endpoint: the only code path allowed to move stock between facilities, and only after a human clicks approve — verified with a real browser click-through, not just an API-shaped request.
  • Dispatch tracking + escalation: delivery confirmation, an overdue- dispatch escalation sweep (real daily cron on both Vercel and Cloud Scheduler), and an optional Slack alert on escalation (docs/SETUP.md §4d).
  • Offline-first: an IndexedDB action queue for approve/reject/confirm clicks made while offline, replayed automatically on reconnect — proven live in a real browser (go offline → queue → reconnect → replay → lands in Firestore), not just code-reviewed.
  • A React + Three.js dashboard (dashboard/) — a public landing page for anonymous visitors, and a live, role-scoped operational dashboard for signed-in users, both sharing one design system.

Repository layout

PRD.md, ARCHITECTURE.md, HANDOFF.md, setu-design.html   - design docs & handoff (read-only reference)
docs/
  DECISIONS.md          - build deviations & why, kept current through the Google Cloud migration
  SETUP.md              - manual setup runbook (start here to go live)
  GAP-ANALYSIS.md        - known, disclosed gaps
firestore.rules, firestore.indexes.json, firebase.json, .firebaserc
dashboard/                                  - the app (deploys to Vercel)
  api/
    webhook/{whatsapp,sms}.js               - Intake Agent (Twilio → Gemini → Firestore)
    agents/forecast.py                      - Forecast Agent (regression)
    agents/allocate.py                      - Allocation Agent (PuLP transportation LP)
    recommendations/decide.js               - Approve/Reject + Notify Agent
    dispatches/confirm.js                   - delivery confirmation
    cron/escalate-overdue-dispatches.js     - overdue-dispatch escalation + Slack alert
    dev/simulate.js                         - drives the real pipeline for demos
  lib/                                      - shared Node logic + the canonical facility dataset
  src/
    components/LandingPage.jsx              - public, pre-login explainer page
    components/PublicNetworkScene.jsx       - landing page's decorative Three.js hero
    components/NetworkScene.jsx             - live, authenticated dashboard's 3D network
    ...                                     - rest of the React dashboard
services/                                   - the SAME app's compute, packaged for Google Cloud Run
  api-node/                                 - Express host wrapping the Node handlers above
  api-agents/                               - Flask host wrapping the two Python agents above
scripts/
  seed.mjs                                  - (re)seed Firestore with synthetic demo data
  create_user.mjs                           - provision a real RBAC account
  test_extraction_fixtures.mjs              - real Gemini extraction accuracy check
.secrets/                                   - service account keys (git-ignored, never commit)

Quick start

# 1. Seed / reset the database (idempotent, safe to re-run)
cd scripts && npm install && npm run seed

# 2. Run the dashboard locally
cd ../dashboard && npm install && npm run dev

Firestore reads/writes are RBAC-gated (firestore.rules) — you'll need a real account to see anything past the public landing page. Follow docs/SETUP.md to provision one, add the required API keys, and deploy (Vercel and/or Google Cloud, both documented).

Constraints preserved from the handoff

  • Human approval required for every transfer. No code path moves stock without an explicit Approve click — see docs/DECISIONS.md section 6.
  • Low-confidence Gemini extractions are flagged, not auto-accepted.
  • No diagnosis/triage scope creep. Nothing in this codebase makes a clinical judgment; it only classifies and moves reported stock data.
  • Budget, stated plainly, not hidden: the original build ran zero-budget end to end (Firebase Spark, Vercel Hobby, Twilio Sandbox, Gemini free tier). Post-submission, the project owner enabled Google Cloud's Blaze plan specifically to migrate compute onto real Cloud Run/Cloud Scheduler (docs/DECISIONS.md §15) — with --min-instances=0/--max-instances caps and a budget alert in place, real spend should stay near $0/month at this project's traffic, but a billing account is genuinely attached now, and that's disclosed here rather than left implied by stale copy.

About

Setu: district health resource network. Turns WhatsApp stock updates into shortage forecasts and transfer recommendations, and a person approves every transfer. Firebase, Cloud Run, Gemini.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages