# danishxd/ecosmart-feeder architecture

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

- Interactive diagram: https://gitdiagram.com/danishxd/ecosmart-feeder
- Repository: https://github.com/danishxd/ecosmart-feeder

## Overview

EcoSmart Feeder monitors fish-pond conditions and supports device management, feeding control, alerts, and sensor-informed chat/recommendations. The primary flow is ESP32 sensor data sent over MQTT to the backend, stored as time-series readings, then exposed to the mobile app through APIs and real-time updates. The mobile app also manages accounts, devices, schedules, and sensor views. Source evidence is incomplete for several mobile screens and recommendation internals, so their detailed runtime links are not inferred.

Main entry points: [`apps/backend/src/app.ts`](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/app.ts) (Fastify API), [`apps/backend/src/modules/iot/iot.service.ts`](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/iot/iot.service.ts) (Sensor processing), [`apps/mobile/lib/api.ts`](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/lib/api.ts) (HTTP client), [`apps/backend/src/modules/iot/iot.routes.ts`](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/iot/iot.routes.ts) (Sensor API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Device firmware"]
  node_esp32["ESP32 sensors<br/>[main.cpp]"]
end

subgraph group_backend["Backend services"]
  node_api["Fastify API<br/>[app.ts]"]
  node_auth["Authentication<br/>[auth.service.ts]"]
  node_devices["Device management<br/>[devices.routes.ts]"]
  node_iot_routes["Sensor API<br/>[iot.routes.ts]"]
  node_iot_service["Sensor processing<br/>[iot.service.ts]"]
  node_mqtt["MQTT bridge<br/>[mqtt.bridge.ts]"]
  node_alerts["Alert rules<br/>[alert.engine.ts]"]
  node_schedules["Feeding schedules"]
  node_socket_server["Socket server<br/>[socket.ts]"]
end

subgraph group_storage["Data stores"]
  node_postgres[("PostgreSQL<br/>[schema.ts]")]
  node_influx[("InfluxDB readings<br/>[influx.ts]")]
end

subgraph group_mobile["Mobile application"]
  node_mobile_auth["Login and signup<br/>[signup.tsx]"]
  node_setup["Device setup<br/>[setup-device.tsx]"]
  node_control["Feeding control<br/>[control.tsx]"]
  node_dashboard["Dashboard and monitoring<br/>[dashboard.tsx]"]
  node_mobile_alerts["Alert screen<br/>[alerts.tsx]"]
  node_mobile_chat["Chat screen<br/>[chat.tsx]"]
  node_api_client["HTTP client<br/>[api.ts]"]
  node_sensor_state["Sensor state<br/>[sensorStore.ts]"]
  node_socket_hook["Live updates<br/>[useWebSocket.ts]"]
  node_notifications["Local notifications"]
end

subgraph group_intelligence["AI features"]
  node_chat["Sensor chat<br/>[chat.service.ts]"]
  node_recommendations["Recommendations"]
end

node_keeper(("Pond keeper"))

node_keeper -->|"uses"| node_mobile_auth
node_keeper -->|"monitors"| node_dashboard
node_esp32 -->|"sends MQTT"| node_mqtt
node_mqtt -->|"passes readings"| node_iot_service
node_api -->|"registers routes"| node_auth
node_api -->|"registers routes"| node_iot_routes
node_api -->|"registers routes"| node_devices
node_api -->|"registers routes"| node_alerts
node_api -->|"registers routes"| node_chat
node_api -->|"registers routes"| node_schedules
node_api -->|"registers routes"| node_recommendations
node_iot_routes -->|"calls"| node_iot_service
node_iot_service -->|"checks devices"| node_postgres
node_iot_service -->|"writes and queries"| node_influx
node_chat -->|"reads sensor data"| node_iot_service
node_auth -->|"stores accounts and tokens"| node_postgres
node_devices -->|"stores devices"| node_postgres
node_mobile_auth -->|"uses"| node_api_client
node_setup -->|"uses"| node_api_client
node_control -->|"uses"| node_api_client
node_control -->|"uses"| node_sensor_state
node_api_client -->|"HTTP requests"| node_api
node_dashboard -.->|"receives live readings"| node_socket_hook
node_socket_hook -->|"updates readings"| node_sensor_state
node_socket_server -->|"pushes WebSocket updates"| node_socket_hook
node_iot_routes -->|"emits sensor alerts"| node_socket_server
node_sensor_state -->|"uses"| node_notifications

click node_esp32 "https://github.com/danishxd/ecosmart-feeder/blob/main/firmware/esp32/main.cpp"
click node_api "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/app.ts"
click node_auth "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/auth/auth.service.ts"
click node_devices "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/devices/devices.routes.ts"
click node_iot_routes "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/iot/iot.routes.ts"
click node_iot_service "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/iot/iot.service.ts"
click node_mqtt "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/iot/mqtt.bridge.ts"
click node_alerts "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/alerts/alert.engine.ts"
click node_schedules "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/schedules/schedules.routes.ts"
click node_chat "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/chat/chat.service.ts"
click node_recommendations "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/recommendation/recommendation.routes.ts"
click node_postgres "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/drizzle/schema.ts"
click node_influx "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/plugins/influx.ts"
click node_mobile_auth "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(auth)/signup.tsx"
click node_setup "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(app)/setup-device.tsx"
click node_control "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(app)/control.tsx"
click node_dashboard "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(app)/dashboard.tsx"
click node_mobile_alerts "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(app)/alerts.tsx"
click node_mobile_chat "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(app)/chat.tsx"
click node_api_client "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/lib/api.ts"
click node_sensor_state "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/stores/sensorStore.ts"
click node_socket_hook "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/hooks/useWebSocket.ts"
click node_notifications "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/hooks/usePushNotification.ts"
click node_socket_server "https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/plugins/socket.ts"

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_esp32 toneBlue
class node_api,node_auth,node_devices,node_iot_routes,node_iot_service,node_mqtt,node_alerts,node_schedules,node_socket_server toneAmber
class node_postgres,node_influx toneMint
class node_mobile_auth,node_setup,node_control,node_dashboard,node_mobile_alerts,node_mobile_chat,node_api_client,node_sensor_state,node_socket_hook,node_notifications toneRose
class node_chat,node_recommendations,node_keeper toneIndigo
```

## Components

### Device firmware

- [ESP32 sensors](https://github.com/danishxd/ecosmart-feeder/blob/main/firmware/esp32/main.cpp): `firmware/esp32/main.cpp`

### Backend services

- [Fastify API](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/app.ts): `apps/backend/src/app.ts`
- [Authentication](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/auth/auth.service.ts): `apps/backend/src/modules/auth/auth.service.ts`
- [Device management](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/devices/devices.routes.ts): `apps/backend/src/modules/devices/devices.routes.ts`
- [Sensor API](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/iot/iot.routes.ts): `apps/backend/src/modules/iot/iot.routes.ts`
- [Sensor processing](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/iot/iot.service.ts): `apps/backend/src/modules/iot/iot.service.ts`
- [MQTT bridge](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/iot/mqtt.bridge.ts): `apps/backend/src/modules/iot/mqtt.bridge.ts`
- [Alert rules](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/alerts/alert.engine.ts): `apps/backend/src/modules/alerts/alert.engine.ts`
- [Feeding schedules](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/schedules/schedules.routes.ts): `apps/backend/src/modules/schedules/schedules.routes.ts`
- [Socket server](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/plugins/socket.ts): `apps/backend/src/plugins/socket.ts`

### Data stores

- [PostgreSQL](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/drizzle/schema.ts): `apps/backend/drizzle/schema.ts`
- [InfluxDB readings](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/plugins/influx.ts): `apps/backend/src/plugins/influx.ts`

### Mobile application

- [Login and signup](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(auth)/signup.tsx): `apps/mobile/app/(auth)/signup.tsx`
- [Device setup](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(app)/setup-device.tsx): `apps/mobile/app/(app)/setup-device.tsx`
- [Feeding control](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(app)/control.tsx): `apps/mobile/app/(app)/control.tsx`
- [Dashboard and monitoring](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(app)/dashboard.tsx): `apps/mobile/app/(app)/dashboard.tsx`
- [Alert screen](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(app)/alerts.tsx): `apps/mobile/app/(app)/alerts.tsx`
- [Chat screen](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/app/(app)/chat.tsx): `apps/mobile/app/(app)/chat.tsx`
- [HTTP client](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/lib/api.ts): `apps/mobile/lib/api.ts`
- [Sensor state](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/stores/sensorStore.ts): `apps/mobile/stores/sensorStore.ts`
- [Live updates](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/hooks/useWebSocket.ts): `apps/mobile/hooks/useWebSocket.ts`
- [Local notifications](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/mobile/hooks/usePushNotification.ts): `apps/mobile/hooks/usePushNotification.ts`

### AI features

- [Sensor chat](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/chat/chat.service.ts): `apps/backend/src/modules/chat/chat.service.ts`
- [Recommendations](https://github.com/danishxd/ecosmart-feeder/blob/main/apps/backend/src/modules/recommendation/recommendation.routes.ts): `apps/backend/src/modules/recommendation/recommendation.routes.ts`

### Other components

- **Pond keeper**

## Connections

- Pond keeper → Login and signup: uses (evidence: `README.md`)
- Pond keeper → Dashboard and monitoring: monitors (evidence: `README.md`)
- ESP32 sensors → MQTT bridge: sends MQTT (evidence: `README.md`)
- MQTT bridge → Sensor processing: passes readings (evidence: `apps/backend/src/modules/iot/mqtt.bridge.ts`)
- Fastify API → Authentication: registers routes (evidence: `apps/backend/src/app.ts`)
- Fastify API → Sensor API: registers routes (evidence: `apps/backend/src/app.ts`)
- Fastify API → Device management: registers routes (evidence: `apps/backend/src/app.ts`)
- Fastify API → Alert rules: registers routes (evidence: `apps/backend/src/app.ts`)
- Fastify API → Sensor chat: registers routes (evidence: `apps/backend/src/app.ts`)
- Fastify API → Feeding schedules: registers routes (evidence: `apps/backend/src/app.ts`)
- Fastify API → Recommendations: registers routes (evidence: `apps/backend/src/app.ts`)
- Sensor API → Sensor processing: calls (evidence: `apps/backend/src/modules/iot/iot.routes.ts`)
- Sensor processing → PostgreSQL: checks devices (evidence: `apps/backend/src/modules/iot/iot.service.ts`)
- Sensor processing → InfluxDB readings: writes and queries (evidence: `apps/backend/src/modules/iot/iot.service.ts`)
- Sensor chat → Sensor processing: reads sensor data (evidence: `apps/backend/src/modules/chat/chat.service.ts`)
- Authentication → PostgreSQL: stores accounts and tokens (evidence: `apps/backend/src/modules/auth/auth.service.ts`)
- Device management → PostgreSQL: stores devices (evidence: `apps/backend/src/modules/devices/devices.routes.ts`)
- Login and signup → HTTP client: uses (evidence: `apps/mobile/app/(auth)/signup.tsx`)
- Device setup → HTTP client: uses (evidence: `apps/mobile/app/(app)/setup-device.tsx`)
- Feeding control → HTTP client: uses (evidence: `apps/mobile/app/(app)/control.tsx`)
- Feeding control → Sensor state: uses (evidence: `apps/mobile/app/(app)/control.tsx`)
- HTTP client → Fastify API: HTTP requests (evidence: `README.md`)
- Dashboard and monitoring → Live updates: receives live readings
- Live updates → Sensor state: updates readings (evidence: `apps/mobile/hooks/useWebSocket.ts`)
- Socket server → Live updates: pushes WebSocket updates (evidence: `README.md`)
- Sensor API → Socket server: emits sensor alerts (evidence: `apps/backend/src/modules/iot/iot.routes.ts`)
- Sensor state → Local notifications: uses (evidence: `apps/mobile/stores/sensorStore.ts`)
