# obinopaul/customgpt architecture

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

- Interactive diagram: https://gitdiagram.com/obinopaul/customgpt
- Repository: https://github.com/obinopaul/customgpt

## Overview

##### Project Type & Purpose
- This is a full-stack chatbot application featuring a Streamlit-based frontend for the UI and backend modules that handle language model integrations (OpenAI, HuggingFace, Ollama, DeepSeek), RAG operations, and data processing.
- It integrates with external systems such as Pinecone/Chroma (vector databases) and MongoDB for chat history storage, while also supporting operations like document uploads, web scraping, GitHub issue solving, and research paper retrieval.

##### File Structure
- Top-level files (e.g., app.py, config.yaml, Dockerfile, README.md) indicate deployment and configuration management.
- The presence of directories such as src, __init__.py files, and separate llm and rag subdirectories suggest a modular codebase. The "src/llm" folder contains files for wrapping around various language models and pipelines. Similarly, "src/rag" includes utility files for document loading, text splitting, vector storage interactions, and web scraping.
- There is also structured data under "lightrag_data" for storing logs and vector-related information, and "references" contains supporting documents.

##### Main Components & Their Interactions
a. Frontend Component:
- Streamlit UI (app.py) that serves as the primary user interface. This component provides interaction points for selecting models, RAG operations, and displaying chatbot responses.

b. Backend Components:
- LLM Processing Module: Composing various handlers in src/llm (e.g., deepseek.py, huggingface.py, llama.py, openai.py) and the llm_pipeline which coordinates model selection and request handling.
- RAG Module: Found in src/rag, which includes document_loader, text_splitter, vector_store, and web_scraper. This module is responsible for enriching context and supporting retrieval operations.
- Pipeline Orchestration: Files such as src/run_lightrag_pipeline.py and src/run_rag_pipeline.py tie together preprocessing, model execution, and post-processing pipelines.
- Utility Module: src/utils.py contains common utilities shared across modules.

c. Data Storage & External Services:
- Vector Database: Integration with Pinecone (default) as well as support for Chroma for similarity search.
- Chat History Database: MongoDB, where chat histories and other logs are stored.
- External APIs: OpenAI API, HuggingFace API, Pinecone API, GitHub API, etc., with API keys managed via environment configuration (.env).

d. Infrastructure & Deployment:
- Dockerfile and container configurations (.devcontainer) for development and deployment.
- Configuration files such as config.yaml and tailwind.config.js (if a web part is involved) which show additional frontend or design aspects.
- Cloud deployment specifics (vercel.json, render.yaml) used for deployment on platforms like Vercel.

##### Architectural Patterns & Design Principles
- Modularity: Separate modules for LLM handling, RAG functionalities, and orchestration.
- Separation of Concerns: Clear division between the UI layer (Streamlit), processing layers (LLM and RAG pipelines), and data persistence (MongoDB, vector databases).
- Integration of external APIs/services: API keys and integrations are managed through environment variables to ensure flexibility and scalability.
- Pipeline-based processing: The existence of “run” scripts to trigger either LightRAG or standard RAG implies a clear pipeline execution model.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    UI["Streamlit Frontend"]:::ui
    click UI "https://github.com/obinopaul/customgpt/blob/main/app.py"
    
    %% Backend Processing Layer
    subgraph "Backend Processing"
        LLM["LLM Module"]:::backend
        click LLM "https://github.com/obinopaul/customgpt/tree/main/src/llm"
        
        RAG["RAG Module"]:::backend
        click RAG "https://github.com/obinopaul/customgpt/tree/main/src/rag"
        
        subgraph "Pipeline Orchestration"
            LightRAG["LightRAG Pipeline"]:::backend
            click LightRAG "https://github.com/obinopaul/customgpt/blob/main/src/run_lightrag_pipeline.py"
            
            RAG_Pipeline["RAG Pipeline"]:::backend
            click RAG_Pipeline "https://github.com/obinopaul/customgpt/blob/main/src/run_rag_pipeline.py"
        end
        
        Utility["Utility Functions"]:::backend
        click Utility "https://github.com/obinopaul/customgpt/blob/main/src/utils.py"
    end
    
    %% External Systems and Data Storage
    External["External APIs&Services"]:::external
    DB["Vector Database (Pinecone/Chroma)"]:::database
    Mongo["Chat History Storage (MongoDB)"]:::database
    
    %% Deployment & Configuration
    Deploy["Deployment & Config"]:::deployment
    click Deploy "https://github.com/obinopaul/customgpt/tree/main/Dockerfile"
    click Deploy "https://github.com/obinopaul/customgpt/blob/main/config.yaml"
    click Deploy "https://github.com/obinopaul/customgpt/blob/main/.devcontainer"
    click Deploy "https://github.com/obinopaul/customgpt/blob/main/vercel.json"
    click Deploy "https://github.com/obinopaul/customgpt/blob/main/render.yaml"
    click Deploy "https://github.com/obinopaul/customgpt/blob/main/tailwind.config.js"
    
    %% Data Storage and References
    DataLogs["Data Storage&Logs"]:::data
    click DataLogs "https://github.com/obinopaul/customgpt/tree/main/lightrag_data"
    
    References["Reference Documents"]:::data
    click References "https://github.com/obinopaul/customgpt/tree/main/references"
    
    %% Inter-component Relationships
    UI -->|"UserInput"| LLM
    UI -->|"UserInput"| RAG
    
    LLM -->|"ModelRequest"| External
    RAG -->|"RAGRequest"| DB
    RAG -->|"DataIngestion"| External
    
    LLM -->|"OrchestratedBy"| LightRAG
    RAG -->|"OrchestratedBy"| RAG_Pipeline
    
    LightRAG -->|"Utilizes"| Utility
    RAG_Pipeline -->|"Utilizes"| Utility
    
    External -->|"DataStoredIn"| Mongo
    
    LLM -->|"ResponseReturned"| UI
    RAG -->|"ContextReturned"| UI
    
    LightRAG -->|"ConfiguredBy"| Deploy
    RAG_Pipeline -->|"ConfiguredBy"| Deploy
    Utility -->|"UsesConfig"| Deploy
    External -->|"EnvVarsUsed"| Deploy
    
    %% Styles
    classDef ui fill:#f9c,stroke:#333,stroke-width:2px;
    classDef backend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef database fill:#cfc,stroke:#333,stroke-width:2px;
    classDef external fill:#fcc,stroke:#333,stroke-width:2px;
    classDef deployment fill:#fc9,stroke:#333,stroke-width:2px;
    classDef data fill:#cff,stroke:#333,stroke-width:2px;
```
