# shinshin86/aituber-onair architecture

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

- Interactive diagram: https://gitdiagram.com/shinshin86/aituber-onair
- Repository: https://github.com/shinshin86/aituber-onair

## Overview

##### Main Components and Their Responsibilities
- AITuberOnAir Core Library: The central component that orchestrates the overall functionality.
- Core Modules:
- AITuberOnAirCore, ChatProcessor, MemoryManager, and EventEmitter in the core folder provide the fundamental logic for AI conversation management and state handling.
- Chat Services:
- The “chat” service layer abstracts the communication with different AI chat providers (e.g., Gemini and OpenAI).
- Within each provider (found under packages/core/src/services/chat/providers), there are dedicated service implementations and factories, as well as summarizer components.
- Voice Services:
- The “voice” service layer is responsible for handling audio/speech-related functionalities.
- It involves several engine implementations (such as AivisSpeechEngine, NijiVoiceEngine, OpenAiEngine, VoicePeakEngine, and VoiceVoxEngine) with a common adapter and factory pattern for uniform interfacing.
- YouTube Integration:
- The YouTube service layer is present to handle interactions with the YouTube Data API, assisting in functionalities related to video streaming or management.
- Constants, Utilities, and Types:
- These modules (under constants, utils, and types directories) configure static values and helper functions for chat, voice, and other interactions, ensuring consistent behavior across the system.
- Monorepo Setup:
- At a higher level, the directory structure shows the use of npm workspaces, which helps in managing multiple packages (in this case, primarily the “core” package).

##### Interaction and Data Flow
- The AITuberOnAirCore serves as the central orchestrator:
- It interacts with ChatProcessor to handle conversation details.
- It makes use of MemoryManager for context and state handling.
- Chat services interact with external AI APIs:
- Factories and provider implementations for Gemini and OpenAI abstract the communication details.
- Summarizers provide additional data processing on chat data.
- Voice services:
- A soft abstraction using VoiceEngineAdapter and factories allows for different speech engines to be swapped as needed based on capabilities.
- Each service layer (chat, voice, YouTube) has clearly defined responsibilities and communicates with the core logic.
- Utility functions and constants support these components by providing standardized configuration and helper methods.

