# surendiran2003/local-rag-llm architecture

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

- Interactive diagram: https://gitdiagram.com/surendiran2003/local-rag-llm
- Repository: https://github.com/surendiran2003/local-rag-llm

## Overview

##### Main Components
- Ollama Service: This component provides an environment to pull and run LLM models locally. It is configured with its own docker-compose.yml (in the ollama directory) and manages GPU/CPU resource settings, volume mapping (for model downloads), and network connectivity (via the “genai-network” Docker bridge).
- GenAI RAG Application: This is the core application (located in the “app” directory) where the Python app (app.py) handles PDF uploads, semantic retrieval, prompt augmentation, and LLM answer generation. It also includes its own Dockerfile, requirements, and docker-compose configuration to deploy this service.
- (Possibly) OpenWebUI: Based on the README, there is a reference to a UI running on a specified port (e.g., “http://localhost:3000/”) which appears to offer additional interactions like admin login and chatting with the local LLM. Although there is no dedicated source code directory for it, this UI is an integral user-facing piece.

##### Relationships & Interactions
- Both the ollama service and the RAG app run on Docker and share a common Docker network (“genai-network”), which facilitates container-to-container communications.
- The GenAI RAG app likely interacts with the ollama service by sending requests (via API calls or docker interactions) to perform tasks such as model inference or embedding generation for the uploaded documents.
- The UI component (OpenWebUI) serves as an entry point for user interaction: one UI endpoint for chatting with the LLM and another (the app) providing file upload and query processing for RAG functionality.
- Volumes are used (at least in ollama) to map a local directory for model downloads which is important for managing large LLM files.

##### Architectural Patterns & Technologies
- Containerization: Both major components use Docker, so depicting container boundaries clearly is important.
- Microservice/Modular Architecture: The design separates responsibilities into distinct services (LLM service vs. retrieval & generation app).
- Communication over a dedicated Docker bridge network ensures secure and isolated interactions.
- Technologies include Python (for the RAG app), Docker & docker-compose (for deployment and service orchestration), and potentially GPU resource management for accelerated LLM computations.

##### Clarity & Detail
- Each component should have a clear label. For example: “Ollama Service – LLM Model Management” and “GenAI RAG App – Document Query & Answer Generation.”

## Diagram (Mermaid)

```mermaid
graph TD
    %% External User
    USER["User"]:::external

    %% Main System Architecture
    subgraph "Local GenAI System Architecture"
        %% Container Services
        subgraph "Container Services"
            OL["Ollama LLM Service<br/>(LLM Model Management)"]:::container
            RAG["GenAI RAG Application<br/>(Document Query & Answer Generation)"]:::container
            UI["OpenWebUI"]:::ui
        end

        %% Infrastructure Components
        subgraph "Infrastructure"
            NET["Docker Network<br/>(genai-network)"]:::infra
            VOL["Volume for Model Storage"]:::infra
            GPU["NVIDIA GPU Resource"]:::infra
        end
    end

    %% Interactions and Data Flow
    USER -->|"initiates"| UI
    UI -->|"forwards request"| RAG
    RAG -->|"sends query"| OL
    OL -->|"responds via"| RAG
    RAG -->|"communicates over"| NET
    OL -->|"communicates over"| NET
    OL -->|"maps to"| VOL
    OL -->|"utilizes"| GPU

    %% Click Events
    click OL "https://github.com/surendiran2003/local-rag-llm/blob/main/ollama/docker-compose.yml"
    click RAG "https://github.com/surendiran2003/local-rag-llm/blob/main/app/app.py"
    click RAG "https://github.com/surendiran2003/local-rag-llm/tree/main/app/Dockerfile"
    click RAG "https://github.com/surendiran2003/local-rag-llm/blob/main/app/docker-compose.yml"
    click RAG "https://github.com/surendiran2003/local-rag-llm/blob/main/app/requirements.txt"

    %% Styles
    classDef container fill:#AED6F1,stroke:#1B4F72,stroke-width:2px,color:#1B2631;
    classDef ui fill:#F9E79F,stroke:#B9770E,stroke-width:2px,color:#7D6608;
    classDef infra fill:#D5F5E3,stroke:#1E8449,stroke-width:2px,color:#145A32;
    classDef external fill:#FADBD8,stroke:#922B21,stroke-width:2px,color:#641E16;
```
