Skip to content

Integrate full GoldenHour app into main (backend + frontend) - #1

Merged
SarmaHighOnCode merged 35 commits into
mainfrom
integration
Jun 20, 2026
Merged

SarmaHighOnCode merged 35 commits into
mainfrom
integration

Conversation

@SarmaHighOnCode

@SarmaHighOnCode SarmaHighOnCode commented Jun 20, 2026 •

Copy link
Copy Markdown
Owner

Brings the complete GoldenHour application from integration into main. main is a strict ancestor of integration, so this is a clean catch-up of the whole app.

What's included

Backend (FastAPI, Python 3.12)

  • All endpoints from API_CONTRACT.md: POST /emergency, GET /emergency/{id}/status, GET /confirm/{token}, POST /confirm/{token}, POST /donor/register, POST /sms/inbound, plus /health, /ready, and the /dev/links · /dev/alerts demo helpers.
  • Three-layer design (routes → services → store) with two interchangeable data stores behind get_store(): InMemoryStore (zero-dependency demo/CI) and SupabaseStore (PostgreSQL + PostGIS).
  • Hospital ranking P(h) = 0.5·prox + 0.3·dept + 0.2·rel with a cold-start reliability gate.
  • Blood-donor matching: ABO/Rh compatibility, PostGIS radius query (donors_nearby RPC + GiST index), sex-aware donation cooldown (90/120 days).
  • Live hospital fetch near the patient's GPS: Google Places API (New) primary, Overpass OSM fallback, region-cached.
  • Venue-local donor synthesis so the blood branch works at any location, not just seeded Jaipur.

Frontend (React 19, Vite, Tailwind)

  • Four screens: Emergency Intake, Live Results, Hospital Confirmation, Donor Registration.
  • Real API client wired to the backend, Supabase Realtime channel for live status, polling fallback.
  • Installable PWA: web app manifest, branded maskable icons, production-only service worker (offline app shell).
  • Motion / Three.js visual layer (GSAP, Lenis smooth scroll, custom cursor).

Infra

  • Docker (docker-compose.yml), Render (render.yaml), Vercel (vercel.json), GitHub Actions CI.

Audit-driven additions (this PR)

A gap analysis against both PRDs and the pitch deck closed three real gaps:

  • GET /confirm/{token} — the confirmation page now shows the real emergency details on load instead of placeholder data.
  • donors_alerted on the results screen is now driven by the API (was hardcoded to 5).
  • Real PWA — manifest + icons + service worker make the "PWA" claim in the deck/README actually installable.

Testing

  • 34 backend tests passing (algorithms + API contract + live confirmation flow). Frontend builds clean on Node 20.x and 22.x.

SarmaHighOnCode and others added 30 commits June 18, 2026 01:19
Build out the GoldenHour backend per the backend PRD, replacing the
stub endpoints and empty service files with a working, tested service.

Core:
- Thin FastAPI routes (main.py) -> services/ -> store.py data layer
- schemas.py mirrors API_CONTRACT.md exactly (incl. SMS "from" alias)
- Three algorithms: hospital ranking (prox/dept/rel score), blood
  matching (ABO table + 5km radius + 90-day cooldown), confirmation
  race resolution (first-to-accept wins, already_confirmed)
- Emergency orchestration + live status with simulated donor responses

Data layer (two interchangeable stores behind get_store()):
- InMemoryStore seeded with 25 Jaipur hospitals + 180 donors (demo/CI)
- SupabaseStore using PostGIS donors_nearby RPC; auto-fallback on init
  failure so boot never breaks
- sql/schema.sql: PostGIS tables, GiST indexes, donors_nearby() RPC
- seed_supabase.py to load the same dataset into a real DB

Infra & docs:
- Dockerfile, docker-compose.yml, .env.example, .gitignore
- CI wired to actually run pytest (3.11/3.12); pr-guard checks for
  conflict markers
- README (root/backend/frontend), index.html meta/description/OG tags
- 24 pytest tests (algorithms + endpoint contract + live flow +
  SupabaseStore via fake client), all passing offline

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Declare SUPABASE_URL (required alongside SUPABASE_ANON_KEY to enable the
real database), plus FRONTEND_URL and CORS_ORIGINS, so a production
deploy uses Supabase instead of silently falling back to demo mode.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Production-readiness improvements to the backend/database path:

- Prefer SUPABASE_SERVICE_KEY for the backend connection (bypasses RLS),
  falling back to the anon key; wire into config + store + render.yaml +
  .env.example
- Add sql/seed.sql (generated by build_seed_sql.py) so the DB can be
  seeded from the Supabase SQL editor as table owner — avoids anon-key
  RLS friction
- Add GET /ready: pings the data layer (503 if unreachable) so a deploy
  can be verified as truly DB-connected vs silently in demo mode
- Document RLS model in schema.sql (default-off + production hardening)
- Add DEPLOY.md: full Render + Supabase runbook (demo vs database mode)
- Tests now 26 (add /ready + ping coverage); docs updated

Co-Authored-By: Claude Opus 4.8 <[email protected]>
- Gate hospital rel(h) on >=20 logged confirmations and renormalize the
  ranking to proximity + department until then, so a fresh deployment ranks
  on prox+dept only instead of trusting seeded reliability it hasn't earned.
- Dispatch blood-needed alerts to the nearest top-K matched donors with an
  explicit "licensed blood bank, not the emergency ward" directive; expose
  recently sent alerts at GET /dev/alerts.
- Make the donation cooldown sex-aware (90 days men / 120 days women) via an
  optional `sex` field on donor registration; absent it, defaults to 90 days.
- Add rare_group (Rh-negative) to the /emergency response and
  unconfirmed_fallback to the /status response.
- Update API_CONTRACT, backend README, .env.example, and the SQL schema/seed
  to match; add 4 tests (30 total, all offline).
Reject lat outside -90..90 and lng outside -180..180 with 422 instead of
computing distances from a failed or spoofed browser geolocation. Applies to
POST /emergency and POST /donor/register; documented in API_CONTRACT.
- Add docs/ with banner, request-flow, and architecture SVGs; embed them in
  the root README (banner + badges, diagrams replacing the ASCII art) and the
  architecture diagram in the backend README.
- Enrich FastAPI/OpenAPI: summary, contact, MIT license, per-tag-group
  descriptions, and a summary on every route so /docs is fully described.
- Refresh the root README API table with the current endpoints and flags.
…conditional header and already_routed simulation
@SarmaHighOnCode SarmaHighOnCode added the enhancement New feature or request label Jun 20, 2026
The frontend confirmation page needs the real emergency details (hospital
name, type, blood group, this hospital's ETA) on load. Without a GET it
always fell back to placeholder data. Adds the endpoint, documents it in
API_CONTRACT.md, and covers it with tests.
donors_alerted was hardcoded to 5; now driven by the API response on every
status poll. Adds a web app manifest, branded maskable icons, and a
production-only service worker for offline app-shell support, fulfilling the
PWA claim in the deck and README.
@SarmaHighOnCode
SarmaHighOnCode merged commit 63fb00a into main Jun 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants