# saram098/ai-powered-chatbot-for-coding-and-document-queries architecture

> Architecture diagram of the GitHub repository saram098/ai-powered-chatbot-for-coding-and-document-queries, 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/saram098/ai-powered-chatbot-for-coding-and-document-queries
- Repository: https://github.com/saram098/ai-powered-chatbot-for-coding-and-document-queries

## Overview

##### Project Type and Purpose
- This is a full-stack application with a clear separation between a FastAPI backend (for handling multiple query types with Groq API integration) and a Streamlit frontend (providing a user-friendly chat interface).
- Its main purpose is to process text, PDF documents, and audio queries for coding and document-related assistance, with chat histories stored per user.

##### Main Components
a. FastAPI Backend
- File: app.py
- Responsibilities:
- Handling incoming queries (text, document, audio)
- Communicating with the Groq API to generate responses
- Managing the query processing logic for different input types
- Key interactions: Receives queries from the frontend and returns response data.

b. Streamlit Frontend
- File: CodeGenie.py
- Responsibilities:
- Providing an interactive chatbot interface for users
- Uploading documents/audio or entering text
- Displaying chat history and responses
- Key interactions: Sends requests to the FastAPI backend and displays results.

c. Data Storage Components
- Chats Folder (auto-created): Stores user-specific chat histories in JSON format.
- Data Folder (auto-created): Holds user-uploaded PDFs and audio files.

d. Environment Configuration
- .env file: Contains vital configuration data like the BASE_URL and GROQ_API_KEY.

e. Dependencies and Frameworks
- FastAPI, Uvicorn – powering the backend server.
- Streamlit – powering the interactive frontend.
- Additional libraries for PDF (PyMuPDF) and audio (SpeechRecognition, pydub) processing.

##### Relationships and Interactions
- The backend processes these queries by:
- Managing file storage by saving relevant documents and user audio in the Data folder.
- Storing chat sessions in the Chats folder.
- From Frontend → Backend (user queries)
- From Backend → Groq API (model query)
- From Groq API → Backend (model response)
- From Backend → Frontend (final response)
- Configuration exchange where the .env file provides settings to both the backend and indirectly the frontend (when quoted as BASE_URL).

##### Architectural Patterns / Design Principles
- Separation of concerns: The frontend handles user interactions, while backend processes and business logic are decoupled.
- Modular design: Each component (query processing, file storage, chat history) is separate.
- Extensibility: The architecture allows the backend to easily update the model (as noted in the README, via the “query_groq” function).

- Under the Backend, add sub-components:
- Query Processing (function: query_groq)
- File management (Data and Chats folders)
- Environment Configuration (link to .env)
- For the Frontend, indicate the interactive UI and user entry points.
- How a text, PDF, or audio query flows from the Streamlit interface to the FastAPI backend.
- The backend sending a model query to and receiving a response from the Groq API.
- Saving of results in the chats folder and retrieval of stored files from the data folder.
- Annotations at each step if needed, noting the libraries or frameworks involved (e.g., “FastAPI”, “Uvicorn”, “Streamlit”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    subgraph "Frontend"
        FUI["Streamlit UI - CodeGenie.py"]:::frontend
    end

    %% Backend
    subgraph "Backend"
        FAPI["FastAPI Backend - app.py"]:::backend
        QP["Query Processing (query_groq)"]:::backend
        CF["Env Config (.env)"]:::config
        DS["Data Storage (Data Folder)"]:::storage
        CS["Chat Storage (Chats Folder)"]:::storage
    end

    %% External Service
    GA["Groq API"]:::external

    %% Interactions
    FUI -->|"sendsQuery"| FAPI
    FAPI -->|"invokes"| QP
    FAPI -->|"loads"| CF
    FAPI -->|"savesFiles"| DS
    FAPI -->|"savesChats"| CS
    FAPI -->|"callsAPI"| GA
    GA -->|"returnsResponse"| FAPI
    FAPI -->|"sendsResponse"| FUI

    %% Click Events
    click FAPI "https://github.com/saram098/ai-powered-chatbot-for-coding-and-document-queries/blob/master/app.py"
    click FUI "https://github.com/saram098/ai-powered-chatbot-for-coding-and-document-queries/blob/master/CodeGenie.py"
    click CF "https://github.com/saram098/ai-powered-chatbot-for-coding-and-document-queries/blob/master/.env"

    %% Styles
    classDef frontend fill:#F9E79F,stroke:#D35400,stroke-width:2px;
    classDef backend fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef storage fill:#ABEBC6,stroke:#148F77,stroke-width:2px;
    classDef config fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
