# worikgh/llm-web architecture

> Architecture diagram of the GitHub repository worikgh/llm-web, 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/worikgh/llm-web
- Repository: https://github.com/worikgh/llm-web

## Overview

##### Main Components

a. Client-Side (Browser):
- WASM Frontend Module (llm-web-fe)
- HTML/CSS Interface
- WebSocket Connection Handler

b. Server-Side:
- Backend Server (llm-web-be)
- Authentication System
- User Data Store
- Session Manager

c. LLM Integration Layer:
- LLM Interface Module (llm-rs)
- OpenAI API Connection
- Model Management

d. Shared Components:
- Common Data Types (llm-web-common)
- Communication Protocols

##### Component Relationships

**[Browser] → [WASM Frontend] ↔ [Backend Server] ↔ [LLM Interface] → [OpenAI API]**

##### Detailed Component Breakdown

Frontend (llm-web-fe):
- Components for:
- Chat Interface (chat_div.rs)
- Login System (login_div.rs)
- Cost Display (cost_div.rs)
- Error Handling (error_div.rs)
- Request Management (make_request.rs)

Backend (llm-web-be):
- Highlight:
- Authorization Handler (authorisation.rs)
- Data Store (data_store.rs)
- Session Management (session.rs)
- Server Core (server.rs)

LLM Interface (llm-rs):
- Include:
- OpenAI Interface (openai_interface.rs)
- Context Management (context.rs)
- Model Information (model_info.rs)
- Fine-tuning Components (fine_tune_*.rs)

##### Additional Elements

- A security boundary showing HTTPS requirement
- WebSocket connection paths
- User data flow
- Where the OpenAI API key is used
- System prompt handling
- Context management flow

##### Technical Details

- Rust/WASM compilation boundary
- Lighttpd proxy configuration
- Certificate handling
- User data storage
- Session management flow
- Model mode switching capability

##### Notes for Implementation

- The separation between frontend and backend
- The role of llm-web-common in sharing types
- The security layer with HTTPS and authentication
- The modular nature of the LLM interface
- The stateful nature of chat sessions
- The cost tracking system

This system design should reflect both the current implementation and allow for the planned features mentioned in the README, such as additional LLM support beyond OpenAI.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Browser
        UI["HTML/CSS Interface"]
        WS["WebSocket Handler"]:::network
        
        subgraph FrontendModule["WASM Frontend (llm-web-fe)"]
            Chat["Chat Interface"]:::frontend
            Login["Login System"]:::frontend
            Cost["Cost Display"]:::frontend
            Error["Error Handler"]:::frontend
            ReqMgr["Request Manager"]:::frontend
        end
    end

    subgraph BackendServer["Backend Server (llm-web-be)"]
        Auth["Authorization Handler"]:::security
        Store[(Data Store)]:::storage
        Session["Session Manager"]:::backend
        ServerCore["Server Core"]:::backend
    end

    subgraph LLMLayer["LLM Integration Layer (llm-rs)"]
        OpenAIIF["OpenAI Interface"]:::llm
        Context["Context Manager"]:::llm
        ModelInfo["Model Information"]:::llm
        FineTune["Fine-tuning Components"]:::llm
    end

    subgraph Shared["Shared Components"]
        Common["Common Data Types"]:::shared
        Protocols["Communication Protocols"]:::shared
    end

    External["OpenAI API"]:::external

    %% Connections
    UI --> FrontendModule
    FrontendModule <--> WS
    WS <-.-> ServerCore
    ServerCore --> Auth
    ServerCore <--> Store
    ServerCore <--> Session
    ServerCore <--> OpenAIIF
    OpenAIIF --> Context
    OpenAIIF --> ModelInfo
    OpenAIIF --> FineTune
    OpenAIIF --> External
    Common --> FrontendModule
    Common --> BackendServer
    Protocols --> WS
    Protocols --> ServerCore

    %% Click Events
    click Chat "https://github.com/worikgh/llm-web/blob/mistress/llm-web-fe/src/chat_div.rs"
    click Login "https://github.com/worikgh/llm-web/blob/mistress/llm-web-fe/src/login_div.rs"
    click Cost "https://github.com/worikgh/llm-web/blob/mistress/llm-web-fe/src/cost_div.rs"
    click Error "https://github.com/worikgh/llm-web/blob/mistress/llm-web-fe/src/error_div.rs"
    click ReqMgr "https://github.com/worikgh/llm-web/blob/mistress/llm-web-fe/src/make_request.rs"
    click Auth "https://github.com/worikgh/llm-web/blob/mistress/llm-web-be/src/authorisation.rs"
    click Store "https://github.com/worikgh/llm-web/blob/mistress/llm-web-be/src/data_store.rs"
    click Session "https://github.com/worikgh/llm-web/blob/mistress/llm-web-be/src/session.rs"
    click ServerCore "https://github.com/worikgh/llm-web/blob/mistress/llm-web-be/src/server.rs"
    click OpenAIIF "https://github.com/worikgh/llm-web/blob/mistress/llm-rs/src/openai_interface.rs"
    click Context "https://github.com/worikgh/llm-web/blob/mistress/llm-rs/src/context.rs"
    click ModelInfo "https://github.com/worikgh/llm-web/blob/mistress/llm-rs/src/model_info.rs"
    click FineTune "https://github.com/worikgh/llm-web/blob/mistress/llm-rs/src/fine_tune_create.rs"
    click Common "https://github.com/worikgh/llm-web/blob/mistress/llm-web-common/src/lib.rs"
    click Protocols "https://github.com/worikgh/llm-web/blob/mistress/llm-web-common/src/communication.rs"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef llm fill:#f1c40f,stroke:#f39c12,color:black
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef storage fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef external fill:#bdc3c7,stroke:#95a5a6,color:black
    classDef shared fill:#9b59b6,stroke:#8e44ad,color:white
    classDef network fill:#1abc9c,stroke:#16a085,color:white
```
