# alvinlee518/llmchat architecture

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

- Interactive diagram: https://gitdiagram.com/alvinlee518/llmchat
- Repository: https://github.com/alvinlee518/llmchat

## Overview

##### Overall Project Context and Purpose
- Project Type: LLMChat is an enterprise solution built in the Java ecosystem that combines large language model (LLM) functionality with LangChain integration. It supports AI chatbot applications, intelligent knowledge bases, and smart customer service.
- Purpose: To provide a robust, modular platform where companies can manage models (both local and external), handle knowledge management (e.g., segmentation, retrieval, embedding), and allow customizable AI applications—all backed by strong RBAC security.

##### Identifying the Main Components
a. Frontend
– Represent the “llmchat-ui” module which is built with Vue3, Vite, and TypeScript.
– Show its role as the client interface (web portal) that renders pages like model management, dataset views, and application debugging.
b. Backend – API Gateway and Business Layers
– Split the backend into several logical “containers” or modules:
- API Layer: The “llmchat-server-api” module exposing REST endpoints (label it “API Gateway”).
- Application Service Layer: The “llmchat-server-service” which coordinates business logic (services for AI Chat, Model, Document, etc.).
- Data Access Layer: The “llmchat-server-repository” handling persistence operations, MyBatis mappers, and entity models.
- Bootstrap/Startup Module: “llmchat-server-start” which acts as the launch point (Main application and controller dispatch).

c. Common Libraries (Shared Modules)
– “llmchat-common” subdivides into several functional libraries:
- Common Core (basic utilities, auto-configurations, exception handling).
- LangChain Integration (“llmchat-common-langchain”) for managing LLM providers, document parsers, retrievers, and other LangChain functionalities.
- MyBatis Integration (“llmchat-common-mybatis”) for data object mapping and code generation.
- Redis Integration (“llmchat-common-redis”) for caching and implementing message queues (e.g., via Redis Streams).
- Security (“llmchat-common-security”) for implementing RBAC, token management, and request handling using Spring Security.

d. External Systems and Dependencies
– Database: PostgreSQL (indicated in the README and likely used by MyBatis).
– Redis: For caching and pub/sub/streaming.
– Vector/Content Store: External services like Weaviate (for document and embedding search) and possibly MinIO for object storage.
– Other External APIs: Integration with external LLM providers (e.g., OpenAI, Azure OpenAI, etc.) and local model providers (LocalAI, Ollama, Xinference).

##### Architectural Patterns & Design Principles to Highlight
- Modular Monolithic/Layered Architecture: Emphasize how the project is split by Maven modules into API, service, repository, and common libraries.
- Separation of Concerns: The division between the frontend (presentation), gateway, business logic, data access, and integration packages.
- Extensibility: The “Common Langchain” module, in particular, is designed to support multiple LLM providers and document processing strategies.
- Asynchronous Messaging: Usage of Redis streams for handling asynchronous tasks (e.g., for processing document segmentation, embedding tasks).
- Security: Integration of RBAC and dedicated security modules using Spring Security.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    subgraph "Frontend"
        FE["Frontend (llmchat-ui)"]:::frontend
    end

    %% Backend Layers
    subgraph "Backend Layers"
        APIGW["API Gateway (llmchat-server-api)"]:::backend
        SERVICE["Business Service Layer (llmchat-server-service)"]:::backend
        REPO["Data Access Layer (llmchat-server-repository)"]:::backend
        BOOTSTRAP["Bootstrap/Startup (llmchat-server-start)"]:::backend
    end

    %% Common Libraries
    subgraph "Common Libraries"
        CORE["Common Core (llmchat-common-core)"]:::common
        LANGCHAIN["Common LangChain (llmchat-common-langchain)"]:::common
        MYBATIS["Common MyBatis (llmchat-common-mybatis)"]:::common
        REDISLIB["Common Redis (llmchat-common-redis)"]:::common
        SECURITY["Common Security (llmchat-common-security)"]:::common
    end

    %% External Systems
    subgraph "External Systems"
        POSTGRES["PostgreSQL"]:::external
        REDIS["Redis"]:::external
        VECTOR["Weaviate/MinIO"]:::external
        EXTLLM["External LLM Providers"]:::external
    end

    %% Deployment
    subgraph "Deployment"
        DOCKER["Docker Compose"]:::deployment
        NGINX["Nginx"]:::deployment
    end

    %% Connections for Frontend and Backend
    FE -->|"HTTP_REST"| APIGW
    APIGW -->|"internal_call"| SERVICE
    BOOTSTRAP -->|"launches"| SERVICE
    SERVICE -->|"data_ops"| REPO

    %% Connections from Business Layer to Common Libraries
    SERVICE -->|"utilizes"| CORE
    SERVICE -->|"utilizes"| LANGCHAIN
    SERVICE -->|"utilizes"| MYBATIS
    SERVICE -->|"utilizes"| REDISLIB
    SERVICE -->|"utilizes"| SECURITY

    %% Connections from Data Access Layer to External Systems
    REPO -->|"persists_to"| POSTGRES
    REPO -->|"caches_via"| REDIS

    %% Connections from LangChain to External Systems
    LANGCHAIN -->|"integrates_with"| EXTLLM
    LANGCHAIN -->|"retrieves_from"| VECTOR

    %% Deployment connections (depicting that backend is containerized)
    SERVICE -->|"deployed_on"| DOCKER
    SERVICE -->|"deployed_with"| NGINX

    %% Styles
    classDef frontend fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef common fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef deployment fill:#D1C4E9,stroke:#6A1B9A,stroke-width:2px;

    %% Click Events
    click FE "https://github.com/alvinlee518/llmchat/tree/main/llmchat-ui"
    click APIGW "https://github.com/alvinlee518/llmchat/tree/main/llmchat-server/llmchat-server-api"
    click SERVICE "https://github.com/alvinlee518/llmchat/tree/main/llmchat-server/llmchat-server-service"
    click REPO "https://github.com/alvinlee518/llmchat/tree/main/llmchat-server/llmchat-server-repository"
    click BOOTSTRAP "https://github.com/alvinlee518/llmchat/tree/main/llmchat-server/llmchat-server-start"
    click CORE "https://github.com/alvinlee518/llmchat/tree/main/llmchat-common/llmchat-common-core"
    click LANGCHAIN "https://github.com/alvinlee518/llmchat/tree/main/llmchat-common/llmchat-common-langchain"
    click MYBATIS "https://github.com/alvinlee518/llmchat/tree/main/llmchat-common/llmchat-common-mybatis"
    click REDISLIB "https://github.com/alvinlee518/llmchat/tree/main/llmchat-common/llmchat-common-redis"
    click SECURITY "https://github.com/alvinlee518/llmchat/tree/main/llmchat-common/llmchat-common-security"
    click DOCKER "https://github.com/alvinlee518/llmchat/tree/main/docs/docker"
    click NGINX "https://github.com/alvinlee518/llmchat/tree/main/docs/nginx"
```
