# venugopalkadamba/agriai_webapp architecture

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

- Interactive diagram: https://gitdiagram.com/venugopalkadamba/agriai_webapp
- Repository: https://github.com/venugopalkadamba/agriai_webapp

## Overview

##### Project Type and Purpose
- This is a full-stack web application that uses machine learning models for agricultural recommendations.
- The purpose is to predict the best crop and fertilizer based on provided soil and crop data using multiple ML pipelines.
- The README clearly outlines that the Flask API serves POST endpoints to return prediction data in JSON, which the React frontend consumes.

##### Analyzing the File Structure
- The project is divided into two top-level directories: “Flask_API” (backend) and “React_Frontend” (frontend).
- In the Flask_API directory:
- app.py is the main entry point.
- A “models” folder contains subdirectories for “crop_recommendation” and “fertilizer_recommendation”, each with multiple model pipeline pickle files and supporting dictionary files.
- Configuration files like Procfile (for Heroku deployment), requirements.txt, and runtime.txt indicate deployment and environment settings.
- In the React_Frontend folder:
- The React app is organized under “agri-ai” containing typical front-end assets (public, src, components, images, styles, etc.).
- The API integrations are defined in an “api” directory (e.g., recommenderapi.js) which handles communication with the Flask API.

##### Key Components
- Frontend (React):
- Web Browser: Users interact via the React application.
- React Components: Components like Home, CropRecommender, FertilizerRecommender, NavBar, etc.
- API Service Module: The “recommenderapi.js” file that handles POST requests to the Flask API.
- Backend (Flask API):
- API Server (app.py): Handles incoming POST requests at endpoints:
- /predict_crop
- /predict_fertilizer
- Machine Learning Models:
- Crop Recommendation Module: Contains pipelines for KNN, Random Forest, and XGBoost (e.g., knn_pipeline.pkl, rf_pipeline.pkl, xgb_pipeline.pkl) plus the label dictionary.
- Fertilizer Recommendation Module: Contains pipelines for RF, SVM, and XGBoost plus dictionaries for crop type, fertilizer name, and soil type.
- Deployment Considerations: The Procfile and runtime.txt denote compatibility with Heroku, indicating cloud deployment.
- External Components & Integrations:
- Deployments: Heroku for the Flask API and Firebase hosting (or similar) for the React app.
- External Data Flow: JSON-based communication between the front end and backend.

##### Architectural Relationships and Data Flow
- The React frontend sends a POST request (via Axios) to the Flask API’s endpoints when a user requests recommendations.
- The Flask API receives the data, processes it through its local machine learning pipelines, and aggregates predictions.
- JSON responses (comprising model predictions and associated probabilities) are then sent back to the frontend.
- The frontend components update the UI to display the prediction results.

##### Final Recommendations for the Principal Software Engineer
- That every component has a clear, descriptive label.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global User
    U("User/Web Browser"):::user

    %% Deployment Environment
    subgraph "Deployment Environment"
        H("Heroku (Backend)"):::deployment
        F("Firebase (Frontend)"):::deployment
    end

    %% React Frontend
    subgraph "React Frontend"
        RC("UI Components (React)"):::frontend
        AS("API Service Module"):::frontend
    end

    %% Flask API Backend
    subgraph "Flask API Backend"
        API("API Server (app.py)"):::backend
        CR("Crop Recommendation Module"):::ml
        FR("Fertilizer Recommendation Module"):::ml
    end

    %% Data Flow Relationships
    U -->|"accesses"| RC
    RC -->|"triggers"| AS
    AS -->|"POST /predict"| API
    API -->|"invokes ML"| CR
    API -->|"invokes ML"| FR
    CR -->|"returns predictions"| API
    FR -->|"returns predictions"| API
    API -->|"sends JSON"| AS
    AS -->|"updates UI"| RC

    %% Deployment Connections
    API ---|"deployed on"| H
    RC ---|"hosted on"| F

    %% Click Events
    click API "https://github.com/venugopalkadamba/agriai_webapp/blob/main/Flask_API/app.py"
    click CR "https://github.com/venugopalkadamba/agriai_webapp/tree/main/Flask_API/models/crop_recommendation"
    click FR "https://github.com/venugopalkadamba/agriai_webapp/tree/main/Flask_API/models/fertilizer_recommendation"
    click RC "https://github.com/venugopalkadamba/agriai_webapp/tree/main/React_Frontend/agri-ai/src/components"
    click AS "https://github.com/venugopalkadamba/agriai_webapp/blob/main/React_Frontend/agri-ai/src/api/recommenderapi.js"

    %% Styles
    classDef user fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef frontend fill:#ccffff,stroke:#333,stroke-width:2px;
    classDef backend fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef ml fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef deployment fill:#99ff99,stroke:#333,stroke-width:2px;
```
