# amaannaseh/kisan-kranti architecture

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

- Interactive diagram: https://gitdiagram.com/amaannaseh/kisan-kranti
- Repository: https://github.com/amaannaseh/kisan-kranti

## Overview

##### Main Components
- AI Crop Disease Prediction Service (located in the “flask-crop-diseases” folder):
– A Python/Flask application that serves crop disease detection functionality.
– Contains several pre-trained AI models (H5 files) and accompanying static assets (JavaScript, CSS, HTML templates) to support visualization and user interaction.
- Market/E-Commerce Module (located in “kisan-e-dukaan”):
– Comprises two parts: the backend (an Express/Node.js service managing controllers, routes, and models for authentication, products, cart, coupons, orders, etc.) and the frontend (a separate React/Vite-based client).
– This module supports digital marketing and commercialization for farmers.
- Main Application / Web Frontend (located in “kisan-kranti”):
– Acts as the central hub integrating various functionalities and pages (crop prices, FAQs, crop reports, organic farming, chatbot, etc.)
– The folder includes components for navigating different aspects of the service (for example, AI-driven pages, brochure pages, complaint handling, and more).

##### Relationships & Interactions
- The AI Crop Disease Prediction Service will function as a microservice exposing endpoints (via Flask) to accept images, process them using the stored H5 models, and return predictions.
– Data flow: Client (or even the main frontend) sends an image → Flask server processes the request → Returns AI results.
- The Market Module entails interaction between its RESTful Node.js backend and its dedicated frontend.
– The backend handles API requests from the frontend for products, authentication, cart management, analytics, etc.
– It may also have interaction (possibly via cross-module API calls or shared services) with the main application.
- The Main Frontend (Kisan-Kranti) acts as an aggregator interface where users can access the market page, the AI-based disease prediction service (either by direct integration or through a link/API call), weather insights, crop reports, and additional farmer support features.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The system is clearly segmented into specialized modules:
– AI service (Flask microservice),
– E-commerce service (Node.js backend with a separate React frontend), and
– The overall web/mobile interface (Kisan-Kranti).
- Microservices/Modular Architecture: Each subsystem (e.g., Flask-based AI service, Node.js backend) can be deployed and scaled independently.
- Client-Server Interaction: Clear API boundaries exist between the frontends and their corresponding backends.
- Reusability and Extensibility: The static assets, controllers, and models are organized for modularity, ensuring that new features (like future blockchain support or hardware integration) can be added with minimal rework.

##### Final Reminders for the Principal Software Engineer
– The main frontend (Kisan-Kranti) and the two services (Flask AI and the e-commerce backend).
– The interaction within the e-commerce system (frontend-to-backend) and within the AI microservice components.
- Component is as granular as needed – break down internal structures (controllers, models, static assets) where clarity is essential.
- Capturing the integration points (API calls, data flow) to not overcomplicate the overall architecture but to ensure all essential paths are visible.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Application Frontend (Kisan-Kranti)
    subgraph "Main Application Frontend (Kisan-Kranti)"
        MA1("index.html"):::react
        MA2("App.jsx"):::react
        MA3("Pages"):::react
        MA4("Components"):::react
        MA5("Assets"):::react
    end

    %% E-Commerce Frontend – React Client
    subgraph "E-Commerce Frontend – React Client"
        EF1("Src"):::react
        EF2("Public"):::react
        EF3("Configuration"):::react
    end

    %% E-Commerce Backend – Node.js API
    subgraph "E-Commerce Backend – Node.js API"
        EB1("Server.js"):::node
        EB2("Controllers"):::node
        EB3("Routes"):::node
        EB4("Models"):::node
        EB5("Middleware"):::node
    end

    %% Flask Crop Disease Service (AI)
    subgraph "Flask Crop Disease Service (AI)"
        F1("Flask App (app.py)"):::flask
        F2("AI Models (.h5)"):::flask
        F3("Templates (HTML)"):::flask
        F4("Static Assets (CSS/JS)"):::flask
    end

    %% Integration: Main Application interactions
    MA5 -->|"PredictionRequest"| F1
    MA5 -->|"ProductAPICall"| EB1
    MA4 -->|"NavigateToMarket"| EF1

    %% Integration: E-Commerce Frontend to Backend
    EF1 -->|"RESTAPI"| EB1

    %% Additional integration from Main Application (Pages) to Flask Service
    MA3 -->|"ImageUpload/Prediction"| F1

    %% Click Events for Flask Crop Disease Service
    click F1 "https://github.com/amaannaseh/kisan-kranti/blob/main/flask-crop-diseases/app.py"
    click F2 "https://github.com/amaannaseh/kisan-kranti/tree/main/flask-crop-diseases/models"
    click F3 "https://github.com/amaannaseh/kisan-kranti/tree/main/flask-crop-diseases/templates"
    click F4 "https://github.com/amaannaseh/kisan-kranti/tree/main/flask-crop-diseases/static"

    %% Click Events for E-Commerce Backend Service
    click EB1 "https://github.com/amaannaseh/kisan-kranti/blob/main/kisan-e-dukaan/backend/server.js"
    click EB2 "https://github.com/amaannaseh/kisan-kranti/tree/main/kisan-e-dukaan/backend/controllers"
    click EB3 "https://github.com/amaannaseh/kisan-kranti/tree/main/kisan-e-dukaan/backend/routes"
    click EB4 "https://github.com/amaannaseh/kisan-kranti/tree/main/kisan-e-dukaan/backend/models"
    click EB5 "https://github.com/amaannaseh/kisan-kranti/tree/main/kisan-e-dukaan/backend/middleware"

    %% Click Events for E-Commerce Frontend
    click EF1 "https://github.com/amaannaseh/kisan-kranti/tree/main/kisan-e-dukaan/frontend/src"
    click EF2 "https://github.com/amaannaseh/kisan-kranti/tree/main/kisan-e-dukaan/frontend/public"
    click EF3 "https://github.com/amaannaseh/kisan-kranti/tree/main/kisan-e-dukaan/frontend"

    %% Click Events for Main Application / Web Frontend
    click MA1 "https://github.com/amaannaseh/kisan-kranti/blob/main/kisan-kranti/index.html"
    click MA2 "https://github.com/amaannaseh/kisan-kranti/blob/main/kisan-kranti/src/App.jsx"
    click MA3 "https://github.com/amaannaseh/kisan-kranti/tree/main/kisan-kranti/src/Pages"
    click MA4 "https://github.com/amaannaseh/kisan-kranti/tree/main/kisan-kranti/src/Components"
    click MA5 "https://github.com/amaannaseh/kisan-kranti/tree/main/kisan-kranti/assets"

    %% Styles
    classDef flask fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef node fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef react fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef integration fill:#FFB6C1,stroke:#000,stroke-width:1px;
```
