# kaoticz/nadekohub architecture

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

- Interactive diagram: https://gitdiagram.com/kaoticz/nadekohub
- Repository: https://github.com/kaoticz/nadekohub

## Overview

##### Project type and purpose
- NadekoHub is a cross-platform desktop application (built on .NET and Avalonia UI) designed to manage Discord bot instances (NadekoBot).
- It follows an MVVM (Model-View-ViewModel) architecture, uses dependency injection, and integrates with external APIs (GitHub, GitLab, “Evermeet” macOS FFmpeg host) and local processes (FFmpeg, yt-dl-pine via command line).

##### File structure
- Top-level
– NadekoHub.sln: .NET solution.
– NadekoHub/: main project directory.
– .github/workflows: CI/CD.
– Dockerfile/.dockerignore: containerization.
- Inside NadekoHub/
– App.axaml(.cs), Program.cs, App.manifest: application entry, Avalonia app.
– Avalonia/: UI resources (Styles, Assets, DesignData for XAML preview).
– Features/: modular feature folders (AppConfig, AppWindow, BotConfig, Home, Common). Each contains Models, Services, ViewModels, Views.
– Common/: shared controls and services.
– Extensions/: DI extensions, HTTP client helpers.
– Enums/, Common/, Usings.cs, ViewLocator.cs: app constants and wiring.

##### README
- Confirms core functions: install/update/remove bot instances, dependency management (FFmpeg, yt-dl), configuration UIs, log streaming, backups.
- No external database; persistence likely via local file system (AppConfigManager).
- Target platforms: Windows, Linux, macOS.

a. Main components
1. UI Layer (Avalonia Views & Resources)
2. Presentation Layer (ViewModels)
3. Service Layer
- AppConfig services (IAppConfigManager, IFfmpegResolver, IYtdlpResolver)
- BotConfig services (IBotOrchestrator, IBotResolver, ILogWriter)
- Home services (IAppResolver)
- Common services (IDependencyResolver)
4. Model Layer (DTOs for API responses, local settings, event args)
5. Infrastructure
- DI Container (IServiceCollectionExt)
- HTTP Client
- Local process runner (ProcessStart for bots, FFmpeg, yt-dl)
- File system (config files, logs, backups)
6. External Services
- GitHub API
- GitLab API
- Evermeet API
- FFmpeg/YT-DLP binaries repos
7. Platform Host
- Docker (optional)
- OS (Windows, Linux, macOS)

b. Relationships & data flow
- On startup, Program.cs → DI Container → App.axaml → MainWindow (AppView).
- AppView uses ViewLocator to pick feature Views (Home, Config, BotConfig).
- UI binds to ViewModels. ViewModels invoke Service Layer via injected interfaces.
- Service Layer calls Models and Infrastructure:
– HTTP calls to external APIs fetch release info.
– Local resolvers download/verify FFmpeg, yt-dl, manage bot binaries.
– BotOrchestrator launches/stops bot processes; LogWriter streams console output.
– AppConfigManager persists settings to file system.
- Events (ProcessStdWrite, BotExit) bubble back to ViewModels to update UI.

c. Architectural patterns & design principles
- MVVM: clear separation of Views, ViewModels, Models.
- Dependency Injection: IServiceCollectionExt for registration of Abstractions → Implementations.
- Modular features: each Feature folder encapsulates Models, Services, ViewModels, Views.
- Single Responsibility: resolvers, orchestrators, log writers each handle one concern.
- Asynchronous calls: non-blocking UI when calling external services or running processes.

d. Relevant technologies/frameworks
- Avalonia UI (cross-platform XAML)
- .NET 6+
- Microsoft.Extensions.DependencyInjection
- System.Net.Http (HttpClient)
- ProcessStart for external binaries
- GitHub/GitLab REST APIs
- GNU GPL v3 license

## Diagram (Mermaid)

