# theomkulpe/docuchat architecture

> Architecture diagram of the GitHub repository theomkulpe/docuchat, 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/theomkulpe/docuchat
- Repository: https://github.com/theomkulpe/docuchat

## Overview

##### Project Type & Purpose
- This project is a full-stack web application that lets users upload PDF files or input webpage URLs.
- Its purpose is to extract text from these sources, split it into meaningful chunks, and then let users query the document’s content using AI models. Key technologies mentioned include Flask (backend API), React (frontend UI), LangChain for text processing, FAISS for vector searches, HuggingFace for embeddings, and Groq’s LLM for generating responses.

##### Core Components from the File Structure
- Frontend (React):
- Files like App.js, index.js, and related CSS/test files indicate a classic create-react-app structured React frontend.
- This part handles user interactions such as file uploads and query submissions.
- Backend (Flask):
- The backend directory contains server.py (likely the Flask API server), requirements.txt, and a utilities file (utils.py).
- This layer is responsible for processing requests from the frontend, handling text extraction, and communicating with AI components.

##### Key Architectural Components
- User Interface (Frontend):
- A component representing the React app that takes user inputs (uploads & URL entries).
- API Gateway (Backend Server):
- A Flask server component that receives requests from the front end.
- Document Processing Pipeline:
- Segments for:
▪ PDF or Webpage Text Extraction – handling the initial extraction process from user-provided sources.
▪ Text Chunking – leveraging LangChain’s RecursiveCharacterTextSplitter to break text into processable chunks.
- Embeddings & Vector Storage:
- A service block showing the integration with HuggingFace embedding models to generate text embeddings.
- The FAISS vector store component where these embeddings are indexed for similarity search.
- AI Query Engine:
- A module representing Groq’s Cloud-based LLM, which receives processed queries and text data to generate intelligent responses.

##### Relationships and Data Flow
- A clear flow:
- The User (client) → Frontend (React) → API Calls to Backend (Flask server).
- Within the backend, denote a sequential processing flow: Input (PDF/URL) → Extraction → Text Chunking → Embedding Generation → Storing/ Searching in FAISS → Querying against LLM (Groq) → Response generation.

##### Architectural Patterns & Design Principles to Highlight
- Separation of Concerns:
- Clearly different layers (Presentation, API, Processing Pipeline, AI Services) to show the decoupled responsibilities between frontend and backend.
- Modular Design:
- Each processing step (extraction, chunking, embedding, querying) is modular and can potentially be enhanced or swapped.
- External Service Integration:
- How external libraries (LangChain, HuggingFace, Groq) and technology (FAISS) are integrated into the core flow.

##### Putting It All Together
- Feedback loop where the backend ultimately returns processed responses back to the Frontend for display.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client("User (Client)"):::external

    %% Frontend Subgraph
    subgraph "Frontend (React)"
        FrontendApp("App Component"):::frontend
        FrontendIndex("Index Component"):::frontend
    end

    %% Backend API Gateway and Dependency Manager
    APIGateway("API Gateway (Flask Server)"):::backend
    DepManager("Dependency Manager"):::backend

    %% Document Processing Pipeline within Backend
    Process("Text Extraction & Chunking (LangChain)"):::processing
    Embedding("Embedding Generator (HuggingFace)"):::processing
    VectorDB("Vector Database (FAISS)"):::database
    LLM("LLM Query Engine (Groq)"):::processing

    %% Data Flow
    Client -->|"initiates"| FrontendApp
    Client -->|"initiates"| FrontendIndex
    FrontendApp -->|"sends request"| APIGateway
    FrontendIndex -->|"sends request"| APIGateway
    APIGateway -->|"processes"| Process
    Process -->|"generates embeddings"| Embedding
    Embedding -->|"indexes vectors"| VectorDB
    VectorDB -->|"queries vectors"| LLM
    LLM -->|"returns response"| APIGateway
    APIGateway -->|"responds"| FrontendApp
    APIGateway -->|"responds"| FrontendIndex
    FrontendApp -->|"displays result"| Client
    FrontendIndex -->|"displays result"| Client

    %% Dependency relationship
    APIGateway ---|"depends_on"| DepManager

    %% Click Events
    click FrontendApp "https://github.com/theomkulpe/docuchat/blob/main/frontend/App.js"
    click FrontendIndex "https://github.com/theomkulpe/docuchat/blob/main/frontend/index.js"
    click APIGateway "https://github.com/theomkulpe/docuchat/blob/main/backend/server.py"
    click Process "https://github.com/theomkulpe/docuchat/blob/main/backend/utils.py"
    click DepManager "https://github.com/theomkulpe/docuchat/blob/main/backend/requirements.txt"

    %% Styles
    classDef external fill:#FFEEAD,stroke:#F1C40F,stroke-width:2px;
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#D5F5E3,stroke:#196F3D,stroke-width:2px;
    classDef processing fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef database fill:#F5CBA7,stroke:#AF601A,stroke-width:2px;
```
