# vicrodh/qbz architecture

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

- Interactive diagram: https://gitdiagram.com/vicrodh/qbz
- Repository: https://github.com/vicrodh/qbz

## Overview

1. **Repository shape**
   This is a Rust + TypeScript monorepo for QBZ, a native desktop music client. The top-level architecture splits into a Tauri desktop app, a Rust daemon/service (`qbzd`), a SvelteKit frontend, and a set of reusable Rust crates for audio, playback, metadata, casting, and remote control.

2. **Desktop shell vs UI**
   The user-facing app is the `src-tauri` Tauri 2 shell paired with the Svelte frontend in `src/`. The frontend owns the presentation layer, stores, and UI state, while Rust handles privileged/system tasks, audio, local services, and external integrations. Frontend-to-backend interaction is primarily via Tauri commands and a newer `commands_v2` API surface.

3. **Core playback pipeline**
   Playback is centered in the Rust crates `qbz-player`, `qbz-audio`, `qbz-cache`, and `qbz-core`. The flow is: track/stream selection → queue/playback engine → streaming source/cache → decoder/audio backend → output device. `qbz-audio` handles device control, backend selection, loudness normalization, and visualizer taps; `qbz-player` manages queue and playback state; `qbz-cache` provides memory/disk audio caching and prefetch.

4. **Audio subsystem boundaries**
   Audio is designed around native, bit-perfect output rather than browser playback. The codebase supports PipeWire, ALSA, ALSA Direct, and PulseAudio, with per-track sample rate switching and device passthrough. Visualizer and loudness analysis are integrated into the audio tap path so they observe playback without becoming part of the UI layer.

5. **Qobuz API and account flow**
   `qbz-qobuz` is the dedicated client/auth layer for Qobuz requests, link resolution, bundle parsing, and endpoint modeling. In the app, Qobuz-facing command modules expose catalog, search, playlists, favorites, discovery, and session/login operations. The frontend does not call Qobuz directly; it goes through backend commands and cached state.

6. **Local library and metadata**
   `qbz-library` is the local music library subsystem. It scans folders, parses tags and CUE sheets, builds a SQLite-backed index, manages thumbnails, and supports sidecar tags so the original audio files remain untouched. In the app, this feeds the “local library” views, tag editing, and related metadata screens.

7. **Offline and cache layers**
   There are two distinct caching concerns: playback/audio caching in `qbz-cache`, and application/offline caching in `src-tauri/src/offline_cache` and related config stores. The app also keeps image/cache layers for artwork and thumbnails. These caches support offline listening, faster browsing, and partial playback before full download completion.

8. **Remote control and Qobuz Connect**
   Qobuz Connect is implemented as a separate protocol stack: `qconnect-protocol`, `qconnect-core`, `qconnect-app`, and `qconnect-transport-ws`. This layer models renderer/controller roles, queue synchronization, and websocket transport. In the desktop app, `qconnect_service`, `qconnect`, and related command paths bridge that protocol into playback and UI state.

9. **Casting and device handoff**
   Casting is handled by `qbz-cast` and the app’s `src-tauri/src/cast` tree. It covers Chromecast, DLNA/UPnP, and AirPlay discovery plus device/session control. This is a separate boundary from local playback: the app can either render locally through the audio stack or hand off streams to a network device.

10. **Integrations and enrichment**
   Third-party metadata and scrobbling live in `qbz-integrations` and matching app-side modules. The main external services are Last.fm, ListenBrainz, MusicBrainz, and Discogs, plus playlist import from Spotify, Apple Music, Tidal, and Deezer. The README also describes a hosted API proxy used to hide API keys for some integrations in prebuilt releases.

11. **Backend orchestration in `src-tauri`**
   The Tauri backend is not just a thin bridge; it contains substantial domain logic: playback, queue, search, library, radio/recommendations, lyrics, share links, auto-theme, device monitoring, updates, and system integration. The `commands/` and `commands_v2/` folders are the primary API boundary to the frontend, while stores and services in `src/lib/` coordinate UI state with those backend capabilities.

