# ganeshchate2004/smartfarming architecture

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

- Interactive diagram: https://gitdiagram.com/ganeshchate2004/smartfarming
- Repository: https://github.com/ganeshchate2004/smartfarming

## Overview

##### Project type and purpose
- This is a full-stack, IoT-enabled agriculture solution combining:
- A React-based frontend (UI/dashboard)
- A Node.js/Express/MongoDB backend (REST API + data persistence)
- A standalone Flask service hosting a CNN model (image classification)
- IoT devices (NodeMCU with sensors) feeding real-time data

##### File structure
- Top‐level directories:
- AI model/ – Flask app (app.py), TensorFlow model, dataset, templates & static
- backend/ – Express app (app.js), controllers, models, routes, MongoDB config
- frontend/ – React app (Vite), components, styles, public assets
- nodemcu.cpp – firmware for NodeMCU
- Patterns & components:
- REST API layer in backend/routes → controllers → models → MongoDB
- Flask microservice for AI (separate server)
- React SPA calling both services via Axios
- IoT firmware pushing sensor data to Express API

##### README for additional insights
- Confirms MERN stack + Flask AI + NodeMCU IoT
- Features: live sensor dashboard, image‐based disease detection, fertilizer/medicine suggestions, price prediction
- Deployment steps for frontend, backend, and AI model

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% IoT Layer
    NodeMCU["NodeMCU (ESP8266)\n+DHT11 + Moisture"]:::device
    click NodeMCU "https://github.com/ganeshchate2004/smartfarming/blob/main/nodemcu.cpp"

    %% Backend Layer
    subgraph "Backend API Server" 
        direction TB
        BE_App["Express.js App\n(app.js + JWT)"]:::service
        BE_Config["MongoDB Config\n(db.js)"]:::service
        BE_Routes["Routes Layer"]:::service
        BE_Controllers["Controllers\n(Business Logic)"]:::service
        BE_Models["Data Models\n(Mongoose Schemas)"]:::service
    end
    click BE_App "https://github.com/ganeshchate2004/smartfarming/blob/main/backend/app.js"
    click BE_Config "https://github.com/ganeshchate2004/smartfarming/blob/main/backend/config/db.js"
    click BE_Routes "https://github.com/ganeshchate2004/smartfarming/tree/main/backend/routes/"
    click BE_Controllers "https://github.com/ganeshchate2004/smartfarming/tree/main/backend/controllers/"
    click BE_Models "https://github.com/ganeshchate2004/smartfarming/tree/main/backend/models/"

    %% Database
    MongoDB["MongoDB"]:::db

    %% AI Service Layer
    subgraph "AI Service (Flask)" 
        direction TB
        AI_App["Flask App\n(app.py)"]:::service
        CNN_Model["CNN Model File\n(potato_disease_model.h5)"]:::service
        AI_Templates["Templates\n(index.html)"]:::service
        AI_Static["Static Assets"]:::service
    end
    click AI_App "https://github.com/ganeshchate2004/smartfarming/blob/main/AI model/app.py"
    click CNN_Model "https://github.com/ganeshchate2004/smartfarming/blob/main/AI model/potato_disease_model.h5"
    click AI_Templates "https://github.com/ganeshchate2004/smartfarming/blob/main/AI model/templates/index.html"
    click AI_Static "https://github.com/ganeshchate2004/smartfarming/tree/main/AI model/static/"

    %% Frontend Layer
    subgraph "Frontend UI (React SPA)" 
        direction TB
        FE_Main["Entry Point\nmain.jsx"]:::service
        FE_Components["Components"]:::service
        FE_Styles["Styles"]:::service
    end
    click FE_Main "https://github.com/ganeshchate2004/smartfarming/blob/main/frontend/src/main.jsx"
    click FE_Components "https://github.com/ganeshchate2004/smartfarming/tree/main/frontend/src/component/"
    click FE_Styles "https://github.com/ganeshchate2004/smartfarming/tree/main/frontend/src/style/"
    click ReactSPA "https://github.com/ganeshchate2004/smartfarming/tree/main/frontend/"

    %% External Services
    MarketAPI["External Market Data API"]:::external

    %% Connections
    NodeMCU -->|"POST sensor data"| BE_App
    BE_App -->|"uses"| BE_Config
    BE_App -->|"handles routes"| BE_Routes
    BE_Routes -->|"calls"| BE_Controllers
    BE_Controllers -->|"queries"| BE_Models
    BE_Models -->|"persists"| MongoDB
    BE_App -->|"GET/POST data"| MongoDB

    FE_Main -->|"Axios calls"| BE_App
    FE_Main -->|"POST image"| AI_App
    AI_App -->|"loads model"| CNN_Model
    AI_App -->|"serves UI"| AI_Templates
    AI_App -->|"serves assets"| AI_Static
    AI_App -->|"returns classification"| FE_Main

    BE_App -->|"proxy image request"| AI_App

    FE_Main -->|"GET price data"| MarketAPI
    BE_App -->|"GET price via API"| MarketAPI

    %% Style Definitions
    classDef service fill:#cce5ff,stroke:#66b3ff,stroke-width:1px
    classDef db fill:#e6ffe6,stroke:#33cc33,stroke-width:1px
    classDef device fill:#fff0b3,stroke:#ffcc00,stroke-width:1px
    classDef external fill:#f2f2f2,stroke:#999999,stroke-width:1px
```
