Skip to content

SpartaKushK/treehacks2026

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CareSync — AI-Powered Elderly Care Platform

TreeHacks 2026

CareSync is an end-to-end healthcare platform where AI agents autonomously monitor patient health, detect anomalies, triage alerts, consult patients via a talking avatar, and book appointments — all with full observability and cryptographic trust.

Architecture

/
  apps/web/              Next.js 14 (App Router) — Dashboard + Patient UI + API
  apps/api/              Python FastAPI — Doctor Agent backend
  ios/                   iOS + Apple Watch app (HealthKit integration)
  packages/shared/       Shared TypeScript types, Zod schemas, LLM abstraction
  mcp-server/            Model Context Protocol server for healthcare tools
  Doctor_Agent_for_TreeHacks/   Doctor Agent (scheduling, triage, calendar)

Quick Start

pnpm install
cd apps/web && npx prisma db push && cd ../..
pnpm dev

Open http://localhost:3000.

The database auto-seeds on first API request with users (pari, alex, dr_smith) and 30 days of health metrics.

Demo Flow

1. Watch Trigger

Tap "Trigger Alert" on the Apple Watch. Haptic feedback confirms. Synthetic health data (low sleep, high resting HR, irregular heart rhythm) uploads to the backend via POST /api/health-data.

2. Clinical Dashboard — Anomaly Detection

On the Clinical Dashboard (/dashboard/anomaly), the anomaly appears in real-time with:

  • Severity score (0–100)
  • Flags: SLEEP_DROP, RHR_SPIKE, STEPS_DROP, SYMPTOM_SPIKE
  • Agent's autonomous triage decision and urgency level
  • Live patient metrics (auto-refreshes every 30s)

3. Trace Inspection

Click into any alert to view the full chain:

  1. Anomaly Detection — flag detection and scoring from wearable data
  2. Secretary Agent Reasoning — LLM-powered analysis with tool-calling
  3. PubMed Evidence Lookup — clinical studies and guidelines from NCBI
  4. Triage Decision — intake questions, urgency scoring, escalation
  5. Appointment Booking — slot negotiation and calendar integration

Each step is logged with actor, event type, timestamp, and full data payload.

4. Patient Voice Consultation

At /patient/call, the patient speaks with Dr. Smith — a HeyGen streaming avatar:

  • Context-aware greeting referencing the specific anomaly (elevated HR, low sleep)
  • Real-time voice conversation via Deepgram STT + HeyGen TTS
  • AI doctor responses generated by Claude with the full health context
  • Live transcript and clinical entity extraction (symptoms, medications, allergies)
  • Red flag detection and automated triage actions
  • 12-language support

5. Appointment Booking

The patient's agent and doctor's agent negotiate appointment slots autonomously:

  • Scheduler Agent checks Google Calendar availability
  • Doctor Agent proposes slots from the doctor's calendar
  • Patient Agent accepts and confirms
  • Booking appears on Google Calendar and in the patient's appointments view at /patient/appointments

Environment Variables

Copy .env.example to .env.local:

cp apps/web/.env.example apps/web/.env.local
Variable Required Description
ANTHROPIC_API_KEY Yes Claude LLM for agent reasoning, voice responses, entity extraction
OPENAI_API_KEY No Alternative LLM provider (GPT-4o-mini)
HEYGEN_API_KEY Yes Streaming avatar for Dr. Smith voice consultations
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY Yes Clerk authentication
CLERK_SECRET_KEY Yes Clerk server-side auth
SUPABASE_URL Yes Supabase project URL for health data storage
SUPABASE_SERVICE_ROLE_KEY Yes Supabase service role key
DATABASE_URL Yes Postgres connection string (Supabase)
GOOGLE_CLIENT_ID No Google Calendar OAuth
GOOGLE_CLIENT_SECRET No Google Calendar OAuth
NEXT_PUBLIC_BASE_URL No Defaults to http://localhost:3000

Deploy to Vercel

  1. Push to GitHub
  2. Import in vercel.com/new
  3. Set root directory to apps/web
  4. Add environment variables (see table above)
  5. Deploy — the build runs prisma generate && next build

Key API Endpoints

Endpoint Method Description
/api/health-data POST Receive health data from iOS/Watch, run anomaly detection
/api/trigger POST Secretary Agent — route health triggers to sub-tools
/api/anomaly/live GET Live patient metrics for the clinical dashboard
/api/anomaly/history GET Alert history with filtering and pagination
/api/voice/respond POST Generate doctor responses + extract clinical entities
/api/heygen/token POST Create HeyGen streaming session tokens
/api/calendar/events GET Fetch calendar events for a patient
/api/patient/agent POST Patient agent stub (receives slot proposals from Doctor Agent)
/api/demo/trace/:traceId GET Retrieve full trace for inspection

Secretary Agent

The Secretary Agent is an LLM-powered orchestrator that receives health triggers and autonomously chains tools:

  • analyze_anomaly — evaluates health anomaly severity and urgency
  • lookup_clinical_evidence — searches PubMed and clinical guidelines
  • triage_patient — runs intake questions, books appointment if needed
  • get_health_summary — retrieves 30-day health trends
  • schedule_appointment — finds available slots and books via Google Calendar
  • notify_doctor_agent — alerts the Doctor Agent for scheduling negotiation

Supports both Anthropic (Claude) and OpenAI (GPT-4o) with automatic fallback.

iOS / Apple Watch App

  • HealthKit Integration — reads steps, heart rate, sleep, active energy, workouts, health events
  • Trigger Alert — sends synthetic anomaly data to the backend for pipeline testing
  • Haptic Feedback — success/failure haptics on the Watch
  • Auto-Sync — periodic health data uploads

Tech Stack

  • Monorepo: pnpm workspaces
  • Web: Next.js 14 (App Router), React 18, TypeScript, Tailwind CSS
  • Auth: Clerk
  • DB: Supabase (Postgres) + Prisma ORM
  • LLM: Anthropic Claude (Messages API + Agent SDK), OpenAI GPT-4o
  • Voice: HeyGen Streaming Avatar, Deepgram STT, ElevenLabs TTS
  • iOS: Swift, SwiftUI, HealthKit, WatchKit
  • Signing: Ed25519 via tweetnacl
  • Clinical: PubMed E-utilities, AHA/CDC/WHO guidelines
  • Calendar: Google Calendar API (OAuth 2.0)
  • Schemas: Zod

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors