How adarshs14193/patient-zero works
1. High-level shape
This repository is a three-part system: a React/Vite frontend, an Express/Node backend API, and a separate rag/ AI pipeline package. The product centers on medical bill ingestion, AI audit, dispute generation, and automated dispute deployment.
2. Frontend boundary
The frontend/ app is the user-facing dashboard and onboarding surface. It uses React Router for page-level navigation (Landing, Auth, Dashboard, LegacyDashboard) and is styled with Tailwind. The dashboard is broken into reusable UI modules such as sidebar, insurance vault, upload bar, settings, and status/toast components.
3. Dashboard composition
Inside frontend/src/components/dashboard/, the UI is organized around operational workflows rather than generic pages: insurance policy management, upload/scan actions, theme/state providers, and account/status surfaces. The views/ folder suggests the main dashboard is tabbed or sectioned into areas like home, bill history, and other proceedings.
4. Client-side data access
The frontend talks to the backend API and also to Supabase directly for auth/state synchronization. frontend/src/lib/supabase.js and the presence of realtime-oriented components indicate the UI listens for backend-driven updates, so a dispute can progress without manual refresh.
5. Backend API layer
The server/ app is the orchestration layer. server/index.js bootstraps Express, while server/src/api/ exposes domain routes for authentication, bills, and insurance. authGuard.js indicates protected endpoints, and passport.js suggests Google OAuth-based login or session setup.
6. Core backend domain flow
The bills API is the main workflow entry point: manual upload, Gmail scan, dispute deployment, and retrieval of compiled “arena” data. disputeController.js likely coordinates the bill-to-dispute lifecycle, while route handlers delegate to services rather than doing processing inline.
7. AI and document-processing services
The backend service layer separates responsibilities: aiExtractionService handles bill/document extraction, aiHelper supports model interaction, auditService compiles discrepancies and notes, and ragService bridges to the retrieval-augmented generation logic. This is the AI analysis boundary where raw bill data becomes structured findings and a draft letter.
8. Autopilot and external integrations
gmailService.js scans incoming mail, autoPilotService.js likely coordinates the automated pipeline, and agentService.js runs the dispute agent. The agent path has a primary automation channel and fallback behavior, matching the README’s Playwright-first / Twilio-fallback design. These services are the main integration boundary to third-party systems and hospital portals.
9. Authentication, policy, and secure storage
server/src/config/supabase.js connects the backend to Supabase, which acts as the persistent store and realtime backend. utilis/crypto.js implies sensitive insurance credentials are encrypted before storage, supporting the insurance vault feature in the UI.
10. Separate RAG package
The top-level rag/ directory is its own Node package with scripts and knowledge-base assets (knowledge_base.json, test bill data, audit/matching scripts). This looks like an isolated AI/RAG toolkit or experimental inference pipeline that supports the backend’s ragService/audit flow rather than being purely frontend or backend code.
11. Data lifecycle
The main lifecycle is: user logs in → uploads a bill or triggers inbox scan → backend ingests PDF/email data → AI extraction and RAG audit run against bill + policy context → dispute letter and findings are stored/returned → UI updates in realtime → user can deploy the agent to hospital channels. That is the core architecture diagram path.
12. External systems that matter architecturally
Supabase is the persistence and realtime spine; Gmail API is the autonomous ingestion source; Gemini is the reasoning/extraction engine; Playwright and Twilio are the outbound enforcement channels; hospital billing portals are the final external target. These integrations define the system boundaries more than any internal framework choice.
13. Key repo-level note
There is a naming mismatch between the README and the tree: the frontend directory is named frontend/ in the repo, not client/. Architecturally, though, it still plays the same role as the client application.
14. What to diagram
For an accurate architecture diagram, draw three main zones: browser UI, backend orchestration/API, and AI/RAG/external services. Show Supabase as shared state/storage/realtime, with separate arrows to Gmail, Gemini, Playwright/Twilio, and hospital portals from the backend services.
Main entry points: Dashboard.jsx Dashboard · disputeController.js Dispute Ctrl · agentService.js Dispute Agent · index.js Express App
Components 29
Frontend
React/Vite client for onboarding and operational dashboard
- Landing · Public marketing entry and auth entrypoint
frontend/src/pages/Landing.jsx - Auth · Login and onboarding flow
frontend/src/pages/Auth.jsx - Dashboard · Primary authenticated shell
frontend/src/pages/Dashboard.jsx - Views · Dashboard sections for home, history, and proceedings
frontend/src/views/HomeView.jsx - Sidebar · Primary dashboard navigation
frontend/src/components/dashboard/Sidebar.jsx - Insurance Vault · Policy and credential management surface
frontend/src/components/dashboard/InsuranceVault.jsx - Upload Bar · Bill upload and scan actions
frontend/src/components/dashboard/FloatingUploadBar.jsx - Supabase Client · Frontend auth and realtime state access
frontend/src/lib/supabase.js
Backend
Express API, orchestration, and domain services
- Express App · API bootstrap and request routing
server/index.js - Auth API · Authentication and session endpoints
server/src/api/auth.js - Bills API · Bill ingestion and dispute endpoints
server/src/api/bills.js - Insurance API · Insurance policy endpoints
server/src/api/insurance.js - Dispute Ctrl · Coordinates bill-to-dispute lifecycle
server/src/controllers/disputeController.js - AI Services · Extraction, audit, and model helper layer
server/src/services/aiExtractionService.js - RAG Bridge · Backend bridge into retrieval and matching logic
server/src/services/ragService.js - Autopilot · Automation coordinator and agent routing
server/src/services/autoPilotService.js - Gmail Scan · Inbox ingestion for bill discovery
server/src/services/gmailService.js - Dispute Agent · Outbound deployment agent for hospital portals
server/src/services/agentService.js - Supabase Sync · Persistent state and realtime backend connection
server/src/config/supabase.js - Crypto · Sensitive credential encryption
server/src/utilis/crypto.js
RAG
Standalone retrieval and audit toolkit
- RAG Chain · Standalone retrieval and generation pipeline
rag/rag_chain.js - Unified Audit · Audit and matching workflow for bills and policy context
rag/unifiedAudit.js - Knowledge Base · RAG reference corpus and sample bill data
rag/knowledge_base.json
Other components
- Supabase · Persistence and realtime spine
- Gemini · Reasoning and extraction engine
- Playwright · Primary portal automation channel
- Twilio · Fallback outbound channel
- Gmail API · Email ingestion source
- Hospital Portals · Final dispute destination
Connections 28
- Landing → Auth: entry · Users move from public landing into auth flow
- Auth → Supabase Client: login · Client authenticates and syncs state
- Dashboard → Views: renders · Dashboard composes the sectioned operational views
- Dashboard → Sidebar: navigates · Dashboard shell uses sidebar navigation
- Dashboard → Insurance Vault: manages · Insurance policy data is managed in the vault UI
- Dashboard → Upload Bar: scans · Upload bar starts bill ingestion and scanning
- Dashboard → Supabase Client: syncs · Dashboard listens for realtime backend state
- Supabase Client → Supabase: connects · Frontend talks to Supabase directly
- Express App → Auth API: routes · Express mounts authentication routes
- Express App → Bills API: routes · Express mounts bill workflow routes
- Express App → Insurance API: routes · Express mounts insurance routes
- Auth API → Supabase Sync: uses · Auth endpoints persist and read shared state
- Bills API → Dispute Ctrl: delegates · Bill requests are coordinated by the dispute controller
- Insurance API → Crypto: protects · Insurance credentials are encrypted before storage
- Dispute Ctrl → AI Services: analyzes · Controller invokes extraction and audit services
- Dispute Ctrl → RAG Bridge: augments · Controller enriches disputes with RAG context
- Dispute Ctrl → Autopilot: orchestrates · Controller hands off automation execution
- Autopilot → Gmail Scan: ingests · Autopilot can trigger inbox scans
- Gmail Scan → Gmail API: reads · Email scanning uses Gmail as source
- AI Services → Gemini: calls · Extraction and analysis rely on Gemini
- RAG Bridge → RAG Chain: invokes · Backend bridges to the local RAG pipeline
- RAG Chain → Unified Audit: runs · Pipeline produces audit and matching outputs
- Unified Audit → Knowledge Base: consults · Audit logic uses the knowledge base and samples
- Autopilot → Dispute Agent: launches · Automation service starts the dispute agent
- Dispute Agent → Playwright: primary · Primary portal automation uses Playwright
- Dispute Agent → Twilio: fallback · Fallback channel uses Twilio
- Dispute Agent → Hospital Portals: submits · Agent deploys disputes to hospital portals
- Supabase Sync → Supabase: stores · Backend persists system state in Supabase