12. **Daemon and local service surface**
   `qbzd` is the service-oriented backend binary. It includes a local API server, middleware, config, login/session management, MPRIS integration, wizard/setup flows, and the same domain areas exposed to the desktop app. This suggests the app can operate both as an interactive desktop client and as a local service endpoint for other components or remote control features.

13. **Frontend state model**
   The Svelte frontend is organized around stores and service modules rather than direct RPC calls from components. Stores capture playback, queue, session, sidebar/navigation, themes, offline state, updates, and remote control state; services encapsulate command routing, remote API access, playback coordination, and image caching. The UI layer is therefore mostly declarative, with orchestration pushed into stores/services.

14. **Build, packaging, and runtime boundaries**
   The repo is structured for multi-platform packaging: Linux native packages, Flatpak, Snap, AppImage, Gentoo, Nix, and an experimental macOS build. CI/CD workflows and packaging manifests live alongside the source, but the architecture remains centered on a native Rust backend plus a SvelteKit UI. The important runtime boundary is still local-process UI ↔ Rust backend ↔ external music/services, not a browser/webserver split.

Main entry points: [`src-tauri/src/commands_v2`](https://github.com/vicrodh/qbz/tree/main/src-tauri/src/commands_v2) (Commands v2), [`crates/qbzd/src`](https://github.com/vicrodh/qbz/tree/main/crates/qbzd/src) (qbzd), [`src-tauri/src/player`](https://github.com/vicrodh/qbz/tree/main/src-tauri/src/player) (App Player), [`src-tauri/src/library`](https://github.com/vicrodh/qbz/tree/main/src-tauri/src/library) (App Library)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_ui_shell["Svelte UI<br/>sveltekit app"]
  node_ui_state["Stores & Services<br/>ui orchestration"]
  node_ui_views["Views<br/>screen layer"]
  node_ui_remote["Remote Runtime<br/>qconnect client<br/>[qconnectRuntime.ts]"]
end

subgraph group_tauri["Desktop App"]
  node_tauri_backend["Tauri Backend<br/>native backend"]
  node_cmd_v2["Commands v2<br/>backend api"]
  node_cmd_legacy["Legacy Commands<br/>compat api"]
  node_app_audio["App Audio<br/>backend audio"]
  node_app_player["App Player<br/>playback engine"]
  node_app_library["App Library<br/>library service"]
  node_app_cache["Offline Cache<br/>local cache"]
  node_app_cast["Casting<br/>device handoff"]
  node_app_connect["Qconnect Service<br/>remote control bridge"]
end

subgraph group_crates["Rust Crates"]
  node_rust_player["qbz-player<br/>playback core"]
  node_rust_audio["qbz-audio<br/>audio backend"]
  node_rust_cache["qbz-cache<br/>audio cache"]
  node_rust_qobuz["qbz-qobuz<br/>api client"]
  node_rust_library["qbz-library<br/>library index"]
  node_rust_cast["qbz-cast<br/>cast stack"]
  node_rust_connect["qconnect stack<br/>protocol stack"]
  node_rust_integrations["qbz-integrations<br/>external services"]
end

subgraph group_service["Daemon"]
  node_daemon["qbzd<br/>local daemon"]
end

subgraph group_packaging["Packaging"]
  node_packaging_ci["Packaging & CI<br/>release automation<br/>[workflows]"]
end

node_ui_shell -->|"uses"| node_ui_state
node_ui_shell -->|"renders"| node_ui_views
node_ui_state -->|"calls"| node_cmd_v2
node_ui_state -->|"syncs"| node_ui_remote
node_ui_remote -->|"bridges"| node_app_connect
node_tauri_backend -->|"exposes"| node_cmd_v2
node_tauri_backend -.->|"keeps"| node_cmd_legacy
node_cmd_v2 -->|"drives"| node_app_player
node_cmd_v2 -->|"queries"| node_app_library
node_cmd_v2 -->|"reads/writes"| node_app_cache
node_cmd_v2 -->|"controls"| node_app_cast
node_cmd_v2 -->|"syncs"| node_rust_integrations
node_app_player -->|"uses"| node_rust_player
node_app_audio -->|"uses"| node_rust_audio
node_app_player -->|"prefetches"| node_rust_cache
node_app_library -->|"indexes"| node_rust_library
node_app_library -->|"enriches"| node_rust_qobuz
node_app_cast -->|"delegates"| node_rust_cast
node_app_connect -->|"implements"| node_rust_connect
node_daemon -->|"coordinates"| node_app_player
node_daemon -->|"serves"| node_app_library
node_daemon -->|"hosts"| node_app_connect
node_packaging_ci -.->|"builds"| node_tauri_backend
node_packaging_ci -.->|"packages"| node_daemon
node_packaging_ci -.->|"bundles"| node_ui_shell

click node_ui_shell "https://github.com/vicrodh/qbz/tree/main/src"
click node_ui_state "https://github.com/vicrodh/qbz/tree/main/src/lib/stores"
click node_ui_views "https://github.com/vicrodh/qbz/tree/main/src/lib/components/views"
click node_ui_remote "https://github.com/vicrodh/qbz/blob/main/src/lib/services/qconnectRuntime.ts"
click node_tauri_backend "https://github.com/vicrodh/qbz/tree/main/src-tauri/src"
click node_cmd_v2 "https://github.com/vicrodh/qbz/tree/main/src-tauri/src/commands_v2"
click node_cmd_legacy "https://github.com/vicrodh/qbz/tree/main/src-tauri/src/commands"
click node_app_audio "https://github.com/vicrodh/qbz/tree/main/src-tauri/src/audio"
click node_app_player "https://github.com/vicrodh/qbz/tree/main/src-tauri/src/player"
click node_app_library "https://github.com/vicrodh/qbz/tree/main/src-tauri/src/library"
click node_app_cache "https://github.com/vicrodh/qbz/tree/main/src-tauri/src/offline_cache"
click node_app_cast "https://github.com/vicrodh/qbz/tree/main/src-tauri/src/cast"
click node_app_connect "https://github.com/vicrodh/qbz/blob/main/src-tauri/src/qconnect_service.rs"
click node_rust_player "https://github.com/vicrodh/qbz/tree/main/crates/qbz-player/src"
click node_rust_audio "https://github.com/vicrodh/qbz/tree/main/crates/qbz-audio/src"
click node_rust_cache "https://github.com/vicrodh/qbz/tree/main/crates/qbz-cache/src"
click node_rust_qobuz "https://github.com/vicrodh/qbz/tree/main/crates/qbz-qobuz/src"
click node_rust_library "https://github.com/vicrodh/qbz/tree/main/crates/qbz-library/src"
click node_rust_cast "https://github.com/vicrodh/qbz/tree/main/crates/qbz-cast/src"
click node_rust_connect "https://github.com/vicrodh/qbz/tree/main/crates/qconnect-protocol/src"
click node_rust_integrations "https://github.com/vicrodh/qbz/tree/main/crates/qbz-integrations/src"
click node_daemon "https://github.com/vicrodh/qbz/tree/main/crates/qbzd/src"
click node_packaging_ci "https://github.com/vicrodh/qbz/blob/main/.github/workflows"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ui_shell,node_ui_state,node_ui_views,node_ui_remote toneBlue
class node_tauri_backend,node_cmd_v2,node_cmd_legacy,node_app_audio,node_app_player,node_app_library,node_app_cache,node_app_cast,node_app_connect toneAmber
class node_rust_player,node_rust_audio,node_rust_cache,node_rust_qobuz,node_rust_library,node_rust_cast,node_rust_connect,node_rust_integrations toneMint
class node_daemon toneRose
class node_packaging_ci toneIndigo
```

## Components

### Frontend

SvelteKit UI, stores, and browser-side orchestration.

- [Svelte UI](https://github.com/vicrodh/qbz/tree/main/src): sveltekit app · Presentation layer, routes, components, stores, and services. · `src`
- [Stores & Services](https://github.com/vicrodh/qbz/tree/main/src/lib/stores): ui orchestration · Frontend state model and command-routing services that coordinate playback, remote state, caching, and updates. · `src/lib/stores`
- [Views](https://github.com/vicrodh/qbz/tree/main/src/lib/components/views): screen layer · Primary app screens and modals for library, playback, search, settings, and onboarding. · `src/lib/components/views`
- [Remote Runtime](https://github.com/vicrodh/qbz/blob/main/src/lib/services/qconnectRuntime.ts): qconnect client · Frontend-side queue/runtime bridge for remote control and Qobuz Connect state. · `src/lib/services/qconnectRuntime.ts`

### Desktop App

Tauri shell and Rust app backend for the native client.

- [Tauri Backend](https://github.com/vicrodh/qbz/tree/main/src-tauri/src): native backend · Desktop shell backend that exposes commands, stores, system integration, and app-specific orchestration. · `src-tauri/src`
- [Commands v2](https://github.com/vicrodh/qbz/tree/main/src-tauri/src/commands_v2): backend api · Primary command surface for auth, catalog, playback, queue, library, integrations, search, and settings. · `src-tauri/src/commands_v2`
- [Legacy Commands](https://github.com/vicrodh/qbz/tree/main/src-tauri/src/commands): compat api · Older command boundary retained for backwards compatibility. · `src-tauri/src/commands`
- [App Audio](https://github.com/vicrodh/qbz/tree/main/src-tauri/src/audio): backend audio · App-level audio integration, device watching, and bridge into the shared playback stack. · `src-tauri/src/audio`
- [App Player](https://github.com/vicrodh/qbz/tree/main/src-tauri/src/player): playback engine · App-side playback engine and streaming source coordination. · `src-tauri/src/player`
- [App Library](https://github.com/vicrodh/qbz/tree/main/src-tauri/src/library): library service · Local library commands plus remote metadata and thumbnails for UI consumption. · `src-tauri/src/library`
- [Offline Cache](https://github.com/vicrodh/qbz/tree/main/src-tauri/src/offline_cache): local cache · Application offline/download cache with metadata, downloader, and path validation. · `src-tauri/src/offline_cache`
- [Casting](https://github.com/vicrodh/qbz/tree/main/src-tauri/src/cast): device handoff · Chromecast, DLNA, and AirPlay discovery and session control. · `src-tauri/src/cast`
- [Qconnect Service](https://github.com/vicrodh/qbz/blob/main/src-tauri/src/qconnect_service.rs): remote control bridge · Desktop bridge into Qobuz Connect protocol state and runtime. · `src-tauri/src/qconnect_service.rs`

### Rust Crates

Reusable Rust subsystems for playback, audio, metadata, casting, and remote control.

- [qbz-player](https://github.com/vicrodh/qbz/tree/main/crates/qbz-player/src): playback core · Queue and playback state machine plus streaming source handling. · `crates/qbz-player/src`
- [qbz-audio](https://github.com/vicrodh/qbz/tree/main/crates/qbz-audio/src): audio backend · Native device output, backend selection, loudness, analyzer taps, and visualizer feed. · `crates/qbz-audio/src`
- [qbz-cache](https://github.com/vicrodh/qbz/tree/main/crates/qbz-cache/src): audio cache · Memory/disk playback caching and prefetch support. · `crates/qbz-cache/src`
- [qbz-qobuz](https://github.com/vicrodh/qbz/tree/main/crates/qbz-qobuz/src): api client · Qobuz auth, client, endpoint modeling, link resolution, and bundle parsing. · `crates/qbz-qobuz/src`
- [qbz-library](https://github.com/vicrodh/qbz/tree/main/crates/qbz-library/src): library index · Folder scanning, cue parsing, SQLite index, tags, thumbnails, and sidecar metadata. · `crates/qbz-library/src`
- [qbz-cast](https://github.com/vicrodh/qbz/tree/main/crates/qbz-cast/src): cast stack · Reusable casting stack for Chromecast, DLNA/UPnP, and AirPlay. · `crates/qbz-cast/src`
- [qconnect stack](https://github.com/vicrodh/qbz/tree/main/crates/qconnect-protocol/src): protocol stack · Protocol, core reducer, app state, and websocket transport for Qobuz Connect. · `crates/qconnect-protocol/src`
- [qbz-integrations](https://github.com/vicrodh/qbz/tree/main/crates/qbz-integrations/src): external services · Last.fm, ListenBrainz, and MusicBrainz clients plus caches and models. · `crates/qbz-integrations/src`

### Daemon

qbzd local service and API surface.

- [qbzd](https://github.com/vicrodh/qbz/tree/main/crates/qbzd/src): local daemon · Service-oriented backend with API server, middleware, login, MPRIS, wizard flows, and session management. · `crates/qbzd/src`

### Packaging

Release, distro, and CI packaging artifacts.

- [Packaging & CI](https://github.com/vicrodh/qbz/blob/main/.github/workflows): release automation · Build workflows, distro packaging, manifests, and release automation. · `.github/workflows`

## Connections

- Svelte UI → Stores & Services: uses · Routes and components depend on stores/services for app behavior.
- Svelte UI → Views: renders · The UI is composed of reusable views and modal components.
- Stores & Services → Commands v2: calls · Frontend orchestration primarily talks to the v2 backend command surface.
- Stores & Services → Remote Runtime: syncs · State services coordinate local and remote queue/runtime state.
- Remote Runtime → Qconnect Service: bridges · Remote runtime state is backed by the desktop Qconnect bridge.
- Tauri Backend → Commands v2: exposes · The Tauri backend publishes the primary command API to the frontend.
- Tauri Backend → Legacy Commands: keeps · Legacy commands remain for compatibility.
- Commands v2 → App Player: drives · Playback, queue, and source actions are coordinated through the app player.
- Commands v2 → App Library: queries · Library views and metadata screens use backend library services.
- Commands v2 → Offline Cache: reads/writes · Offline and download state is managed through the app cache layer.
- Commands v2 → Casting: controls · Device discovery and handoff flow through the cast subsystem.
- Commands v2 → qbz-integrations: syncs · Metadata enrichment and scrobbling/integration actions reach external services.
- App Player → qbz-player: uses · The app player delegates core queue and playback behavior to the shared crate.
- App Audio → qbz-audio: uses · Device output and analyzer taps are implemented in the shared audio crate.
- App Player → qbz-cache: prefetches · Playback uses shared caching for streaming, prefetch, and partial download.
- App Library → qbz-library: indexes · Local library scanning and indexing are handled by the shared library crate.
- App Library → qbz-qobuz: enriches · Remote metadata and link resolution rely on the Qobuz client layer.
- Casting → qbz-cast: delegates · The app cast tree is a thin bridge over the reusable cast stack.
- Qconnect Service → qconnect stack: implements · Desktop remote-control behavior is backed by the Qconnect protocol stack.
- qbzd → App Player: coordinates · The daemon exposes playback and queue capabilities through its service API.
- qbzd → App Library: serves · Local service endpoints provide library and metadata access.
- qbzd → Qconnect Service: hosts · Qconnect-related service paths are surfaced from the daemon.
- Packaging & CI → Tauri Backend: builds · Release automation packages the desktop backend and app shell.
- Packaging & CI → qbzd: packages · Separate workflows ship the qbzd service binary and manifests.
- Packaging & CI → Svelte UI: bundles · Frontend assets are bundled into desktop and distro artifacts.
