# fooxboy/musicx-wpf architecture

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

- Interactive diagram: https://gitdiagram.com/fooxboy/musicx-wpf
- Repository: https://github.com/fooxboy/musicx-wpf

## Overview

##### Project Type and Purpose
- This is a full‑stack, multi‑component music application platform:
– Desktop client (WPF/UWP) called “MusicX,”
– Web client (React) under MusicX.Site,
– Backend server (ASP.NET Core + SignalR) under MusicX.Server,
– Shared libraries (MusicX.Core, MusicX.Shared) for domain models & IPC,
– A suite of specialized libraries (DiscordRPC, FFMediaToolkit, IF.Lastfm.Core, VkNet.*),
– Aux tools (PsCompiler, SignalR.Protobuf),
– Infrastructure descr. (Dockerfile, docker‑compose, InfluxDB config).

##### High‑Level Components
A. Desktop Client (“MusicX” app)
B. Web Client (“MusicX.Site” React SPA)
C. Backend API & Real‑Time Hub (“MusicX.Server”)
D. Shared/Core Libraries (“MusicX.Core”, “MusicX.Shared”)
E. Third‑Party & Support Libraries
F. External Services & Data Stores

##### Subcomponents & Boundaries
A. Desktop Client (UI layer)
- Views & ViewModels (XAML + C#)
- Controls, Behaviors, Converters, Shaders, Styles
- Services (PlayerService, NavigationService, ShareService, etc.)
- Registry patches & Native interop
- References: MusicX.Core, MusicX.Shared, DiscordRPC, FFMediaToolkit, IF.Lastfm.Core, VkNet.AudioBypassService

B. Web Client
- React SPA: package.json, src/*.js, public/*
- Consumes REST endpoints & SignalR hub on the backend

C. Backend Server
- Controllers (Connect, Radio, Metrics) – expose HTTP JSON APIs
- SignalR Hub (ListenTogetherHub) – real‑time group sessions
- Services: RadioManager, RadioService, ListenTogetherService, SessionManager
- Config & settings (appsettings.json, launchSettings.json)
- Connects to: InfluxDB (metrics?), optional DB for sessions

D. Shared/Core Libraries
- MusicX.Core – domain models, Boom/Genius/VkService API wrappers, business logic
- MusicX.Shared – DTOs for SignalR callbacks, model checkers, versioning, HubBuilder extensions
- Used by both Desktop and Server for message contracts

E. Third‑Party & Support Libraries
- DiscordRPC – Discord Rich Presence via Named Pipes
- FFMediaToolkit – FFmpeg binding for audio/video decoding & encoding
- IF.Lastfm.Core – Last.fm REST client & scrobblers
- VkNet.AudioBypassService & VkNet.Extensions.DependencyInjection – bypass flows for VK audio
- SignalR.Protobuf – Protobuf protocol extension for SignalR messaging
- PsCompiler – auxiliary tool (likely for PowerShell compilation)

F. External Services & Data Stores
- Music Providers: Boom, Genius, VK, Last.fm, GitHub (to fetch artwork, metadata)
- Discord IPC
- InfluxDB (for metrics)
- Optional: file system (cache), local registry (for URL schemes)

##### Relationships & Data Flows
- Desktop ↔ MusicX.Core / MusicX.Shared: in‑process code calls
- Desktop → External Music APIs: HTTP/REST for metadata & streaming links
- Desktop → DiscordRPC via Named Pipe → Discord App
- Desktop ↔ Backend SignalR Hub: WebSocket for ListenTogether events
- Web Client ↔ Backend HTTP + SignalR
- Backend ↔ MusicX.Core / MusicX.Shared: shared model & logic
- Backend → InfluxDB (metrics writes)
- Support Libraries: imported by Desktop, Web (where applicable), Server

##### Architectural Patterns & Principles
- Layered Architecture: UI → Services → Domain/Core → External APIs
- Shared Kernel (MusicX.Core, MusicX.Shared) for common DTOs & business rules
- Publish‑Subscribe / Real‑Time with SignalR Hub
- Adapter/Wrapper pattern for each external API (BoomService, GeniusService, VKService, LastfmClient)
- Dependency Injection across Server & Libraries
- Micro‑library approach: each major concern in its own NuGet‑style project

##### Final Touches
- Every component used in code (project in solution) is represented.
- Keep it at one or two pages: high-level view first, then a zoomed‑in view for the desktop client’s internal layers if needed.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Desktop Client" 
        Desktop["MusicX Desktop Client"]:::desktop
    end
    subgraph "Web Client"
        Web["MusicX.Site React SPA"]:::web
    end
    subgraph "Backend Server"
        Controllers["Controllers"]:::backend
        Hub["ListenTogetherHub"]:::backend
        Services["Services"]:::backend
        Config["Config Files"]:::backend
    end
    subgraph "Shared/Core Libraries"
        Core["MusicX.Core"]:::shared
        Shared["MusicX.Shared"]:::shared
    end
    subgraph "Third-Party & Support Libraries"
        DiscordRPC["DiscordRPC"]:::third
        FFMediaToolkit["FFMediaToolkit"]:::third
        Lastfm["IF.Lastfm.Core"]:::third
        VkBypass["VkNet.AudioBypassService"]:::third
        VkDI["VkNet.Extensions.DependencyInjection"]:::third
        SignalRProto["SignalR.Protobuf"]:::third
        PsCompiler["PsCompiler"]:::third
    end
    subgraph "External Services & Data Stores"
        MusicAPIs["Music Providers\n(Boom, Genius, VK, Last.fm)"]:::external
        DiscordApp["Discord App"]:::external
        InfluxDB["InfluxDB"]:::external
        FileSystem["File System (Cache)"]:::external
        DockerFiles["Infra: Dockerfile,\ndocker-compose.yml"]:::external
    end

    Desktop -->|"in-process calls"| Core
    Desktop -->|"in-process calls"| Shared
    Desktop -->|"uses"| DiscordRPC
    Desktop -->|"uses"| FFMediaToolkit
    Desktop -->|"uses"| Lastfm
    Desktop -->|"uses"| VkBypass
    Desktop -->|"IPC Named Pipe"| DiscordApp
    Desktop -->|"WebSocket (SignalR)"| Hub

    Web -->|"HTTP/REST, SignalR"| Controllers
    Web -->|"SignalR WS"| Hub

    Controllers -->|"calls domain logic"| Core
    Controllers -->|"uses DTOs"| Shared
    Controllers -->|"writes metrics"| InfluxDB
    Hub -->|"uses DTOs"| Shared
    Services -->|"uses domain logic"| Core
    Services -->|"uses DTOs"| Shared

    Core -->|"HTTP/REST"| MusicAPIs
    Shared -->|"contracts for SignalR"| Hub

    %% Click Events
    click Desktop "https://github.com/fooxboy/musicx-wpf/tree/master/MusicX/"
    click Web "https://github.com/fooxboy/musicx-wpf/tree/master/MusicX.Site/musicx-site/"
    click Controllers "https://github.com/fooxboy/musicx-wpf/blob/master/MusicX.Server/Controllers/ConnectController.cs"
    click Controllers "https://github.com/fooxboy/musicx-wpf/blob/master/MusicX.Server/Controllers/RadioController.cs"
    click Controllers "https://github.com/fooxboy/musicx-wpf/blob/master/MusicX.Server/Controllers/MetricsController.cs"
    click Hub "https://github.com/fooxboy/musicx-wpf/blob/master/MusicX.Server/Hubs/ListenTogetherHub.cs"
    click Services "https://github.com/fooxboy/musicx-wpf/blob/master/MusicX.Server/Services/RadioManager.cs"
    click Services "https://github.com/fooxboy/musicx-wpf/blob/master/MusicX.Server/Services/RadioService.cs"
    click Services "https://github.com/fooxboy/musicx-wpf/blob/master/MusicX.Server/Services/ListenTogetherService.cs"
    click Services "https://github.com/fooxboy/musicx-wpf/blob/master/MusicX.Server/Services/SessionManager.cs"
    click Config "https://github.com/fooxboy/musicx-wpf/blob/master/MusicX.Server/appsettings.json"
    click Config "https://github.com/fooxboy/musicx-wpf/blob/master/MusicX.Server/appsettings.Development.json"
    click Config "https://github.com/fooxboy/musicx-wpf/blob/master/MusicX.Server/Properties/launchSettings.json"
    click Core "https://github.com/fooxboy/musicx-wpf/tree/master/MusicX.Core/"
    click Shared "https://github.com/fooxboy/musicx-wpf/tree/master/MusicX.Shared/"
    click DiscordRPC "https://github.com/fooxboy/musicx-wpf/tree/master/DiscordRPC/"
    click FFMediaToolkit "https://github.com/fooxboy/musicx-wpf/tree/master/FFMediaToolkit/"
    click Lastfm "https://github.com/fooxboy/musicx-wpf/tree/master/IF.Lastfm.Core/"
    click VkBypass "https://github.com/fooxboy/musicx-wpf/tree/master/VkNet.AudioBypassService/"
    click VkDI "https://github.com/fooxboy/musicx-wpf/tree/master/VkNet.Extensions.DependencyInjection/"
    click SignalRProto "https://github.com/fooxboy/musicx-wpf/tree/master/SignalR.Protobuf/"
    click PsCompiler "https://github.com/fooxboy/musicx-wpf/blob/master/PsCompiler/Program.cs"

    classDef desktop fill:#D0E8FF,stroke:#007ACC,stroke-width:2px
    classDef web fill:#E0F8D8,stroke:#33A532,stroke-width:2px
    classDef backend fill:#FFE8C4,stroke:#FF8000,stroke-width:2px
    classDef shared fill:#F3E0FF,stroke:#8041C6,stroke-width:2px
    classDef third fill:#D8F3EF,stroke:#17A2B8,stroke-width:2px
    classDef external fill:#F0F0F0,stroke:#888888,stroke-width:1px,stroke-dasharray: 5 5
```