```mermaid
graph TD
    %% Startup and DI
    ProgramCS["Program.cs"]:::infra
    DI["IServiceCollectionExt (DI Container)"]:::infra
    AppAXAML["App.axaml"]:::infra
    ViewLocator["ViewLocator.cs"]:::infra

    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        Avalonia["Avalonia Resources"]:::ui
        Assets["Assets"]:::ui
        subgraph "AppConfig Views"
            AppConfigViews["Features/AppConfig/Views"]:::ui
        end
        subgraph "AppWindow Views"
            AppWindowViews["Features/AppWindow/Views"]:::ui
        end
        subgraph "BotConfig Views"
            BotConfigViews["Features/BotConfig/Views"]:::ui
        end
        subgraph "Common Views"
            CommonViews["Features/Common/Views"]:::ui
        end
        subgraph "Home Views"
            HomeViews["Features/Home/Views"]:::ui
        end
    end

    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        subgraph "AppConfig VMs"
            ACVM["Features/AppConfig/ViewModels"]:::vm
        end
        subgraph "AppWindow VMs"
            AWVM["Features/AppWindow/ViewModels"]:::vm
        end
        subgraph "BotConfig VMs"
            BCVM["Features/BotConfig/ViewModels"]:::vm
        end
        subgraph "Common VMs"
            COVM["Features/Common/ViewModels"]:::vm
        end
        subgraph "Home VMs"
            HOVM["Features/Home/ViewModels"]:::vm
        end
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        subgraph "AppConfig Services"
            IAppConfigManager["IAppConfigManager"]:::service
            IFfmpegResolver["IFfmpegResolver"]:::service
            IYtdlpResolver["IYtdlpResolver"]:::service
            AppConfigManager["AppConfigManager"]:::service
            FfmpegWin["FfmpegWindowsResolver"]:::service
            FfmpegMac["FfmpegMacResolver"]:::service
            FfmpegLin["FfmpegLinuxResolver"]:::service
            YtdlpResolver["YtdlpResolver"]:::service
        end
        subgraph "BotConfig Services"
            IBotOrch["IBotOrchestrator"]:::service
            IBotResolver["IBotResolver"]:::service
            ILogWriter["ILogWriter"]:::service
            NadekoOrch["NadekoOrchestrator"]:::service
            NadekoRes["NadekoResolver"]:::service
            LogWriter["LogWriter"]:::service
        end
        subgraph "Home Services"
            IAppResolver["IAppResolver"]:::service
            AppResolver["AppResolver"]:::service
        end
        subgraph "Common Services"
            IDepResolver["IDependencyResolver"]:::service
        end
    end

    %% Model Layer
    subgraph "Model Layer"
        direction TB
        AppConfigModels["Features/AppConfig/Models"]:::model
        AppConfigEvermeet["Features/AppConfig/Models/Api/Evermeet"]:::model
        BotConfigModels["Features/BotConfig/Models"]:::model
        BotConfigGitlab["Features/BotConfig/Models/Api/Gitlab"]:::model
        BotConfigEvents["Features/BotConfig/Models/*.EventArgs.cs"]:::model
        CommonModels["Features/Common/Models"]:::model
        HomeModels["Features/Home/Models"]:::model
        HomeGithub["Features/Home/Models/Api/Github"]:::model
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        HttpClientExt["HttpClientExt.cs"]:::infra
        ServiceCollectionExt["IServiceCollectionExt.cs"]:::infra
        WindowExt["WindowExt.cs"]:::infra
        Usings["Usings.cs"]:::infra
    end

    %% External Services
    subgraph "External Systems/APIs"
        direction TB
        GitHubAPI["GitHub API"]:::external
        GitLabAPI["GitLab API"]:::external
        EvermeetAPI["Evermeet API"]:::external
        FfmpegRepo["FFmpeg/YT-DLP Binaries"]:::external
    end

    %% Platform & Containerization
    subgraph "Platform & Containerization"
        direction TB
        Dockerfile["Dockerfile"]:::infra
        Dockerignore[".dockerignore"]:::infra
        CI1[".github/workflows/dotnet.yml"]:::infra
        CI2[".github/workflows/publish-release.yml"]:::infra
        AppManifest["app.manifest"]:::infra
    end

    %% Arrows: startup
    ProgramCS -->|builds DI| DI
    DI -->|configures| AppAXAML
    AppAXAML -->|loads| ViewLocator

    %% UI to Presentation
    Avalonia -->|binds to| ACVM
    Assets -->|resources for| ACVM
    AppConfigViews -->|data-context| ACVM
    AppWindowViews -->|data-context| AWVM
    BotConfigViews -->|data-context| BCVM
    CommonViews -->|data-context| COVM
    HomeViews -->|data-context| HOVM

    %% Presentation to Service
    ACVM -->|injects| IAppConfigManager
    ACVM -->|injects| IFfmpegResolver
    ACVM -->|injects| IYtdlpResolver
    AWVM -->|injects| IDepResolver
    BCVM -->|injects| IBotOrch
    BCVM -->|injects| IBotResolver
    BCVM -->|injects| ILogWriter
    HOVM -->|injects| IAppResolver

    %% Service to Model & Infra & External
    IAppConfigManager -->|uses| AppConfigModels
    IFfmpegResolver -->|resolves| FfmpegRepo
    IYtdlpResolver -->|resolves| FfmpegRepo
    IBotResolver -->|fetches| BotConfigGitlab
    IBotResolver -->|fetches| GitLabAPI
    IAppResolver -->|queries| GitHubAPI
    IAppResolver -->|uses| HomeGithub
    ILogWriter -->|writes to| BotConfigEvents
    AppConfigManager -->|persists| AppConfigModels
    AppConfigManager -->|writes to| Usings

    %% Infra support
    * --> HttpClientExt
    * --> ServiceCollectionExt
    * --> WindowExt

    %% Legend omitted for brevity

    %% Click events
    click Avalonia "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Avalonia"
    click Assets "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Assets"
    click AppConfigViews "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Features/AppConfig/Views"
    click AppWindowViews "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Features/AppWindow/Views"
    click BotConfigViews "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Features/BotConfig/Views"
    click CommonViews "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Features/Common/Views"
    click HomeViews "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Features/Home/Views"
    click ACVM "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Features/AppConfig/ViewModels"
    click AWVM "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Features/AppWindow/ViewModels"
    click BCVM "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Features/BotConfig/ViewModels"
    click COVM "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Features/Common/ViewModels"
    click HOVM "https://github.com/kaoticz/nadekohub/tree/main/NadekoHub/Features/Home/ViewModels"
    click AppConfigManager "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Features/AppConfig/Services/AppConfigManager.cs"
    click IAppConfigManager "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Features/AppConfig/Services/IAppConfigManager.cs"
    click IFfmpegResolver "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Features/AppConfig/Services/IFfmpegResolver.cs"
    click IYtdlpResolver "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Features/AppConfig/Services/IYtdlpResolver.cs"
    click NadekoOrch "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Features/BotConfig/Services/NadekoOrchestrator.cs"
    click IBotOrch "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Features/BotConfig/Services/IBotOrchestrator.cs"
    click IBotResolver "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Features/BotConfig/Services/IBotResolver.cs"
    click ILogWriter "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Features/BotConfig/Services/ILogWriter.cs"
    click IAppResolver "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Features/Home/Services/IAppResolver.cs"
    click HttpClientExt "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Extensions/HttpClientExt.cs"
    click ServiceCollectionExt "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Extensions/IServiceCollectionExt.cs"
    click WindowExt "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Extensions/WindowExt.cs"
    click ProgramCS "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Program.cs"
    click ViewLocator "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/ViewLocator.cs"
    click Usings "https://github.com/kaoticz/nadekohub/blob/main/NadekoHub/Usings.cs"

    classDef ui fill:#58a6ff,stroke:#000,stroke-width:1px;
    classDef vm fill:#85e89d,stroke:#000,stroke-width:1px;
    classDef service fill:#ffa500,stroke:#000,stroke-width:1px;
    classDef infra fill:#d3d3d3,stroke:#000,stroke-width:1px;
    classDef model fill:#f0e68c,stroke:#000,stroke-width:1px;
    classDef external fill:#da70d6,stroke:#000,stroke-width:1px;
```
