# koboldai/koboldai-client architecture

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

- Interactive diagram: https://gitdiagram.com/koboldai/koboldai-client
- Repository: https://github.com/koboldai/koboldai-client

## Overview

a) Client-Server Communication:
- Browser → Frontend → Backend API
- WebUI ↔ AI Model Processing
- Story Data ↔ Storage System

b) Model Processing Flow:
- Model Loading → Text Generation → Output Processing
- Settings → Model Configuration → Generation Parameters

##### External Integrations (Use cloud symbols)

a) Deployment Options:
- Google Colab Integration
- Docker Containers
- CUDA Support
- ROCm Support
- Standalone Version

b) Model Sources:
- HuggingFace Hub
- Local Model Storage
- External API Services

##### Key Subsystems (Use nested containers)

a) Story Management:
- Save/Load System
- Memory Management
- World Info
- Author's Note

b) Generation Modes:
- Novel Writing
- Adventure Mode
- Chatbot Mode

##### Technical Infrastructure (Use infrastructure symbols)

a) Runtime Environment:
- Python Backend
- Lua Scripting Engine
- CUDA/ROCm GPU Support
- TPU Support

b) Dependencies:
- External Libraries
- Model Frameworks
- Runtime Requirements

Important Design Considerations:

##### Modular architecture that allows for different
- AI models
- Runtime environments
- Deployment options

##### Clear separation between
- User interface components
- Core processing logic
- Model handling
- Extension systems

##### Flexibility of the system through
- Multiple deployment options
- Various model support
- Different usage modes

##### Important technical details
- API endpoints
- File storage locations
- Configuration systems
- Security boundaries

- Blue: Core components
- Green: User-facing elements
- Yellow: Processing systems
- Red: Critical infrastructure
- Purple: External integrations

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main Layers
    subgraph Frontend
        Templates["HTML Templates"]
        StaticAssets["Static Assets"]
        subgraph UIComponents
            JS["JavaScript Core"]
            CSS["CSS Styling"]
            IconicUI["Open Iconic UI"]
            SwaggerUI["Swagger UI"]
        end
    end

    subgraph BackendCore
        Server["Main Server"]
        ModelMgmt["Model Management"]
        Bridge["Bridge Component"]
        FileOps["File Operations"]
        Settings["Settings Management"]
        Logger["Logging System"]
    end

    subgraph AIModelLayer
        ModelLoaders["Model Loaders"]
        ModelMaps["Model Maps"]
        ModelStorage["Model Storage"]
        Warpers["Text Warpers"]
        Structures["Model Structures"]
    end

    subgraph Extensions
        Userscripts["Userscripts Engine"]
        SoftPrompts["Softprompts Support"]
        APIInterface["API Interface"]
        APIDoc["API Documentation"]
        Examples["Example Scripts"]
    end

    subgraph Deployment
        Colab["Google Colab"]
        subgraph Docker
            CUDA["CUDA Support"]
            ROCm["ROCm Support"]
            Standalone["Standalone Version"]
        end
    end

    subgraph Runtime
        Python["Python Backend"]
        LuaEngine["Lua Engine"]
        GPUSupport["GPU Support"]
        TPUSupport["TPU Support"]
        Requirements["Requirements"]
        EnvConfigs["Environment Configs"]
        LuaLibs["Lua Libraries"]
    end

    subgraph StoryMgmt
        SaveLoad["Save/Load System"]
        Memory["Memory Management"]
        WorldInfo["World Info"]
        AuthorNote["Author's Note"]
        Stories["Story Storage"]
        Samples["Sample Content"]
    end

    %% Connections
    Frontend --> BackendCore
    BackendCore --> AIModelLayer
    BackendCore --> Extensions
    AIModelLayer --> StoryMgmt
    Runtime --> BackendCore
    Deployment --> Runtime

    %% Click Events
    click Templates "https://github.com/KoboldAI/KoboldAI-Client/blob/main//templates/index.html"
    click JS "https://github.com/KoboldAI/KoboldAI-Client/blob/main//static/application.js"
    click CSS "https://github.com/KoboldAI/KoboldAI-Client/blob/main//static/custom.css"
    click IconicUI "https://github.com/KoboldAI/KoboldAI-Client/tree/main//static/open-iconic"
    click SwaggerUI "https://github.com/KoboldAI/KoboldAI-Client/tree/main//static/swagger-ui"
    click Server "https://github.com/KoboldAI/KoboldAI-Client/blob/main//aiserver.py"
    click ModelMgmt "https://github.com/KoboldAI/KoboldAI-Client/blob/main//breakmodel.py"
    click Bridge "https://github.com/KoboldAI/KoboldAI-Client/blob/main//bridge.lua"
    click FileOps "https://github.com/KoboldAI/KoboldAI-Client/blob/main//fileops.py"
    click Settings "https://github.com/KoboldAI/KoboldAI-Client/blob/main//gensettings.py"
    click Logger "https://github.com/KoboldAI/KoboldAI-Client/blob/main//logger.py"
    click ModelMaps "https://github.com/KoboldAI/KoboldAI-Client/tree/main//maps"
    click ModelStorage "https://github.com/KoboldAI/KoboldAI-Client/tree/main//models"
    click Warpers "https://github.com/KoboldAI/KoboldAI-Client/blob/main//warpers.py"
    click Structures "https://github.com/KoboldAI/KoboldAI-Client/blob/main//structures.py"
    click Userscripts "https://github.com/KoboldAI/KoboldAI-Client/tree/main//userscripts"
    click APIDoc "https://github.com/KoboldAI/KoboldAI-Client/blob/main//userscripts/api_documentation.html"
    click Examples "https://github.com/KoboldAI/KoboldAI-Client/tree/main//userscripts/examples"
    click Colab "https://github.com/KoboldAI/KoboldAI-Client/tree/main//colab"
    click CUDA "https://github.com/KoboldAI/KoboldAI-Client/tree/main//docker-cuda"
    click ROCm "https://github.com/KoboldAI/KoboldAI-Client/tree/main//docker-rocm"
    click Standalone "https://github.com/KoboldAI/KoboldAI-Client/tree/main//docker-standalone"
    click Requirements "https://github.com/KoboldAI/KoboldAI-Client/blob/main//requirements.txt"
    click EnvConfigs "https://github.com/KoboldAI/KoboldAI-Client/tree/main//environments"
    click LuaLibs "https://github.com/KoboldAI/KoboldAI-Client/tree/main//extern/lualibs"
    click Stories "https://github.com/KoboldAI/KoboldAI-Client/tree/main//stories"
    click Samples "https://github.com/KoboldAI/KoboldAI-Client/blob/main//stories/sample_story.json"

    %% Styling
    classDef frontend fill:#90EE90
    classDef backend fill:#87CEEB
    classDef ai fill:#FFD700
    classDef ext fill:#DDA0DD
    classDef deploy fill:#FF6B6B
    classDef runtime fill:#20B2AA
    classDef story fill:#FFA07A

    class Templates,StaticAssets,UIComponents,JS,CSS,IconicUI,SwaggerUI frontend
    class Server,ModelMgmt,Bridge,FileOps,Settings,Logger backend
    class ModelLoaders,ModelMaps,ModelStorage,Warpers,Structures ai
    class Userscripts,SoftPrompts,APIInterface,APIDoc,Examples ext
    class Colab,Docker,CUDA,ROCm,Standalone deploy
    class Python,LuaEngine,GPUSupport,TPUSupport,Requirements,EnvConfigs,LuaLibs runtime
    class SaveLoad,Memory,WorldInfo,AuthorNote,Stories,Samples story
```
