# parithoshd/agrivantage architecture

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

- Interactive diagram: https://gitdiagram.com/parithoshd/agrivantage
- Repository: https://github.com/parithoshd/agrivantage

## Overview

The AgriVantage project is a specialized voice bot system designed for the agricultural sector. Its primary goal is to allow farmers to call a dedicated number (managed via Twilio) and receive answers to agriculture-related queries, even in areas with limited internet access. The system leverages FastAPI for its web framework, integrates speech-to-text services (primarily OpenAI Whisper—with Deepgram as an alternative), and uses a Retrieval-Augmented Generation (RAG) chain via LangChain and FAISS to process local documents stored under the "documents" directory.

##### Main Components
- User’s Phone: The entry point where farmers initiate a call.
- Twilio: Manages incoming voice calls, recording, and triggering webhooks.
- FastAPI Server (main.py): Acts as the central controller to receive HTTP requests from Twilio.
- Speech-to-Text Services: Represents the integration with OpenAI Whisper (and optionally Deepgram) which transcribes the recorded call audio into text.
- RAG Chain Modules: Comprising LangChain and FAISS. This part of the architecture handles query processing using the text transcripts and retrieves relevant information from locally stored documents (found in the "documents" folder).
- Document Processing Component: Responsible for loading and splitting the PDF/text files to build a vector store for the FAISS retrieval system.
- NGROK Tunnel: Dynamically exposes the local FastAPI server to the public internet, easing development and testing.

##### Relationships and Interactions
- Additionally, add a component for Document Processing that feeds into the LangChain & FAISS module, indicating that local documents (from the "documents" directory) are pre-processed and indexed.

##### Architectural Patterns and Technologies
- Microservices-like decomposition: voice capture, transcription processing, and document-based answer retrieval.
- Modularity where additional services (like Deepgram) can be optionally integrated into the speech-to-text pipeline.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interface
    subgraph "External Interface"
        A["User Phone"]:::external
        B["Twilio Voice API"]:::external
        C["NGROK Tunnel"]:::external
    end

    %% Backend Processing
    subgraph "Backend Processing"
        D["FastAPI Server (main.py)"]:::backend
        E["Speech-to-Text Service (OpenAI Whisper/Deepgram)"]:::service
        F["RAG Chain Modules (LangChain & FAISS)"]:::backend
        G["Document Processing (PDF/Text Loader)"]:::backend
    end

    %% Flow Connections
    A -->|"initiates_call"| B
    B -->|"forwards_call"| C
    C -->|"webhook_request"| D

    D -->|"transcription_request"| E
    E -->|"transcribed_text"| F
    D -->|"orchestrates_query"| F
    G -->|"feeds_indexed_docs"| F
    F -->|"sends_answer"| D

    D -->|"response_forward"| C
    C -->|"sends_response"| B
    B -->|"responds_to"| A

    %% Click Events
    click D "https://github.com/parithoshd/agrivantage/blob/main/main.py"
    click G "https://github.com/parithoshd/agrivantage/tree/main/documents/"

    %% Styles
    classDef external fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef service fill:#ADD8E6,stroke:#333,stroke-width:2px;
```
