# tushank99/patient-triage architecture

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

- Interactive diagram: https://gitdiagram.com/tushank99/patient-triage
- Repository: https://github.com/tushank99/patient-triage

## Overview

TriageFlow is an ED triage assistant: a nurse submits a complaint and vitals, receives an ESI recommendation with confidence, rationale, and cited history, then accepts or overrides it; the result is audited. The backend also ingests patient documents for retrieval and supports a waiting-room queue with reassessment flags. The graph follows the documented assessment stages and includes these product branches. Several connections come from README documentation or the source index; unsampled implementations are represented only at their supported directory paths.

Main entry points: [`backend/app/services/triage_pipeline.py`](https://github.com/tushank99/patient-triage/blob/main/backend/app/services/triage_pipeline.py) (Assessment orchestrator), [`backend/app/models.py`](https://github.com/tushank99/patient-triage/blob/main/backend/app/models.py) (Clinical database), [`backend/app/main.py`](https://github.com/tushank99/patient-triage/blob/main/backend/app/main.py) (HTTP application), [`backend/app/ingestion/service.py`](https://github.com/tushank99/patient-triage/blob/main/backend/app/ingestion/service.py) (Document ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Nurse experience"]
  node_web["Triage interface<br/>[index.tsx]"]
  node_client["API client<br/>[api.ts]"]
  node_context["Triage context<br/>[triage-context.tsx]"]
end

subgraph group_api["Application API"]
  node_api_main["HTTP application<br/>[main.py]"]
  node_triage_route["Triage endpoint<br/>[triage.py]"]
  node_visit["Visit service<br/>[visit_service.py]"]
end

subgraph group_assessment["Triage assessment"]
  node_pipeline["Assessment orchestrator<br/>[triage_pipeline.py]"]
  node_facts["Clinical facts<br/>[facts.py]"]
  node_ml["ESI model<br/>[model.py]"]
  node_llm["LLM assessment<br/>[assessor.py]"]
  node_rules["Safety rules<br/>[rules_engine.py]"]
  node_fusion["Decision fusion<br/>[fusion.py]"]
  node_grounding["Claim grounding<br/>[grounding.py]"]
end

subgraph group_records["Patient records"]
  node_history["History context<br/>[history_store.py]"]
  node_retrieval["Patient retrieval<br/>[retriever.py]"]
  node_database[("Clinical database<br/>[models.py]")]
  node_ingestion["Document ingestion<br/>[service.py]"]
  node_worker["Ingestion worker<br/>[worker.py]"]
end

subgraph group_operations["Queue and operations"]
  node_queue_api["Queue endpoints<br/>[queue.py]"]
  node_queue_service["Queue services<br/>[demo_queue.py]"]
end

node_nurse(("Nurse"))

node_nurse -->|"enters triage"| node_web
node_web -->|"uses state"| node_context
node_context -->|"calls API"| node_client
node_client -->|"sends requests"| node_api_main
node_api_main -->|"registers route"| node_triage_route
node_triage_route -.->|"handles visits"| node_visit
node_visit -->|"runs assessment"| node_pipeline
node_visit -->|"persists visits"| node_database
node_pipeline -->|"loads history"| node_history
node_history -->|"retrieves passages"| node_retrieval
node_history -->|"extracts facts"| node_facts
node_retrieval -->|"reads patient chunks"| node_database
node_pipeline -->|"predicts ESI"| node_ml
node_pipeline -->|"requests assessment"| node_llm
node_pipeline -->|"computes safety floor"| node_rules
node_pipeline -->|"combines decisions"| node_fusion
node_pipeline -->|"checks claims"| node_grounding
node_pipeline -.->|"audits result"| node_database
node_api_main -->|"registers route"| node_queue_api
node_queue_api -.->|"manages queue"| node_queue_service
node_queue_service -.->|"reads queue state"| node_database
node_api_main -.->|"exposes document routes"| node_ingestion
node_ingestion -->|"enqueues processing"| node_worker
node_worker -->|"processes jobs"| node_ingestion
node_ingestion -->|"stores extracted chunks"| node_database

click node_web "https://github.com/tushank99/patient-triage/blob/main/frontend/src/routes/index.tsx"
click node_client "https://github.com/tushank99/patient-triage/blob/main/frontend/src/lib/api.ts"
click node_context "https://github.com/tushank99/patient-triage/blob/main/frontend/src/lib/triage-context.tsx"
click node_api_main "https://github.com/tushank99/patient-triage/blob/main/backend/app/main.py"
click node_triage_route "https://github.com/tushank99/patient-triage/blob/main/backend/app/routers/triage.py"
click node_visit "https://github.com/tushank99/patient-triage/blob/main/backend/app/services/visit_service.py"
click node_pipeline "https://github.com/tushank99/patient-triage/blob/main/backend/app/services/triage_pipeline.py"
click node_history "https://github.com/tushank99/patient-triage/blob/main/backend/app/services/history_store.py"
click node_retrieval "https://github.com/tushank99/patient-triage/blob/main/backend/app/retrieval/retriever.py"
click node_facts "https://github.com/tushank99/patient-triage/blob/main/backend/app/clinical/facts.py"
click node_ml "https://github.com/tushank99/patient-triage/blob/main/backend/app/ml/model.py"
click node_llm "https://github.com/tushank99/patient-triage/blob/main/backend/app/llm/assessor.py"
click node_rules "https://github.com/tushank99/patient-triage/blob/main/backend/app/clinical/rules_engine.py"
click node_fusion "https://github.com/tushank99/patient-triage/blob/main/backend/app/clinical/fusion.py"
click node_grounding "https://github.com/tushank99/patient-triage/blob/main/backend/app/llm/grounding.py"
click node_database "https://github.com/tushank99/patient-triage/blob/main/backend/app/models.py"
click node_ingestion "https://github.com/tushank99/patient-triage/blob/main/backend/app/ingestion/service.py"
click node_worker "https://github.com/tushank99/patient-triage/blob/main/backend/app/ingestion/worker.py"
click node_queue_api "https://github.com/tushank99/patient-triage/blob/main/backend/app/routers/queue.py"
click node_queue_service "https://github.com/tushank99/patient-triage/blob/main/backend/app/services/demo_queue.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_web,node_client,node_context toneBlue
class node_api_main,node_triage_route,node_visit toneAmber
class node_pipeline,node_facts,node_ml,node_llm,node_rules,node_fusion,node_grounding toneMint
class node_history,node_retrieval,node_database,node_ingestion,node_worker toneRose
class node_queue_api,node_queue_service,node_nurse toneIndigo
```

## Components

### Nurse experience

- [Triage interface](https://github.com/tushank99/patient-triage/blob/main/frontend/src/routes/index.tsx): `frontend/src/routes/index.tsx`
- [API client](https://github.com/tushank99/patient-triage/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`
- [Triage context](https://github.com/tushank99/patient-triage/blob/main/frontend/src/lib/triage-context.tsx): `frontend/src/lib/triage-context.tsx`

### Application API

- [HTTP application](https://github.com/tushank99/patient-triage/blob/main/backend/app/main.py): `backend/app/main.py`
- [Triage endpoint](https://github.com/tushank99/patient-triage/blob/main/backend/app/routers/triage.py): `backend/app/routers/triage.py`
- [Visit service](https://github.com/tushank99/patient-triage/blob/main/backend/app/services/visit_service.py): `backend/app/services/visit_service.py`

### Triage assessment

- [Assessment orchestrator](https://github.com/tushank99/patient-triage/blob/main/backend/app/services/triage_pipeline.py): `backend/app/services/triage_pipeline.py`
- [Clinical facts](https://github.com/tushank99/patient-triage/blob/main/backend/app/clinical/facts.py): `backend/app/clinical/facts.py`
- [ESI model](https://github.com/tushank99/patient-triage/blob/main/backend/app/ml/model.py): `backend/app/ml/model.py`
- [LLM assessment](https://github.com/tushank99/patient-triage/blob/main/backend/app/llm/assessor.py): `backend/app/llm/assessor.py`
- [Safety rules](https://github.com/tushank99/patient-triage/blob/main/backend/app/clinical/rules_engine.py): `backend/app/clinical/rules_engine.py`
- [Decision fusion](https://github.com/tushank99/patient-triage/blob/main/backend/app/clinical/fusion.py): `backend/app/clinical/fusion.py`
- [Claim grounding](https://github.com/tushank99/patient-triage/blob/main/backend/app/llm/grounding.py): `backend/app/llm/grounding.py`

### Patient records

- [History context](https://github.com/tushank99/patient-triage/blob/main/backend/app/services/history_store.py): `backend/app/services/history_store.py`
- [Patient retrieval](https://github.com/tushank99/patient-triage/blob/main/backend/app/retrieval/retriever.py): `backend/app/retrieval/retriever.py`
- [Clinical database](https://github.com/tushank99/patient-triage/blob/main/backend/app/models.py): `backend/app/models.py`
- [Document ingestion](https://github.com/tushank99/patient-triage/blob/main/backend/app/ingestion/service.py): `backend/app/ingestion/service.py`
- [Ingestion worker](https://github.com/tushank99/patient-triage/blob/main/backend/app/ingestion/worker.py): `backend/app/ingestion/worker.py`

### Queue and operations

- [Queue endpoints](https://github.com/tushank99/patient-triage/blob/main/backend/app/routers/queue.py): `backend/app/routers/queue.py`
- [Queue services](https://github.com/tushank99/patient-triage/blob/main/backend/app/services/demo_queue.py): `backend/app/services/demo_queue.py`

### Other components

- **Nurse**

## Connections

- Nurse → Triage interface: enters triage
- Triage interface → Triage context: uses state (evidence: `frontend/src/lib/triage-context.tsx`)
- Triage context → API client: calls API (evidence: `frontend/src/lib/triage-context.tsx`)
- API client → HTTP application: sends requests
- HTTP application → Triage endpoint: registers route (evidence: `backend/app/main.py`)
- Triage endpoint → Visit service: handles visits
- Visit service → Assessment orchestrator: runs assessment (evidence: `backend/app/services/visit_service.py`)
- Visit service → Clinical database: persists visits (evidence: `backend/app/services/visit_service.py`)
- Assessment orchestrator → History context: loads history (evidence: `backend/app/services/triage_pipeline.py`)
- History context → Patient retrieval: retrieves passages (evidence: `backend/app/services/history_store.py`)
- History context → Clinical facts: extracts facts (evidence: `backend/app/services/history_store.py`)
- Patient retrieval → Clinical database: reads patient chunks (evidence: `backend/app/retrieval/retriever.py`)
- Assessment orchestrator → ESI model: predicts ESI (evidence: `backend/app/services/triage_pipeline.py`)
- Assessment orchestrator → LLM assessment: requests assessment (evidence: `backend/app/services/triage_pipeline.py`)
- Assessment orchestrator → Safety rules: computes safety floor (evidence: `backend/app/services/triage_pipeline.py`)
- Assessment orchestrator → Decision fusion: combines decisions (evidence: `backend/app/services/triage_pipeline.py`)
- Assessment orchestrator → Claim grounding: checks claims (evidence: `backend/app/services/triage_pipeline.py`)
- Assessment orchestrator → Clinical database: audits result
- HTTP application → Queue endpoints: registers route (evidence: `backend/app/main.py`)
- Queue endpoints → Queue services: manages queue
- Queue services → Clinical database: reads queue state
- HTTP application → Document ingestion: exposes document routes
- Document ingestion → Ingestion worker: enqueues processing (evidence: `backend/app/ingestion/service.py`)
- Ingestion worker → Document ingestion: processes jobs (evidence: `backend/app/ingestion/worker.py`)
- Document ingestion → Clinical database: stores extracted chunks (evidence: `backend/app/ingestion/service.py`)