##### Architectural Patterns and Key Design Principles
- Modularity:
- Each service (chat, voice, YouTube) is encapsulated in its own module, making the system easier to maintain and extend.
- Abstraction and Factories:
- The use of factories for chat and voice providers decouples the core logic from provider-specific implementations.
- Clear Separation of Concerns:
- Core functionalities (like state management and event handling) are separated from peripheral services such as voice and YouTube integration.
- Use of npm workspaces:
- This supports scalable development and testing across multiple packages.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Modules
    subgraph "Core Modules"
        AITuber["AITuberOnAir Core Library"]:::core
        CP["ChatProcessor"]:::core
        MM["MemoryManager"]:::core
        EE["EventEmitter"]:::core
    end

    %% Chat Services
    subgraph "Chat Services"
        CS["ChatService"]:::chat
        CSF["ChatServiceFactory"]:::chat
        subgraph "Gemini Chat Provider"
            GCS["GeminiChatService"]:::provider
            GCSP["GeminiChatServiceProvider"]:::provider
            GS["Gemini Summarizer"]:::provider
        end
        subgraph "OpenAI Chat Provider"
            OCS["OpenAIChatService"]:::provider
            OCSP["OpenAIChatServiceProvider"]:::provider
            OS["OpenAI Summarizer"]:::provider
        end
    end

    %% Voice Services
    subgraph "Voice Services"
        VS["VoiceService"]:::voice
        VEA["VoiceEngineAdapter"]:::voice
        subgraph "Voice Engine Implementations"
            ASE["AivisSpeechEngine"]:::voiceImpl
            NVE["NijiVoiceEngine"]:::voiceImpl
            OAE["OpenAiEngine"]:::voiceImpl
            VPE["VoicePeakEngine"]:::voiceImpl
            VVE["VoiceVoxEngine"]:::voiceImpl
        end
        VEF["VoiceEngineFactory"]:::voiceFactory
        VEI["VoiceEngine (Interface)"]:::voiceFactory
    end

    %% YouTube Integration
    subgraph "YouTube Integration"
        YD["YouTubeDataApiService"]:::youtube
        YS["YouTubeService"]:::youtube
        extYT["External YouTube API"]:::external
    end

    %% Support Modules
    subgraph "Support Modules"
        CT["Constants"]:::support
        UT["Utilities"]:::support
        TY["Types"]:::support
    end

    %% Monorepo & Build/Testing Infrastructure
    subgraph "Monorepo & Build/Testing"
        WS["npm Workspaces"]:::monorepo
        TS["Test Suites & Configurations"]:::monorepo
    end

    %% Relationships (Data Flow)
    AITuber -->|"orchestrates"| CP
    AITuber -->|"uses"| MM
    AITuber -->|"emitsEvents"| EE

    AITuber -->|"utilizes"| CS
    AITuber -->|"utilizes"| VS
    AITuber -->|"integratesWith"| YS

    CP -->|"callsChatServices"| CS

    CS -->|"delegatesTo"| CSF
    CSF -->|"creates"| GCS
    CSF -->|"creates"| OCS

    GCS -->|"accessedVia"| GCSP
    GCS -->|"summarizedBy"| GS

    OCS -->|"accessedVia"| OCSP
    OCS -->|"summarizedBy"| OS

    VS -->|"callsAdapter"| VEA
    VEA --> ASE
    VEA --> NVE
    VEA --> OAE
    VEA --> VPE
    VEA --> VVE

    VEF -->|"createsInstances"| ASE
    VEF --> NVE
    VEF --> OAE
    VEF --> VPE
    VEF --> VVE

    YS --> YD
    YD -->|"calls"| extYT

    %% Support Modules feeding into Core
    CT --- AITuber
    UT --- AITuber
    TY --- AITuber

    %% Monorepo supporting all layers
    WS --- AITuber
    TS --- AITuber

    %% Click Events
    click AITuber "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/core/AITuberOnAirCore.ts"
    click CP "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/core/ChatProcessor.ts"
    click MM "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/core/MemoryManager.ts"
    click EE "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/core/EventEmitter.ts"

    click CS "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/chat/ChatService.ts"
    click CSF "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/chat/ChatServiceFactory.ts"

    click GCS "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/chat/providers/gemini/GeminiChatService.ts"
    click GCSP "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/chat/providers/gemini/GeminiChatServiceProvider.ts"
    click GS "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/chat/providers/gemini/GeminiSummarizer.ts"

    click OCS "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/chat/providers/openai/OpenAIChatService.ts"
    click OCSP "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/chat/providers/openai/OpenAIChatServiceProvider.ts"
    click OS "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/chat/providers/openai/OpenAISummarizer.ts"

    click VS "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/voice/VoiceService.ts"
    click VEA "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/voice/VoiceEngineAdapter.ts"

    click ASE "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/voice/engines/AivisSpeechEngine.ts"
    click NVE "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/voice/engines/NijiVoiceEngine.ts"
    click OAE "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/voice/engines/OpenAiEngine.ts"
    click VPE "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/voice/engines/VoicePeakEngine.ts"
    click VVE "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/voice/engines/VoiceVoxEngine.ts"
    click VEF "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/voice/engines/VoiceEngineFactory.ts"
    click VEI "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/voice/engines/VoiceEngine.ts"

    click YD "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/youtube/YouTubeDataApiService.ts"
    click YS "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/src/services/youtube/YouTubeService.ts"

    click CT "https://github.com/shinshin86/aituber-onair/tree/main/packages/core/src/constants/"
    click UT "https://github.com/shinshin86/aituber-onair/tree/main/packages/core/src/utils/"
    click TY "https://github.com/shinshin86/aituber-onair/tree/main/packages/core/src/types/"

    click WS "https://github.com/shinshin86/aituber-onair/blob/main/package.json"
    click WS "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/package.json"
    click TS "https://github.com/shinshin86/aituber-onair/tree/main/packages/core/tests/"
    click TS "https://github.com/shinshin86/aituber-onair/blob/main/packages/core/vitest.config.ts"

    %% Styling
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef chat fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef provider fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef voice fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef voiceImpl fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef voiceFactory fill:#FF8C00,stroke:#000,stroke-width:2px;
    classDef youtube fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef support fill:#E6E6FA,stroke:#000,stroke-width:2px;
    classDef monorepo fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef external fill:#FFE4B5,stroke:#000,stroke-width:2px;
```
