# ayush1273/hospo architecture

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

- Interactive diagram: https://gitdiagram.com/ayush1273/hospo
- Repository: https://github.com/ayush1273/hospo

## Overview

HOSP-AI COMMAND is a hospital operations decision-support dashboard. Administrators submit or select operational data, inspect current HMS status, and request a 24-hour ICU forecast, deterministic risk assessment, retrieved policies, and advisory recommendations; a separate pharmacy workflow provides medicine stock intelligence and demand forecasting. The README documents the major forecasting, risk, RAG, Gemini, and dashboard capabilities. Some client-to-API and pharmacy UI wiring is not shown in the excerpts, so those links are omitted.

Main entry points: [`backend/api/endpoints/analysis.py`](https://github.com/ayush1273/hospo/blob/main/backend/api/endpoints/analysis.py) (Analysis and HMS API), [`backend/api/router.py`](https://github.com/ayush1273/hospo/blob/main/backend/api/router.py) (API router), [`backend/api/endpoints/pharmacy.py`](https://github.com/ayush1273/hospo/blob/main/backend/api/endpoints/pharmacy.py) (Pharmacy API), [`backend/main.py`](https://github.com/ayush1273/hospo/blob/main/backend/main.py) (FastAPI application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and inputs"]
  node_app["FastAPI application<br/>[main.py]"]
  node_router["API router<br/>[router.py]"]
  node_analysis_api["Analysis and HMS API<br/>[analysis.py]"]
  node_health_api["Health API<br/>[health.py]"]
  node_schemas_ops["Operational schemas<br/>[operational.py]"]
  node_schemas_analysis["Analysis results<br/>[analysis.py]"]
  node_pharmacy_api["Pharmacy API<br/>[pharmacy.py]"]
end

subgraph group_ops["Operational intelligence"]
  node_resources[("Models and cached data<br/>[resources.py]")]
  node_hms["HMS ingestion and features<br/>[hms_service.py]"]
  node_forecast["24-hour occupancy forecast"]
  node_risk["Operational risk scoring<br/>[risk_service.py]"]
end

subgraph group_policy["Policy recommendations"]
  node_rag["Policy retrieval<br/>[rag_service.py]"]
  node_llm["Recommendation synthesis<br/>[llm_service.py]"]
end

subgraph group_pharmacy["Pharmacy intelligence"]
  node_pharmacy_service["Medicine stock intelligence"]
  node_pharmacy_predict["Medicine demand forecast"]
  node_pharmacy_schema["Pharmacy schemas<br/>[pharmacy.py]"]
end

subgraph group_client["Command dashboard"]
  node_home["Dashboard page<br/>[Home.tsx]"]
  node_pharmacy_view["Pharmacy view<br/>[PharmacyView.tsx]"]
  node_predictive_view["Predictive intelligence view"]
  node_charts["Interactive charts<br/>[line-chart.tsx]"]
end

node_admin(("Hospital administrator"))
node_gemini{{"Google Gemini"}}

node_admin -->|"uses"| node_home
node_home -.->|"requests analysis"| node_app
node_app -->|"mounts"| node_router
node_router -->|"routes"| node_analysis_api
node_router -->|"routes"| node_health_api
node_router -->|"routes"| node_pharmacy_api
node_app -->|"loads lifecycle"| node_resources
node_resources -->|"loads baseline data"| node_hms
node_analysis_api -->|"validates and engineers"| node_hms
node_analysis_api -->|"requests prediction"| node_forecast
node_analysis_api -->|"scores conditions"| node_risk
node_analysis_api -->|"retrieves policies"| node_rag
node_analysis_api -->|"synthesizes guidance"| node_llm
node_rag -->|"reads policy data"| node_resources
node_rag -->|"embeds queries"| node_gemini
node_llm -.->|"generates response"| node_gemini
node_analysis_api -->|"accepts inputs"| node_schemas_ops
node_analysis_api -->|"returns response"| node_schemas_analysis
node_pharmacy_api -->|"requests stock intelligence"| node_pharmacy_service
node_pharmacy_api -->|"requests demand forecasts"| node_pharmacy_predict
node_pharmacy_api -->|"uses request and response types"| node_pharmacy_schema
node_pharmacy_service -->|"builds typed results"| node_pharmacy_schema
node_pharmacy_predict -->|"builds typed forecasts"| node_pharmacy_schema
node_home -.->|"renders data visualizations"| node_charts

click node_app "https://github.com/ayush1273/hospo/blob/main/backend/main.py"
click node_router "https://github.com/ayush1273/hospo/blob/main/backend/api/router.py"
click node_analysis_api "https://github.com/ayush1273/hospo/blob/main/backend/api/endpoints/analysis.py"
click node_health_api "https://github.com/ayush1273/hospo/blob/main/backend/api/endpoints/health.py"
click node_schemas_ops "https://github.com/ayush1273/hospo/blob/main/backend/schemas/operational.py"
click node_schemas_analysis "https://github.com/ayush1273/hospo/blob/main/backend/schemas/analysis.py"
click node_resources "https://github.com/ayush1273/hospo/blob/main/backend/core/resources.py"
click node_hms "https://github.com/ayush1273/hospo/blob/main/backend/services/hms_service.py"
click node_forecast "https://github.com/ayush1273/hospo/blob/main/backend/services/forecast_service.py"
click node_risk "https://github.com/ayush1273/hospo/blob/main/backend/services/risk_service.py"
click node_rag "https://github.com/ayush1273/hospo/blob/main/backend/services/rag_service.py"
click node_llm "https://github.com/ayush1273/hospo/blob/main/backend/services/llm_service.py"
click node_pharmacy_api "https://github.com/ayush1273/hospo/blob/main/backend/api/endpoints/pharmacy.py"
click node_pharmacy_service "https://github.com/ayush1273/hospo/blob/main/backend/services/pharmacy_service.py"
click node_pharmacy_predict "https://github.com/ayush1273/hospo/blob/main/backend/services/pharmacy_predict_service.py"
click node_pharmacy_schema "https://github.com/ayush1273/hospo/blob/main/backend/schemas/pharmacy.py"
click node_home "https://github.com/ayush1273/hospo/blob/main/client/src/pages/Home.tsx"
click node_pharmacy_view "https://github.com/ayush1273/hospo/blob/main/client/src/components/PharmacyView.tsx"
click node_predictive_view "https://github.com/ayush1273/hospo/blob/main/client/src/components/PredictiveIntelligenceSection.tsx"
click node_charts "https://github.com/ayush1273/hospo/blob/main/client/src/components/charts/line-chart.tsx"

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_router,node_analysis_api,node_health_api,node_schemas_ops,node_schemas_analysis,node_pharmacy_api toneBlue
class node_resources,node_hms,node_forecast,node_risk toneAmber
class node_rag,node_llm toneMint
class node_pharmacy_service,node_pharmacy_predict,node_pharmacy_schema toneRose
class node_home,node_pharmacy_view,node_predictive_view,node_charts,node_admin,node_gemini toneIndigo
```

## Components

### API and inputs

- [FastAPI application](https://github.com/ayush1273/hospo/blob/main/backend/main.py): `backend/main.py`
- [API router](https://github.com/ayush1273/hospo/blob/main/backend/api/router.py): `backend/api/router.py`
- [Analysis and HMS API](https://github.com/ayush1273/hospo/blob/main/backend/api/endpoints/analysis.py): `backend/api/endpoints/analysis.py`
- [Health API](https://github.com/ayush1273/hospo/blob/main/backend/api/endpoints/health.py): `backend/api/endpoints/health.py`
- [Operational schemas](https://github.com/ayush1273/hospo/blob/main/backend/schemas/operational.py): `backend/schemas/operational.py`
- [Analysis results](https://github.com/ayush1273/hospo/blob/main/backend/schemas/analysis.py): `backend/schemas/analysis.py`
- [Pharmacy API](https://github.com/ayush1273/hospo/blob/main/backend/api/endpoints/pharmacy.py): `backend/api/endpoints/pharmacy.py`

### Operational intelligence

- [Models and cached data](https://github.com/ayush1273/hospo/blob/main/backend/core/resources.py): `backend/core/resources.py`
- [HMS ingestion and features](https://github.com/ayush1273/hospo/blob/main/backend/services/hms_service.py): `backend/services/hms_service.py`
- [24-hour occupancy forecast](https://github.com/ayush1273/hospo/blob/main/backend/services/forecast_service.py): `backend/services/forecast_service.py`
- [Operational risk scoring](https://github.com/ayush1273/hospo/blob/main/backend/services/risk_service.py): `backend/services/risk_service.py`

### Policy recommendations

- [Policy retrieval](https://github.com/ayush1273/hospo/blob/main/backend/services/rag_service.py): `backend/services/rag_service.py`
- [Recommendation synthesis](https://github.com/ayush1273/hospo/blob/main/backend/services/llm_service.py): `backend/services/llm_service.py`

### Pharmacy intelligence

- [Medicine stock intelligence](https://github.com/ayush1273/hospo/blob/main/backend/services/pharmacy_service.py): `backend/services/pharmacy_service.py`
- [Medicine demand forecast](https://github.com/ayush1273/hospo/blob/main/backend/services/pharmacy_predict_service.py): `backend/services/pharmacy_predict_service.py`
- [Pharmacy schemas](https://github.com/ayush1273/hospo/blob/main/backend/schemas/pharmacy.py): `backend/schemas/pharmacy.py`

### Command dashboard

- [Dashboard page](https://github.com/ayush1273/hospo/blob/main/client/src/pages/Home.tsx): `client/src/pages/Home.tsx`
- [Pharmacy view](https://github.com/ayush1273/hospo/blob/main/client/src/components/PharmacyView.tsx): `client/src/components/PharmacyView.tsx`
- [Predictive intelligence view](https://github.com/ayush1273/hospo/blob/main/client/src/components/PredictiveIntelligenceSection.tsx): `client/src/components/PredictiveIntelligenceSection.tsx`
- [Interactive charts](https://github.com/ayush1273/hospo/blob/main/client/src/components/charts/line-chart.tsx): `client/src/components/charts/line-chart.tsx`

### Other components

- **Hospital administrator**
- **Google Gemini**

## Connections

- Hospital administrator → Dashboard page: uses (evidence: `README.md`)
- Dashboard page → FastAPI application: requests analysis
- FastAPI application → API router: mounts (evidence: `backend/main.py`)
- API router → Analysis and HMS API: routes (evidence: `backend/api/router.py`)
- API router → Health API: routes (evidence: `backend/api/router.py`)
- API router → Pharmacy API: routes (evidence: `backend/api/router.py`)
- FastAPI application → Models and cached data: loads lifecycle (evidence: `backend/main.py`)
- Models and cached data → HMS ingestion and features: loads baseline data (evidence: `backend/core/resources.py`)
- Analysis and HMS API → HMS ingestion and features: validates and engineers (evidence: `backend/api/endpoints/analysis.py`)
- Analysis and HMS API → 24-hour occupancy forecast: requests prediction (evidence: `backend/api/endpoints/analysis.py`)
- Analysis and HMS API → Operational risk scoring: scores conditions (evidence: `backend/api/endpoints/analysis.py`)
- Analysis and HMS API → Policy retrieval: retrieves policies (evidence: `backend/api/endpoints/analysis.py`)
- Analysis and HMS API → Recommendation synthesis: synthesizes guidance (evidence: `backend/api/endpoints/analysis.py`)
- Policy retrieval → Models and cached data: reads policy data (evidence: `backend/services/rag_service.py`)
- Policy retrieval → Google Gemini: embeds queries (evidence: `backend/services/rag_service.py`)
- Recommendation synthesis → Google Gemini: generates response
- Analysis and HMS API → Operational schemas: accepts inputs (evidence: `backend/api/endpoints/analysis.py`)
- Analysis and HMS API → Analysis results: returns response (evidence: `backend/api/endpoints/analysis.py`)
- Pharmacy API → Medicine stock intelligence: requests stock intelligence (evidence: `backend/api/endpoints/pharmacy.py`)
- Pharmacy API → Medicine demand forecast: requests demand forecasts (evidence: `backend/api/endpoints/pharmacy.py`)
- Pharmacy API → Pharmacy schemas: uses request and response types (evidence: `backend/api/endpoints/pharmacy.py`)
- Medicine stock intelligence → Pharmacy schemas: builds typed results (evidence: `backend/services/pharmacy_service.py`)
- Medicine demand forecast → Pharmacy schemas: builds typed forecasts (evidence: `backend/services/pharmacy_predict_service.py`)
- Dashboard page → Interactive charts: renders data visualizations
