# abdullah0991/smart-farm-iot architecture

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

- Interactive diagram: https://gitdiagram.com/abdullah0991/smart-farm-iot
- Repository: https://github.com/abdullah0991/smart-farm-iot

## Overview

This is an Expo mobile app for monitoring farm devices and their environmental telemetry. The main flow is sign-in, load or claim devices, inspect device snapshots and connectivity, then open sensor history with live MQTT updates. Separate branches cover device naming/region management, LED commands, authentication recovery, and persisted language/theme preferences. The graph follows the README and source-index references; unsampled implementations are represented only where documented, and uncertain relationships are omitted.

Main entry points: [`src/app/index.tsx`](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/index.tsx) (Device dashboard), [`src/app/sensor/[mac]/[sensor].tsx`](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/sensor/%5Bmac%5D/%5Bsensor%5D.tsx) (Sensor detail screen), [`src/services/mqttClient.ts`](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/mqttClient.ts) (MQTT subscriber), [`src/services/apiClient.ts`](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/apiClient.ts) (Backend API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App experience"]
  node_login["Sign in<br/>[login.tsx]"]
  node_dashboard["Device dashboard<br/>[index.tsx]"]
  node_status_badge["Status badge"]
  node_sensor_detail["Sensor detail screen<br/>[&#91;sensor&#93;.tsx]"]
  node_history_chart["History chart"]
  node_led_control["LED control<br/>[LedControl.tsx]"]
end

subgraph group_device["Device management"]
  node_device_store["Device actions<br/>[useDeviceStore.ts]"]
  node_add_device["Claim device<br/>[add-device.tsx]"]
  node_device_detail["Device details<br/>[&#91;mac&#93;.tsx]"]
  node_connectivity["Connectivity status"]
  node_weather_types["Weather data model<br/>[weather.ts]"]
end

subgraph group_telemetry["Telemetry and history"]
  node_mqtt["MQTT subscriber<br/>[mqttClient.ts]"]
  node_decoder["Telemetry decoder<br/>[deviceTelemetry.ts]"]
  node_live_store["Live telemetry state"]
  node_sensor_store["Sensor state<br/>[useSensorStore.ts]"]
  node_sensor_config["Sensor definitions<br/>[sensors.ts]"]
  node_history_hook["History and live merge"]
  node_timeline["History timeline<br/>[sensorTimeline.ts]"]
  node_sensor_rules["Reading interpretation<br/>[sensorDetails.ts]"]
  node_publisher["MQTT publisher<br/>[mqttPublisher.ts]"]
end

subgraph group_platform["Shared platform"]
  node_auth["Authentication state<br/>[useAuthStore.ts]"]
  node_session["Session token<br/>[authToken.ts]"]
  node_api["Backend API client<br/>[apiClient.ts]"]
  node_preferences["Language preference"]
  node_translations["Translation catalogs<br/>[translations.ts]"]
  node_appearance["Theme preference<br/>[useThemeStore.ts]"]
  node_themes["Theme definitions<br/>[themes.ts]"]
end

node_person(("Farm user"))
node_backend["Application backend"]
node_broker["MQTT broker"]

node_person -->|"signs in"| node_login
node_login -->|"submits credentials"| node_auth
node_auth -->|"validates session"| node_api
node_auth -->|"persists token"| node_session
node_person -->|"views devices"| node_dashboard
node_dashboard -->|"refreshes devices"| node_device_store
node_device_store -->|"fetches and updates"| node_api
node_api -->|"requests data"| node_backend
node_person -->|"claims device"| node_add_device
node_add_device -->|"claims device"| node_device_store
node_person -->|"opens device"| node_device_detail
node_device_detail -->|"reads device state"| node_device_store
node_dashboard -->|"shows status"| node_status_badge
node_device_detail -->|"shows status"| node_status_badge
node_status_badge -->|"derives state"| node_connectivity
node_dashboard -->|"loads snapshots"| node_api
node_dashboard -->|"prefers newer readings"| node_live_store
node_mqtt -->|"subscribes"| node_broker
node_mqtt -->|"decodes messages"| node_decoder
node_mqtt -->|"records telemetry"| node_live_store
node_mqtt -->|"updates legacy readings"| node_sensor_store
node_person -->|"opens history"| node_sensor_detail
node_sensor_detail -->|"loads timeline"| node_history_hook
node_history_hook -->|"requests history"| node_api
node_history_hook -->|"buffers live packets"| node_live_store
node_history_hook -->|"builds timeline"| node_timeline
node_sensor_detail -->|"renders chart"| node_history_chart
node_history_chart -->|"plots buckets"| node_timeline
node_sensor_detail -->|"interprets readings"| node_sensor_rules
node_sensor_detail -->|"reads live state"| node_live_store
node_sensor_store -->|"initializes readings"| node_sensor_config
node_person -->|"controls LED"| node_led_control
node_led_control -->|"publishes command"| node_mqtt
node_person -->|"chooses language"| node_preferences
node_preferences -->|"selects catalog"| node_translations
node_person -->|"chooses appearance"| node_appearance
node_appearance -->|"uses definitions"| node_themes

click node_login "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/login.tsx"
click node_auth "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useAuthStore.ts"
click node_session "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/authToken.ts"
click node_dashboard "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/index.tsx"
click node_device_store "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useDeviceStore.ts"
click node_add_device "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/add-device.tsx"
click node_device_detail "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/device/%5Bmac%5D.tsx"
click node_connectivity "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/utils/deviceConnectivity.ts"
click node_status_badge "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/components/DeviceConnectionBadge.tsx"
click node_api "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/apiClient.ts"
click node_mqtt "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/mqttClient.ts"
click node_decoder "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/deviceTelemetry.ts"
click node_live_store "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useLiveTelemetryStore.ts"
click node_sensor_store "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useSensorStore.ts"
click node_sensor_config "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/constants/sensors.ts"
click node_sensor_detail "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/sensor/%5Bmac%5D/%5Bsensor%5D.tsx"
click node_history_hook "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/hooks/useSensorHistory.ts"
click node_timeline "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/utils/sensorTimeline.ts"
click node_history_chart "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/components/SensorHistoryChart.tsx"
click node_sensor_rules "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/utils/sensorDetails.ts"
click node_led_control "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/components/LedControl.tsx"
click node_publisher "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/mqttPublisher.ts"
click node_preferences "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useLanguageStore.ts"
click node_translations "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/i18n/translations.ts"
click node_appearance "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useThemeStore.ts"
click node_themes "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/theme/themes.ts"
click node_weather_types "https://github.com/abdullah0991/smart-farm-iot/blob/main/src/types/weather.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_login,node_dashboard,node_status_badge,node_sensor_detail,node_history_chart,node_led_control,node_person toneBlue
class node_device_store,node_add_device,node_device_detail,node_connectivity,node_weather_types toneAmber
class node_mqtt,node_decoder,node_live_store,node_sensor_store,node_sensor_config,node_history_hook,node_timeline,node_sensor_rules,node_publisher toneMint
class node_auth,node_session,node_api,node_preferences,node_translations,node_appearance,node_themes toneRose
class node_backend,node_broker toneIndigo
```

## Components

### App experience

- [Sign in](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/login.tsx): `src/app/login.tsx`
- [Device dashboard](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/index.tsx): `src/app/index.tsx`
- [Status badge](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/components/DeviceConnectionBadge.tsx): `src/components/DeviceConnectionBadge.tsx`
- [Sensor detail screen](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/sensor/%5Bmac%5D/%5Bsensor%5D.tsx): `src/app/sensor/[mac]/[sensor].tsx`
- [History chart](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/components/SensorHistoryChart.tsx): `src/components/SensorHistoryChart.tsx`
- [LED control](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/components/LedControl.tsx): `src/components/LedControl.tsx`

### Device management

- [Device actions](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useDeviceStore.ts): `src/store/useDeviceStore.ts`
- [Claim device](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/add-device.tsx): `src/app/add-device.tsx`
- [Device details](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/app/device/%5Bmac%5D.tsx): `src/app/device/[mac].tsx`
- [Connectivity status](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/utils/deviceConnectivity.ts): `src/utils/deviceConnectivity.ts`
- [Weather data model](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/types/weather.ts): `src/types/weather.ts`

### Telemetry and history

- [MQTT subscriber](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/mqttClient.ts): `src/services/mqttClient.ts`
- [Telemetry decoder](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/deviceTelemetry.ts): `src/services/deviceTelemetry.ts`
- [Live telemetry state](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useLiveTelemetryStore.ts): `src/store/useLiveTelemetryStore.ts`
- [Sensor state](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useSensorStore.ts): `src/store/useSensorStore.ts`
- [Sensor definitions](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/constants/sensors.ts): `src/constants/sensors.ts`
- [History and live merge](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/hooks/useSensorHistory.ts): `src/hooks/useSensorHistory.ts`
- [History timeline](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/utils/sensorTimeline.ts): `src/utils/sensorTimeline.ts`
- [Reading interpretation](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/utils/sensorDetails.ts): `src/utils/sensorDetails.ts`
- [MQTT publisher](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/mqttPublisher.ts): `src/services/mqttPublisher.ts`

### Shared platform

- [Authentication state](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useAuthStore.ts): `src/store/useAuthStore.ts`
- [Session token](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/authToken.ts): `src/services/authToken.ts`
- [Backend API client](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/services/apiClient.ts): `src/services/apiClient.ts`
- [Language preference](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useLanguageStore.ts): `src/store/useLanguageStore.ts`
- [Translation catalogs](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/i18n/translations.ts): `src/i18n/translations.ts`
- [Theme preference](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/store/useThemeStore.ts): `src/store/useThemeStore.ts`
- [Theme definitions](https://github.com/abdullah0991/smart-farm-iot/blob/main/src/theme/themes.ts): `src/theme/themes.ts`

### Other components

- **Farm user**
- **Application backend**
- **MQTT broker**

## Connections

- Farm user → Sign in: signs in (evidence: `src/app/login.tsx`)
- Sign in → Authentication state: submits credentials (evidence: `src/app/login.tsx`)
- Authentication state → Backend API client: validates session (evidence: `src/store/useAuthStore.ts`)
- Authentication state → Session token: persists token (evidence: `src/store/useAuthStore.ts`)
- Farm user → Device dashboard: views devices (evidence: `README.md`)
- Device dashboard → Device actions: refreshes devices (evidence: `src/app/index.tsx`)
- Device actions → Backend API client: fetches and updates (evidence: `src/store/useDeviceStore.ts`)
- Backend API client → Application backend: requests data (evidence: `src/services/apiClient.ts`)
- Farm user → Claim device: claims device (evidence: `README.md`)
- Claim device → Device actions: claims device (evidence: `src/app/add-device.tsx`)
- Farm user → Device details: opens device (evidence: `README.md`)
- Device details → Device actions: reads device state (evidence: `src/app/device/[mac].tsx`)
- Device dashboard → Status badge: shows status (evidence: `src/app/index.tsx`)
- Device details → Status badge: shows status (evidence: `src/app/device/[mac].tsx`)
- Status badge → Connectivity status: derives state (evidence: `src/components/DeviceConnectionBadge.tsx`)
- Device dashboard → Backend API client: loads snapshots (evidence: `src/app/index.tsx`)
- Device dashboard → Live telemetry state: prefers newer readings (evidence: `README.md`)
- MQTT subscriber → MQTT broker: subscribes (evidence: `src/services/mqttClient.ts`)
- MQTT subscriber → Telemetry decoder: decodes messages (evidence: `src/services/mqttClient.ts`)
- MQTT subscriber → Live telemetry state: records telemetry (evidence: `src/services/mqttClient.ts`)
- MQTT subscriber → Sensor state: updates legacy readings (evidence: `src/services/mqttClient.ts`)
- Farm user → Sensor detail screen: opens history (evidence: `README.md`)
- Sensor detail screen → History and live merge: loads timeline (evidence: `src/app/sensor/[mac]/[sensor].tsx`)
- History and live merge → Backend API client: requests history (evidence: `src/hooks/useSensorHistory.ts`)
- History and live merge → Live telemetry state: buffers live packets (evidence: `src/hooks/useSensorHistory.ts`)
- History and live merge → History timeline: builds timeline (evidence: `src/hooks/useSensorHistory.ts`)
- Sensor detail screen → History chart: renders chart (evidence: `src/app/sensor/[mac]/[sensor].tsx`)
- History chart → History timeline: plots buckets (evidence: `src/components/SensorHistoryChart.tsx`)
- Sensor detail screen → Reading interpretation: interprets readings (evidence: `src/app/sensor/[mac]/[sensor].tsx`)
- Sensor detail screen → Live telemetry state: reads live state (evidence: `src/app/sensor/[mac]/[sensor].tsx`)
- Sensor state → Sensor definitions: initializes readings (evidence: `src/store/useSensorStore.ts`)
- Farm user → LED control: controls LED (evidence: `README.md`)
- LED control → MQTT subscriber: publishes command (evidence: `src/components/LedControl.tsx`)
- Farm user → Language preference: chooses language (evidence: `README.md`)
- Language preference → Translation catalogs: selects catalog (evidence: `src/i18n/index.ts`)
- Farm user → Theme preference: chooses appearance (evidence: `README.md`)
- Theme preference → Theme definitions: uses definitions (evidence: `src/store/useThemeStore.ts`)
