A file for guiding coding agents. Kopuz is a Rust + Dioxus
music player; one Cargo workspace holds the daemon and its frontends, laid out by
layer under shared/, daemon/ and apps/ (see Directory Structure). See
CONTRIBUTING.md for the human process and README.md for platform setup.
- Serve (dev):
just serve— regenerates Tailwind, thendx serve --package kopuz-legacy. Debug builds use a separatekopuz-debug.db, so this never touches real data (KOPUZ_DB_PATHoverrides the location). - Build (release):
just build(=dx build --package kopuz-legacy --release). - GPUI frontend:
just gpui runbuilds it andkopuzdand starts both on a dev socket;just gpuilists the rest. Seeapps/kopuz/CLAUDE.md. - Lint (gate):
cargo clippy --workspace --all-targets -- -D warnings. Run it in both debug and--release— some code iscfg-gated. Prefix withSQLX_OFFLINE=trueif it tries to reach a live DB. - Format:
cargo fmt --all(check:cargo fmt --all -- --check). - Test:
SQLX_OFFLINE=true cargo test -p <crate>, filtering by name where you can — the suite is large. E.g.cargo test -p kopuz-db <test name>.
Run clippy (debug + release), fmt, and the tests covering your change before each commit.
- SQLite via
sqlx. Schema migrations aredaemon/db/migrations/*.sql; sqlx checksums their bytes, so keep them LF and never edit an already-applied migration — add a new one. query!/query_as!macros are compile-checked againstdaemon/db/.sqlx/. After adding or changing one, regenerate the cache: pointDATABASE_URLat a temp DB,sqlx migrate run, thencargo sqlx prepare(run fromdaemon/db). Runtimesqlx::query_as(most track queries) is not macro-checked and needs no prepare.- Crate wall: the frontend crates (
hooks,pages,components) reach the daemon throughapiand nothing else. They do not depend ondb,daemon,server,readeror (off Android)player: no database handle, no domain model, no media source, no credentials, no system integration. A feature that needs one of those is a daemon service with an API method, not a hook. Pages render the wire rows themselves —api::TrackInfo,AlbumInfo,PlaylistCatalog— so there is no conversion layer to keep in step. - Settings file:
config::Settings(typed sections, flattened to top-level keys) lives only in the TOML layers next to the DB (shared/config/src/store.rs): defaults →settings.local.toml→settings.toml→settings.d/*.tomldrop-ins →KOPUZ_CONFIG_*env. State, credentials, sources and UI prefs are not settings; they live in their own daemon stores and tables. Change settings with typedSettingsEdits throughedit_config; a save writes only the keys that changed, intosettings.toml, orsettings.local.tomlwhen the main file is hjem-managed (store symlink / read-only, never written). A key a managed file, drop-in or env var pins is refused per edit and renders locked, citing that file's path or the var's name. The daemon polls the files' mtimes and reloads live; env is read once.
- Each backend implements the
MediaSourcetrait (source.rs): Local, Jellyfin, Subsonic/Custom, YtMusic, SoundCloud, Spotify, Apple Music, Nextcloud. The daemon owns them; a frontend asksSourceApiwhat the active one can do and never branches on a service name. - Cover resolution lives in
cover.rs(locate/track/from_path); dispatch on the cover ref's own shape, not the active source. What a frontend sees is anArtworkRef, resolved to bytes byArtworkApi. - InnerTube headers are all-or-nothing. Every
youtubei/v1/*call sendsUser-Agent(from theYouTubeClient),X-Goog-Api-Format-Version,X-YouTube-Client-Name/-Version,X-OriginandReferer, plusCookie+ a SAPISIDHASHAuthorizationwhen signed in. YouTube answers a request missing them with a bare 403 while the endpoints that send them keep working from the same session, so the symptom looks like an expired login and is not.discover.rs::postis the reference; copy it rather than hand-rolling a builder.
- Fluent
.ftlinapps/common/i18n/locales/, baselineen.ftl. Add every new key to all locales —scripts/check_locales.nu(CI) requires parity withen.ftl, andscripts/check_i18n_usage.nuchecks that keys are actually used.
- Diagnostics via
tracing;println!/eprintln!are clippy-denied outside explicit exceptions. .clippy.tomlforbids holding a Dioxus signal borrow across.await— clone the value out first.- Prefer real error handling over
unwrap()/expect()outside tests. - Keep comments to the non-obvious why; don't restate the code.
Three layers, enforced by scripts/check_layers.nu (CI):
shared/— the daemon ↔ frontend contract. Depends on nothing else in the repo.daemon/— the daemon and everything behind it. Depends only onshared/.apps/— the frontends.apps/common/(shared by frontends only) depends only onshared/; each app (apps/cli,apps/legacy/,apps/kopuz/) onshared/andapps/common/, never ondaemon/or another app. The one exception, listed in the script: the Dioxus app hosts the daemon in-process and drivesplayeron Android.
A bare cargo build / cargo test covers the default members (everything but
the Dioxus app); pass --workspace or -p kopuz-legacy for it.
apps/legacy/kopuz— the legacy Dioxus app, package and binarykopuz-legacy(entrymain.rs,build.rsfont/asset embedding + Android packaging). Hosts the daemon core in-process.shared/api— the client-facing trait and its wire types;shared/proto— the gRPC schema;apps/common/client— the same trait over a socket.daemon/core— the core: session, library, catalog, radio, sources, mutations, jobs, artwork, andLocalApiover them.daemon/kopuzd— the headless binary and the tonic shell.shared/config—Settingsand its typed edits, the settings store,Source,MusicService,MusicServer.daemon/reader— domain models (Track,Album,TrackId), scanner, tag IO. Daemon-side: what crosses to a frontend isapi::TrackInfo.daemon/db— SQLite backend,ReadStore/Storage, migrations.daemon/server—MediaSourcebackends, sync, cover resolution.apps/legacy/hooks— Dioxus data hooks over the API (queries, player controller, artwork, sources).apps/legacy/pages,apps/legacy/components,apps/legacy/kopuz_route— UI + routing.apps/kopuz/— the native GPUI frontend:app(thekopuzbinary) and its feature crates, a socket-only client.vendor/gpui-pre-linuxis its patched gpui platform crate, applied through the root[patch.crates-io].daemon/playeraudio ·daemon/radio·daemon/scrobble·daemon/discord-presence·apps/common/i18n·shared/utils(CoverUrl, image-URL builders; frontend utilities do not link SQLite).apps/legacy/kopuz/android-src/— Kotlin media-session classes itsbuild.rscopies into the Android build.packaging/(flatpak / AUR / nix) ·scripts/(codegen + vendor helpers).
The bar for every issue and PR is the AI Policy in CONTRIBUTING.md. On top
of it, an agent:
- opens an issue or PR only when its human explicitly asks for one;
- opens PRs as drafts; the human marks them ready for review;
- keeps a PR to one behavior change, and puts a refactor the change needs in its own PR lower in a stack;
- fills the template as given: no added, removed or renamed headings, and no subheadings;
- writes Why and What Changed as behavior in a few sentences, never a file-by-file walk through the diff;
- turns a Testing cell from ❎ to ✅ only for a check it ran, with the screenshot or recording attached;
- makes follow-up commits only when its human asks, and never replies to reviewers;
- writes commit subjects in the scoped format from
CONTRIBUTING.md(crate/module: description,various:across crates), never the conventionalfix(scope):/feat:/perf(scope):form; - creates no new branch: it commits on the branch its human is on, or the existing branch of the PR it is updating, and asks before starting one;
- never adds an AI
Co-authored-by:trailer or a "Generated with …" footer to a commit, issue or PR. The AI usage checkbox is the only disclosure.