# abhinavhh/smart_irrigation architecture

> Architecture diagram of the GitHub repository abhinavhh/smart_irrigation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhinavhh/smart_irrigation
- Repository: https://github.com/abhinavhh/smart_irrigation

## Overview

##### Project type and purpose
- Frontend: React + Vite single-page application for real-time dashboards, charts, and user workflows.
- Backend (described in README): Spring Boot monolith providing REST and WebSocket APIs, persisting to PostgreSQL, caching in Redis, scheduling irrigation, handling authentication, email, and ML recommendations.
- Edge/IoT: ESP32/Arduino microcontrollers collect sensor data (BLE/Wi-Fi) and forward via MQTT to the backend.

##### File structure (frontend portion)
- Top level:
- index.html, package.json / package-lock.json, Vite and PostCSS configs, Tailwind config, eslint.config.js, .env, vercel.json → build & deployment controls.
- public/ → static assets and redirect rules.
- src/ → React app:
- main.jsx & index.css → app bootstrap for Vite.
- App.jsx / App.css → core layout.
- Components/ → UI widgets & pages: graphs, forms, panels, navbars, notifications, authentication flows.
- api/axios.jsx → centralized HTTP client.
- assets/database.sql → sample DB scripts (for backend).

##### README for additional insights
IoT Sensors → Microcontroller → Spring Boot API → {PostgreSQL, Redis, WebSockets → React Frontend, SMTP, Scheduler}
- Technology stack tables detail frameworks, libraries, and infrastructure choices.

