# tegnike/aituber-kit architecture

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

- Interactive diagram: https://gitdiagram.com/tegnike/aituber-kit
- Repository: https://github.com/tegnike/aituber-kit

## Overview

##### Main Components
- Frontend (Client) Layer:
- Built using Next.js (evident from next.config.js, src/pages/_app.tsx, etc.).
- Comprises interactive UI components (in src/components) for chat, Live2D/VRM viewer, settings, slides, and more.
- Handles localization (locales/ folder) and styling (Tailwind CSS, src/styles, etc.).

- Backend/API Layer:
- Next.js API routes (found in src/pages/api) serve as the backend endpoints for processing chat requests, audio synthesis (calls to VOICEVOX, ElevenLabs, etc.), VRM and Live2D asset management, and external linkages.
- Docker and docker-compose configurations indicate containerized deployment, which might involve a separate and secure API key handling server.

- External Service Integrations:
- Requests to various LLM services (OpenAI, Anthropic, Google Gemini, etc.) and TTS engines (VOICEVOX, Azure, ElevenLabs, and others).
- Realtime API integration and WebSocket support for lower latency messaging and external server connectivity.

- Real-Time and Communication Modules:
- WebSocket integration (such as src/components/websocketManager.tsx and src/features/stores/websocketStore.ts) for external linkage mode and real-time chat.
- YouTube-related functionality (in src/features/youtube) to fetch live chat and automate AI character responses.

- Assets and Multimedia:
- Localization of UI through JSON language files (in locales/).

##### Understand the Architectural Patterns
- Component-based UI architecture with React/Next.js:
- Separation between UI components, state management (stores in src/features/stores), and feature-specific logic (src/features/chat, src/features/slide, etc.).
- API gateway pattern through Next.js API routes:
- These API endpoints consolidate various external integrations while shielding API keys (as noted in security considerations).
- Modular and extensible design:
- Separate directories for “lib” functions (VRM animation libraries, i18n) to support various features.
- Documentation and website (under website/) indicating an extensible public documentation and developer guide architecture.
- Containerization:
- Dockerfile and docker-compose.yml indicate a deployment strategy that packages the app with its dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    User["User"]:::external

    %% Frontend (Client Layer)
    subgraph "Frontend (Client Layer)"
        FE_UI["Next.js Frontend UI"]:::frontend
        FE_Pages["Pages"]:::frontend
        FE_Comp["Components"]:::frontend
        FE_Styles["Styles"]:::frontend
        FE_VRM["VRM/Live2D Viewer"]:::frontend
        FE_YT["YouTube Integration (Frontend)"]:::frontend
        %% Composition within Frontend
        FE_UI --- FE_Pages
        FE_UI --- FE_Comp
        FE_UI --- FE_Styles
        FE_UI --- FE_VRM
        FE_UI --- FE_YT
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        BE_API["API Endpoints"]:::backend
    end

    %% Real-Time Communication
    subgraph "Real-Time Communication"
        WS_Comm["WebSocket Communication"]:::realtime
    end

    %% External Integrations
    subgraph "External Integrations"
        Ext_AI_TTS["External AI & TTS Services"]:::external
        Ext_YT["YouTube API"]:::external
    end

    %% Assets & Localization
    subgraph "Assets & Localization"
        Assets_MM["Assets & Multimedia Management"]:::assets
        I18n["i18n & Localization Helper"]:::assets
    end

    %% Containerization & Deployment
    subgraph "Deployment & Containerization"
        Deploy["Containerization & Deployment"]:::deploy
    end

    %% Connections
    User --> FE_UI
    FE_UI -->|"apiRequest"| BE_API
    FE_UI ---|"loads assets"| Assets_MM
    FE_UI -->|"real-time chat"| WS_Comm
    BE_API -->|"AI/TTS calls"| Ext_AI_TTS
    BE_API -->|"YouTube data"| Ext_YT
    BE_API -->|"realtime updates"| WS_Comm
    FE_UI -->|"deployed via"| Deploy
    BE_API -->|"deployed via"| Deploy

    %% Click Events for Component Mappings
    click FE_Pages "https://github.com/tegnike/aituber-kit/tree/main/src/pages"
    click FE_Comp "https://github.com/tegnike/aituber-kit/tree/main/src/components"
    click FE_Styles "https://github.com/tegnike/aituber-kit/tree/main/src/styles"
    click BE_API "https://github.com/tegnike/aituber-kit/tree/main/src/pages/api"
    click WS_Comm "https://github.com/tegnike/aituber-kit/blob/main/src/components/websocketManager.tsx"
    click FE_YT "https://github.com/tegnike/aituber-kit/blob/main/src/components/youtubeManager.tsx"
    click Ext_YT "https://github.com/tegnike/aituber-kit/tree/main/src/features/youtube"
    click Assets_MM "https://github.com/tegnike/aituber-kit/tree/main/public"
    click FE_VRM "https://github.com/tegnike/aituber-kit/tree/main/public/live2d"
    click I18n "https://github.com/tegnike/aituber-kit/blob/main/src/lib/i18n.js"
    click Deploy "https://github.com/tegnike/aituber-kit/tree/main/Dockerfile"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef realtime fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef assets fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef deploy fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
