# jayeshbhandarkar/agrigenius architecture

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

- Interactive diagram: https://gitdiagram.com/jayeshbhandarkar/agrigenius
- Repository: https://github.com/jayeshbhandarkar/agrigenius

## Overview

##### Project Type & Purpose
- AgriGenius is a Python-based web application with an AI-powered chatbot aimed at answering agricultural queries.
- It leverages a Retrieval-Augmented Generation (RAG) model to fetch and process information from pdfs and websites to generate specific, informed responses for farmers.
- The project consists of a Flask web server backed by a sophisticated language model integration which uses the meta-llama/Llama-2-70b-chat-hf model via the Together API.

##### Analyzing the File Structure
- Top-Level Files:
- README.md (provides the project overview, installation and usage details, and architectural insights)
- app.py (likely the main entry point that starts the Flask web server)
- chat1.py & chat2.py (modules that implement the chatbot functionality; chat2.py indicates integration with the Together API for language model calls)
- requirements.txt (lists necessary third-party packages such as Flask, PyPDF2, langchain, chroma, etc.)
- Directories:
- Data: Contains PDF files and agricultural data (e.g., Farming Schemes.pdf, farmerbook.pdf) used in content retrieval.
- static & templates: Represent the frontend assets (CSS, JavaScript, and HTML) providing the web interface for user interaction.

##### Final Advice
- Modules, especially those handling NLP and retrieval functions, are clearly depicted.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    U["User (Web Browser)"]:::external

    %% Frontend UI Subgraph
    subgraph "Frontend UI"
        F_HTML["HTML (index.html)"]:::frontend
        F_CSS["CSS (style.css)"]:::frontend
        F_JS["JS (index.js)"]:::frontend
    end

    %% Backend: Flask Web Server
    FS["Flask Web Server"]:::backend

    %% Chat Modules Subgraph
    subgraph "Chat Modules"
        Chat1["Chat Module (chat1.py)"]:::chat
        Chat2["Chat Module with TogetherAPI Integration (chat2.py)"]:::chat
    end

    %% Data Processing & Retrieval Node
    DP["PDF/Data Retrieval"]:::data

    %% External API Integration Node
    TAPI["Together API Integration"]:::external

    %% Request Flow
    U -->|"initiates"| F_HTML
    F_HTML -->|"loads"| F_CSS
    F_CSS -->|"applies"| F_JS
    F_JS -->|"sends query"| FS
    FS -->|"routes to"| Chat1
    FS -->|"routes to"| Chat2
    Chat1 -->|"fetches data"| DP
    Chat2 -->|"fetches data"| DP
    Chat2 -->|"calls"| TAPI

    %% Response Flow (dotted lines for return path)
    DP -- "retrievedData" --> Chat1
    DP -- "retrievedData" --> Chat2
    Chat1 -- "response" --> FS
    Chat2 -- "response" --> FS
    FS -- "backToUI" --> F_JS
    F_JS -- "updatesUI" --> F_CSS
    F_CSS -- "rendersPage" --> F_HTML
    F_HTML -- "deliversResponse" --> U

    %% Click Events for Component Mapping
    click F_HTML "https://github.com/jayeshbhandarkar/agrigenius/blob/main/templates/index.html"
    click F_CSS "https://github.com/jayeshbhandarkar/agrigenius/blob/main/static/css/style.css"
    click F_JS "https://github.com/jayeshbhandarkar/agrigenius/blob/main/static/js/index.js"
    click FS "https://github.com/jayeshbhandarkar/agrigenius/blob/main/app.py"
    click Chat1 "https://github.com/jayeshbhandarkar/agrigenius/blob/main/chat1.py"
    click Chat2 "https://github.com/jayeshbhandarkar/agrigenius/blob/main/chat2.py"
    click DP "https://github.com/jayeshbhandarkar/agrigenius/tree/main/Data"

    %% Style Definitions
    classDef frontend fill:#AED6F1,stroke:#2471A3,stroke-width:2px,color:black;
    classDef backend fill:#ABEBC6,stroke:#1D8348,stroke-width:2px,color:black;
    classDef chat fill:#F9E79F,stroke:#B7950B,stroke-width:2px,color:black;
    classDef data fill:#F5CBA7,stroke:#E59866,stroke-width:2px,color:black;
    classDef external fill:#D5F5E3,stroke:#27AE60,stroke-width:2px,color:black;
```
