# sairam-k26/farming-land_analysis_platform architecture

> Architecture diagram of the GitHub repository sairam-k26/farming-land_analysis_platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sairam-k26/farming-land_analysis_platform
- Repository: https://github.com/sairam-k26/farming-land_analysis_platform

## Overview

##### Project Type and Purpose
- This is a full-stack farming companion platform.
- It comprises:
- Multiple ML prediction microservices (crop recommendation, disease prediction, rainfall forecast, surface-water level, crop-yield, soil-moisture)
- A Flutter mobile client
- A static website

##### File Structure
- Top-level folders:
- Crop_recommendation (model pickle + notebook)
- Plant Disease Prediction (notebooks + main.py)
- Rainfall_prediction (Flask app.py + models)
- Surface_water_Level_predictor (notebook + pickle)
- crop_Yield_Prediction (notebook + pickle)
- soil_moisture (ESP C code + main.py)
- Flutter (mobile UI code + pubspec)
- website (HTML/CSS/JS)
- Dataset (CSV files)
- Notice: Rainfall_prediction includes an app.py (Flask service). Others currently are notebooks but can be or should be refactored into RESTful Python services (Flask/FastAPI).

##### README for Insights
- Six core features, each backed by an ML model.
- Mobile client and website serve as frontends.
- No relational database folder present—data files and model pickles live in repo; consider adding a user-data store (e.g., PostgreSQL).

##### Main Components
a. Frontend Layer
- Flutter Mobile App (Android/iOS)
- Static Website (HTML/CSS/JS)
b. API Gateway / Load Balancer
- Single ingress point for all prediction requests
c. Microservice Layer (six services)
1. Crop Recommendation Service (loads crop_recommendation.pkl)
2. Plant Disease Prediction Service (exposes /predict_disease)
3. Rainfall Prediction Service (Flask app.py using cat/gnb/logreg/xgb .pkl)
4. Surface Water Level Service (loads Surface_Water_level_detector.pkl)
5. Crop Yield Prediction Service (uses crop_yield .pkl; notebook logic)
6. Soil Moisture Prediction Service (Python main.py + optionally ESP device)
d. Data & Model Storage
- Dataset CSVs (for retraining)
- Model artifact storage (pickle files)
e. (Optional) User Data Store
- Authentication, user preferences, logging

##### Relationships & Data Flow
- User action in mobile/website → HTTP(S) request to API Gateway
- Gateway routes to appropriate microservice
- Microservice loads model from artifact store, reads input payload, runs prediction, returns JSON response
- (Optional) Microservice logs request/response to User Data Store
- Soil Moisture Service might also interact with IoT device (ESP module) via MQTT/HTTP

##### Architectural Patterns & Design Principles
- Microservices: Each feature is its own deployable service
- Separation of concerns: Frontend vs. API vs. ML models vs. data
- RESTful APIs for communication
- CI/CD pipeline can build/deploy each service independently
- Containerization (Docker) for each microservice

##### Tools & Frameworks
- Flutter (Dart) for mobile UI
- Static website: HTML/CSS (no framework specified)
- Python 3.x for backend services
- Flask or FastAPI for REST endpoints
- scikit-learn / pickle for model loading
- CSV data for training; consider a database for production

##### Final Checklist
- Components: Frontends, API Gateway, 6 ML microservices, Storage
- Technology labels: Flutter, Flask, Python, scikit-learn, pickle, CSV, ESP hardware

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        FlutterApp["Flutter Mobile App"]:::frontend
        StaticWebsite["Static Website"]:::frontend
    end

    %% API Gateway
    APIGateway["API Gateway / Load Balancer"]:::gateway

    %% Microservice Layer in Cloud VPC
    subgraph "Cloud VPC"
        direction TB
        CropRecSvc["Crop Recommendation Service"]:::service
        DiseaseSvc["Plant Disease Prediction Service"]:::service
        RainfallSvc["Rainfall Prediction Service (Flask)"]:::service
        SurfaceWaterSvc["Surface Water Level Service"]:::service
        CropYieldSvc["Crop Yield Prediction Service"]:::service
        SoilMoistureSvc["Soil Moisture Prediction Service"]:::service
    end

    %% Storage Layer
    subgraph "Storage & Data"
        direction TB
        ModelStore["Model Artifact Store"]:::storage
        DataSet["Dataset CSVs"]:::storage
        UserDataDB["User Data Store (optional)"]:::storage
    end

    %% Data Flow
    FlutterApp -->|HTTPS| APIGateway
    StaticWebsite -->|HTTPS| APIGateway

    APIGateway -->|route to service| CropRecSvc
    APIGateway -->|route to service| DiseaseSvc
    APIGateway -->|route to service| RainfallSvc
    APIGateway -->|route to service| SurfaceWaterSvc
    APIGateway -->|route to service| CropYieldSvc
    APIGateway -->|route to service| SoilMoistureSvc

    CropRecSvc -->|load model| ModelStore
    DiseaseSvc -->|load model| ModelStore
    RainfallSvc -->|load model| ModelStore
    SurfaceWaterSvc -->|load model| ModelStore
    CropYieldSvc -->|load model| ModelStore
    SoilMoistureSvc -->|load model| ModelStore

    CropRecSvc -->|optional log| UserDataDB
    DiseaseSvc -->|optional log| UserDataDB
    RainfallSvc -->|optional log| UserDataDB
    SurfaceWaterSvc -->|optional log| UserDataDB
    CropYieldSvc -->|optional log| UserDataDB
    SoilMoistureSvc -->|optional log| UserDataDB

    ModelStore --> DataSet

    %% Click Events
    click FlutterApp "https://github.com/sairam-k26/farming-land_analysis_platform/tree/main/Flutter/"
    click StaticWebsite "https://github.com/sairam-k26/farming-land_analysis_platform/blob/main/website/vivasayi.html"
    click CropRecSvc "https://github.com/sairam-k26/farming-land_analysis_platform/blob/main/Crop_recommendation/vivasayi_crop_recommendation.ipynb"
    click DiseaseSvc "https://github.com/sairam-k26/farming-land_analysis_platform/blob/main/Plant Disease Prediction/main.py"
    click RainfallSvc "https://github.com/sairam-k26/farming-land_analysis_platform/blob/main/Rainfall_prediction/app.py"
    click SurfaceWaterSvc "https://github.com/sairam-k26/farming-land_analysis_platform/blob/main/Surface_water_Level_predictor/Surface_Water_level_detector.ipynb"
    click CropYieldSvc "https://github.com/sairam-k26/farming-land_analysis_platform/blob/main/crop_Yield_Prediction/crop_Yield_prediction.ipynb"
    click SoilMoistureSvc "https://github.com/sairam-k26/farming-land_analysis_platform/blob/main/soil_moisture/main.py"
    click DataSet "https://github.com/sairam-k26/farming-land_analysis_platform/tree/main/Dataset/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#1f77b4,stroke-width:1px
    classDef gateway fill:#d1c4e9,stroke:#9467bd,stroke-width:1px
    classDef service fill:#d4edda,stroke:#2ca02c,stroke-width:1px
    classDef storage fill:#fff3cd,stroke:#ff7f0e,stroke-width:1px
```
