# pangcodenaemail2-star/smartswine architecture

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

- Interactive diagram: https://gitdiagram.com/pangcodenaemail2-star/smartswine
- Repository: https://github.com/pangcodenaemail2-star/smartswine

## Overview

SmartSwine is a pig-farm monitoring dashboard backed by a local API and an optional AI camera integration. The main workflow is to view herd and farm data, manage pig profiles and records, and send observations or camera images for analysis; settings also support AI dataset validation, training, and calibration. The graph preserves the dashboard’s distinct feature areas and the API, persistence, and inference layers. Some source was only indexed or excerpted, so uncertain internal links are omitted.

Main entry points: [`smartswine-dashboard/src/App.jsx`](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/App.jsx) (Page router), [`smartswine-dashboard/src/layouts/DashboardLayout.jsx`](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/layouts/DashboardLayout.jsx) (Dashboard layout), [`smartswine-dashboard/src/api.js`](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/api.js) (API client), [`aitrain/PigAI_Webapp_Integration/integration/routes.py`](https://github.com/pangcodenaemail2-star/smartswine/blob/main/aitrain/PigAI_Webapp_Integration/integration/routes.py) (AI routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["Farm dashboard"]
  node_app["Page router<br/>[App.jsx]"]
  node_dashboard_page["Herd dashboard<br/>[Dashboard.jsx]"]
  node_pig_records["Pig records<br/>[PigRecords.jsx]"]
  node_health_alerts["Health alerts<br/>[HealthAlerts.jsx]"]
  node_environment["Environment<br/>[Environment.jsx]"]
  node_live_pen["Live pen<br/>[LivePen.jsx]"]
  node_live_camera["Live camera<br/>[LiveCamera.jsx]"]
  node_reports["Reports<br/>[Reports.jsx]"]
  node_feed_costs["Feed costs<br/>[FeedCosts.jsx]"]
  node_settings["AI settings<br/>[Settings.jsx]"]
  node_layout["Dashboard layout"]
end

subgraph group_api["Farm API"]
  node_api_client["API client<br/>[api.js]"]
  node_backend["Farm API<br/>[app.py]"]
end

subgraph group_ai["AI camera"]
  node_ai_routes["AI routes<br/>[routes.py]"]
  node_ai_service["Camera inference<br/>[service.py]"]
  node_behavior["Behavior model<br/>[behavior.py]"]
  node_ai_config["AI configuration<br/>[config.py]"]
end

subgraph group_state["Persistence"]
  node_sqlite[("SQLite records<br/>[storage.py]")]
end

node_farmer(("Farm user"))

node_farmer -->|"uses"| node_app
node_app -->|"routes to"| node_dashboard_page
node_app -->|"routes to"| node_pig_records
node_app -->|"routes to"| node_health_alerts
node_app -->|"routes to"| node_live_pen
node_app -->|"routes to"| node_live_camera
node_app -->|"routes to"| node_reports
node_app -->|"routes to"| node_feed_costs
node_app -->|"routes to"| node_settings
node_farmer -->|"views"| node_environment
node_dashboard_page -->|"renders in"| node_layout
node_pig_records -->|"renders in"| node_layout
node_health_alerts -->|"renders in"| node_layout
node_live_pen -->|"renders in"| node_layout
node_live_camera -->|"renders in"| node_layout
node_reports -->|"renders in"| node_layout
node_feed_costs -->|"renders in"| node_layout
node_settings -->|"renders in"| node_layout
node_dashboard_page -->|"requests data"| node_api_client
node_pig_records -->|"requests records"| node_api_client
node_health_alerts -->|"requests data"| node_api_client
node_reports -->|"requests data"| node_api_client
node_feed_costs -->|"requests data"| node_api_client
node_settings -->|"requests data"| node_api_client
node_settings -->|"trains models"| node_ai_routes
node_pig_records -->|"sends pig requests"| node_backend
node_dashboard_page -.->|"requests dashboard data"| node_backend
node_backend -->|"reads and writes"| node_sqlite
node_backend -->|"includes router"| node_ai_routes
node_ai_routes -->|"processes images"| node_ai_service
node_ai_routes -->|"uses behavior model"| node_behavior
node_ai_routes -->|"uses settings"| node_ai_config
node_ai_service -->|"loads configuration"| node_ai_config

click node_app "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/App.jsx"
click node_dashboard_page "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/Dashboard.jsx"
click node_pig_records "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/PigRecords.jsx"
click node_health_alerts "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/HealthAlerts.jsx"
click node_environment "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/Environment.jsx"
click node_live_pen "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/LivePen.jsx"
click node_live_camera "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/LiveCamera.jsx"
click node_reports "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/Reports.jsx"
click node_feed_costs "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/FeedCosts.jsx"
click node_settings "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/Settings.jsx"
click node_layout "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/layouts/DashboardLayout.jsx"
click node_api_client "https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/api.js"
click node_backend "https://github.com/pangcodenaemail2-star/smartswine/blob/main/backend/app.py"
click node_ai_routes "https://github.com/pangcodenaemail2-star/smartswine/blob/main/aitrain/PigAI_Webapp_Integration/integration/routes.py"
click node_ai_service "https://github.com/pangcodenaemail2-star/smartswine/blob/main/aitrain/PigAI_Webapp_Integration/integration/service.py"
click node_behavior "https://github.com/pangcodenaemail2-star/smartswine/blob/main/aitrain/PigAI_Webapp_Integration/integration/behavior.py"
click node_ai_config "https://github.com/pangcodenaemail2-star/smartswine/blob/main/aitrain/PigAI_Webapp_Integration/integration/config.py"
click node_sqlite "https://github.com/pangcodenaemail2-star/smartswine/blob/main/backend/storage.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_dashboard_page,node_pig_records,node_health_alerts,node_environment,node_live_pen,node_live_camera,node_reports,node_feed_costs,node_settings,node_layout,node_farmer toneBlue
class node_api_client,node_backend toneAmber
class node_ai_routes,node_ai_service,node_behavior,node_ai_config toneMint
class node_sqlite toneRose
```

## Components

### Farm dashboard

- [Page router](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/App.jsx): `smartswine-dashboard/src/App.jsx`
- [Herd dashboard](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/Dashboard.jsx): `smartswine-dashboard/src/pages/Dashboard.jsx`
- [Pig records](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/PigRecords.jsx): `smartswine-dashboard/src/pages/PigRecords.jsx`
- [Health alerts](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/HealthAlerts.jsx): `smartswine-dashboard/src/pages/HealthAlerts.jsx`
- [Environment](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/Environment.jsx): `smartswine-dashboard/src/pages/Environment.jsx`
- [Live pen](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/LivePen.jsx): `smartswine-dashboard/src/pages/LivePen.jsx`
- [Live camera](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/LiveCamera.jsx): `smartswine-dashboard/src/pages/LiveCamera.jsx`
- [Reports](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/Reports.jsx): `smartswine-dashboard/src/pages/Reports.jsx`
- [Feed costs](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/FeedCosts.jsx): `smartswine-dashboard/src/pages/FeedCosts.jsx`
- [AI settings](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/pages/Settings.jsx): `smartswine-dashboard/src/pages/Settings.jsx`
- [Dashboard layout](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/layouts/DashboardLayout.jsx): `smartswine-dashboard/src/layouts/DashboardLayout.jsx`

### Farm API

- [API client](https://github.com/pangcodenaemail2-star/smartswine/blob/main/smartswine-dashboard/src/api.js): `smartswine-dashboard/src/api.js`
- [Farm API](https://github.com/pangcodenaemail2-star/smartswine/blob/main/backend/app.py): `backend/app.py`

### AI camera

- [AI routes](https://github.com/pangcodenaemail2-star/smartswine/blob/main/aitrain/PigAI_Webapp_Integration/integration/routes.py): `aitrain/PigAI_Webapp_Integration/integration/routes.py`
- [Camera inference](https://github.com/pangcodenaemail2-star/smartswine/blob/main/aitrain/PigAI_Webapp_Integration/integration/service.py): `aitrain/PigAI_Webapp_Integration/integration/service.py`
- [Behavior model](https://github.com/pangcodenaemail2-star/smartswine/blob/main/aitrain/PigAI_Webapp_Integration/integration/behavior.py): `aitrain/PigAI_Webapp_Integration/integration/behavior.py`
- [AI configuration](https://github.com/pangcodenaemail2-star/smartswine/blob/main/aitrain/PigAI_Webapp_Integration/integration/config.py): `aitrain/PigAI_Webapp_Integration/integration/config.py`

### Persistence

- [SQLite records](https://github.com/pangcodenaemail2-star/smartswine/blob/main/backend/storage.py): `backend/storage.py`

### Other components

- **Farm user**

## Connections

- Farm user → Page router: uses (evidence: `smartswine-dashboard/src/App.jsx`)
- Page router → Herd dashboard: routes to (evidence: `smartswine-dashboard/src/App.jsx`)
- Page router → Pig records: routes to (evidence: `smartswine-dashboard/src/App.jsx`)
- Page router → Health alerts: routes to (evidence: `smartswine-dashboard/src/App.jsx`)
- Page router → Live pen: routes to (evidence: `smartswine-dashboard/src/App.jsx`)
- Page router → Live camera: routes to (evidence: `smartswine-dashboard/src/App.jsx`)
- Page router → Reports: routes to (evidence: `smartswine-dashboard/src/App.jsx`)
- Page router → Feed costs: routes to (evidence: `smartswine-dashboard/src/App.jsx`)
- Page router → AI settings: routes to (evidence: `smartswine-dashboard/src/App.jsx`)
- Farm user → Environment: views (evidence: `smartswine-dashboard/src/pages/Environment.jsx`)
- Herd dashboard → Dashboard layout: renders in (evidence: `smartswine-dashboard/src/pages/Dashboard.jsx`)
- Pig records → Dashboard layout: renders in (evidence: `smartswine-dashboard/src/pages/PigRecords.jsx`)
- Health alerts → Dashboard layout: renders in (evidence: `smartswine-dashboard/src/pages/HealthAlerts.jsx`)
- Live pen → Dashboard layout: renders in (evidence: `smartswine-dashboard/src/pages/LivePen.jsx`)
- Live camera → Dashboard layout: renders in (evidence: `smartswine-dashboard/src/pages/LiveCamera.jsx`)
- Reports → Dashboard layout: renders in (evidence: `smartswine-dashboard/src/pages/Reports.jsx`)
- Feed costs → Dashboard layout: renders in (evidence: `smartswine-dashboard/src/pages/FeedCosts.jsx`)
- AI settings → Dashboard layout: renders in (evidence: `smartswine-dashboard/src/pages/Settings.jsx`)
- Herd dashboard → API client: requests data (evidence: `smartswine-dashboard/src/pages/Dashboard.jsx`)
- Pig records → API client: requests records (evidence: `smartswine-dashboard/src/pages/PigRecords.jsx`)
- Health alerts → API client: requests data (evidence: `smartswine-dashboard/src/pages/HealthAlerts.jsx`)
- Reports → API client: requests data (evidence: `smartswine-dashboard/src/pages/Reports.jsx`)
- Feed costs → API client: requests data (evidence: `smartswine-dashboard/src/pages/FeedCosts.jsx`)
- AI settings → API client: requests data (evidence: `smartswine-dashboard/src/pages/Settings.jsx`)
- AI settings → AI routes: trains models (evidence: `smartswine-dashboard/src/pages/Settings.jsx`)
- Pig records → Farm API: sends pig requests (evidence: `smartswine-dashboard/src/pages/PigRecords.jsx`)
- Herd dashboard → Farm API: requests dashboard data
- Farm API → SQLite records: reads and writes (evidence: `backend/app.py`)
- Farm API → AI routes: includes router (evidence: `backend/app.py`)
- AI routes → Camera inference: processes images (evidence: `aitrain/PigAI_Webapp_Integration/integration/routes.py`)
- AI routes → Behavior model: uses behavior model (evidence: `aitrain/PigAI_Webapp_Integration/integration/routes.py`)
- AI routes → AI configuration: uses settings (evidence: `aitrain/PigAI_Webapp_Integration/integration/routes.py`)
- Camera inference → AI configuration: loads configuration (evidence: `aitrain/PigAI_Webapp_Integration/integration/service.py`)
