# sharvan-m/goat_precision_livestock architecture

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

- Interactive diagram: https://gitdiagram.com/sharvan-m/goat_precision_livestock
- Repository: https://github.com/sharvan-m/goat_precision_livestock

## Overview

GoatVision is a livestock vision and biometrics dashboard: users upload images or video, then receive goat detections, tracking and view-quality-gated weight estimates, or ocular FAMACHA anemia results. The backend API coordinates these domain stages, while dedicated services implement anemia scoring and weight-analysis steps. The README also documents herd analytics and CSV/Excel auditing. The main API and video-processing excerpts show orchestration; some frontend-to-backend links and unsampled capabilities are documented or indicated by the tree, so uncertain links are omitted or dashed.

Main entry points: [`backend/main.py`](https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/main.py) (FastAPI gateway), [`goat_weight_system/video_processor.py`](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/video_processor.py) (Video processor), [`backend/services/anemia_pipeline.py`](https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/services/anemia_pipeline.py) (Anemia pipeline), [`goat_weight_system/regression_models.py`](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/regression_models.py) (Weight regression)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["Dashboard"]
  node_upload_ui["Media upload<br/>[UploadDropzone.tsx]"]
  node_image_analysis_ui["Image analysis<br/>[page.tsx]"]
  node_goat_detection_ui["Goat detection<br/>[page.tsx]"]
  node_anemia_ui["Anemia screening<br/>[page.tsx]"]
  node_tracking_ui["Tracking view<br/>[page.tsx]"]
  node_records_ui["Records view<br/>[page.tsx]"]
  node_analytics_ui["Herd analytics<br/>[page.tsx]"]
end

subgraph group_api_health["API &amp; health screening"]
  node_api["FastAPI gateway<br/>[main.py]"]
  node_video_route["Video analysis route<br/>[video_analysis.py]"]
  node_anemia_pipeline["Anemia pipeline<br/>[anemia_pipeline.py]"]
  node_conjunctiva_model["Conjunctiva detection"]
  node_colorimetry["FAMACHA colorimetry"]
end

subgraph group_weight["Weight vision"]
  node_video_analyzer["Video analyzer"]
  node_video_processor["Video processor<br/>[video_processor.py]"]
  node_detector["Goat detector<br/>[detector.py]"]
  node_view_gate["View-quality gate<br/>[view_evaluator.py]"]
  node_measurements["Morphology measures"]
  node_regression["Weight regression"]
  node_tracking["Animal tracking<br/>[tracker.py]"]
  node_bytetrack["ByteTrack system"]
end

subgraph group_herd["Herd records"]
  node_logging[("Analysis logging<br/>[data_logger.py]")]
  node_dataset[("Weight dataset<br/>[dataset_manager.py]")]
end

node_farmer(("Livestock user"))
node_external_roboflow{{"Roboflow service"}}

node_farmer -->|"uploads media"| node_upload_ui
node_image_analysis_ui -->|"selects file"| node_upload_ui
node_goat_detection_ui -->|"selects file"| node_upload_ui
node_image_analysis_ui -.->|"submits analysis"| node_api
node_goat_detection_ui -->|"posts detection"| node_api
node_anemia_ui -.->|"requests screening"| node_api
node_api -.->|"routes video"| node_video_route
node_video_route -->|"calls analyzer"| node_video_analyzer
node_api -->|"uses detection"| node_detector
node_api -->|"evaluates view"| node_view_gate
node_api -->|"extracts features"| node_measurements
node_api -->|"predicts weight"| node_regression
node_api -->|"runs screening"| node_anemia_pipeline
node_anemia_pipeline -->|"gets predictions"| node_conjunctiva_model
node_anemia_pipeline -->|"scores color"| node_colorimetry
node_conjunctiva_model -.->|"queries model"| node_external_roboflow
node_video_processor -->|"detects goats"| node_detector
node_video_processor -->|"scores views"| node_view_gate
node_video_processor -->|"extracts measures"| node_measurements
node_video_processor -->|"predicts weight"| node_regression
node_video_processor -->|"tracks IDs"| node_tracking
node_tracking -->|"uses detections"| node_detector
node_video_processor -->|"logs results"| node_logging
node_regression -->|"loads data"| node_dataset
node_tracking_ui -.->|"requests telemetry"| node_api
node_records_ui -.->|"views history"| node_logging
node_analytics_ui -.->|"summarizes herd"| node_logging
node_bytetrack -.->|"provides tracking"| node_tracking

