Project Info
This project did not submit a demo video on Devpost.
Inspiration
Independent physicians running small practices carry a weight most people never see. Every patient visit generates hours of work before and after the appointment itself, work that pulls them away from the reason they went to medical school in the first place. There are tools today that listen to the appointment and write the clinical note automatically. That problem is largely solved. Nobody has built what happens before the patient walks in, and after they leave. Before: the physician scrambles through a chart trying to remember who this patient is, what has changed, and what is urgent. They walk in underprepared. After: they have to convert everything discussed into a document the patient can actually use. Most patients leave without one. They forget 80% of what was said. They miss follow-ups. They come back to the emergency room. We wanted to know: what if the AI read the chart for you, spoke the key points as you walked in the room, and drafted the care plan while you were still in the conversation? Thus, Margin was born.
What it does
Margin is a real-time clinical AI copilot for independent physicians. For this demo it is configured for an endocrinologist managing diabetes patients. If Margin works here, it works anywhere. Before the visit, Margin reads the full patient chart and speaks a clinical brief aloud through Deepgram Aura 2 before the physician enters the room. Hands-free. Eyes-free. The physician can ask follow-up questions by voice. Deepgram nova-2-medical transcribes in real time with clinical keyword boosting and answers come back spoken in under two seconds. Three Fetch.ai uAgents coordinate the pipeline. The Orchestrator receives requests from ASI:One, the Knowledge Agent runs RAG, and the Brief Agent generates the response via Claude. After the appointment the physician types their note. Margin runs parallel RAG queries against 227 chunks of ADA 2025 guidelines, KDIGO protocols, and FDA DailyMed, then generates a five-section evidence-grounded care plan. A two-layer safety check verifies every medication against the patient's allergy list, checks CKD dose contraindications, and validates recommendations against clinical guidelines before the physician sees anything. Eight parallel Claude Haiku evaluators score every care plan and brief from 0 to 100 across medication accuracy, guideline adherence, completeness, billing support, and readability. CMS-validated billing codes appear automatically with reimbursement estimates. At end of day the physician sees a quality scorecard and tomorrow's schedule already prepared.
How we built it
CMS-validated billing codes appear automatically with reimbursement estimates. At end of day the physician sees a quality scorecard and tomorrow's schedule already prepared. How we built it Three Fetch.ai uAgents all mailbox-enabled, communicating over the Agentverse ACP protocol with deterministic seed-phrase addresses that stay stable across restarts. Three Fetch.ai uAgents all mailbox-enabled, communicating over the Agentverse ACP protocol with deterministic seed-phrase addresses that stay stable across restarts. Claude Sonnet 4.6 for all clinical reasoning and Claude Haiku for all parallel tasks like billing and the eight evaluators, cutting evaluation latency roughly 70%. Claude Sonnet 4.6 for all clinical reasoning and Claude Haiku for all parallel tasks like billing and the eight evaluators, cutting evaluation latency roughly 70%. Redis Cloud as the sole database with no SQL and no object storage. The Redis 8.0 native vectorset powers ANN search at 1024 dimensions under 10ms, built entirely from scratch with no existing library. Redis Cloud as the sole database with no SQL and no object storage. The Redis 8.0 native vectorset powers ANN search at 1024 dimensions under 10ms, built entirely from scratch with no existing library. 227 medical guideline chunks embedded with Voyage AI voyage-3, retrieved via four parallel VSIM queries through an 8-worker thread pool in under 200ms. 227 medical guideline chunks embedded with Voyage AI voyage-3, retrieved via four parallel VSIM queries through an 8-worker thread pool in under 200ms. Deepgram nova-2-medical for WebSocket STT and Aura 2 luna-en for TTS. The full voice loop completes in under two seconds. Deepgram nova-2-medical for WebSocket STT and Aura 2 luna-en for TTS. The full voice loop completes in under two seconds. Arize Phoenix with AnthropicInstrumentor auto-tracing every Claude call, RAG spans, and eight evaluator spans logging PASS or FAIL per dimension. Arize Phoenix with AnthropicInstrumentor auto-tracing every Claude call, RAG spans, and eight evaluator spans logging PASS or FAIL per dimension. Sentry initialized before FastAPI mounts with a custom tunnel endpoint to bypass hospital firewalls, session replay, and care plan quality wired as a custom measurement with alerts firing below 60.
Challenges we ran into
Sentry initialized before FastAPI mounts with a custom tunnel endpoint to bypass hospital firewalls, session replay, and care plan quality wired as a custom measurement with alerts firing below 60. Challenges we ran into Redis 8.0 native vectorset had no Python library and no documentation at build time. We reverse-engineered the command syntax and discovered RESP3 protocol was required for correct type handling. Redis 8.0 native vectorset had no Python library and no documentation at build time. We reverse-engineered the command syntax and discovered RESP3 protocol was required for correct type handling. Making Claude clinically safe was harder than expected. A patient with an Aspirin allergy prescribed Aspirin by her cardiologist post-heart attack broke simple allergy checking entirely. Real medical safety needs explicit exception logic. Making Claude clinically safe was harder than expected. A patient with an Aspirin allergy prescribed Aspirin by her cardiologist post-heart attack broke simple allergy checking entirely. Real medical safety needs explicit exception logic. Layer 2 verification had to be specific to be useful. Generic guideline checks meant nothing. Precise rules like checking statin dose against LDL and CV risk actually caught real problems. Layer 2 verification had to be specific to be useful. Generic guideline checks meant nothing. Precise rules like checking statin dose against LDL and CV risk actually caught real problems. Sentry is blocked by hospital IT and ad blockers. We built a tunnel endpoint that validates the DSN and proxies envelopes through our own domain. Sentry is blocked by hospital IT and ad blockers. We built a tunnel endpoint that validates the DSN and proxies envelopes through our own domain. Coordinating three mailbox-enabled uAgents without deadlock required preserving the original sender address across two agent hops and isolating timeouts per agent. Coordinating three mailbox-enabled uAgents without deadlock required preserving the original sender address across two agent hops and isolating timeouts per agent. Running eight evaluators in parallel while keeping the HTTP response unblocked required per-evaluator exception isolation so one timeout never kills the whole response.
Accomplishments we're proud of
Running eight evaluators in parallel while keeping the HTTP response unblocked required per-evaluator exception isolation so one timeout never kills the whole response. Accomplishments that we're proud of Zero drug-allergy false negatives across all three demo patients and more than fifteen test scenarios including physician-approved exceptions correctly bypassed. Zero drug-allergy false negatives across all three demo patients and more than fifteen test scenarios including physician-approved exceptions correctly bypassed. Redis 8.0 vectorset RAG built entirely from scratch with ANN search under 10ms at 1024 dimensions and no separate vector database needed. Redis 8.0 vectorset RAG built entirely from scratch with ANN search under 10ms at 1024 dimensions and no separate vector database needed. Full voice loop in under two seconds from Deepgram STT through Claude to Deepgram TTS, fast enough for real clinical conversation. Full voice loop in under two seconds from Deepgram STT through Claude to Deepgram TTS, fast enough for real clinical conversation. Quality scores consistently above 80 out of 100 on ADA 2025-grounded care plans with a self-correction loop logging both versions to a Redis fine-tuning dataset. Quality scores consistently above 80 out of 100 on ADA 2025-grounded care plans with a self-correction loop logging both versions to a Redis fine-tuning dataset. All three Fetch.ai agents mailbox-enabled with the full ACP ChatMessage pipeline working end-to-end from ASI:One to Brief Agent and back. All three Fetch.ai agents mailbox-enabled with the full ACP ChatMessage pipeline working end-to-end from ASI:One to Brief Agent and back. Production-quality observability with Sentry traces, Arize Phoenix LLM traces, and a care plan quality SLO treating AI output with the same rigour as API latency.
What we learned
Production-quality observability with Sentry traces, Arize Phoenix LLM traces, and a care plan quality SLO treating AI output with the same rigour as API latency. What we learned Redis 8.0 is production-ready as a vector database. VSIM at 1024 dimensions under 10ms eliminates the need for any dedicated vector infrastructure. Redis 8.0 is production-ready as a vector database. VSIM at 1024 dimensions under 10ms eliminates the need for any dedicated vector infrastructure. Parallel evaluation is nearly free. Eight evaluators via ThreadPoolExecutor costs almost no additional wall-clock time. Build quality signals in from day one. Parallel evaluation is nearly free. Eight evaluators via ThreadPoolExecutor costs almost no additional wall-clock time. Build quality signals in from day one. Medical voice is a different domain. General-purpose ASR misses HbA1c, eGFR, semaglutide, and tirzepatide. Deepgram nova-2-medical was better from the very first test. Medical voice is a different domain. General-purpose ASR misses HbA1c, eGFR, semaglutide, and tirzepatide. Deepgram nova-2-medical was better from the very first test. Clinical AI is a verification problem not a language problem. Claude writes fluent prose immediately. Grounding, checking, and scoring the output is 80% of the work. Clinical AI is a verification problem not a language problem. Claude writes fluent prose immediately. Grounding, checking, and scoring the output is 80% of the work. The physician's workflow is sacred. Every prototype that added an AI step got cut. The product inserts into the existing workflow without changing it.
What's next
The physician's workflow is sacred. Every prototype that added an AI step got cut. The product inserts into the existing workflow without changing it. What's next for Margin The next step is a pilot with three independent physician practices, live within 48 hours of onboarding. After that a cardiology configuration with ACC/AHA guidelines and cardiac medication formulary. On the infrastructure side HIPAA-compliant deployment with AWS HIPAA-eligible regions, encryption at rest, and Business Associate Agreements with all vendors. Real FHIR EHR integration and live Dexcom and LibreView CGM APIs are on the roadmap. The simulator already matches their output format exactly so swapping in the real APIs is a single function call. Finally multi-specialty tenant support with Redis key namespacing will let Margin scale to any independent practice. Links Margin Orchestrator Agent The entry-point Fetch.ai uAgent for the Margin Clinical AI system. Accepts ACP ChatMessage requests from ASI:One / Agentverse, routes them through the Knowledge and Brief agents, and returns a spoken clinical brief. Runs as a mailbox agent connected to Agentverse. -Margin Brief Agent A Fetch.ai uAgent that generates AI-powered pre-visit clinical briefs using Claude. Runs as a mailbox agent connected to Agentverse. Margin Knowledge Agent A Fetch.ai uAgent that performs RAG (Retrieval-Augmented Generation) over clinical guidelines using LangChain + FAISS + HuggingFace embeddings. Runs as a mailbox agent connected to Agentverse. ASI:One CHAT Link
Margin
The AI Copilot Built for Endocrinologists
Less charting. More care.
Margin is a real-time clinical AI copilot that reads a patient's full record before you walk in the room, speaks the briefing aloud, drafts a guideline-grounded care plan while you type your note, and catches drug-allergy conflicts before you sign — so the only thing left on your plate is the medicine.
Live Demo · Backend API Docs · Report a Bug
The Problem
Endocrinologists spend 45 of every 60 appointment minutes on administrative work — reviewing charts, dictating notes, coding visits, and cross-referencing drug databases. Only 15 minutes reach the patient. For complex diabetes patients on 6+ medications with CKD staging, CGM data, and multiple comorbidities, that ratio is even worse.
Why Existing Solutions Fail
| Tool | Why it fails |
|---|---|
| Epic / Cerner | Chart navigation is a research project per patient |
| Generic AI note-takers | No clinical reasoning, no RAG over guidelines, no safety checks |
| GPT wrappers | No patient-record grounding; hallucinate doses and diagnoses |
| Dragon Medical | Transcription only — no synthesis, no planning, no verification |
| Ambient AI (Suki, Nuance DAX) | Post-visit only; can't advise during the visit |
Our Solution
Margin provides three things that no existing tool combines:
-
Pre-visit intelligence — A spoken patient brief (real-time TTS via Deepgram Aura 2) generated from the full patient record before the doctor enters the room.
-
Real-time safety — A two-layer verification system (patient-record matching + external guideline grounding via RAG) that flags allergy conflicts, dose violations, and guideline deviations before any output reaches the clinician.
-
Structured care plans — Five-section care plans generated with retrieved evidence from ADA 2025, KDIGO, and FDA DailyMed, evaluated by 5 parallel AI evaluators and scored on a 0–100 quality scale.
Key Features
Clinical Workflow
- Pre-visit spoken brief — Synthesizes HbA1c, CGM metrics, medications, lab trends, and pending items into a bulleted summary, read aloud via Deepgram Aura 2 (
aura-2-luna-en) - Live voice Q&A — Ask follow-up questions via Deepgram
nova-2-medicalSTT; answers are grounded against the patient record and spoken back in real-time - Auto-save clinical notes — Notes are saved to Redis every 4 seconds; never lose work
- Guideline-grounded care plans — RAG over ADA 2025 / KDIGO / FDA DailyMed, with 5-section structured output
- ICD-10 + CPT billing suggestions — CMS-validated codes with national average reimbursement
- Walk-in patient registration — Real-time registration with atomic MR number generation
AI Safety (Verified by Arize)
- Layer 1 — Patient-record verification: allergy conflicts, dosage cross-checking against patient medications, CGM interpretation bounds, CKD dose contraindications
- Layer 2 — External-source verification: RAG-sourced guideline citations that must support every recommendation
- 5 clinical evaluators — Medication accuracy (35%), completeness (20%), guideline adherence (25%), billing code support (10%), plain-language readability (10%)
- Self-correction loop — If Layer 1/2 flags exist, the care plan regenerates once; both versions are logged to a correction dataset for future fine-tuning
Observability
- Sentry — Full distributed tracing across browser + backend; 5 tracked transactions with p95 latency alerts; 10% session replay (100% on errors); ad-blocker bypass via tunnel endpoint
- Arize Phoenix — OpenTelemetry instrumentation on all Claude calls via
AnthropicInstrumentor(); RAG retrieval spans; quality scores logged as Arize metrics
Data & Integrations
- Redis Cloud — Sole persistence layer (30+ key patterns, 8h–30d TTL tiers)
- Redis 8.0 vectorset — Native ANN vector search (no RediSearch module) at 1024 dimensions
- Fetch.ai uAgents — 3-agent multi-agent system (Orchestrator + Knowledge + Brief agents) for Agentverse ACP integration
- APScheduler — Background refresh: CGM every 5 min, labs every 2 hours, adherence every 4 hours, device metrics every hour
- FDA DailyMed — Live drug information fallback (free, no API key required)
How It Works
Doctor opens Margin → selects patient from today's schedule
↓
[Orchestrator Agent] reads full patient record from Redis
↓
[Knowledge Agent] runs 4–5 parallel RAG queries against
ADA 2025 + KDIGO + FDA DailyMed vector index (Redis 8.0 vectorset)
↓
[Brief Agent] calls Claude Sonnet 4.6 → generates spoken brief
↓
[Safety Layer 1] verifies against patient record (allergies, doses, CGM bounds)
↓
Deepgram Aura 2 reads brief aloud while doctor enters room
↓
Doctor speaks notes → Deepgram nova-2-medical transcribes in real-time
↓
[Care Plan Agent] retrieves 12 guideline chunks (4 parallel queries)
+ fetches drug info from FDA DailyMed for up to 5 medications
↓
Claude Sonnet 4.6 generates 5-section structured care plan
↓
[Safety Layer 2] verifies care plan against guidelines
→ if flags exist, regenerates once, logs correction to dataset
↓
5 parallel evaluators score: medication accuracy, completeness,
guideline adherence, billing support, readability → quality score 0–100
↓
Claude Haiku suggests ICD-10 + CPT billing codes (cached 24h)
↓
Visit data archived to Redis (30-day TTL) for continuity
Architecture Overview
┌─────────────────────────────────────────────────────┐
│ BROWSER │
│ React 18 + TypeScript + Vite + TailwindCSS │
│ Deepgram WebSocket (STT) │ Sentry Replay │
└───────────────┬─────────────────────────────────────┘
│ HTTPS/REST + Sentry trace headers
┌───────────────▼─────────────────────────────────────┐
│ FASTAPI BACKEND (Python) │
│ 16 endpoints │ Uvicorn ASGI │ APScheduler │
│ ThreadPoolExecutor (_rag_pool ×8, _verify_pool ×4)│
└──┬──────────┬──────────┬──────────┬─────────────────┘
│ │ │ │
▼ ▼ ▼ ▼
Redis Claude Deepgram Arize Phoenix
Cloud Sonnet 4.6 Aura 2 TTS (OTLP traces)
(vectorset Haiku
+ JSON (billing)
+ cache)
│ │
▼ ▼
Voyage AI FDA DailyMed Fetch.ai Agentverse
embeddings (drug info) (3 uAgents)
Technology Stack
Frontend
| Technology | Version | Purpose |
|---|---|---|
| React | 18.2 | UI framework |
| TypeScript | 5.3 | Type safety |
| Vite | 5.0 | Build tool + dev proxy |
| TailwindCSS | 3.4 | Styling |
| Axios | — | HTTP client |
| Sentry Browser SDK | — | Error tracking + session replay |
| Deepgram JS SDK | — | WebSocket STT + TTS playback |
Backend
| Technology | Version | Purpose |
|---|---|---|
| FastAPI | 0.111 | API framework |
| Uvicorn | 0.30 | ASGI server |
| Pydantic | 2.7 | Request/response models |
| APScheduler | 3.10.4 | Background job scheduler |
| uAgents | 0.12.0 | Fetch.ai multi-agent framework |
| python-dotenv | — | Environment management |
AI / ML
| Technology | Purpose |
|---|---|
Claude Sonnet 4.6 (claude-sonnet-4-6) | Patient briefs, care plans, voice Q&A, end-of-day summaries |
Claude Haiku (claude-haiku-4-5) | Billing code suggestion, 5× parallel evaluators |
Deepgram nova-2-medical | STT — medical terminology + keyword boosting |
Deepgram Aura 2 (aura-2-luna-en) | TTS — spoken patient briefs |
Voyage AI voyage-3 | 1024-dimensional embeddings for medical guidelines RAG |
| Arize Phoenix (OTLP) | LLM observability, distributed traces, evaluation logging |
Infrastructure
| Technology | Purpose |
|---|---|
| Redis Cloud | Sole database: JSON storage, Redis 8.0 vectorset (RAG), caching, sessions |
| Sentry | Error tracking, performance monitoring, session replay |
| Render | Backend deployment |
| Vercel / Netlify | Frontend deployment |
| FDA DailyMed API | Free drug information (no key required) |
AI Components
RAG Pipeline
- Corpus: 227 medical guideline chunks (ADA 2025 Standards of Care, KDIGO kidney guidelines, FDA DailyMed)
- Embedding model: Voyage AI
voyage-3(1024 dimensions, ~200ms per call) - Vector store: Redis 8.0 native vectorset (
VADD/VSIM/VGETATTR) — no RediSearch module required - Query strategy: 4–5 parallel semantic queries via
asyncio.gather+ThreadPoolExecutor - Result: Top 12 deduplicated chunks ranked by cosine similarity score
Multi-Agent System (Fetch.ai uAgents)
- Orchestrator (port 8010,
mailbox=True): Entry point for Agentverse ACP messages; parses patient name, coordinates pipeline - Knowledge Agent (port 8011): Runs RAG via LangChain + FAISS, returns
GuidelineChunk[] - Brief Agent (port 8013): Calls Claude to generate the patient brief, returns ACP ChatMessage
- Protocol: ACP ChatMessage (
uagents_core.contrib.protocols.chat)
Safety Verification System (Arize-monitored)
Layer 1 — Patient Record Check (rule-based, no LLM)
├── Allergy conflict detection (medications vs. allergy list + physician exceptions)
├── Dosage cross-validation (Claude output vs. patient medication record)
├── CGM interpretation bounds (flag if output contradicts CGM data)
└── CKD dosing rules (eGFR-based contraindication detection)
Layer 2 — External Source Check (citation-based)
├── RAG-sourced guideline citations must support each recommendation
├── FDA DailyMed drug interaction cross-check
└── Flags: type (hallucination/warning/critical), severity, suggested correction
Evaluation Pipeline
Quality Score = Σ (weight × pass_rate) × 100
Medication Accuracy: 35% (Claude Haiku evaluator)
Guideline Adherence: 25% (Claude Haiku evaluator)
Completeness: 20% (Claude Haiku evaluator)
Billing Code Support: 10% (Claude Haiku evaluator)
Plain Language: 10% (Claude Haiku evaluator)
All 5 evaluators run in parallel via ThreadPoolExecutor. Results logged to Arize Phoenix. Score < 60 triggers a Sentry quality alert.
Sponsor Technologies Used
| Sponsor | Integration |
|---|---|
| Anthropic | Claude Sonnet 4.6 (briefs, plans, Q&A) + Haiku (billing, 5× evals) |
| Deepgram | nova-2-medical STT (WebSocket) + aura-2-luna-en TTS (HTTPS) |
| Redis | Redis Cloud: JSON store + Redis 8.0 vectorset (RAG) + caching |
| Arize | Phoenix OTLP traces on all Claude calls; 5 custom clinical evaluators |
| Fetch.ai | uAgents 0.12 — 3-agent orchestration + Agentverse ACP integration |
| Sentry | Error tracking, performance monitoring, session replay, AI quality SLO |
Installation
Prerequisites
- Python 3.9+
- Node.js 18+
- Redis Cloud account (or local Redis Stack with vector support)
- API keys: Anthropic, Deepgram, Voyage AI, Arize, Sentry
1. Clone
git clone https://github.com/your-org/margin.git
cd margin
2. Backend Setup
cd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
# Edit .env with your API keys
3. Frontend Setup
cd frontend
npm install
cp .env.example .env.local
# Edit .env.local with your API keys
4. Embed Medical Guidelines (run once)
cd backend
python scripts/embed_medical_sources.py
This embeds 227 medical guideline chunks into your Redis 8.0 vectorset. Takes ~2 minutes.
Environment Variables
Backend (backend/.env)
# AI
ANTHROPIC_API_KEY=sk-ant-...
VOYAGE_API_KEY=pa-...
# Voice
DEEPGRAM_API_KEY=...
# Observability
ARIZE_API_KEY=ak-...
ARIZE_SPACE_ID=...
PHOENIX_COLLECTOR_ENDPOINT=https://app.phoenix.arize.com/v1/traces
SENTRY_DSN=https://...@ingest.us.sentry.io/...
# Data
REDIS_URL=redis://default:PASSWORD@host:PORT
# Agents
AGENT_SEED_PHRASE=margin_orchestrator_seed_2026
# Deployment
PUBLIC_BACKEND_URL=https://YOUR-APP.onrender.com
ALLOWED_ORIGINS=https://YOUR-APP.onrender.com,http://localhost:5173
Frontend (frontend/.env.local)
VITE_API_URL=http://localhost:8000
VITE_DEEPGRAM_API_KEY=your-deepgram-key
VITE_SENTRY_DSN=https://...@ingest.us.sentry.io/...
Running the Project
Backend
cd backend
source venv/bin/activate
uvicorn main:app --reload --port 8000
On startup the backend will:
- Seed mock patient data into Redis (pipeline batch)
- Create the Redis 8.0 vectorset index (
margin_medical_vs) - Register Arize Phoenix OTLP endpoint (background thread)
- Start APScheduler (CGM refresh every 5 min, labs every 2h, adherence every 4h, devices every 1h)
- Start uAgents Bureau (Orchestrator port 8010, Knowledge port 8011, Brief port 8013)
Frontend
cd frontend
npm run dev
Opens at http://localhost:3000. The Vite proxy forwards /api/* to http://localhost:8000.
Running Agents Standalone
cd backend
python multi_agent.py
Running the Evaluation Pipeline
Evaluations run automatically on every POST /api/care-plan call. The response includes quality_score (0–100) and eval_results (5 evaluator verdicts).
curl -X POST http://localhost:8000/api/care-plan \
-H "Content-Type: application/json" \
-d '{"session_id": "your-session", "patient_id": "maria-santos"}'
Embedding Medical Sources (one-time)
cd backend
python scripts/embed_medical_sources.py
Project Structure
margin/
├── backend/
│ ├── main.py # FastAPI app, 16+ endpoints, startup logic
│ ├── multi_agent.py # Fetch.ai uAgents (Orchestrator, Knowledge, Brief)
│ ├── scheduler.py # APScheduler (CGM, labs, adherence, devices)
│ ├── requirements.txt
│ ├── models/
│ │ ├── patient.py # Pydantic models: Patient, CGMData, Appointment, etc.
│ │ └── requests.py # API request/response types
│ ├── services/
│ │ ├── claude_service.py # Claude API (Sonnet 4.6 + Haiku)
│ │ ├── redis_service.py # All Redis read/write operations
│ │ ├── vector_service.py # Redis 8.0 vectorset: VADD/VSIM/VGETATTR
│ │ ├── arize_service.py # 2-layer verification + 5 parallel evaluators
│ │ ├── cgm_simulator.py # Physiological CGM data generator
│ │ ├── tts_service.py # Deepgram Aura 2 TTS
│ │ ├── medical_sources_service.py # FDA DailyMed API client
│ │ ├── langchain_rag_service.py # LangChain + FAISS (Agentverse path)
│ │ └── external_apis_service.py # Dexcom/Withings/FHIR stubs
│ ├── data/
│ │ ├── mock_patients.py # 3 demo patients (Robert Chen, Maria Santos, James Wilson)
│ │ ├── mock_cgm_data.py # CGM simulation parameters
│ │ ├── mock_lab_data.py # Lab reference values
│ │ ├── mock_adherence_data.py # Medication adherence metrics
│ │ ├── mock_schedule.py # Dynamic clinic schedule generator
│ │ ├── icd10_codes.json # CMS ICD-10 code database
│ │ ├── cpt_codes.json # CMS CPT codes + national averages
│ │ └── drug_interactions.json # Drug interaction reference
│ └── scripts/
│ └── embed_medical_sources.py # One-time vectorset seeding (227 chunks)
└── frontend/
├── package.json
├── vite.config.ts # Dev server + /api proxy to port 8000
└── src/
├── main.tsx # Sentry init + React entry point
├── App.tsx # Root component: 5-view state machine
├── types/index.ts # TypeScript interfaces
├── api/marginApi.ts # Axios client: 14 typed API functions
├── components/
│ ├── Dashboard.tsx # Schedule + patient selection
│ ├── BriefChat.tsx # Pre-visit brief + voice Q&A
│ ├── NoteEditor.tsx # Clinical note editor (auto-save 4s)
│ ├── CarePlanDocument.tsx # 5-section care plan renderer
│ ├── BillingCodes.tsx # ICD-10 / CPT selector
│ ├── EndOfDaySummary.tsx # Quality scorecard + tomorrow preview
│ ├── WalkInForm.tsx # New patient registration
│ ├── ArizeAlert.tsx # Safety flag/warning banner
│ ├── CGMPanel.tsx # CGM graph + TIR/GMI/CV metrics
│ └── LoginPage.tsx # Demo authentication
└── hooks/
├── useSession.ts # Session UUID management
└── useDeepgram.ts # Deepgram STT WebSocket + TTS playback
API Overview
| Method | Endpoint | Purpose |
|---|---|---|
POST | /api/session | Create session (8h Redis TTL) |
POST | /api/voice | Generate brief or answer voice Q&A |
POST | /api/save-note | Persist clinical note (24h TTL) |
POST | /api/care-plan | Generate + verify + evaluate care plan |
POST | /api/billing-codes | Suggest ICD-10 + CPT codes (24h cache) |
POST | /api/confirm-billing | Calculate total billed from CPT averages |
POST | /api/walkin | Register walk-in patient |
POST | /api/care-plan/verify | Re-verify doctor-edited care plan |
POST | /api/brief/validate | Validate brief bullets (3 evaluators) |
GET | /api/appointments/{date} | List appointments for date |
GET | /api/end-of-day | Daily summary + tomorrow forecast |
GET | /api/patient/{id}/cgm | Current CGM data (204 if no device) |
GET | /api/patient/{id}/alerts | Active clinical alerts |
GET | /api/patient/{id}/refresh-status | Data freshness timestamps |
GET | /api/patient/{id}/visit-data | Visit history (30 most recent) |
PATCH | /api/appointments/{date}/{id}/status | Update appointment status |
POST | /api/patient/{id}/save-visit | Archive complete visit (30d TTL) |
POST | /api/sentry-tunnel | Sentry proxy (ad-blocker bypass) |
GET | /api/health | Health check |
POST | /submit | Fetch.ai Agentverse ACP endpoint |
Full interactive docs available at http://localhost:8000/docs (Swagger UI).
Demo Walkthrough
Patient 1: Robert Chen — High-Risk T2DM
- Age 67, HbA1c 8.2% (worsening), CKD Stage 3a (eGFR 58), new Semaglutide start
- Demonstrates: CKD dosing alerts, new medication counseling, nephropathy monitoring plan, Penicillin allergy check
Patient 2: Maria Santos — Nocturnal Hypoglycemia
- Age 54, HbA1c 6.8% (stable), FreeStyle Libre 3, overnight CGM dips to 42 mg/dL
- Demonstrates: CGM live panel, TIR graph, allergy exception (NSAIDs → Ibuprofen physician-approved), hypoglycemia management plan
Patient 3: James Wilson — T1DM Pump User
- Age 38, HbA1c 7.1% (improving), Dexcom G7 + Control-IQ, elevated TSH
- Demonstrates: Pump + CGM integration, post-meal spike management, thyroid medication, endocrinology referral
Example Voice Flow
- Select Maria Santos → brief auto-generates and plays aloud
- Ask "What was her lowest glucose overnight?" → answer spoken back in under 2 seconds
- Type clinical note → auto-saves every 4 seconds
- Click "Generate Care Plan" → 5-section plan with quality score
- Click "Suggest Billing Codes" → ICD-10 + CPT with reimbursement estimates
Deployment
Backend (Render)
# Set all environment variables in Render dashboard
# Build command:
pip install -r requirements.txt
# Start command:
uvicorn main:app --host 0.0.0.0 --port $PORT
Frontend (Vercel / Netlify)
# Build command:
npm run build
# Output directory:
dist/
# Set VITE_API_URL to your Render backend URL
Known Limitations
- Authentication: Demo uses dummy auth — no JWT, no role-based access. Production requires a full auth layer.
- CGM & Device Data: Dexcom, Abbott LibreView, and Withings integrations are production stubs — demo runs on physiologically accurate simulation.
- FHIR / EHR: Lab data comes from mock seed — Epic/Cerner FHIR integration is stubbed.
- No Docker: Docker Compose is not yet configured — requires manual dependency setup.
- Single-tenant: Session model is designed for single-doctor demo; multi-tenant requires tenant-scoped Redis key namespacing.
- HIPAA: Demo is not HIPAA-compliant — no PHI encryption at rest, no audit logging, no BAA on third-party services.
Future Roadmap
- Epic + Cerner FHIR integration (labs, medications, problem list)
- Real Dexcom Clarity + Abbott LibreView CGM API integration
- Multi-provider support (tenant-scoped Redis namespacing)
- HIPAA-compliant infrastructure (AWS HIPAA, encryption at rest, audit log)
- Docker Compose for local development
- Fine-tuning pipeline from correction dataset (
margin:corrections:dataset) - Streaming care plan generation (token-by-token UI)
- Patient portal (care plan + education delivery to patient)
- Prescription assistant (e-prescribing integration)
- HEDIS + MIPS quality measure auto-reporting
Contributors
| Name | Role |
|---|---|
| Purva Bansod | Full-stack + AI architecture |
Built with Claude Sonnet 4.6 · Deepgram · Redis · Arize · Fetch.ai · Sentry
Analysis
View
Metric
- 2
Figures cover GitHub contributors during the hackathon window. A co-authored commit counts in full for each author, so per-member totals add up to more than the whole-team figures.
Technology
- AnthropicIn code
- CSSIn code
- FastAPIIn code
- HTMLIn code
- JavaScriptIn code
- LangChainIn code
- PythonIn code
- ReactIn code
- RedisIn code
- Tailwind CSSIn code
- TypeScriptIn code
11 of 11 appear in the indexed code.
AI coding agents
No AI coding agent signals were found in this repository.
Detected from committed agent config files and commit authorship. Absence of a signal is not proof an agent was unused.
Codebase size
Source size
484 KB
Source files
55
Counts recognized source files only; vendored directories, binaries and lockfiles are excluded, so this is smaller than the repository on disk.
Repository
purva-b/Margin-Medical-Copilot
66 files · 601 KB · @ 2fa3739
Structure
Interface
15 files · 23%Screens, components and styles rendered to the user.
API & routing
1 file · 2%Request entry points: routes, handlers and controllers.
Application logic
32 files · 48%Domain rules, services and shared utilities.
Data & schema
3 files · 5%Schema definitions, migrations and data access.
Supporting
Layers are inferred from where files sit in the tree, not from reading the code. A project that names its directories unconventionally will read oddly here — open the file browser to check anything the diagram implies.
Languages
- Python58%
- TypeScript35%
- Markdown6%
- CSS0%
- HTML0%
- JavaScript0%
- Other (1)0%
Share of indexed source by file size. Binary and vendored files are excluded.
Dependencies
backend/requirements.txt
pypi · 23- anthropic
- apscheduler
- arize-phoenix[otel]
- deepgram-sdk
- eval-type-backport
- faiss-cpu
- fastapi
- httpx
- langchain
- langchain-community
- langchain-core
- langchain-huggingface
- openinference-instrumentation-anthropic
- opentelemetry-api
- opentelemetry-sdk
- pydantic
- python-dotenv
- redis
- +5 more
frontend/package.json
npm · 13- @deepgram/sdk
- @sentry/react
- axios
- react
- react-dom
- +8 more
Declared in the repository’s manifests at the indexed commit. A declared package is not proof it is used, and runtime dependencies are listed first.
This project’s features have not been analysed yet.
Export this project's context (description, README, evidence, key source files) to chat with an AI agent elsewhere.