# docker/genai-stack architecture

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

- Interactive diagram: https://gitdiagram.com/docker/genai-stack
- Repository: https://github.com/docker/genai-stack

## Overview

##### Main Components

a) Core Infrastructure:
- Neo4j Database (vector storage + knowledge graph)
- Ollama/OpenAI/Claude LLM Service
- Embedding Service (multiple options: sentence_transformer, openai, aws, google-genai)

b) Applications Layer:
- Support Bot (bot.py)
- Stack Overflow Loader (loader.py)
- PDF Reader Bot (pdf_bot.py)
- Standalone API (api.py)
- Frontend Application (front-end/)

**┌─ Client Layer ─────────────────────────────────┐**
- Web UIs (Ports 8501-8505)                   │
- Svelte Frontend                             │
- ┬─────────────────────────┘
- ↓
**┌─ Application Layer ───────────────────────────┐**
- ┌─────────┐ ┌────────┐ ┌───────┐ ┌─────────┐ │
- Support  │ │Loader  │ │PDF    │ │API      │ │
- Bot      │ │App     │ │Reader │ │Service  │ │
- ┬────┘ └───┬────┘ └───┬───┘ └────┬────┘ │
- ┼──────────┼─────────┼──────────┼───────┘
- ↓          ↓         ↓          ↓
**┌─ Service Layer ──────────────────────────────┐**
- ┌─────────────┐    ┌──────────────────────┐ │
- Chain Service│    │Embedding Service     │ │
- (chains.py)  │    │(Multiple Providers)  │ │
- ┘    └──────────────────────┘ │
- ┬─────────────────┬────────────────┘
- ↓                 ↓
**┌─ Infrastructure Layer ─────────────────────────┐**
- ┌─────────────┐    ┌──────────────────────┐   │
- Neo4j        │    │LLM Service          │   │
- Database     │◄──►│(Ollama/OpenAI/Claude)│   │
- ┘    └──────────────────────┘   │
- ┘

##### Important Elements to Highlight

a) Data Flow Patterns:
- Bidirectional communication between apps and Neo4j
- Streaming responses from LLM services
- Vector embedding flow from content to database

b) Integration Points:
- Environment configuration connections
- API endpoints and ports
- Docker container relationships

##### Technical Details

- Port mappings (8501-8505)
- Database connection (7474/7687)
- External service connections (Ollama: 11434)
- Environment variable dependencies

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style definitions
    classDef client fill:#3498db,stroke:#2980b9,color:white
    classDef app fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#f1c40f,stroke:#f39c12,color:black
    classDef infra fill:#9b59b6,stroke:#8e44ad,color:white
    
    subgraph Client["Client Layer"]
        FE["Svelte Frontend"]
        WebUIs["Web UIs (Ports 8501-8505)"]
    end

    subgraph Apps["Application Layer"]
        SB["Support Bot"]
        LD["Stack Overflow Loader"]
        PR["PDF Reader"]
        API["API Service"]
    end

    subgraph Services["Service Layer"]
        CS["Chain Service"]
        ES["Embedding Service"]
        subgraph EMO["Embedding Options"]
            ST["Sentence Transformer"]
            OAI["OpenAI"]
            AWS["AWS"]
            GGL["Google GenAI"]
        end
    end

    subgraph Infra["Infrastructure Layer"]
        Neo["Neo4j Database"]
        subgraph LLM["LLM Services"]
            Ollama["Ollama"]
            OpenAI["OpenAI"]
            Claude["Claude"]
        end
    end

    %% Connections
    FE --> SB & LD & PR & API
    WebUIs --> SB & LD & PR & API
    SB & LD & PR & API --> CS
    SB & LD & PR & API --> ES
    ES --> EMO
    CS --> Neo
    CS --> LLM
    Neo <--> LLM

    %% Click events
    click FE "https://github.com/docker/genai-stack/tree/main/front-end/"
    click SB "https://github.com/docker/genai-stack/blob/main/bot.py"
    click LD "https://github.com/docker/genai-stack/blob/main/loader.py"
    click PR "https://github.com/docker/genai-stack/blob/main/pdf_bot.py"
    click API "https://github.com/docker/genai-stack/blob/main/api.py"
    click CS "https://github.com/docker/genai-stack/blob/main/chains.py"
    click ES "https://github.com/docker/genai-stack/tree/main/embedding_model/"
    click Ollama "https://github.com/docker/genai-stack/blob/main/install_ollama.sh"

    %% Style applications
    class FE,WebUIs client
    class SB,LD,PR,API app
    class CS,ES,ST,OAI,AWS,GGL service
    class Neo,Ollama,OpenAI,Claude infra

    %% Legend
    subgraph Legend
        C1["Client Component"]:::client
        A1["Application Component"]:::app
        S1["Service Component"]:::service
        I1["Infrastructure Component"]:::infra
    end
```
