# hung-3008/kgchat-03 architecture

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

- Interactive diagram: https://gitdiagram.com/hung-3008/kgchat-03
- Repository: https://github.com/hung-3008/kgchat-03

## Overview

##### Project type and purpose
- This is a backend library/service module for managing and interacting with multiple Large Language Model (LLM) providers.
- It is organized as a plugin‐style system where each provider (OpenAI, Gemini, Ollama, etc.) implements a common interface and can be registered dynamically.

##### File structure
- Top‐level directory “backend/llm”:
- base/        – Abstract classes and interfaces (LLMClient, Config, Factory)
- factory/     – A registry and factory that selects and instantiates the correct client
- providers/   – One subfolder per provider, each with its own Client and Config classes
- utils/       – Shared utilities (exceptions, rate limiter, retry handler)
- No frontend or database components; the core functionality is API calls to external LLM services.

##### README for additional insights
- (Empty in this case, so rely entirely on code structure.)

## Diagram (Mermaid)

```mermaid
flowchart TB
    Consumer["Consumer"]:::consumer

    subgraph "Base Components"
      LLMClient["LLMClient"]:::base
      BaseFactory["BaseFactory"]:::base
      LLMConfig["LLMConfig"]:::base
    end

    subgraph "Factory/Registry"
      LLMRegistry["LLMRegistry"]:::factory
    end

    subgraph "Provider Clients"
      OpenAIClient["OpenAIClient"]:::provider
      GeminiClient["GeminiClient"]:::provider
      OllamaClient["OllamaClient"]:::provider
      GeminiConfig["GeminiConfig"]:::provider
    end

    subgraph "Utilities"
      Exceptions["Exceptions"]:::utils
      RateLimiter["RateLimiter"]:::utils
      RetryHandler["RetryHandler"]:::utils
    end

    ExternalAPI["External LLM API"]:::external

    Consumer -->|"request prompt"| LLMRegistry
    LLMRegistry -->|"chooses provider"| BaseFactory
    BaseFactory -->|"instantiates provider"| OpenAIClient
    BaseFactory -->|"instantiates provider"| GeminiClient
    BaseFactory -->|"instantiates provider"| OllamaClient
    GeminiClient -->|"uses"| GeminiConfig
    OpenAIClient -->|"wrap calls with"| RateLimiter
    OpenAIClient -->|"wrap calls with"| RetryHandler
    GeminiClient -->|"wrap calls with"| RateLimiter
    GeminiClient -->|"wrap calls with"| RetryHandler
    OllamaClient -->|"wrap calls with"| RateLimiter
    OllamaClient -->|"wrap calls with"| RetryHandler
    OpenAIClient -->|"sends HTTP"| ExternalAPI
    GeminiClient -->|"sends HTTP"| ExternalAPI
    OllamaClient -->|"sends HTTP"| ExternalAPI
    ExternalAPI -->|"returns response"| Consumer

    click LLMClient "https://github.com/hung-3008/kgchat-03/blob/main/backend/llm/base/llm_client.py"
    click BaseFactory "https://github.com/hung-3008/kgchat-03/blob/main/backend/llm/base/base_factory.py"
    click LLMConfig "https://github.com/hung-3008/kgchat-03/blob/main/backend/llm/base/llm_config.py"
    click LLMRegistry "https://github.com/hung-3008/kgchat-03/blob/main/backend/llm/factory/llm_registry.py"
    click OpenAIClient "https://github.com/hung-3008/kgchat-03/blob/main/backend/llm/providers/openai/openai_client.py"
    click GeminiClient "https://github.com/hung-3008/kgchat-03/blob/main/backend/llm/providers/gemini/gemini_client.py"
    click OllamaClient "https://github.com/hung-3008/kgchat-03/blob/main/backend/llm/providers/ollama/ollama_client.py"
    click GeminiConfig "https://github.com/hung-3008/kgchat-03/blob/main/backend/llm/providers/gemini/gemini_config.py"
    click Exceptions "https://github.com/hung-3008/kgchat-03/blob/main/backend/llm/utils/exceptions.py"
    click RateLimiter "https://github.com/hung-3008/kgchat-03/blob/main/backend/llm/utils/rate_limiter.py"
    click RetryHandler "https://github.com/hung-3008/kgchat-03/blob/main/backend/llm/utils/retry_handler.py"

    classDef base fill:#ADD8E6,stroke:#000
    classDef factory fill:#90EE90,stroke:#000
    classDef provider fill:#FFFFE0,stroke:#000
    classDef utils fill:#FFD580,stroke:#000
    classDef external fill:#D3D3D3,stroke:#000
    classDef consumer fill:#FFFFFF,stroke:#000
```
