# niranjanmkiran-crypto/hemapulse-ai architecture

> Architecture diagram of the GitHub repository niranjanmkiran-crypto/hemapulse-ai, 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/niranjanmkiran-crypto/hemapulse-ai
- Repository: https://github.com/niranjanmkiran-crypto/hemapulse-ai

## Overview

HemaPulse AI is a hospital blood-inventory and demand decision-support platform. Hospital staff use the web app to review stock, forecasts, shortage/expiry risks, alerts and recommendations, then perform inventory or emergency actions through the API. The backend routes coordinate forecasting and decision engines over seeded in-memory operational data. The README documents additional scenario simulation, explainable recommendations and FEFO workflows; unsampled implementations are represented only where the tree and documented capabilities support them. Some UI-to-API links are evidenced by the sampled client endpoints and component references; deeper behavior of unsampled routes is not inferred.

Main entry points: [`frontend/src/App.tsx`](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/App.tsx) (App Shell), [`backend/app/api/routes.py`](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/api/routes.py) (API Routes), [`frontend/src/api/client.ts`](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/api/client.ts) (API Client), [`backend/app/services/seed_data.py`](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/seed_data.py) (In-Memory Store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Staff Web App"]
  node_app["App Shell<br/>[App.tsx]"]
  node_overview["Decision Overview"]
  node_forecastview["Demand Forecast"]
  node_inventoryview["Inventory FEFO"]
  node_shortageview["Shortage Radar"]
  node_emergencyview["Emergency Center"]
  node_recommendview["Recommendations"]
  node_alertsview["Alerts<br/>[AlertsView.tsx]"]
  node_reportsview["Reports<br/>[ReportsView.tsx]"]
end

subgraph group_api["API &amp; Contracts"]
  node_client["API Client<br/>[client.ts]"]
  node_server["FastAPI App<br/>[main.py]"]
  node_routes["API Routes<br/>[routes.py]"]
  node_schemas["API Schemas<br/>[schemas.py]"]
end

subgraph group_engines["Decision Engines"]
  node_forecast["ML Forecasting<br/>[ml_forecasting.py]"]
  node_shortage["Shortage Engine<br/>[shortage_engine.py]"]
  node_emergency["Emergency &amp; Anomaly"]
  node_expiry["Expiry &amp; FEFO<br/>[expiry_engine.py]"]
  node_recommend["Recommendation Engine"]
end

subgraph group_state["Domain &amp; State"]
  node_domain["Blood Domain<br/>[domain.py]"]
  node_store[("In-Memory Store<br/>[seed_data.py]")]
  node_config["App Configuration<br/>[config.py]"]
end

node_staff(("Hospital Staff"))

node_staff -->|"uses"| node_app
node_app -->|"renders"| node_overview
node_app -->|"renders"| node_forecastview
node_app -->|"renders"| node_inventoryview
node_app -->|"renders"| node_shortageview
node_app -->|"renders"| node_emergencyview
node_app -->|"renders"| node_recommendview
node_app -->|"renders"| node_alertsview
node_app -->|"renders"| node_reportsview
node_app -->|"loads overview"| node_client
node_forecastview -->|"requests forecast"| node_client
node_inventoryview -->|"requests inventory"| node_client
node_shortageview -->|"requests risks"| node_client
node_emergencyview -->|"declares incident"| node_client
node_recommendview -->|"requests actions"| node_client
node_alertsview -->|"requests alerts"| node_client
node_reportsview -->|"requests reports"| node_client
node_client -->|"calls API"| node_routes
node_server -->|"mounts routes"| node_routes
node_server -->|"initializes data"| node_store
node_server -->|"warms model"| node_forecast
node_server -->|"reads settings"| node_config
node_routes -->|"reads and writes"| node_store
node_routes -->|"requests forecasts"| node_forecast
node_routes -->|"evaluates shortage"| node_shortage
node_routes -->|"handles incidents"| node_emergency
node_routes -->|"gets expiry status"| node_expiry
node_routes -->|"gets and executes"| node_recommend
node_forecast -->|"reads demand data"| node_store
node_shortage -->|"reads inventory"| node_store
node_emergency -->|"updates incident state"| node_store
node_expiry -->|"ranks expiring stock"| node_store
node_recommend -->|"records actions"| node_store
node_schemas -->|"uses types"| node_domain
node_store -->|"seeds domain data"| node_domain
node_routes -->|"validates responses"| node_schemas

click node_app "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/App.tsx"
click node_overview "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/dashboard/DecisionOverview.tsx"
click node_forecastview "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/forecast/DemandForecastView.tsx"
click node_inventoryview "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/inventory/InventoryFefoView.tsx"
click node_shortageview "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/shortage/ShortageExpiryRadar.tsx"
click node_emergencyview "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/emergency/EmergencyCenter.tsx"
click node_recommendview "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/recommendations/RecommendationsView.tsx"
click node_alertsview "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/alerts/AlertsView.tsx"
click node_reportsview "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/reports/ReportsView.tsx"
click node_client "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/api/client.ts"
click node_server "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/main.py"
click node_routes "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/api/routes.py"
click node_schemas "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/models/schemas.py"
click node_forecast "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/ml_forecasting.py"
click node_shortage "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/shortage_engine.py"
click node_emergency "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/emergency_engine.py"
click node_expiry "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/expiry_engine.py"
click node_recommend "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/recommendation_engine.py"
click node_domain "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/models/domain.py"
click node_store "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/seed_data.py"
click node_config "https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/core/config.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_overview,node_forecastview,node_inventoryview,node_shortageview,node_emergencyview,node_recommendview,node_alertsview,node_reportsview toneBlue
class node_client,node_server,node_routes,node_schemas toneAmber
class node_forecast,node_shortage,node_emergency,node_expiry,node_recommend toneMint
class node_domain,node_store,node_config toneRose
class node_staff toneIndigo
```

## Components

### Staff Web App

- [App Shell](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Decision Overview](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/dashboard/DecisionOverview.tsx): `frontend/src/components/dashboard/DecisionOverview.tsx`
- [Demand Forecast](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/forecast/DemandForecastView.tsx): `frontend/src/components/forecast/DemandForecastView.tsx`
- [Inventory FEFO](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/inventory/InventoryFefoView.tsx): `frontend/src/components/inventory/InventoryFefoView.tsx`
- [Shortage Radar](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/shortage/ShortageExpiryRadar.tsx): `frontend/src/components/shortage/ShortageExpiryRadar.tsx`
- [Emergency Center](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/emergency/EmergencyCenter.tsx): `frontend/src/components/emergency/EmergencyCenter.tsx`
- [Recommendations](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/recommendations/RecommendationsView.tsx): `frontend/src/components/recommendations/RecommendationsView.tsx`
- [Alerts](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/alerts/AlertsView.tsx): `frontend/src/components/alerts/AlertsView.tsx`
- [Reports](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/components/reports/ReportsView.tsx): `frontend/src/components/reports/ReportsView.tsx`

### API & Contracts

- [API Client](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/frontend/src/api/client.ts): `frontend/src/api/client.ts`
- [FastAPI App](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/main.py): `backend/app/main.py`
- [API Routes](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`
- [API Schemas](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/models/schemas.py): `backend/app/models/schemas.py`

### Decision Engines

- [ML Forecasting](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/ml_forecasting.py): `backend/app/services/ml_forecasting.py`
- [Shortage Engine](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/shortage_engine.py): `backend/app/services/shortage_engine.py`
- [Emergency & Anomaly](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/emergency_engine.py): `backend/app/services/emergency_engine.py`
- [Expiry & FEFO](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/expiry_engine.py): `backend/app/services/expiry_engine.py`
- [Recommendation Engine](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/recommendation_engine.py): `backend/app/services/recommendation_engine.py`

### Domain & State

- [Blood Domain](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/models/domain.py): `backend/app/models/domain.py`
- [In-Memory Store](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/services/seed_data.py): `backend/app/services/seed_data.py`
- [App Configuration](https://github.com/niranjanmkiran-crypto/hemapulse-ai/blob/main/backend/app/core/config.py): `backend/app/core/config.py`

### Other components

- **Hospital Staff**

## Connections

- Hospital Staff → App Shell: uses (evidence: `README.md`)
- App Shell → Decision Overview: renders (evidence: `frontend/src/App.tsx`)
- App Shell → Demand Forecast: renders (evidence: `frontend/src/App.tsx`)
- App Shell → Inventory FEFO: renders (evidence: `frontend/src/App.tsx`)
- App Shell → Shortage Radar: renders (evidence: `frontend/src/App.tsx`)
- App Shell → Emergency Center: renders (evidence: `frontend/src/App.tsx`)
- App Shell → Recommendations: renders (evidence: `frontend/src/App.tsx`)
- App Shell → Alerts: renders (evidence: `frontend/src/App.tsx`)
- App Shell → Reports: renders (evidence: `frontend/src/App.tsx`)
- App Shell → API Client: loads overview (evidence: `frontend/src/App.tsx`)
- Demand Forecast → API Client: requests forecast (evidence: `frontend/src/components/forecast/DemandForecastView.tsx`)
- Inventory FEFO → API Client: requests inventory (evidence: `frontend/src/components/inventory/InventoryFefoView.tsx`)
- Shortage Radar → API Client: requests risks (evidence: `frontend/src/components/shortage/ShortageExpiryRadar.tsx`)
- Emergency Center → API Client: declares incident (evidence: `frontend/src/components/emergency/EmergencyCenter.tsx`)
- Recommendations → API Client: requests actions (evidence: `frontend/src/components/recommendations/RecommendationsView.tsx`)
- Alerts → API Client: requests alerts (evidence: `frontend/src/components/alerts/AlertsView.tsx`)
- Reports → API Client: requests reports (evidence: `frontend/src/components/reports/ReportsView.tsx`)
- API Client → API Routes: calls API (evidence: `frontend/src/api/client.ts`)
- FastAPI App → API Routes: mounts routes (evidence: `backend/app/main.py`)
- FastAPI App → In-Memory Store: initializes data (evidence: `backend/app/main.py`)
- FastAPI App → ML Forecasting: warms model (evidence: `backend/app/main.py`)
- FastAPI App → App Configuration: reads settings (evidence: `backend/app/main.py`)
- API Routes → In-Memory Store: reads and writes (evidence: `backend/app/api/routes.py`)
- API Routes → ML Forecasting: requests forecasts (evidence: `backend/app/api/routes.py`)
- API Routes → Shortage Engine: evaluates shortage (evidence: `backend/app/api/routes.py`)
- API Routes → Emergency & Anomaly: handles incidents (evidence: `backend/app/api/routes.py`)
- API Routes → Expiry & FEFO: gets expiry status (evidence: `backend/app/api/routes.py`)
- API Routes → Recommendation Engine: gets and executes (evidence: `backend/app/api/routes.py`)
- ML Forecasting → In-Memory Store: reads demand data (evidence: `backend/app/services/ml_forecasting.py`)
- Shortage Engine → In-Memory Store: reads inventory (evidence: `backend/app/services/shortage_engine.py`)
- Emergency & Anomaly → In-Memory Store: updates incident state (evidence: `backend/app/services/emergency_engine.py`)
- Expiry & FEFO → In-Memory Store: ranks expiring stock (evidence: `backend/app/services/expiry_engine.py`)
- Recommendation Engine → In-Memory Store: records actions (evidence: `backend/app/services/recommendation_engine.py`)
- API Schemas → Blood Domain: uses types (evidence: `backend/app/models/schemas.py`)
- In-Memory Store → Blood Domain: seeds domain data (evidence: `backend/app/services/seed_data.py`)
- API Routes → API Schemas: validates responses (evidence: `backend/app/api/routes.py`)
