# vp-1234ms/greenintellect architecture

> Architecture diagram of the GitHub repository vp-1234ms/greenintellect, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vp-1234ms/greenintellect
- Repository: https://github.com/vp-1234ms/greenintellect

## Overview

##### Project’s Major Components
- AI/ML Module: This includes the trained models (stored in the Models directory for crops and fruits) and the analysis notebooks (under Notebooks). These components are used for disease detection and prediction.
- Data Management: The Project_Data folder holds crop and fruit data alongside Excel datasets for results. This can be connected to the database layer.
- Web Application: The Web_Development folder holds code for the UI (Next.js/React components such as Posts.jsx, SensorGraph.jsx, etc.), API endpoints (e.g., Web_Development/api/route.js), backend logic (Flask detection/prediction modules), and configurations for both frontend and backend (various config files, package.json, etc.).
- Sensor & Hardware Integration: Described in the README (sensor data on air temperature, soil moisture, etc.) – though the sensors aren’t explicitly in the file tree, the referenced hardware integration should be documented.
- Business and Community Engagement: Business_Model and Project_Idea folders provide presentations and PDFs that outline the business strategy and the educational/community aspects of the project.
- External Services and Databases: The tech stack mentions PostgreSQL, MongoDB, and even IoT/MQTT for sensor integration. These backends will need representation.

##### Architectural Relationships and Interactions
- End users (farmers, researchers, etc.) interact via the frontend to upload plant images and view predictions.
- The Web UI sends image and sensor data to the backend API.
- The Flask modules receive these requests and invoke the corresponding AI model (TensorFlow) for disease detection.
- After processing, results are stored in the database (PostgreSQL/MongoDB) and returned to the client.
- Sensor data from IoT devices is also fed into the database and may be visualized on the web platform.
- The notebooks and ML pipelines allow continuous model improvement and retraining, integrating new data from the Project_Data folder.
- The system also interfaces with third-party APIs for community and educational content as described in the README.

##### Important Architectural Patterns/Design Principles
- Separation of Concerns: Clear division between user interface (frontend), application logic (backend), and AI model processing.
- Modular Design: Each component (image detection, sensor handling, data visualization) exists as separate, interactable modules – allowing for easier maintenance and scaling.
- Service-Oriented Architecture (SOA): The REST APIs (exposed in Web_Development/api) serve as communication channels between distinct services.
- Extensibility: Notebooks and Models directories indicate a design geared towards continual experimentation and improvement.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-Level User
    EndUsers("Farmers/Researchers"):::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        FrontendUI("Web UI (Next.js/React)"):::frontend
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        APIEndpoints("API Endpoints"):::backend
        BackendAPI("Flask API & Middleware"):::backend
    end

    %% AI/ML Processing Layer
    subgraph "AI/ML Processing Layer"
        TrainedModels("Trained Models (TensorFlow)"):::ai
        Notebooks("Analysis Notebooks"):::ai
    end

    %% Data & Sensor Layer
    subgraph "Data & Sensor Layer"
        SensorData("Sensor Data (IoT/MQTT)"):::sensor
        DataManagement("Project Data"):::sensor
    end

    %% External Databases & Services
    subgraph "External Services & Databases"
        PostgreSQL("PostgreSQL DB"):::database
        MongoDB("MongoDB"):::database
        IoT("IoT/MQTT Broker"):::external
    end

    %% Business & Community Module
    subgraph "Business & Community Module"
        BusinessCommunity("Business Model Documentation"):::business
        ProjectIdea("Project Idea Documents"):::business
    end

    %% Data Flow Connections
    EndUsers -->|"uploads_data"| FrontendUI
    FrontendUI -->|"sends_request"| APIEndpoints
    APIEndpoints -->|"processes_data"| BackendAPI
    BackendAPI -->|"invokes_model"| TrainedModels
    BackendAPI -->|"invokes_notebook"| Notebooks
    BackendAPI -->|"stores_results"| PostgreSQL
    BackendAPI -->|"stores_results"| MongoDB
    BackendAPI -->|"returns_prediction"| FrontendUI

    SensorData -->|"feeds_data"| DataManagement
    DataManagement -->|"updates_DB"| PostgreSQL
    DataManagement -->|"updates_DB"| MongoDB
    IoT -->|"delivers_data"| SensorData

    Notebooks -->|"trains_models"| TrainedModels

    %% Optional links for business context (informational)
    BusinessCommunity ---|"guides_strategy"| FrontendUI
    ProjectIdea ---|"informs_design"| FrontendUI

    %% Click Events
    click TrainedModels "https://github.com/vp-1234ms/greenintellect/tree/main/Models/"
    click Notebooks "https://github.com/vp-1234ms/greenintellect/tree/main/Notebooks/"
    click DataManagement "https://github.com/vp-1234ms/greenintellect/tree/main/Project_Data/"
    click FrontendUI "https://github.com/vp-1234ms/greenintellect/tree/main/Web_Development/"
    click APIEndpoints "https://github.com/vp-1234ms/greenintellect/blob/main/Web_Development/api/route.js"
    click BackendAPI "https://github.com/vp-1234ms/greenintellect/tree/main/Web_Development/Flask/"
    click BusinessCommunity "https://github.com/vp-1234ms/greenintellect/tree/main/Business_Model/"
    click ProjectIdea "https://github.com/vp-1234ms/greenintellect/tree/main/Project_Idea/"

    %% Styles
    classDef frontend fill:#80cbc4,stroke:#00695c,stroke-width:2px;
    classDef backend fill:#ffcc80,stroke:#ff8f00,stroke-width:2px;
    classDef ai fill:#c5e1a5,stroke:#33691e,stroke-width:2px;
    classDef sensor fill:#b39ddb,stroke:#4a148c,stroke-width:2px;
    classDef database fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef business fill:#f48fb1,stroke:#ad1457,stroke-width:2px;
    classDef external fill:#90caf9,stroke:#01579b,stroke-width:2px;
```
