# nilsherzig/llocalsearch architecture

> Architecture diagram of the GitHub repository nilsherzig/llocalsearch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nilsherzig/llocalsearch
- Repository: https://github.com/nilsherzig/llocalsearch

## Overview

##### Main Components

a) Frontend Layer:
- Built with Svelte (evident from the /src directory structure)
- Components for chat interface, settings, and sidebar
- Dark/light mode toggle functionality
- Mobile-friendly responsive design

b) Backend Layer:
- Go-based backend (visible in /backend directory)
- LLM integration components
- Tool management system
- Chain management system

c) External Services:
- Ollama LLM service integration
- SearxNG search engine integration
- Vector database for storage
- Metrics service (separate container)

##### Key Architectural Elements

**[Client Layer]**
- ↓↑
**[Nginx Reverse Proxy]**
- ↓↑
**[Backend Services]**
- ↓↑
**[External Services/Tools]**

##### Specific Component Details

Frontend Components (Blue Section):
- Chat Interface
- Settings Management
- Sidebar Navigation
- Dark/Light Mode Toggle
- Source Display
- Chat History

Backend Components (Green Section):
- API Server
- Agent Chain Manager
- LLM Tools:
- Web Search
- Web Scraping
- Vector DB Search
- Custom Handlers
- Prompt Management

External Services (Yellow Section):
- Ollama LLM Service
- SearxNG Search
- Vector Database
- Metrics Service

##### Data Flow Indicators

- User input flow from frontend to backend
- LLM processing flow
- Tool execution paths
- Response delivery back to frontend
- Metrics collection paths

##### Technical Stack Indicators

Technology labels:
- Svelte/TypeScript (Frontend)
- Go (Backend)
- Docker containers
- Nginx (Reverse Proxy)
- Ollama (LLM)
- SearxNG (Search)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI["Chat Interface"]:::frontend
        Settings["Settings Management"]:::frontend
        Sidebar["Sidebar Navigation"]:::frontend
        DarkMode["Dark/Light Mode Toggle"]:::frontend
        Sources["Source Display"]:::frontend
        History["Chat History"]:::frontend
    end

    subgraph "Nginx Layer"
        Nginx["Nginx Reverse Proxy"]:::proxy
    end

    subgraph "Backend Core"
        API["API Server"]:::backend
        AgentChain["Agent Chain Manager"]:::backend
        MainBackend["Main Backend"]:::backend
    end

    subgraph "LLM Tools"
        WebSearch["Web Search"]:::tool
        WebScrape["Web Scraping"]:::tool
        VectorSearch["Vector DB Search"]:::tool
    end

    subgraph "Chain Management"
        FuncHandler["Function Call Handler"]:::chain
        SourceChain["Source Chain"]:::chain
        Parser["Custom Parser"]:::chain
    end

    subgraph "Backend Utils"
        CustomHandler["Custom Handlers"]:::util
        PromptMgmt["Prompt Management"]:::util
        VectorDBHandler["Vector DB Handler"]:::util
        LLMBackend["LLM Backend Integration"]:::util
    end

    subgraph "External Services"
        Ollama["Ollama LLM Service"]:::external
        SearxNG["SearxNG Search"]:::external
        VectorDB["Vector Database"]:::external
        Metrics["Metrics Service"]:::external
    end

    %% Connections
    UI --> Nginx
    Settings --> Nginx
    Sidebar --> Nginx
    DarkMode --> Nginx
    Sources --> Nginx
    History --> Nginx

    Nginx --> API
    API --> AgentChain
    AgentChain --> MainBackend
    
    MainBackend --> WebSearch
    MainBackend --> WebScrape
    MainBackend --> VectorSearch
    
    WebSearch --> FuncHandler
    WebScrape --> FuncHandler
    VectorSearch --> FuncHandler
    
    FuncHandler --> SourceChain
    SourceChain --> Parser
    
    Parser --> CustomHandler
    CustomHandler --> PromptMgmt
    PromptMgmt --> VectorDBHandler
    VectorDBHandler --> LLMBackend
    
    LLMBackend --> Ollama
    WebSearch --> SearxNG
    VectorSearch --> VectorDB
    API --> Metrics

    %% Click Events
    click UI "https://github.com/nilsherzig/llocalsearch/blob/main/src/routes/chat/[slug]/+page.svelte"
    click Settings "https://github.com/nilsherzig/llocalsearch/blob/main/src/lib/settings_window.svelte"
    click Sidebar "https://github.com/nilsherzig/llocalsearch/blob/main/src/lib/sidebar.svelte"
    click DarkMode "https://github.com/nilsherzig/llocalsearch/blob/main/src/lib/toggle_darkmode_button.svelte"
    click Sources "https://github.com/nilsherzig/llocalsearch/blob/main/src/lib/sources.svelte"
    click History "https://github.com/nilsherzig/llocalsearch/blob/main/src/lib/chatHistory.svelte"
    click API "https://github.com/nilsherzig/llocalsearch/blob/main/backend/apiServer.go"
    click AgentChain "https://github.com/nilsherzig/llocalsearch/blob/main/backend/agentChain.go"
    click MainBackend "https://github.com/nilsherzig/llocalsearch/blob/main/backend/main.go"
    click WebSearch "https://github.com/nilsherzig/llocalsearch/blob/main/backend/llm_tools/simple_websearch.go"
    click WebScrape "https://github.com/nilsherzig/llocalsearch/blob/main/backend/llm_tools/tool_webscrape.go"
    click VectorSearch "https://github.com/nilsherzig/llocalsearch/blob/main/backend/llm_tools/tool_search_vector_db.go"
    click FuncHandler "https://github.com/nilsherzig/llocalsearch/blob/main/backend/lschains/ollama_functioncall.go"
    click SourceChain "https://github.com/nilsherzig/llocalsearch/blob/main/backend/lschains/source_chain_example.go"
    click Parser "https://github.com/nilsherzig/llocalsearch/blob/main/backend/lschains/custom_structured_parser.go"
    click CustomHandler "https://github.com/nilsherzig/llocalsearch/blob/main/backend/utils/customHandler.go"
    click PromptMgmt "https://github.com/nilsherzig/llocalsearch/blob/main/backend/utils/prompts.go"
    click VectorDBHandler "https://github.com/nilsherzig/llocalsearch/blob/main/backend/utils/vector_db_handler.go"
    click LLMBackend "https://github.com/nilsherzig/llocalsearch/blob/main/backend/utils/llm_backends.go"
    click SearxNG "https://github.com/nilsherzig/llocalsearch/blob/main/searxng/settings.yml"
    click Metrics "https://github.com/nilsherzig/llocalsearch/blob/main/metrics/main.go"
    click Nginx "https://github.com/nilsherzig/llocalsearch/blob/main/nginx.conf"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef proxy fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef tool fill:#e74c3c,stroke:#c0392b,color:white
    classDef chain fill:#9b59b6,stroke:#8e44ad,color:white
    classDef util fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#e67e22,stroke:#d35400,color:white
```
