# keganhollern/aika architecture

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

- Interactive diagram: https://gitdiagram.com/keganhollern/aika
- Repository: https://github.com/keganhollern/aika

## Overview

##### Main Components

a. Core Components:
- Discord Integration Layer
- AI Processing Layer
- Voice Processing System
- Storage System
- Action Handlers

b. External Services:
- Discord API
- OpenAI Services (ChatGPT, DALL-E, Whisper)
- ElevenLabs TTS
- S3 Storage
- Third-party APIs (YouTube, DuckDuckGo, MyAnimeList, Waifu.pics)

**[External Services Layer]**
- ↕
**[Integration Layer]**
- ↕
**[Core Processing Layer]**
- ↕
**[Storage Layer]**

##### Component Details

a. Discord Integration Layer:
- Separate components for text chat and voice chat handling
- Discordai and discordchat subsystems
- Chatbot component as the main entry point

b. AI Processing Layer:
- Separate components for different AI functions:
- Text processing (ChatGPT)
- Image generation (DALL-E)
- Vision processing
- Voice transcription (Whisper)

c. Voice Processing System:
- Components for:
- Voice reception
- Transcoding
- Text-to-Speech
- Audio mixing
- YouTube playback

d. Action Handlers:
- Related actions:
- Web actions (anime, search, tenor, waifu)
- YouTube actions (download, search, player)
- Discord actions
- Math actions
- OpenAI actions

##### Data Flow Representation

- Event-based communication (curved lines)

##### Important Details

- Configuration management
- System message handling
- Token management
- Guild-specific settings
- Error handling paths
- Storage interactions (S3 and disk)

##### Deployment Context

A small section showing:
- Docker container boundary
- Required environment variables
- External dependency connections

- Any abbreviations used
- Special symbols

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External["External Services"]
        Discord["Discord API"]
        OpenAI["OpenAI Services"]
        ElevenLabs["ElevenLabs TTS"]
        S3["S3 Storage"]
        ThirdParty["Third-party APIs"]
    end

    subgraph Integration["Integration Layer"]
        DiscordBot["Discord Bot"]:::core
        click DiscordBot "https://github.com/KeganHollern/Aika/blob/beta/discord/chatbot.go"
        AIIntegration["AI Integration"]:::core
        click AIIntegration "https://github.com/KeganHollern/Aika/tree/beta/discord/discordai/"
        ChatMgmt["Chat Management"]:::core
        click ChatMgmt "https://github.com/KeganHollern/Aika/tree/beta/discord/discordchat/"
        VoiceChat["Voice Chat"]:::core
        click VoiceChat "https://github.com/KeganHollern/Aika/blob/beta/discord/discordchat/voicechat.go"
    end

    subgraph Processing["Core Processing Layer"]
        direction TB
        AICore["Core AI Processing"]:::ai
        click AICore "https://github.com/KeganHollern/Aika/blob/beta/ai/request.go"
        AIBrain["AI Brain Logic"]:::ai
        click AIBrain "https://github.com/KeganHollern/Aika/blob/beta/discord/discordai/aibrain.go"
        
        subgraph AIServices["AI Services"]
            DALLE["DALL-E Integration"]:::ai
            click DALLE "https://github.com/KeganHollern/Aika/blob/beta/actions/openai/dalle.go"
            Vision["Vision Processing"]:::ai
            click Vision "https://github.com/KeganHollern/Aika/blob/beta/actions/openai/vision.go"
        end

        subgraph Voice["Voice Processing"]
            VoiceReceiver["Voice Reception"]:::voice
            click VoiceReceiver "https://github.com/KeganHollern/Aika/blob/beta/voice/receiver.go"
            Transcoding["Transcoding"]:::voice
            click Transcoding "https://github.com/KeganHollern/Aika/tree/beta/voice/transcoding/"
            TTS["Text-to-Speech"]:::voice
            click TTS "https://github.com/KeganHollern/Aika/blob/beta/voice/tts.go"
            ElevenLabsInt["ElevenLabs Integration"]:::voice
            click ElevenLabsInt "https://github.com/KeganHollern/Aika/blob/beta/voice/elevenlabs.go"
            Mixer["Audio Mixing"]:::voice
            click Mixer "https://github.com/KeganHollern/Aika/blob/beta/voice/transcoding/mixer.go"
        end

        subgraph Actions["Action Handlers"]
            WebActions["Web Actions"]:::action
            click WebActions "https://github.com/KeganHollern/Aika/tree/beta/actions/web/"
            YouTubeActions["YouTube Actions"]:::action
            click YouTubeActions "https://github.com/KeganHollern/Aika/tree/beta/actions/youtube/"
            MathActions["Math Actions"]:::action
            click MathActions "https://github.com/KeganHollern/Aika/tree/beta/actions/math/"
            DiscordActions["Discord Actions"]:::action
            click DiscordActions "https://github.com/KeganHollern/Aika/tree/beta/actions/discord/"
            OpenAIActions["OpenAI Actions"]:::action
            click OpenAIActions "https://github.com/KeganHollern/Aika/tree/beta/actions/openai/"
        end
    end

    subgraph Storage["Storage Layer"]
        S3Storage["S3 Storage"]:::storage
        click S3Storage "https://github.com/KeganHollern/Aika/blob/beta/storage/s3.go"
        DiskStorage["Disk Storage"]:::storage
        click DiskStorage "https://github.com/KeganHollern/Aika/blob/beta/storage/disk.go"
    end

    subgraph Config["Configuration"]
        MainConfig["Main Config"]:::config
        click MainConfig "https://github.com/KeganHollern/Aika/blob/beta/data/config.yaml"
        SystemMsg["System Messages"]:::config
        click SystemMsg "https://github.com/KeganHollern/Aika/blob/beta/discord/discordai/system.txt"
        VoiceSystemMsg["Voice System Messages"]:::config
        click VoiceSystemMsg "https://github.com/KeganHollern/Aika/blob/beta/discord/discordai/system_vc.txt"
    end

    subgraph Utils["Utilities"]
        DataPipes["Data Pipes"]:::util
        click DataPipes "https://github.com/KeganHollern/Aika/blob/beta/utils/bytepipe.go"
        StringProc["String Processing"]:::util
        click StringProc "https://github.com/KeganHollern/Aika/blob/beta/utils/stringpipe.go"
    end

    %% Connections
    Discord <--> DiscordBot
    OpenAI <--> AICore
    ElevenLabs <--> ElevenLabsInt
    S3 <--> S3Storage
    ThirdParty <-.-> WebActions

    DiscordBot --> AIIntegration
    DiscordBot --> ChatMgmt
    DiscordBot --> VoiceChat

    AIIntegration --> AICore
    AICore --> AIBrain
    AICore --> AIServices
    
    VoiceChat --> VoiceReceiver
    VoiceReceiver --> Transcoding
    Transcoding --> Mixer
    TTS --> Mixer
    ElevenLabsInt --> TTS

    Actions --> AICore
    Actions --> Storage

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef ai fill:#9b59b6,stroke:#8e44ad,color:white
    classDef voice fill:#e74c3c,stroke:#c0392b,color:white
    classDef storage fill:#e67e22,stroke:#d35400,color:white
    classDef action fill:#2ecc71,stroke:#27ae60,color:white
    classDef config fill:#f1c40f,stroke:#f39c12,color:black
    classDef util fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef external fill:#1abc9c,stroke:#16a085,color:white
```
