# teclaguna/ragchatbot architecture

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

## Overview

##### Main Components
- Client/User Interface – Represents front-end clients that consume the API (for example, a web application or Postman/Insomnia used during testing).
- API Server – Central component running within app.py using FastAPI, which exposes REST endpoints for functionalities like uploading PDFs (/embed), querying (/query), scraping (/scrape_and_embed), and establishing WebSocket connections.
- Document Processing Module – Handles PDF parsing and the extraction of text and other structured content.
- External Model Service – Represents the integration with Hugging Face’s models (e.g., Mistral-7B) used to generate language embeddings.
- Langchain Integration – Orchestrates the retrieval and generation logic for the RAG (Retrieval-Augmented Generation) bot.
- Vector Store (ChromaDB) – Used for storing and retrieving vector embeddings of documents.
- Database (MongoDB) – Persists documents, conversations, and related metadata.
- Docker Container – The environment in which the entire application is packaged and deployed; note that the provided Dockerfile contains detailed instructions to create a reproducible image.
- WebSocket Component – Enables real-time bidirectional communication for the chatbot experience.

##### Relationships and Interactions
- The Document Processing Module for handling PDFs.
- The External Model Service (via Hugging Face) which is triggered for LLM inference.
- Langchain that orchestrates the retrieval process.
- The Vector Store (ChromaDB) which is queried for embeddings.
- The Database (MongoDB) for saving/retrieving document and conversation data.

##### Architectural Patterns and Design Principles
- That the application uses a modular design where each major functionality (data ingestion, processing, vector search, and persistence) is distinctly separated.
- The overall architecture can be represented as a monolithic backend layer (the FastAPI application) that integrates with many external services.
- Docker encapsulation is critical, as it ensures that the application—including all its dependencies like system libraries and Python packages—is consistent between development and deployment environments.
- Best practices such as separation of concerns (e.g., dedicated endpoints for embedding vs. querying), clear data flow, and integration with external APIs.

##### Relevant Technologies and Tools
- That the API Server is developed in Python (using FastAPI).
- Integration with third-party APIs such as Hugging Face and Langchain.
- Database components with MongoDB and differentiate between the vector storage (ChromaDB) and persistent storage (MongoDB).
- Containerization using Docker.
- Optionally, include placeholders or labels for PDF processing (possibly using Unstructured) and other tools mentioned in the README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client/User Interface"):::external
    DC("Docker Container"):::container

    subgraph "API Components"
      direction TB
      APIServer("API Server (FastAPI)"):::api
      DPM("Document Processing Module"):::api
      HF("External Model Service (Hugging Face)"):::external
      Langchain("Langchain Integration"):::api
      Chroma("Vector Store (ChromaDB)"):::db
      Mongo("Database (MongoDB)"):::db
      WebSocket("WebSocket Component"):::api
    end

    Client -->|"REST_calls"| DC
    DC -->|"Runs"| APIServer
    APIServer -->|"ProcessesPDF"| DPM
    APIServer -->|"LLM_inference"| HF
    APIServer -->|"Orchestration"| Langchain
    APIServer -->|"Vector_search"| Chroma
    APIServer -->|"Persists_data"| Mongo
    APIServer -->|"Real-time"| WebSocket

    click APIServer "https://github.com/teclaguna/ragchatbot/blob/main/app.py"
    click DPM "https://github.com/teclaguna/ragchatbot/blob/main/app.py"
    click HF "https://github.com/teclaguna/ragchatbot/blob/main/app.py"
    click Langchain "https://github.com/teclaguna/ragchatbot/blob/main/app.py"
    click Chroma "https://github.com/teclaguna/ragchatbot/blob/main/app.py"
    click Mongo "https://github.com/teclaguna/ragchatbot/blob/main/app.py"
    click WebSocket "https://github.com/teclaguna/ragchatbot/blob/main/app.py"
    click DC "https://github.com/teclaguna/ragchatbot/tree/main/DockerFile"

    classDef external fill:#FFE6E6,stroke:#FF0000,stroke-width:2px;
    classDef api fill:#E8F4FD,stroke:#1E90FF,stroke-width:2px;
    classDef db fill:#E6FFE6,stroke:#006400,stroke-width:2px;
    classDef container fill:#F5E6FF,stroke:#800080,stroke-width:2px;
```
