# rishabhdev0/medlife architecture

> Architecture diagram of the GitHub repository rishabhdev0/medlife, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rishabhdev0/medlife
- Repository: https://github.com/rishabhdev0/medlife

## Overview

Medkit is a browser-based clinical training simulator. A trainee selects an ER case or polyclinic patient, conducts an encounter by voice or text, examines the patient, orders tests and treatment, and completes disposition; an attending agent then grades the session and presents a debrief. The graph covers both documented care modes, the shared state and clinical data layer, and the voice and grading integrations. Some backend and UI relationships are documented in the README rather than shown in source excerpts; those links cite the README.

Main entry points: [`src/game/store.ts`](https://github.com/rishabhdev0/medlife/blob/main/src/game/store.ts) (Session state), [`src/components/EncounterScreen.tsx`](https://github.com/rishabhdev0/medlife/blob/main/src/components/EncounterScreen.tsx) (Encounter screen), [`src/App.tsx`](https://github.com/rishabhdev0/medlife/blob/main/src/App.tsx) (Screen router), [`src/components/ExamineOverlay.tsx`](https://github.com/rishabhdev0/medlife/blob/main/src/components/ExamineOverlay.tsx) (Examination tools)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Training experience"]
  node_app["Screen router<br/>[App.tsx]"]
  node_case_ui["Case selection"]
  node_encounter_ui["Encounter screen"]
  node_examine["Examination tools<br/>[ExamineOverlay.tsx]"]
  node_debrief_ui["Debrief screen<br/>[DebriefScreen.tsx]"]
end

subgraph group_clinical["Clinical simulation"]
  node_state["Session state<br/>[store.ts]"]
  node_case_data["Patient case catalogs"]
  node_clinical_data["Tests and guidelines<br/>[tests.ts]"]
  node_clinic_rules["Clinic specialties<br/>[clinic.ts]"]
  node_scene["3D clinic scene<br/>[Polyclinic.tsx]"]
end

subgraph group_voice["Patient voice"]
  node_conversation_store["Conversation manager"]
  node_persona["Patient persona<br/>[patientPersona.ts]"]
  node_conversation["Voice conversation<br/>[conversation.ts]"]
  node_worker["Voice worker<br/>[voice_agent.py]"]
  node_livekit(("LiveKit Cloud"))
  node_speech_services(("Speech services"))
end

subgraph group_grading["Assessment"]
  node_debrief_request["Debrief request builder<br/>[debriefRequest.ts]"]
  node_debrief_hook["Attending agent hook"]
  node_agent_client["Managed agent client<br/>[managedAgent.ts]"]
  node_backend["FastAPI proxy<br/>[server.py]"]
  node_attending(("Claude attending grader"))
end

node_trainee(("Trainee doctor"))

node_trainee -->|"uses"| node_app
node_app -->|"routes to"| node_case_ui
node_app -->|"routes to"| node_encounter_ui
node_app -->|"routes to"| node_debrief_ui
node_case_ui -->|"selects case"| node_state
node_encounter_ui -->|"reads session"| node_state
node_encounter_ui -->|"renders"| node_scene
node_encounter_ui -->|"renders"| node_examine
node_examine -->|"updates session"| node_state
node_state -->|"loads cases"| node_case_data
node_state -->|"uses specialties"| node_clinic_rules
node_examine -->|"reads tests"| node_clinical_data
node_scene -->|"reads clinic state"| node_state
node_encounter_ui -->|"manages patient voice"| node_conversation_store
node_conversation_store -->|"builds persona"| node_persona
node_conversation_store -->|"creates conversation"| node_conversation
node_conversation -->|"connects room"| node_livekit
node_livekit -->|"transports audio"| node_worker
node_worker -->|"uses STT and TTS"| node_speech_services
node_debrief_ui -->|"builds evaluation request"| node_debrief_request
node_debrief_ui -->|"starts grading"| node_debrief_hook
node_debrief_hook -->|"streams agent session"| node_agent_client
node_agent_client -.->|"calls proxy"| node_backend
node_backend -->|"proxies grading"| node_attending
node_attending -.->|"returns evaluation"| node_debrief_hook

click node_app "https://github.com/rishabhdev0/medlife/blob/main/src/App.tsx"
click node_case_ui "https://github.com/rishabhdev0/medlife/blob/main/src/components/CaseLibraryScreen.tsx"
click node_encounter_ui "https://github.com/rishabhdev0/medlife/blob/main/src/components/EncounterScreen.tsx"
click node_examine "https://github.com/rishabhdev0/medlife/blob/main/src/components/ExamineOverlay.tsx"
click node_debrief_ui "https://github.com/rishabhdev0/medlife/blob/main/src/components/DebriefScreen.tsx"
click node_state "https://github.com/rishabhdev0/medlife/blob/main/src/game/store.ts"
click node_case_data "https://github.com/rishabhdev0/medlife/blob/main/src/data/polyclinicPatients.ts"
click node_clinical_data "https://github.com/rishabhdev0/medlife/blob/main/src/data/tests.ts"
click node_clinic_rules "https://github.com/rishabhdev0/medlife/blob/main/src/game/clinic.ts"
click node_scene "https://github.com/rishabhdev0/medlife/blob/main/src/components/three/Polyclinic.tsx"
click node_conversation_store "https://github.com/rishabhdev0/medlife/blob/main/src/voice/conversationStore.ts"
click node_persona "https://github.com/rishabhdev0/medlife/blob/main/src/voice/patientPersona.ts"
click node_conversation "https://github.com/rishabhdev0/medlife/blob/main/src/voice/conversation.ts"
click node_worker "https://github.com/rishabhdev0/medlife/blob/main/backend/voice_agent.py"
click node_debrief_request "https://github.com/rishabhdev0/medlife/blob/main/src/agents/debriefRequest.ts"
click node_debrief_hook "https://github.com/rishabhdev0/medlife/blob/main/src/agents/useAttendingDebrief.ts"
click node_agent_client "https://github.com/rishabhdev0/medlife/blob/main/src/agents/managedAgent.ts"
click node_backend "https://github.com/rishabhdev0/medlife/blob/main/backend/server.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_case_ui,node_encounter_ui,node_examine,node_debrief_ui toneBlue
class node_state,node_case_data,node_clinical_data,node_clinic_rules,node_scene toneAmber
class node_conversation_store,node_persona,node_conversation,node_worker,node_livekit,node_speech_services toneMint
class node_debrief_request,node_debrief_hook,node_agent_client,node_backend,node_attending toneRose
class node_trainee toneIndigo
```

## Components

### Training experience

- [Screen router](https://github.com/rishabhdev0/medlife/blob/main/src/App.tsx): `src/App.tsx`
- [Case selection](https://github.com/rishabhdev0/medlife/blob/main/src/components/CaseLibraryScreen.tsx): `src/components/CaseLibraryScreen.tsx`
- [Encounter screen](https://github.com/rishabhdev0/medlife/blob/main/src/components/EncounterScreen.tsx): `src/components/EncounterScreen.tsx`
- [Examination tools](https://github.com/rishabhdev0/medlife/blob/main/src/components/ExamineOverlay.tsx): `src/components/ExamineOverlay.tsx`
- [Debrief screen](https://github.com/rishabhdev0/medlife/blob/main/src/components/DebriefScreen.tsx): `src/components/DebriefScreen.tsx`

### Clinical simulation

- [Session state](https://github.com/rishabhdev0/medlife/blob/main/src/game/store.ts): `src/game/store.ts`
- [Patient case catalogs](https://github.com/rishabhdev0/medlife/blob/main/src/data/polyclinicPatients.ts): `src/data/polyclinicPatients.ts`
- [Tests and guidelines](https://github.com/rishabhdev0/medlife/blob/main/src/data/tests.ts): `src/data/tests.ts`
- [Clinic specialties](https://github.com/rishabhdev0/medlife/blob/main/src/game/clinic.ts): `src/game/clinic.ts`
- [3D clinic scene](https://github.com/rishabhdev0/medlife/blob/main/src/components/three/Polyclinic.tsx): `src/components/three/Polyclinic.tsx`

### Patient voice

- [Conversation manager](https://github.com/rishabhdev0/medlife/blob/main/src/voice/conversationStore.ts): `src/voice/conversationStore.ts`
- [Patient persona](https://github.com/rishabhdev0/medlife/blob/main/src/voice/patientPersona.ts): `src/voice/patientPersona.ts`
- [Voice conversation](https://github.com/rishabhdev0/medlife/blob/main/src/voice/conversation.ts): `src/voice/conversation.ts`
- [Voice worker](https://github.com/rishabhdev0/medlife/blob/main/backend/voice_agent.py): `backend/voice_agent.py`
- **LiveKit Cloud**
- **Speech services**

### Assessment

- [Debrief request builder](https://github.com/rishabhdev0/medlife/blob/main/src/agents/debriefRequest.ts): `src/agents/debriefRequest.ts`
- [Attending agent hook](https://github.com/rishabhdev0/medlife/blob/main/src/agents/useAttendingDebrief.ts): `src/agents/useAttendingDebrief.ts`
- [Managed agent client](https://github.com/rishabhdev0/medlife/blob/main/src/agents/managedAgent.ts): `src/agents/managedAgent.ts`
- [FastAPI proxy](https://github.com/rishabhdev0/medlife/blob/main/backend/server.py): `backend/server.py`
- **Claude attending grader**

### Other components

- **Trainee doctor**

## Connections

- Trainee doctor → Screen router: uses
- Screen router → Case selection: routes to (evidence: `src/App.tsx`)
- Screen router → Encounter screen: routes to (evidence: `src/App.tsx`)
- Screen router → Debrief screen: routes to (evidence: `src/App.tsx`)
- Case selection → Session state: selects case (evidence: `src/components/CaseLibraryScreen.tsx`)
- Encounter screen → Session state: reads session (evidence: `src/components/EncounterScreen.tsx`)
- Encounter screen → 3D clinic scene: renders (evidence: `src/components/EncounterScreen.tsx`)
- Encounter screen → Examination tools: renders (evidence: `src/components/EncounterScreen.tsx`)
- Examination tools → Session state: updates session (evidence: `src/components/ExamineOverlay.tsx`)
- Session state → Patient case catalogs: loads cases (evidence: `src/game/store.ts`)
- Session state → Clinic specialties: uses specialties (evidence: `src/game/store.ts`)
- Examination tools → Tests and guidelines: reads tests (evidence: `src/components/ExamineOverlay.tsx`)
- 3D clinic scene → Session state: reads clinic state (evidence: `src/components/three/Polyclinic.tsx`)
- Encounter screen → Conversation manager: manages patient voice (evidence: `src/components/EncounterScreen.tsx`)
- Conversation manager → Patient persona: builds persona (evidence: `src/voice/conversationStore.ts`)
- Conversation manager → Voice conversation: creates conversation (evidence: `src/voice/conversationStore.ts`)
- Voice conversation → LiveKit Cloud: connects room (evidence: `src/voice/conversation.ts`)
- LiveKit Cloud → Voice worker: transports audio
- Voice worker → Speech services: uses STT and TTS
- Debrief screen → Debrief request builder: builds evaluation request (evidence: `src/components/DebriefScreen.tsx`)
- Debrief screen → Attending agent hook: starts grading (evidence: `src/components/DebriefScreen.tsx`)
- Attending agent hook → Managed agent client: streams agent session (evidence: `src/agents/useAttendingDebrief.ts`)
- Managed agent client → FastAPI proxy: calls proxy
- FastAPI proxy → Claude attending grader: proxies grading
- Claude attending grader → Attending agent hook: returns evaluation
