# Music iOS App — AGENTS.md ## Project This repository contains the native iOS client for [Music](https://music.lucasskt.dk), whose web app source is in `~/music-v2`. Treat the current web app and its backend API as the source of truth for product scope, data, and user flows. When a web feature or flow changes, update the iOS app and this guide to match. Do not add product features beyond the web app unless explicitly requested. The iOS client is closed source for now. It targets iOS only and uses SwiftUI for the entire interface. Connect to the same production backend/API and authentication model used by the web app (`https://music.lucasskt.dk/api`); confirm actual routes and payloads in `~/music-v2` rather than assuming them. Keep credentials and private configuration out of source control. ## Product and user flows to mirror - **Authentication:** unauthenticated users are sent to sign in. Sign-in accepts email and password; the web UI has no “remember me” control. On iOS, request the backend's persistent refresh cookie (`remember: true`) and rely on secure cookie storage to restore sessions across launches; do not expose a remember toggle. The current web sign-in page says registration is closed, even though registration endpoints/helpers remain in the backend. Do not expose sign-up unless the web product opens registration. A sign-out API/helper exists, but the current web UI has no visible sign-out or account-management flow; do not invent profile management or account settings. - **Home and discovery:** the Home screen presents album carousels grouped by a selection of random genres. Selecting an album opens its detail page. There are no dedicated genre browsing/detail screens in the current web UI. - **Search:** the shared navigation search opens Search and updates results as the query changes. Search covers tracks, albums, and artists, with a short debounce; the backend also searches track names and lyric text. Empty search and no-result states show up to nine recently played tracks stored locally in the browser on the web app. Selecting a track plays it; selecting an album or artist opens its detail page. - **Catalog pages:** album pages show artwork, title, artists, Play and Shuffle actions, and the album’s tracks. Artist pages show artist artwork/name, Play and Shuffle actions, the artist’s tracks, and albums. A separate artist Songs page lists that artist’s tracks. Tracks link to their album and artist pages. - **Personal library:** tracks can be saved to and removed from the signed-in user’s Library. Library navigation has Songs, Albums, and Artists views. Songs can be played in order or shuffled and removed from the Library. The Albums and Artists lists are derived from the user’s saved tracks; they are not separately saved collections. - **Playback:** provide persistent playback controls for current track/artwork and artist, play/pause, previous/next, shuffle, repeat, seek with elapsed/remaining time, volume, queue access, and fullscreen player access. Track actions include playing only that track, playing next, adding to queue, saving/removing from Library, and navigating to the track’s artist or album. The queue can be reordered and tracks in it can be selected for playback. Preserve appropriate iOS background/audio-session and system media-control behavior when implementing the equivalent native experience. - **Playback handoff:** after authentication, restore the unexpired playback handoff only if the player is empty. Save current track, position, queue, history, repeat mode, and playing state through `/api/user/playback-handoff`; refresh position every 15 seconds while playing and save on meaningful state changes or app backgrounding. Consume the handoff only after a successful playing or paused restore, and clear it when the player is cleared. Handoff failures must not interrupt local playback. - **Fullscreen player and lyrics:** show artwork, track and artist, playback controls, seek and volume controls over an animated, artwork-derived color wash. Display plain lyrics when available. For synced lyrics, highlight and follow the current line and allow tapping a line to seek to its timestamp. Lyrics may be absent or unsynced. - **Admin catalog tools:** the web app exposes an admin-only panel with tables for genres, artists, albums, and songs, plus create/edit forms. Forms support artist artwork, album artwork/artists/genre, and song audio/artists/album plus lyrics and synced-lyrics metadata. Song creation can create a single album as part of the flow. The backend has delete APIs, but the current web table delete buttons are unimplemented; do not present deletion as an existing user-facing flow unless the web UI implements it. Keep administration restricted to admin accounts. ### Explicit current limitations - User-created playlists are **not implemented**. The web track menu’s “Add to playlist” action only displays a “Playlists are not implemented” notice. Do not build playlist creation, editing, or management as part of parity unless the web version adds it or the user explicitly requests it. - The current web UI does not provide public registration, visible sign-out/account controls, profile editing, subscriptions, downloads/offline listening, social features, or a dedicated genre browser. Backend routes or helpers alone do not make a feature part of the user-facing scope. - Search’s recently played list is currently local to the web browser; do not imply it is synced to the account. ## Design direction The iOS app should feel native to iOS and use an Apple Music-inspired **liquid glass** visual style throughout the app: layered translucent materials, blur, depth, and restrained motion where they support clarity. Apply this consistently to navigation, library and catalog screens, controls, queue, dialogs, and fullscreen playback. Preserve the web app’s information architecture, feature set, and interaction intent while adapting layouts and controls to native iOS conventions. Do not copy web-only layout constraints literally when a native pattern serves the same flow. Use large, custom page headings near the top of the content on the Home, Library, and Search tabs. Hide the navigation bar on those tab roots when needed to keep headings close to the status area; restore navigation bars on pushed detail pages so back navigation remains visible. Keep Search's query input connected through SwiftUI's `.searchable` modifier on the Search tab. ## Out of scope - Features, services, or user flows absent from the current web app, unless explicitly approved. - Ads, analytics, tracking, or other privacy-invasive behavior. - iPadOS, macOS, watchOS, Android, web clients, or other multi-platform targets; this project is iOS only. - Opening registration or adding account/profile functionality beyond the current web experience without an explicit scope change. ## Working principles - The user directs product decisions; keep implementation clear and maintainable, with comments where they clarify non-obvious behavior. - Before creating or updating a UI, inspect the corresponding screen and shared layout in `~/music-v2`. Mirror its structure and information hierarchy in native SwiftUI, using liquid glass only where it suits the screen and supports clarity. - Use Apple's standard red accent (`.red`) and otherwise prefer SwiftUI's semantic system colors and materials. Avoid custom color values unless the user asks for them. - Always add a SwiftUI preview for every UI view you create or update. - Before implementing or changing a view, search the codebase for existing components and practically similar UI in other screens. Reuse or extend an existing component when it fits; when the same view is needed in two or more places, extract a reusable SwiftUI component with configuration for meaningful differences instead of duplicating the implementation. In the completion report, identify any reusable component created or changed and the screens that use it. - Use XcodeBuildMCP's compile-only `build_sim` action to build this Xcode project when build verification is needed; do not run `xcodebuild` from the shell when XcodeBuildMCP is available. Do not use a build-and-run action or launch a simulator without the user's explicit confirmation. - Before completing code changes, run available linting and type checking or a build for the affected code. Fix errors introduced by the change, and clearly report any unrelated baseline or environment failures that prevent a clean check. - Do not boot, open, or launch an iOS simulator without the user's explicit confirmation. This includes XcodeBuildMCP actions such as `build_run_sim` that automatically open the simulator. Prefer compile-only simulator builds when validation is needed. - Reuse the web app’s backend API and data model. Inspect `~/music-v2` when route behavior, authentication, content fields, or feature scope is unclear. - Match the web version’s structure and scope, while making the experience idiomatic to SwiftUI and iOS. - Update this document when the web app’s features, flows, design direction, or technical scope changes. Flag uncertainty for review instead of silently adding new product behavior. ## Source organization - Keep SwiftUI screens under `Music/View/`, grouped by feature (`Track/`, `Player/`, `Home/`, `Auth/`, and `Album/`). `ContentView.swift` is the sole view exception and stays directly under `Music/` as the app's root content view. - Keep utility code under `Music/Utils/`, including API code under `Music/Utils/API/`.