# pranaypr9/sih-cattle-breed-recognition architecture

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

- Interactive diagram: https://gitdiagram.com/pranaypr9/sih-cattle-breed-recognition
- Repository: https://github.com/pranaypr9/sih-cattle-breed-recognition

## Overview

Pashu Pehchaan is a web application for recognizing Indian cattle and buffalo breeds from uploaded images. A user selects a photo, the React app sends it to Flask, and the backend validates and stores a copy, runs breed inference, records the top predictions in PostgreSQL, and returns results for display. The backend also exposes health, breed-list, and prediction-history endpoints. A separate training workflow fine-tunes the classifier and produces weights and class labels. The graph follows shown calls and documented capabilities; some API endpoints have no sampled frontend consumer.

Main entry points: [`backend/app.py`](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/app.py) (Flask routes), [`frontend/src/App.jsx`](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/frontend/src/App.jsx) (App workflow), [`backend/models/db_models.py`](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/models/db_models.py) (Breed and prediction records), [`backend/ml/model.py`](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/ml/model.py) (ResNet50 model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_app_ui["App workflow<br/>[App.jsx]"]
  node_upload_ui["Image upload<br/>[ImageUpload.jsx]"]
  node_result_ui["Result display"]
  node_header_ui["Status header<br/>[Header.jsx]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_api["Recognition API"]
  node_flask["Flask routes<br/>[app.py]"]
  node_config["Runtime config<br/>[config.py]"]
end

subgraph group_ml["Breed classifier"]
  node_classifier["ResNet50 model<br/>[model.py]"]
  node_inference["Image inference<br/>[predict.py]"]
  node_labels["Breed labels<br/>[class_labels.json]"]
  node_training["Model training<br/>[train.py]"]
end

subgraph group_data["Prediction data"]
  node_image_store[("Uploaded images")]
  node_models_db["Breed and prediction records<br/>[db_models.py]"]
end

node_user(("Field user"))
node_postgres[("PostgreSQL")]

node_user -->|"selects image"| node_upload_ui
node_upload_ui -->|"sends selection"| node_app_ui
node_app_ui -->|"requests prediction"| node_api_client
node_app_ui -->|"checks health"| node_api_client
node_api_client -->|"posts image"| node_flask
node_flask -->|"returns prediction"| node_app_ui
node_app_ui -->|"renders result"| node_result_ui
node_app_ui -->|"renders status"| node_header_ui
node_flask -->|"loads settings"| node_config
node_flask -->|"loads model"| node_classifier
node_flask -->|"loads class labels"| node_labels
node_flask -->|"runs inference"| node_inference
node_inference -->|"executes model"| node_classifier
node_flask -->|"saves image"| node_image_store
node_flask -->|"records and queries"| node_models_db
node_models_db -->|"persists records"| node_postgres
node_training -->|"builds model"| node_classifier
node_training -->|"writes labels"| node_labels
node_training -->|"saves weights"| node_classifier
node_flask -->|"lists breeds"| node_models_db
node_flask -->|"lists history"| node_models_db

click node_app_ui "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/frontend/src/App.jsx"
click node_upload_ui "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/frontend/src/components/ImageUpload.jsx"
click node_result_ui "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/frontend/src/components/PredictionResult.jsx"
click node_header_ui "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/frontend/src/components/Header.jsx"
click node_api_client "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/frontend/src/api/api.js"
click node_flask "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/app.py"
click node_config "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/config.py"
click node_image_store "https://github.com/pranaypr9/sih-cattle-breed-recognition/tree/main/backend/uploads"
click node_models_db "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/models/db_models.py"
click node_classifier "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/ml/model.py"
click node_inference "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/ml/predict.py"
click node_labels "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/ml/class_labels.json"
click node_training "https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/ml/train.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_ui,node_upload_ui,node_result_ui,node_header_ui,node_api_client,node_user toneBlue
class node_flask,node_config,node_postgres toneAmber
class node_classifier,node_inference,node_labels,node_training toneMint
class node_image_store,node_models_db toneRose
```

## Components

### Web interface

- [App workflow](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Image upload](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/frontend/src/components/ImageUpload.jsx): `frontend/src/components/ImageUpload.jsx`
- [Result display](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/frontend/src/components/PredictionResult.jsx): `frontend/src/components/PredictionResult.jsx`
- [Status header](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/frontend/src/components/Header.jsx): `frontend/src/components/Header.jsx`
- [API client](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/frontend/src/api/api.js): `frontend/src/api/api.js`

### Recognition API

- [Flask routes](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/app.py): `backend/app.py`
- [Runtime config](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/config.py): `backend/config.py`

### Breed classifier

- [ResNet50 model](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/ml/model.py): `backend/ml/model.py`
- [Image inference](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/ml/predict.py): `backend/ml/predict.py`
- [Breed labels](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/ml/class_labels.json): `backend/ml/class_labels.json`
- [Model training](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/ml/train.py): `backend/ml/train.py`

### Prediction data

- [Uploaded images](https://github.com/pranaypr9/sih-cattle-breed-recognition/tree/main/backend/uploads): `backend/uploads`
- [Breed and prediction records](https://github.com/pranaypr9/sih-cattle-breed-recognition/blob/main/backend/models/db_models.py): `backend/models/db_models.py`

### Other components

- **Field user**
- **PostgreSQL**

## Connections

- Field user → Image upload: selects image (evidence: `frontend/src/components/ImageUpload.jsx`)
- Image upload → App workflow: sends selection (evidence: `frontend/src/App.jsx`)
- App workflow → API client: requests prediction (evidence: `frontend/src/App.jsx`)
- App workflow → API client: checks health (evidence: `frontend/src/App.jsx`)
- API client → Flask routes: posts image (evidence: `frontend/src/api/api.js`)
- Flask routes → App workflow: returns prediction (evidence: `backend/app.py`)
- App workflow → Result display: renders result (evidence: `frontend/src/App.jsx`)
- App workflow → Status header: renders status (evidence: `frontend/src/App.jsx`)
- Flask routes → Runtime config: loads settings (evidence: `backend/app.py`)
- Flask routes → ResNet50 model: loads model (evidence: `backend/app.py`)
- Flask routes → Breed labels: loads class labels (evidence: `backend/app.py`)
- Flask routes → Image inference: runs inference (evidence: `backend/app.py`)
- Image inference → ResNet50 model: executes model (evidence: `backend/ml/predict.py`)
- Flask routes → Uploaded images: saves image (evidence: `backend/app.py`)
- Flask routes → Breed and prediction records: records and queries (evidence: `backend/app.py`)
- Breed and prediction records → PostgreSQL: persists records (evidence: `README.md`)
- Model training → ResNet50 model: builds model (evidence: `backend/ml/train.py`)
- Model training → Breed labels: writes labels (evidence: `backend/ml/train.py`)
- Model training → ResNet50 model: saves weights (evidence: `README.md`)
- Flask routes → Breed and prediction records: lists breeds (evidence: `backend/app.py`)
- Flask routes → Breed and prediction records: lists history (evidence: `backend/app.py`)
