# shyaamsundar2310422/livestock_health_ai architecture

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

- Interactive diagram: https://gitdiagram.com/shyaamsundar2310422/livestock_health_ai
- Repository: https://github.com/shyaamsundar2310422/livestock_health_ai

## Overview

This is a Streamlit livestock-health application combining cattle image screening and explainability with animal digital-twin records, telemetry, and risk scoring. The main user workflow is to select an animal, submit an image for a model prediction, optionally inspect a Grad-CAM explanation, and view the animal’s recorded health and risk state. The repository also includes DMI prediction and feed inventory/procurement functionality. Some app and domain source is excerpted only partially; links for unsampled or unverified behavior are omitted.

Main entry points: [`app.py`](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/app.py) (Streamlit App), [`src/digital_twin.py`](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/digital_twin.py) (Twin State), [`src/database.py`](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/database.py) (SQLite Persistence), [`src/model.py`](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/model.py) (Image Inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_screening["Health Screening"]
  node_app["Streamlit App<br/>[app.py]"]
  node_vision["Image Inference<br/>[model.py]"]
  node_explain["Grad-CAM<br/>[gradcam.py]"]
end

subgraph group_twins["Animal Digital Twins"]
  node_twin_ui["Twin Views<br/>[app.py]"]
  node_twin_domain["Twin State<br/>[digital_twin.py]"]
  node_risk["Risk Assessment<br/>[digital_twin.py]"]
end

subgraph group_nutrition["Nutrition and Supply"]
  node_dmi_ui["DMI Interface<br/>[app.py]"]
  node_dmi["DMI Prediction<br/>[dmi_model.py]"]
  node_inventory["Feed Inventory<br/>[feed_inventory.py]"]
  node_demand["Feed Demand<br/>[feed_demand.py]"]
  node_shortage["Feed Shortage<br/>[feed_shortage.py]"]
  node_procurement["Procurement Planning"]
end

subgraph group_shared["Shared Services"]
  node_sqlite[("SQLite Persistence<br/>[database.py]")]
  node_settings["Model and Data Config<br/>[config.py]"]
end

node_user(("Farm User"))

node_user -->|"uses"| node_app
node_app -->|"runs inference"| node_vision
node_app -->|"requests heatmaps"| node_explain
node_explain -->|"loads model"| node_vision
node_vision -->|"reads settings"| node_settings
node_app -->|"renders twin views"| node_twin_ui
node_app -->|"loads twin state"| node_twin_domain
node_app -->|"shows risk factors"| node_risk
node_twin_domain -->|"reads records"| node_sqlite
node_twin_domain -->|"persists observations"| node_sqlite
node_risk -->|"scores twin data"| node_twin_domain
node_sqlite -->|"uses paths"| node_settings
node_app -->|"uses DMI model"| node_dmi
node_dmi -->|"reads configuration"| node_settings
node_app -->|"uses inventory"| node_inventory
node_app -->|"uses optimizer"| node_procurement
node_procurement -->|"validates items"| node_inventory
node_sqlite -->|"references inventory logic"| node_inventory

click node_app "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/app.py"
click node_vision "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/model.py"
click node_explain "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/gradcam.py"
click node_twin_ui "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/app.py"
click node_twin_domain "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/digital_twin.py"
click node_risk "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/digital_twin.py"
click node_sqlite "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/database.py"
click node_settings "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/config.py"
click node_dmi_ui "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/app.py"
click node_dmi "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/dmi_model.py"
click node_inventory "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/feed_inventory.py"
click node_demand "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/feed_demand.py"
click node_shortage "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/feed_shortage.py"
click node_procurement "https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/procurement_optimizer.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_vision,node_explain,node_user toneBlue
class node_twin_ui,node_twin_domain,node_risk toneAmber
class node_dmi_ui,node_dmi,node_inventory,node_demand,node_shortage,node_procurement toneMint
class node_sqlite,node_settings toneRose
```

## Components

### Health Screening

- [Streamlit App](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/app.py): `app.py`
- [Image Inference](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/model.py): `src/model.py`
- [Grad-CAM](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/gradcam.py): `src/gradcam.py`

### Animal Digital Twins

- [Twin Views](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/app.py): `app.py`
- [Twin State](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/digital_twin.py): `src/digital_twin.py`
- [Risk Assessment](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/digital_twin.py): `src/digital_twin.py`

### Nutrition and Supply

- [DMI Interface](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/app.py): `app.py`
- [DMI Prediction](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/dmi_model.py): `src/dmi_model.py`
- [Feed Inventory](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/feed_inventory.py): `src/feed_inventory.py`
- [Feed Demand](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/feed_demand.py): `src/feed_demand.py`
- [Feed Shortage](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/feed_shortage.py): `src/feed_shortage.py`
- [Procurement Planning](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/procurement_optimizer.py): `src/procurement_optimizer.py`

### Shared Services

- [SQLite Persistence](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/database.py): `src/database.py`
- [Model and Data Config](https://github.com/shyaamsundar2310422/livestock_health_ai/blob/main/src/config.py): `src/config.py`

### Other components

- **Farm User**

## Connections

- Farm User → Streamlit App: uses (evidence: `README.md`)
- Streamlit App → Image Inference: runs inference (evidence: `app.py`)
- Streamlit App → Grad-CAM: requests heatmaps (evidence: `app.py`)
- Grad-CAM → Image Inference: loads model (evidence: `src/gradcam.py`)
- Image Inference → Model and Data Config: reads settings (evidence: `src/model.py`)
- Streamlit App → Twin Views: renders twin views (evidence: `app.py`)
- Streamlit App → Twin State: loads twin state (evidence: `app.py`)
- Streamlit App → Risk Assessment: shows risk factors (evidence: `app.py`)
- Twin State → SQLite Persistence: reads records (evidence: `src/digital_twin.py`)
- Twin State → SQLite Persistence: persists observations (evidence: `src/digital_twin.py`)
- Risk Assessment → Twin State: scores twin data (evidence: `README.md`)
- SQLite Persistence → Model and Data Config: uses paths (evidence: `src/database.py`)
- Streamlit App → DMI Prediction: uses DMI model (evidence: `app.py`)
- DMI Prediction → Model and Data Config: reads configuration (evidence: `src/dmi_model.py`)
- Streamlit App → Feed Inventory: uses inventory (evidence: `app.py`)
- Streamlit App → Procurement Planning: uses optimizer (evidence: `app.py`)
- Procurement Planning → Feed Inventory: validates items (evidence: `src/procurement_optimizer.py`)
- SQLite Persistence → Feed Inventory: references inventory logic (evidence: `src/database.py`)
