# kittynxr/maowbot architecture

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

- Interactive diagram: https://gitdiagram.com/kittynxr/maowbot
- Repository: https://github.com/kittynxr/maowbot

## Overview

##### Main Components

a) Core System Components:
- Plugin System (gRPC + In-Process)
- EventBus (Central Message Broker)
- Platform Integrations (Twitch, Discord, VRChat)
- Authentication System
- Database Layer
- Service Layer
- Task Scheduler

b) External Components:
- External Plugin Clients
- Platform Services (Twitch, Discord, VRChat APIs)
- SQLite Database

**Layer 1 (External Clients):**
- External Plugins (gRPC)
- Platform Services (Twitch/Discord/VRChat)

**Layer 2 (Interface Layer):**
- Plugin Manager
- Platform Integration Managers
- Authentication Manager

**Layer 3 (Core Services):**
- EventBus (Central Hub)
- Message Service
- User Service

**Layer 4 (Data Layer):**
- Repository Layer
- SQLite Database
- Message Cache

##### Key Relationships to Highlight

a) Data Flow Paths:
- Service communication with EventBus

b) Component Dependencies:
- How Services depend on Repositories
- EventBus subscribers (DB Logger, Plugin Manager, Services)
- Authentication flow between Platform Integrations and Auth Manager

##### Additional Elements

- Task Scheduler (Monthly Maintenance, Credential Refresh)
- Cache System
- Crypto Helper
- DB Migrations

##### Specific Implementation Details

- SQLite as the primary database
- gRPC for external plugin communication
- Event-driven architecture with publish/subscribe pattern
- Platform-specific runtime implementations
- Service layer business logic separation

##### Notes Section

Annotations for:
- Current development status
- Key dependencies (sqlx, tonic, etc.)
- Testing approach (in-memory DB)
- Migration handling

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions while avoiding implementation-specific details that might change frequently.

This system design should effectively communicate the modular, event-driven nature of the application while highlighting its plugin architecture and multi-platform support capabilities.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef external fill:#E0E0E0,stroke:#333
    classDef core fill:#B3E0FF,stroke:#333
    classDef data fill:#90EE90,stroke:#333
    classDef auth fill:#FFE599,stroke:#333
    classDef event fill:#E6B3FF,stroke:#333
    classDef service fill:#FFB366,stroke:#333

    %% External Layer
    subgraph External
        TwitchAPI["Twitch API"]:::external
        DiscordAPI["Discord API"]:::external
        VRChatAPI["VRChat API"]:::external
        GRPCPlugins["External gRPC Plugins"]:::external
    end

    %% Core Application Layer
    subgraph CoreApp
        PluginSystem["Plugin System"]:::core
        PluginMgr["Plugin Manager"]:::core
        TUIPlugin["TUI Plugin Support"]:::core
        GRPCServer["gRPC Server"]:::core
        
        EventBus["EventBus"]:::event
        DBLogger["DB Logger"]:::event
        
        PlatformMgr["Platform Manager"]:::core
        TwitchInteg["Twitch Integration"]:::core
        DiscordInteg["Discord Integration"]:::core
        VRChatInteg["VRChat Integration"]:::core
        
        AuthSystem["Auth System"]:::auth
        UserMgr["User Manager"]:::auth
        
        MessageCache["Message Cache"]:::core
    end

    %% Services Layer
    subgraph Services
        MessageSvc["Message Service"]:::service
        UserSvc["User Service"]:::service
    end

    %% Data Layer
    subgraph Data
        SQLiteDB[(SQLite DB)]:::data
        Analytics["Analytics"]:::data
        Credentials["Credentials"]:::data
        UserDB["User Management"]:::data
    end

    %% Task Scheduler
    subgraph Tasks
        CredRefresh["Credential Refresh"]:::core
        MonthlyMaint["Monthly Maintenance"]:::core
    end

    %% Relationships
    TwitchAPI --> TwitchInteg
    DiscordAPI --> DiscordInteg
    VRChatAPI --> VRChatInteg
    GRPCPlugins --> GRPCServer

    TwitchInteg & DiscordInteg & VRChatInteg --> PlatformMgr
    PlatformMgr --> EventBus
    
    GRPCServer --> PluginMgr
    PluginMgr --> EventBus
    TUIPlugin --> PluginMgr
    
    EventBus --> DBLogger
    DBLogger --> SQLiteDB
    
    AuthSystem --> UserMgr
    UserMgr --> Credentials
    
    MessageSvc --> EventBus
    UserSvc --> UserDB
    
    EventBus --> MessageCache
    
    CredRefresh --> Credentials
    MonthlyMaint --> Analytics

    %% Click Events
    click PluginSystem "https://github.com/kittynXR/maowbot/tree/master/src/plugins/"
    click PluginMgr "https://github.com/kittynXR/maowbot/blob/master/src/plugins/manager.rs"
    click TUIPlugin "https://github.com/kittynXR/maowbot/blob/master/src/plugins/tui_plugin.rs"
    click EventBus "https://github.com/kittynXR/maowbot/tree/master/src/eventbus/"
    click DBLogger "https://github.com/kittynXR/maowbot/blob/master/src/eventbus/db_logger.rs"
    click TwitchInteg "https://github.com/kittynXR/maowbot/tree/master/src/platforms/twitch/"
    click DiscordInteg "https://github.com/kittynXR/maowbot/tree/master/src/platforms/discord/"
    click VRChatInteg "https://github.com/kittynXR/maowbot/tree/master/src/platforms/vrchat/"
    click PlatformMgr "https://github.com/kittynXR/maowbot/blob/master/src/platforms/manager.rs"
    click AuthSystem "https://github.com/kittynXR/maowbot/tree/master/src/auth/"
    click UserMgr "https://github.com/kittynXR/maowbot/blob/master/src/auth/user_manager.rs"
    click MessageSvc "https://github.com/kittynXR/maowbot/blob/master/src/services/message_service.rs"
    click UserSvc "https://github.com/kittynXR/maowbot/blob/master/src/services/user_service.rs"
    click CredRefresh "https://github.com/kittynXR/maowbot/blob/master/src/tasks/credential_refresh.rs"
    click MonthlyMaint "https://github.com/kittynXR/maowbot/blob/master/src/tasks/monthly_maintenance.rs"
    click MessageCache "https://github.com/kittynXR/maowbot/blob/master/src/cache/message_cache.rs"
    click Analytics "https://github.com/kittynXR/maowbot/blob/master/src/repositories/sqlite/analytics.rs"
    click Credentials "https://github.com/kittynXR/maowbot/blob/master/src/repositories/sqlite/credentials.rs"
    click UserDB "https://github.com/kittynXR/maowbot/blob/master/src/repositories/sqlite/user.rs"
```
