# enkiponics/smartcityfarmagent architecture

> Architecture diagram of the GitHub repository enkiponics/smartcityfarmagent, 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/enkiponics/smartcityfarmagent
- Repository: https://github.com/enkiponics/smartcityfarmagent

## Overview

SmartCityFarm Agent is an aquaponics analysis and recommendation PoC. Sensor data is unified and regularized; separate workflows provide LSTM forecasts, Bayesian risk classification, and plant-disease detection. The agent can load pipeline artifacts, add that context to a user query, and request recommendations from OpenRouter. Users can access this through the CLI/Python API or the FastAPI dashboard. The dashboard also exposes plots, status, and data summaries. Workflow-to-artifact links are documented in the README; unsampled workflow details are not inferred.

Main entry points: [`agent.py`](https://github.com/enkiponics/smartcityfarmagent/blob/main/agent.py) (Agent and context loading), [`pipelines/data`](https://github.com/enkiponics/smartcityfarmagent/tree/main/pipelines/data) (Analysis artifacts), [`dashboard.py`](https://github.com/enkiponics/smartcityfarmagent/blob/main/dashboard.py) (FastAPI endpoints), [`pipelines/data/data_input`](https://github.com/enkiponics/smartcityfarmagent/tree/main/pipelines/data/data_input) (Unified sensor data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Sensor preparation"]
  node_sensorfiles["Sensor CSVs"]
  node_homogenize["Data homogenization<br/>[data_prep.py]"]
  node_prepared["Unified sensor data"]
end

subgraph group_analysis["Analysis workflows"]
  node_lstm["LSTM forecasting<br/>[lstm_wf.py]"]
  node_bayes["Bayesian classification<br/>[bn_wf.py]"]
  node_vision["Plant disease detection<br/>[yolo_wf.py]"]
  node_artifacts["Analysis artifacts"]
end

subgraph group_agent["Recommendation agent"]
  node_agent["Agent and context loading<br/>[agent.py]"]
  node_recommendations["Recommendations<br/>[agent.py]"]
  node_cli["CLI entry<br/>[agent.py]"]
  node_pythonapi["Python API<br/>[agent.py]"]
end

subgraph group_web["Dashboard"]
  node_dashboard["FastAPI endpoints<br/>[dashboard.py]"]
  node_ui["Web interface<br/>[dashboard.html]"]
end

node_user(("User"))
node_openrouter{{"OpenRouter LLM"}}

node_sensorfiles -->|"reads and merges"| node_homogenize
node_homogenize -->|"writes datasets"| node_prepared
node_prepared -->|"trains and forecasts"| node_lstm
node_prepared -.->|"classifies sensor data"| node_bayes
node_sensorfiles -.->|"analyzes plant image"| node_vision
node_lstm -.->|"writes forecasts"| node_artifacts
node_bayes -.->|"writes classifications"| node_artifacts
node_vision -.->|"writes detections"| node_artifacts
node_artifacts -->|"loads pipeline context"| node_agent
node_user -->|"asks question"| node_cli
node_user -->|"calls agent_chat"| node_pythonapi
node_user -->|"submits query"| node_ui
node_ui -.->|"calls API"| node_dashboard
node_dashboard -->|"runs analysis"| node_agent
node_cli -->|"invokes chat"| node_agent
node_pythonapi -->|"invokes chat"| node_agent
node_agent -->|"sends chat request"| node_openrouter
node_openrouter -->|"returns response"| node_agent
node_agent -->|"returns recommendations"| node_recommendations
node_dashboard -->|"serves interface"| node_ui
node_dashboard -->|"reads plot files"| node_artifacts

click node_sensorfiles "https://github.com/enkiponics/smartcityfarmagent/tree/main/pipelines/data/data_input"
click node_homogenize "https://github.com/enkiponics/smartcityfarmagent/blob/main/pipelines/utils/data_prep.py"
click node_prepared "https://github.com/enkiponics/smartcityfarmagent/tree/main/pipelines/data/data_input"
click node_lstm "https://github.com/enkiponics/smartcityfarmagent/blob/main/pipelines/lstm_wf.py"
click node_bayes "https://github.com/enkiponics/smartcityfarmagent/blob/main/pipelines/bn_wf.py"
click node_vision "https://github.com/enkiponics/smartcityfarmagent/blob/main/pipelines/yolo_wf.py"
click node_artifacts "https://github.com/enkiponics/smartcityfarmagent/tree/main/pipelines/data"
click node_agent "https://github.com/enkiponics/smartcityfarmagent/blob/main/agent.py"
click node_recommendations "https://github.com/enkiponics/smartcityfarmagent/blob/main/agent.py"
click node_dashboard "https://github.com/enkiponics/smartcityfarmagent/blob/main/dashboard.py"
click node_ui "https://github.com/enkiponics/smartcityfarmagent/blob/main/dashboard.html"
click node_cli "https://github.com/enkiponics/smartcityfarmagent/blob/main/agent.py"
click node_pythonapi "https://github.com/enkiponics/smartcityfarmagent/blob/main/agent.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_sensorfiles,node_homogenize,node_prepared,node_user toneBlue
class node_lstm,node_bayes,node_vision,node_artifacts toneAmber
class node_agent,node_recommendations,node_cli,node_pythonapi,node_openrouter toneMint
class node_dashboard,node_ui toneRose
```

## Components

### Sensor preparation

- [Sensor CSVs](https://github.com/enkiponics/smartcityfarmagent/tree/main/pipelines/data/data_input): `pipelines/data/data_input`
- [Data homogenization](https://github.com/enkiponics/smartcityfarmagent/blob/main/pipelines/utils/data_prep.py): `pipelines/utils/data_prep.py`
- [Unified sensor data](https://github.com/enkiponics/smartcityfarmagent/tree/main/pipelines/data/data_input): `pipelines/data/data_input`

### Analysis workflows

- [LSTM forecasting](https://github.com/enkiponics/smartcityfarmagent/blob/main/pipelines/lstm_wf.py): `pipelines/lstm_wf.py`
- [Bayesian classification](https://github.com/enkiponics/smartcityfarmagent/blob/main/pipelines/bn_wf.py): `pipelines/bn_wf.py`
- [Plant disease detection](https://github.com/enkiponics/smartcityfarmagent/blob/main/pipelines/yolo_wf.py): `pipelines/yolo_wf.py`
- [Analysis artifacts](https://github.com/enkiponics/smartcityfarmagent/tree/main/pipelines/data): `pipelines/data`

### Recommendation agent

- [Agent and context loading](https://github.com/enkiponics/smartcityfarmagent/blob/main/agent.py): `agent.py`
- [Recommendations](https://github.com/enkiponics/smartcityfarmagent/blob/main/agent.py): `agent.py`
- [CLI entry](https://github.com/enkiponics/smartcityfarmagent/blob/main/agent.py): `agent.py`
- [Python API](https://github.com/enkiponics/smartcityfarmagent/blob/main/agent.py): `agent.py`

### Dashboard

- [FastAPI endpoints](https://github.com/enkiponics/smartcityfarmagent/blob/main/dashboard.py): `dashboard.py`
- [Web interface](https://github.com/enkiponics/smartcityfarmagent/blob/main/dashboard.html): `dashboard.html`

### Other components

- **User**
- **OpenRouter LLM**

## Connections

- Sensor CSVs → Data homogenization: reads and merges (evidence: `pipelines/utils/data_prep.py`)
- Data homogenization → Unified sensor data: writes datasets (evidence: `pipelines/utils/data_prep.py`)
- Unified sensor data → LSTM forecasting: trains and forecasts (evidence: `pipelines/lstm_wf.py`)
- Unified sensor data → Bayesian classification: classifies sensor data
- Sensor CSVs → Plant disease detection: analyzes plant image
- LSTM forecasting → Analysis artifacts: writes forecasts
- Bayesian classification → Analysis artifacts: writes classifications
- Plant disease detection → Analysis artifacts: writes detections
- Analysis artifacts → Agent and context loading: loads pipeline context (evidence: `agent.py`)
- User → CLI entry: asks question (evidence: `README.md`)
- User → Python API: calls agent_chat (evidence: `README.md`)
- User → Web interface: submits query (evidence: `README.md`)
- Web interface → FastAPI endpoints: calls API
- FastAPI endpoints → Agent and context loading: runs analysis (evidence: `dashboard.py`)
- CLI entry → Agent and context loading: invokes chat (evidence: `README.md`)
- Python API → Agent and context loading: invokes chat (evidence: `README.md`)
- Agent and context loading → OpenRouter LLM: sends chat request (evidence: `agent.py`)
- OpenRouter LLM → Agent and context loading: returns response (evidence: `agent.py`)
- Agent and context loading → Recommendations: returns recommendations (evidence: `agent.py`)
- FastAPI endpoints → Web interface: serves interface (evidence: `dashboard.py`)
- FastAPI endpoints → Analysis artifacts: reads plot files (evidence: `dashboard.py`)
