# greeneye-ai/greeneyeai-server architecture

> Architecture diagram of the GitHub repository greeneye-ai/greeneyeai-server, 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/greeneye-ai/greeneyeai-server
- Repository: https://github.com/greeneye-ai/greeneyeai-server

## Overview

This is a greenhouse monitoring and control service: browser and ESP clients interact with a Python server that records sensor/device state, queues relay commands, and exposes schedules, charts’ data, plant status, and a camera stream. The main runtime orchestrates automatic light/water/fan schedules and optional camera-based plant classification. Edges reflect calls and route registration visible in the excerpts; the README is empty and browser implementation details are only partly sampled.

Main entry points: [`server/server.py`](https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/server.py) (HTTP server), [`main.py`](https://github.com/greeneye-ai/greeneyeai-server/blob/main/main.py) (Application runtime), [`web_paths.py`](https://github.com/greeneye-ai/greeneyeai-server/blob/main/web_paths.py) (Web API handlers), [`server/database.py`](https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/database.py) (SQLite worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Runtime orchestration"]
  node_main["Application runtime<br/>[main.py]"]
end

subgraph group_http["HTTP service"]
  node_server["HTTP server<br/>[server.py]"]
  node_request["Request parser<br/>[request.py]"]
  node_response["Response builder<br/>[response.py]"]
  node_status["HTTP statuses<br/>[status.py]"]
  node_cluster["Static asset cache<br/>[cluster.py]"]
end

subgraph group_control["Greenhouse control"]
  node_routes["Web API handlers<br/>[web_paths.py]"]
  node_esp_routes["ESP API handlers<br/>[esp_paths.py]"]
  node_scheduler["Automatic schedules<br/>[main.py]"]
  node_command_queue["Relay command queue<br/>[web_paths.py]"]
end

subgraph group_state["State and storage"]
  node_data["Shared runtime state<br/>[data.py]"]
  node_database["SQLite worker<br/>[database.py]"]
  node_dbfile[("SQLite database<br/>[main.db]")]
  node_schedule_file["Schedule file<br/>[schedule.json]"]
end

subgraph group_vision["Camera and plants"]
  node_camera["Camera capture<br/>[main.py]"]
  node_classifier["Plant classifier<br/>[main.py]"]
  node_model["YOLO model<br/>[best.pt]"]
  node_stream["Video stream API<br/>[web_paths.py]"]
end

node_browser(("Browser UI"))
node_esp(("ESP device"))

node_browser -->|"sends HTTP"| node_server
node_esp -->|"sends HTTP"| node_server
node_server -->|"parses requests"| node_request
node_server -->|"sends responses"| node_response
node_response -->|"uses codes"| node_status
node_server -->|"serves assets"| node_cluster
node_main -->|"constructs and starts"| node_server
node_main -->|"registers routes"| node_routes
node_main -->|"registers routes"| node_esp_routes
node_server -->|"dispatches handlers"| node_routes
node_server -->|"dispatches handlers"| node_esp_routes
node_server -->|"shares state"| node_data
node_server -->|"shares database"| node_database
node_server -->|"updates cache"| node_cluster
node_main -->|"creates schema"| node_database
node_database -.->|"reads and writes"| node_dbfile
node_routes -->|"reads and updates"| node_data
node_routes -->|"queries and inserts"| node_database
node_routes -->|"enqueues commands"| node_command_queue
node_esp_routes -->|"reads and acknowledges"| node_command_queue
node_esp_routes -->|"records telemetry"| node_database
node_scheduler -->|"checks mode and schedule"| node_data
node_scheduler -->|"reads device state"| node_database
node_scheduler -->|"enqueues relay actions"| node_command_queue
node_routes -->|"saves schedule"| node_schedule_file
node_main -->|"loads schedule"| node_schedule_file
node_camera -->|"publishes JPEG frames"| node_data
node_classifier -->|"waits for frames; stores labels"| node_data
node_classifier -.->|"loads model"| node_model
node_stream -->|"streams frames"| node_data
node_main -->|"starts capture"| node_camera
node_main -->|"starts processing"| node_classifier
node_routes -->|"registers stream handler"| node_stream

click node_main "https://github.com/greeneye-ai/greeneyeai-server/blob/main/main.py"
click node_routes "https://github.com/greeneye-ai/greeneyeai-server/blob/main/web_paths.py"
click node_esp_routes "https://github.com/greeneye-ai/greeneyeai-server/blob/main/esp_paths.py"
click node_server "https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/server.py"
click node_request "https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/request.py"
click node_response "https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/response.py"
click node_status "https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/status.py"
click node_cluster "https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/cluster.py"
click node_data "https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/data.py"
click node_database "https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/database.py"
click node_dbfile "https://github.com/greeneye-ai/greeneyeai-server/blob/main/main.db"
click node_scheduler "https://github.com/greeneye-ai/greeneyeai-server/blob/main/main.py"
click node_command_queue "https://github.com/greeneye-ai/greeneyeai-server/blob/main/web_paths.py"
click node_camera "https://github.com/greeneye-ai/greeneyeai-server/blob/main/main.py"
click node_classifier "https://github.com/greeneye-ai/greeneyeai-server/blob/main/main.py"
click node_model "https://github.com/greeneye-ai/greeneyeai-server/blob/main/best.pt"
click node_stream "https://github.com/greeneye-ai/greeneyeai-server/blob/main/web_paths.py"
click node_schedule_file "https://github.com/greeneye-ai/greeneyeai-server/blob/main/schedule.json"

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_main,node_browser toneBlue
class node_server,node_request,node_response,node_status,node_cluster toneAmber
class node_routes,node_esp_routes,node_scheduler,node_command_queue toneMint
class node_data,node_database,node_dbfile,node_schedule_file toneRose
class node_camera,node_classifier,node_model,node_stream,node_esp toneIndigo
```

## Components

### Runtime orchestration

- [Application runtime](https://github.com/greeneye-ai/greeneyeai-server/blob/main/main.py): `main.py`

### HTTP service

- [HTTP server](https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/server.py): `server/server.py`
- [Request parser](https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/request.py): `server/request.py`
- [Response builder](https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/response.py): `server/response.py`
- [HTTP statuses](https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/status.py): `server/status.py`
- [Static asset cache](https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/cluster.py): `server/cluster.py`

### Greenhouse control

- [Web API handlers](https://github.com/greeneye-ai/greeneyeai-server/blob/main/web_paths.py): `web_paths.py`
- [ESP API handlers](https://github.com/greeneye-ai/greeneyeai-server/blob/main/esp_paths.py): `esp_paths.py`
- [Automatic schedules](https://github.com/greeneye-ai/greeneyeai-server/blob/main/main.py): `main.py`
- [Relay command queue](https://github.com/greeneye-ai/greeneyeai-server/blob/main/web_paths.py): `web_paths.py`

### State and storage

- [Shared runtime state](https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/data.py): `server/data.py`
- [SQLite worker](https://github.com/greeneye-ai/greeneyeai-server/blob/main/server/database.py): `server/database.py`
- [SQLite database](https://github.com/greeneye-ai/greeneyeai-server/blob/main/main.db): `main.db`
- [Schedule file](https://github.com/greeneye-ai/greeneyeai-server/blob/main/schedule.json): `schedule.json`

### Camera and plants

- [Camera capture](https://github.com/greeneye-ai/greeneyeai-server/blob/main/main.py): `main.py`
- [Plant classifier](https://github.com/greeneye-ai/greeneyeai-server/blob/main/main.py): `main.py`
- [YOLO model](https://github.com/greeneye-ai/greeneyeai-server/blob/main/best.pt): `best.pt`
- [Video stream API](https://github.com/greeneye-ai/greeneyeai-server/blob/main/web_paths.py): `web_paths.py`

### Other components

- **Browser UI**
- **ESP device**

## Connections

- Browser UI → HTTP server: sends HTTP
- ESP device → HTTP server: sends HTTP
- HTTP server → Request parser: parses requests (evidence: `server/server.py`)
- HTTP server → Response builder: sends responses (evidence: `server/server.py`)
- Response builder → HTTP statuses: uses codes (evidence: `server/response.py`)
- HTTP server → Static asset cache: serves assets (evidence: `server/server.py`)
- Application runtime → HTTP server: constructs and starts (evidence: `main.py`)
- Application runtime → Web API handlers: registers routes (evidence: `main.py`)
- Application runtime → ESP API handlers: registers routes (evidence: `main.py`)
- HTTP server → Web API handlers: dispatches handlers (evidence: `server/server.py`)
- HTTP server → ESP API handlers: dispatches handlers (evidence: `server/server.py`)
- HTTP server → Shared runtime state: shares state (evidence: `server/server.py`)
- HTTP server → SQLite worker: shares database (evidence: `server/server.py`)
- HTTP server → Static asset cache: updates cache (evidence: `server/server.py`)
- Application runtime → SQLite worker: creates schema (evidence: `main.py`)
- SQLite worker → SQLite database: reads and writes
- Web API handlers → Shared runtime state: reads and updates (evidence: `web_paths.py`)
- Web API handlers → SQLite worker: queries and inserts (evidence: `web_paths.py`)
- Web API handlers → Relay command queue: enqueues commands (evidence: `web_paths.py`)
- ESP API handlers → Relay command queue: reads and acknowledges (evidence: `esp_paths.py`)
- ESP API handlers → SQLite worker: records telemetry (evidence: `esp_paths.py`)
- Automatic schedules → Shared runtime state: checks mode and schedule (evidence: `main.py`)
- Automatic schedules → SQLite worker: reads device state (evidence: `main.py`)
- Automatic schedules → Relay command queue: enqueues relay actions (evidence: `main.py`)
- Web API handlers → Schedule file: saves schedule (evidence: `web_paths.py`)
- Application runtime → Schedule file: loads schedule (evidence: `main.py`)
- Camera capture → Shared runtime state: publishes JPEG frames (evidence: `main.py`)
- Plant classifier → Shared runtime state: waits for frames; stores labels (evidence: `main.py`)
- Plant classifier → YOLO model: loads model
- Video stream API → Shared runtime state: streams frames (evidence: `web_paths.py`)
- Application runtime → Camera capture: starts capture (evidence: `main.py`)
- Application runtime → Plant classifier: starts processing (evidence: `main.py`)
- Web API handlers → Video stream API: registers stream handler (evidence: `main.py`)