a. Main components
1. IoT Layer: Sensors (temperature, humidity, soil moisture) + Microcontroller (ESP32/Arduino)
2. API Layer: Spring Boot application
3. Data Stores: PostgreSQL, Redis Cache
4. Real-time Channels: MQTT (sensor → backend), STOMP/WebSocket (backend → frontend)
5. Frontend: React SPA (Vite bundler, Tailwind, Chart.js / D3.js visuals, React Router)
6. External Services: SMTP mail server, Scheduler service, Prometheus/Grafana, ELK logging
b. Relationships & interactions
- Sensors → Microcontroller (BLE/Wi-Fi)
- Microcontroller → Spring Boot (MQTT over TLS)
- Spring Boot → PostgreSQL (JDBC)
- Spring Boot ↔ Redis (cache for thresholds, session data)
- Spring Boot → Frontend (WebSocket/STOMP + REST endpoints via Axios)
- Frontend → User’s browser (UI interaction)
- Spring Boot → SMTP (JavaMail) for OTP & notifications
- Spring Boot → Scheduler (internal job scheduling)
- Monitoring stack hooks into Spring Boot (Prometheus exporters, ELK ingest)
c. Architectural patterns & design principles
- Monolithic service with layered architecture: controller, service, repository (Spring Data JPA).
- Publish/subscribe for real-time updates (WebSocket + STOMP).
- CQRS-like separation: REST for commands/queries; WebSockets for push.
- Context API in React for global state.
- Configuration-as-code (.env files, Vite, Tailwind) and containerization readiness (Docker Compose).
d. Key technologies / libraries
- Frontend: React 18, Vite, Tailwind CSS, Chart.js, D3.js, Material-UI, React Router, React Hook Form, Axios
- Backend: Spring Boot 3.1, Spring Security + JWT, Spring Data JPA (PostgreSQL), STOMP+WebSocket, JavaMail, JUnit/Mockito
- Infra: Docker, Docker Compose, GitHub Actions, Prometheus, Grafana, ELK

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% IoT Edge Layer
    subgraph "IoT Edge" 
        direction TB
        IoTSensors["Sensors\n(Temp, Humidity,\nSoil Moisture)"]:::iot
        Microcontroller["Microcontroller\n(ESP32/Arduino)"]:::iot
    end

    %% Backend Services Layer
    subgraph "Backend Services" 
        direction TB
        SpringBoot["Spring Boot API\n(Spring Boot 3.1 + JWT)"]:::backend
        PostgreSQL[(PostgreSQL)]:::backend
        Redis{{Redis Cache}}:::backend
    end

    %% Frontend Layer
    subgraph "Frontend (React + Vite SPA)" 
        direction TB
        subgraph "Core" 
            direction TB
            IndexHTML["index.html"]:::frontend
            MainJS["main.jsx"]:::frontend
            AppJS["App.jsx"]:::frontend
            IndexCSS["index.css"]:::frontend
        end
        subgraph "UI Component Library" 
            direction TB
            Button["Button.jsx"]:::frontend
            Card["Card.jsx"]:::frontend
            AddCrop["AddCrop.jsx"]:::frontend
            ControlPanel["ControlPanel.jsx"]:::frontend
            CropDetails["CropDetails.jsx"]:::frontend
            ForgotPassword["ForgotPassword.jsx"]:::frontend
            Graph["Graph.jsx"]:::frontend
            MultiSensorGraph["MultiSensorGraph.jsx"]:::frontend
            Navbar["Navbar.jsx"]:::frontend
            Notifications["Notifications.jsx"]:::frontend
            Profile["Profile.jsx"]:::frontend
            ResetPassword["ResetPassword.jsx"]:::frontend
        end
        subgraph "Pages (Routes & Views)" 
            direction TB
            Home["Home.jsx"]:::frontend
            Login["Login.jsx"]:::frontend
            Register["Register.jsx"]:::frontend
            CustomIcons["CustomIcons.jsx"]:::frontend
        end
        AxiosClient["axios.jsx"]:::frontend
        subgraph "Assets & Sample DB" 
            direction TB
            AssetImage["untitled-5-o.avif"]:::frontend
            DatabaseSQL["database.sql"]:::frontend
        end
        subgraph "Build & Tooling" 
            direction TB
            PackageJSON["package.json"]:::frontend
            PackageLock["package-lock.json"]:::frontend
            ViteConfig["vite.config.js"]:::frontend
            TailwindConfig["tailwind.config.js"]:::frontend
            PostCSSConfig["postcss.config.js"]:::frontend
            ESLintConfig["eslint.config.js"]:::frontend
            EnvFile[".env"]:::frontend
            VercelJSON["vercel.json"]:::frontend
        end
        subgraph "Public Static Folder" 
            direction TB
            Redirects["_redirects"]:::frontend
        end
    end

    %% External Services Layer
    subgraph "External & Infra" 
        direction TB
        SMTP["SMTP Mail Server"]:::external
        Scheduler["Scheduler Service"]:::external
        Monitoring["Monitoring & Logging\n(Prometheus, Grafana, ELK)"]:::external
    end

    %% Relationships
    IoTSensors -->|"BLE/Wi-Fi"| Microcontroller
    Microcontroller -->|"MQTT over TLS"| SpringBoot
    SpringBoot -->|"JDBC"| PostgreSQL
    SpringBoot -->|"Cache"| Redis
    SpringBoot -->|"WebSocket/STOMP"| ReactApp
    SpringBoot -->|"REST API\n(HTTP/REST)"| ReactApp
    ReactApp -->|"UI Interaction"| Home
    SpringBoot -->|"JavaMail"| SMTP
    SpringBoot -->|"Scheduled Jobs"| Scheduler
    Monitoring -->|"Metrics & Logs"| SpringBoot

    %% Frontend interaction node alias
    ReactApp["React SPA\n(Chart.js, D3.js,\nReact Router)"]:::frontend

    %% Connections to ReactApp
    IndexHTML --> ReactApp
    MainJS --> ReactApp
    AppJS --> ReactApp
    IndexCSS --> ReactApp
    Button --> ReactApp
    Card --> ReactApp
    AddCrop --> ReactApp
    ControlPanel --> ReactApp
    CropDetails --> ReactApp
    ForgotPassword --> ReactApp
    Graph --> ReactApp
    MultiSensorGraph --> ReactApp
    Navbar --> ReactApp
    Notifications --> ReactApp
    Profile --> ReactApp
    ResetPassword --> ReactApp
    Home --> ReactApp
    Login --> ReactApp
    Register --> ReactApp
    CustomIcons --> ReactApp
    AxiosClient --> ReactApp
    AssetImage --> ReactApp
    DatabaseSQL --> ReactApp
    PackageJSON --> ReactApp
    PackageLock --> ReactApp
    ViteConfig --> ReactApp
    TailwindConfig --> ReactApp
    PostCSSConfig --> ReactApp
    ESLintConfig --> ReactApp
    EnvFile --> ReactApp
    VercelJSON --> ReactApp
    Redirects --> ReactApp

    %% Click Events
    click IndexHTML "https://github.com/abhinavhh/smart_irrigation/blob/main/index.html"
    click MainJS "https://github.com/abhinavhh/smart_irrigation/blob/main/src/main.jsx"
    click AppJS "https://github.com/abhinavhh/smart_irrigation/blob/main/src/App.jsx"
    click IndexCSS "https://github.com/abhinavhh/smart_irrigation/blob/main/src/index.css"
    click Button "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/ui/Button.jsx"
    click Card "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/ui/Card.jsx"
    click AddCrop "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/AddCrop.jsx"
    click ControlPanel "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/ControlPanel.jsx"
    click CropDetails "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/CropDetails.jsx"
    click ForgotPassword "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/ForgotPassword.jsx"
    click Graph "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/Graph.jsx"
    click MultiSensorGraph "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/MultiSensorGraph.jsx"
    click Navbar "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/Navbar.jsx"
    click Notifications "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/Notifications.jsx"
    click Profile "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/Profile.jsx"
    click ResetPassword "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Components/ResetPassword.jsx"
    click Home "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Pages/Home.jsx"
    click Login "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Pages/Login.jsx"
    click Register "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Pages/Register.jsx"
    click CustomIcons "https://github.com/abhinavhh/smart_irrigation/blob/main/src/Pages/CustomIcons.jsx"
    click AxiosClient "https://github.com/abhinavhh/smart_irrigation/blob/main/src/api/axios.jsx"
    click AssetImage "https://github.com/abhinavhh/smart_irrigation/blob/main/src/assets/untitled-5-o.avif"
    click DatabaseSQL "https://github.com/abhinavhh/smart_irrigation/blob/main/src/assets/database.sql"
    click PackageJSON "https://github.com/abhinavhh/smart_irrigation/blob/main/package.json"
    click PackageLock "https://github.com/abhinavhh/smart_irrigation/blob/main/package-lock.json"
    click ViteConfig "https://github.com/abhinavhh/smart_irrigation/blob/main/vite.config.js"
    click TailwindConfig "https://github.com/abhinavhh/smart_irrigation/blob/main/tailwind.config.js"
    click PostCSSConfig "https://github.com/abhinavhh/smart_irrigation/blob/main/postcss.config.js"
    click ESLintConfig "https://github.com/abhinavhh/smart_irrigation/blob/main/eslint.config.js"
    click EnvFile "https://github.com/abhinavhh/smart_irrigation/blob/main/.env"
    click VercelJSON "https://github.com/abhinavhh/smart_irrigation/blob/main/vercel.json"
    click Redirects "https://github.com/abhinavhh/smart_irrigation/tree/main/public/_redirects"

    %% Styles
    classDef iot fill:#9f6,stroke:#333,stroke-width:1px
    classDef backend fill:#6cf,stroke:#333,stroke-width:1px
    classDef frontend fill:#f90,stroke:#333,stroke-width:1px
    classDef external fill:#ccc,stroke:#333,stroke-width:1px
```
