# lokeshreddydodla/wtlossinahealth-server architecture

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

- Interactive diagram: https://gitdiagram.com/lokeshreddydodla/wtlossinahealth-server
- Repository: https://github.com/lokeshreddydodla/wtlossinahealth-server

## Overview

AiHealth Server is a FastAPI backend for patient and care-provider health services, including AI-assisted health queries, cohort research, profile onboarding, and health-data reporting. A typical query enters through an API route, is authorized and shaped for an agent, then streams a response; patient and provider APIs expose the broader health-data workflows. The repository also contains clinical, meal-analysis, voice, and monitoring capabilities. The graph emphasizes documented route wiring and indexed module references; several internal services and integrations are represented only at subsystem level because their source was not sampled.

Main entry points: [`app/import_routes.py`](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/app/import_routes.py) (Route registry), [`lib/services`](https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/services) (Patient health services), [`rest_server/v1/health_query_agent/query_v3.py`](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/v1/health_query_agent/query_v3.py) (Health-query API), [`rest_server/v1/research_agent/query.py`](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/v1/research_agent/query.py) (Cohort research API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_application["FastAPI application<br/>[main.py]"]
  node_route_registry["Route registry<br/>[import_routes.py]"]
  node_patient_api["Patient API<br/>[router.py]"]
  node_provider_api["Care-provider API<br/>[router.py]"]
  node_health_query_api["Health-query API<br/>[query_v3.py]"]
  node_research_api["Cohort research API<br/>[query.py]"]
  node_profile_api["Profile-agent API<br/>[router.py]"]
end

subgraph group_ai["AI experiences"]
  node_health_query["Health-query agent"]
  node_research_agent["Research agent"]
  node_meal_agent["Meal analysis"]
  node_voice["Voice interaction"]
end

subgraph group_health["Health services"]
  node_profile_service["Profile onboarding"]
  node_clinical["Metabolic assessment"]
  node_patient_services["Patient health services"]
  node_reports["Health reports"]
end

subgraph group_platform["Platform services"]
  node_data_store[("Relational storage<br/>[postgres_store.py]")]
  node_model_gateway["Model gateway<br/>[gateway.py]"]
  node_streaming["SSE streaming<br/>[sse.py]"]
  node_event_bus["Event bus<br/>[bus.py]"]
end

subgraph group_async["Background work"]
  node_task_manager["Task manager"]
  node_workers["Background tasks"]
end

node_caller(("Patient or provider"))

node_caller -.->|"requests API"| node_application
node_application -->|"registers routes"| node_route_registry
node_route_registry -->|"includes router"| node_patient_api
node_route_registry -->|"includes router"| node_provider_api
node_route_registry -->|"includes v1 routes"| node_health_query_api
node_route_registry -->|"includes v1 routes"| node_research_api
node_route_registry -->|"includes router"| node_profile_api
node_caller -.->|"asks health question"| node_health_query_api
node_health_query_api -->|"resolves agent"| node_health_query
node_health_query -->|"requests completion"| node_model_gateway
node_health_query_api -->|"streams response"| node_streaming
node_caller -.->|"asks cohort question"| node_research_api
node_research_api -->|"runs research"| node_research_agent
node_research_agent -->|"requests completion"| node_model_gateway
node_research_api -->|"streams response"| node_streaming
node_profile_api -->|"calls service"| node_profile_service
node_patient_api -.->|"exposes health routes"| node_patient_services
node_provider_api -.->|"exposes patient routes"| node_patient_services
node_patient_services -.->|"persists health data"| node_data_store
node_patient_services -.->|"supports reporting"| node_reports
node_meal_agent -.->|"uses model"| node_model_gateway
node_voice -.->|"streams audio interactions"| node_streaming
node_clinical -.->|"assesses patient data"| node_patient_services
node_task_manager -->|"enqueues tasks"| node_workers
node_application -->|"initializes storage"| node_data_store

click node_application "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/app/main.py"
click node_route_registry "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/app/import_routes.py"
click node_patient_api "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/patients/router.py"
click node_provider_api "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/care_provider/router.py"
click node_health_query_api "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/v1/health_query_agent/query_v3.py"
click node_research_api "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/v1/research_agent/query.py"
click node_profile_api "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/profile_agent/router.py"
click node_health_query "https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/ai_foundation/agents/health_query"
click node_research_agent "https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/ai_foundation/agents/research_agent"
click node_meal_agent "https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/ai_foundation/agents/meal_analysis"
click node_voice "https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/ai_foundation/voice"
click node_profile_service "https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/services/profile_agent"
click node_clinical "https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/ai_foundation/clinical/metabolic"
click node_patient_services "https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/services"
click node_reports "https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/services/reports"
click node_data_store "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/lib/core/postgres_store.py"
click node_model_gateway "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/lib/ai_foundation/models/gateway.py"
click node_streaming "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/lib/ai_foundation/streaming/sse.py"
click node_event_bus "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/lib/ai_foundation/events/bus.py"
click node_task_manager "https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/lib/managers/arq_task_manager.py"
click node_workers "https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/workers/tasks"

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_application,node_route_registry,node_patient_api,node_provider_api,node_health_query_api,node_research_api,node_profile_api toneBlue
class node_health_query,node_research_agent,node_meal_agent,node_voice toneAmber
class node_profile_service,node_clinical,node_patient_services,node_reports toneMint
class node_data_store,node_model_gateway,node_streaming,node_event_bus toneRose
class node_task_manager,node_workers,node_caller toneIndigo
```

## Components

### API and access

- [FastAPI application](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/app/main.py): `app/main.py`
- [Route registry](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/app/import_routes.py): `app/import_routes.py`
- [Patient API](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/patients/router.py): `rest_server/patients/router.py`
- [Care-provider API](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/care_provider/router.py): `rest_server/care_provider/router.py`
- [Health-query API](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/v1/health_query_agent/query_v3.py): `rest_server/v1/health_query_agent/query_v3.py`
- [Cohort research API](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/v1/research_agent/query.py): `rest_server/v1/research_agent/query.py`
- [Profile-agent API](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/rest_server/profile_agent/router.py): `rest_server/profile_agent/router.py`

### AI experiences

- [Health-query agent](https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/ai_foundation/agents/health_query): `lib/ai_foundation/agents/health_query`
- [Research agent](https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/ai_foundation/agents/research_agent): `lib/ai_foundation/agents/research_agent`
- [Meal analysis](https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/ai_foundation/agents/meal_analysis): `lib/ai_foundation/agents/meal_analysis`
- [Voice interaction](https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/ai_foundation/voice): `lib/ai_foundation/voice`

### Health services

- [Profile onboarding](https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/services/profile_agent): `lib/services/profile_agent`
- [Metabolic assessment](https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/ai_foundation/clinical/metabolic): `lib/ai_foundation/clinical/metabolic`
- [Patient health services](https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/services): `lib/services`
- [Health reports](https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/services/reports): `lib/services/reports`

### Platform services

- [Relational storage](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/lib/core/postgres_store.py): `lib/core/postgres_store.py`
- [Model gateway](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/lib/ai_foundation/models/gateway.py): `lib/ai_foundation/models/gateway.py`
- [SSE streaming](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/lib/ai_foundation/streaming/sse.py): `lib/ai_foundation/streaming/sse.py`
- [Event bus](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/lib/ai_foundation/events/bus.py): `lib/ai_foundation/events/bus.py`

### Background work

- [Task manager](https://github.com/lokeshreddydodla/wtlossinahealth-server/blob/lokesh-dev/lib/managers/arq_task_manager.py): `lib/managers/arq_task_manager.py`
- [Background tasks](https://github.com/lokeshreddydodla/wtlossinahealth-server/tree/lokesh-dev/lib/workers/tasks): `lib/workers/tasks`

### Other components

- **Patient or provider**

## Connections

- Patient or provider → FastAPI application: requests API
- FastAPI application → Route registry: registers routes (evidence: `app/main.py`)
- Route registry → Patient API: includes router (evidence: `app/import_routes.py`)
- Route registry → Care-provider API: includes router (evidence: `app/import_routes.py`)
- Route registry → Health-query API: includes v1 routes (evidence: `app/import_routes.py`)
- Route registry → Cohort research API: includes v1 routes (evidence: `app/import_routes.py`)
- Route registry → Profile-agent API: includes router (evidence: `app/import_routes.py`)
- Patient or provider → Health-query API: asks health question (evidence: `rest_server/v1/health_query_agent/query_v3.py`)
- Health-query API → Health-query agent: resolves agent (evidence: `rest_server/v1/health_query_agent/query_v3.py`)
- Health-query agent → Model gateway: requests completion (evidence: `lib/ai_foundation/agents/health_query/reasoning_engine.py`)
- Health-query API → SSE streaming: streams response (evidence: `rest_server/v1/health_query_agent/query_v3.py`)
- Patient or provider → Cohort research API: asks cohort question (evidence: `rest_server/v1/research_agent/query.py`)
- Cohort research API → Research agent: runs research (evidence: `rest_server/v1/research_agent/query.py`)
- Research agent → Model gateway: requests completion (evidence: `lib/ai_foundation/agents/research_agent/reasoning_engine.py`)
- Cohort research API → SSE streaming: streams response (evidence: `rest_server/v1/research_agent/query.py`)
- Profile-agent API → Profile onboarding: calls service (evidence: `rest_server/profile_agent/router.py`)
- Patient API → Patient health services: exposes health routes (evidence: `rest_server/patients/router.py`)
- Care-provider API → Patient health services: exposes patient routes (evidence: `rest_server/care_provider/router.py`)
- Patient health services → Relational storage: persists health data (evidence: `lib/services/package_query_service.py`)
- Patient health services → Health reports: supports reporting
- Meal analysis → Model gateway: uses model
- Voice interaction → SSE streaming: streams audio interactions
- Metabolic assessment → Patient health services: assesses patient data
- Task manager → Background tasks: enqueues tasks (evidence: `lib/managers/arq_task_manager.py`)
- FastAPI application → Relational storage: initializes storage (evidence: `app/main.py`)