click node_upload_ui "https://github.com/sharvan-m/goat_precision_livestock/blob/main/components/UploadDropzone.tsx"
click node_image_analysis_ui "https://github.com/sharvan-m/goat_precision_livestock/blob/main/app/analyze/page.tsx"
click node_goat_detection_ui "https://github.com/sharvan-m/goat_precision_livestock/blob/main/app/detect/page.tsx"
click node_anemia_ui "https://github.com/sharvan-m/goat_precision_livestock/blob/main/app/anemia/page.tsx"
click node_tracking_ui "https://github.com/sharvan-m/goat_precision_livestock/blob/main/app/tracking/page.tsx"
click node_records_ui "https://github.com/sharvan-m/goat_precision_livestock/blob/main/app/records/page.tsx"
click node_analytics_ui "https://github.com/sharvan-m/goat_precision_livestock/blob/main/frontend/app/analytics/page.tsx"
click node_api "https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/main.py"
click node_video_route "https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/routes/video_analysis.py"
click node_anemia_pipeline "https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/services/anemia_pipeline.py"
click node_conjunctiva_model "https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/services/conjunctiva_roboflow.py"
click node_colorimetry "https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/services/famacha_colorimeter.py"
click node_video_analyzer "https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_video_analyzer.py"
click node_video_processor "https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/video_processor.py"
click node_detector "https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/detector.py"
click node_view_gate "https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/view_evaluator.py"
click node_measurements "https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/measurement_extractor.py"
click node_regression "https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/regression_models.py"
click node_tracking "https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/tracker.py"
click node_bytetrack "https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/bytetrack_system.py"
click node_logging "https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/data_logger.py"
click node_dataset "https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/dataset_manager.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_upload_ui,node_image_analysis_ui,node_goat_detection_ui,node_anemia_ui,node_tracking_ui,node_records_ui,node_analytics_ui,node_farmer toneBlue
class node_api,node_video_route,node_anemia_pipeline,node_conjunctiva_model,node_colorimetry toneAmber
class node_video_analyzer,node_video_processor,node_detector,node_view_gate,node_measurements,node_regression,node_tracking,node_bytetrack toneMint
class node_logging,node_dataset toneRose
class node_external_roboflow toneIndigo
```

## Components

### Dashboard

- [Media upload](https://github.com/sharvan-m/goat_precision_livestock/blob/main/components/UploadDropzone.tsx): `components/UploadDropzone.tsx`
- [Image analysis](https://github.com/sharvan-m/goat_precision_livestock/blob/main/app/analyze/page.tsx): `app/analyze/page.tsx`
- [Goat detection](https://github.com/sharvan-m/goat_precision_livestock/blob/main/app/detect/page.tsx): `app/detect/page.tsx`
- [Anemia screening](https://github.com/sharvan-m/goat_precision_livestock/blob/main/app/anemia/page.tsx): `app/anemia/page.tsx`
- [Tracking view](https://github.com/sharvan-m/goat_precision_livestock/blob/main/app/tracking/page.tsx): `app/tracking/page.tsx`
- [Records view](https://github.com/sharvan-m/goat_precision_livestock/blob/main/app/records/page.tsx): `app/records/page.tsx`
- [Herd analytics](https://github.com/sharvan-m/goat_precision_livestock/blob/main/frontend/app/analytics/page.tsx): `frontend/app/analytics/page.tsx`

### API & health screening

- [FastAPI gateway](https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/main.py): `backend/main.py`
- [Video analysis route](https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/routes/video_analysis.py): `backend/routes/video_analysis.py`
- [Anemia pipeline](https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/services/anemia_pipeline.py): `backend/services/anemia_pipeline.py`
- [Conjunctiva detection](https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/services/conjunctiva_roboflow.py): `backend/services/conjunctiva_roboflow.py`
- [FAMACHA colorimetry](https://github.com/sharvan-m/goat_precision_livestock/blob/main/backend/services/famacha_colorimeter.py): `backend/services/famacha_colorimeter.py`

### Weight vision

- [Video analyzer](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_video_analyzer.py): `goat_video_analyzer.py`
- [Video processor](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/video_processor.py): `goat_weight_system/video_processor.py`
- [Goat detector](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/detector.py): `goat_weight_system/detector.py`
- [View-quality gate](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/view_evaluator.py): `goat_weight_system/view_evaluator.py`
- [Morphology measures](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/measurement_extractor.py): `goat_weight_system/measurement_extractor.py`
- [Weight regression](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/regression_models.py): `goat_weight_system/regression_models.py`
- [Animal tracking](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/tracker.py): `goat_weight_system/tracker.py`
- [ByteTrack system](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/bytetrack_system.py): `goat_weight_system/bytetrack_system.py`

### Herd records

- [Analysis logging](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/data_logger.py): `goat_weight_system/data_logger.py`
- [Weight dataset](https://github.com/sharvan-m/goat_precision_livestock/blob/main/goat_weight_system/dataset_manager.py): `goat_weight_system/dataset_manager.py`

### Other components

- **Livestock user**
- **Roboflow service**

## Connections

- Livestock user → Media upload: uploads media (evidence: `components/UploadDropzone.tsx`)
- Image analysis → Media upload: selects file (evidence: `app/analyze/page.tsx`)
- Goat detection → Media upload: selects file (evidence: `app/detect/page.tsx`)
- Image analysis → FastAPI gateway: submits analysis
- Goat detection → FastAPI gateway: posts detection (evidence: `app/detect/page.tsx`)
- Anemia screening → FastAPI gateway: requests screening
- FastAPI gateway → Video analysis route: routes video
- Video analysis route → Video analyzer: calls analyzer (evidence: `backend/routes/video_analysis.py`)
- FastAPI gateway → Goat detector: uses detection (evidence: `backend/main.py`)
- FastAPI gateway → View-quality gate: evaluates view (evidence: `backend/main.py`)
- FastAPI gateway → Morphology measures: extracts features (evidence: `backend/main.py`)
- FastAPI gateway → Weight regression: predicts weight (evidence: `backend/main.py`)
- FastAPI gateway → Anemia pipeline: runs screening (evidence: `backend/main.py`)
- Anemia pipeline → Conjunctiva detection: gets predictions (evidence: `backend/services/anemia_pipeline.py`)
- Anemia pipeline → FAMACHA colorimetry: scores color (evidence: `backend/services/anemia_pipeline.py`)
- Conjunctiva detection → Roboflow service: queries model
- Video processor → Goat detector: detects goats (evidence: `goat_weight_system/video_processor.py`)
- Video processor → View-quality gate: scores views (evidence: `goat_weight_system/video_processor.py`)
- Video processor → Morphology measures: extracts measures (evidence: `goat_weight_system/video_processor.py`)
- Video processor → Weight regression: predicts weight (evidence: `goat_weight_system/video_processor.py`)
- Video processor → Animal tracking: tracks IDs (evidence: `goat_weight_system/video_processor.py`)
- Animal tracking → Goat detector: uses detections (evidence: `goat_weight_system/tracker.py`)
- Video processor → Analysis logging: logs results (evidence: `goat_weight_system/video_processor.py`)
- Weight regression → Weight dataset: loads data (evidence: `goat_weight_system/regression_models.py`)
- Tracking view → FastAPI gateway: requests telemetry
- Records view → Analysis logging: views history
- Herd analytics → Analysis logging: summarizes herd
- ByteTrack system → Animal tracking: provides tracking
