How jayesh-cmd/daydreamin works
1. Two-process architecture
- The repo is split into a SwiftUI iOS client and a Python FastAPI backend.
- The iPhone app does not stream directly from third-party services; it talks to the backend over HTTP, and the backend resolves metadata, streaming, lyrics, and recommendations.
2. iOS app boundary
- Bitsongs/BitsongApp.swift is the app entry point.
- Bitsongs/Views/MusicPlayerView.swift is the main screen, assembled from reusable UI components under Views/Components/.
- The UI is mostly presentation-only; state and playback behavior are centralized in the view model.
3. Client state and playback orchestration
- ViewModels/MusicPlayerViewModel.swift is the core client-side controller.
- It manages current song state, queue/up-next data, search results, playback state, and coordination with the network layer.
- It is the bridge between SwiftUI views and the backend API.
4. Client networking layer
- Services/NetworkService.swift is the only explicit server-facing client module.
- It holds the backend base URL and performs API calls to the FastAPI server for search, chart data, play/stream resolution, lyrics, recommendations, and caching.
- This is the main architectural boundary between local UI and remote data/services.
5. Playback and system integrations on iOS
- The app uses AVPlayer for actual audio playback.
- It also integrates with MPNowPlayingInfoCenter and MPRemoteCommandCenter to support lock-screen metadata and remote controls.
- Haptics are handled locally through Utilities/HapticManager.swift.
6. UI composition and visual theming
- AlbumArtView, PlaybackControlsView, SearchBarView, UpNextView, and DynamicBackgroundView split the player into clear subviews.
- Utilities/ColorExtractor.swift suggests the artwork drives dynamic theming/background colors.
- Asset catalogs contain album art variants and app icons; these are presentation assets, not core data.
7. Backend responsibilities
- Server/app.py is the backend entry point and exposes the mobile API.
- It acts as an orchestration service: search, trending/chart retrieval, stream URL generation/proxying, lyrics lookup, recommendation generation, and cache management.
- The backend is the only component that talks to external music/content sources.
8. External service dependencies
- Search and metadata are sourced from the iTunes API.
- Audio streaming is resolved via yt-dlp, with ffmpeg required for processing/compatibility.
- Lyrics come from LRCLIB.
- These integrations matter architecturally because the server converts unstable third-party sources into a simpler app-facing API.
9. Recommendation subsystem
- Server/recommendation/ is a self-contained engine with behavior-based and content-based strategies.
- behavior.py, content.py, engine.py, and storage.py indicate separation between scoring logic, strategy composition, and persistence.
- Server/data/songs.json and Server/data/tally_counter.json are the primary data stores for recommendation inputs and transition history.
10. Caching and persistence
- The backend maintains an audio cache separate from recommendation data, with cached files stored under song_cache/.
- The README describes cache eviction when size exceeds 600 MB, implying the server owns lifecycle management for streamed media artifacts.
- This keeps repeated plays fast without pushing cache complexity into the iOS client.
11. API shape and data flow
- Typical flow: user searches in the app → iOS calls /api/mobile/search or /api/mobile/chart → user selects a song → iOS calls /api/mobile/play → backend returns a stream URL and may record transition data → AVPlayer plays audio.
- Recommendations and “Up Next” are separate follow-up calls driven by the selected/current song.
- Lyrics are also a separate lookup, so the UI can present them independently of playback.
12. Validation and test boundary
- Server/tests/test_recommendation.py focuses on recommendation correctness, indicating this logic is treated as an isolated backend subsystem.
- requirements.txt and the README setup show the backend is intended to run as a local Python service alongside the Xcode app during development.
Main entry points: MusicPlayerView.swift Player Screen · MusicPlayerViewModel.swift Player VM · app.py API Server · engine.py Reco Engine
Components 27
iOS Client
SwiftUI app, local playback, and UI composition.
- App Entry · Launches the iOS application and wires the main scene.
Bitsongs/BitsongApp.swift - Player Screen · Main music player screen assembled from reusable components.
Bitsongs/Views/MusicPlayerView.swift - Player VM · Central client controller for playback state, queue, search, and backend coordination.
Bitsongs/ViewModels/MusicPlayerViewModel.swift - API Client · Single iOS boundary for backend calls: search, charts, play, lyrics, recommendations, and cache-aware requests.
Bitsongs/Services/NetworkService.swift - Song Model · Shared song representation used by the client UI and view model.
Bitsongs/Models/Song.swift - Album Art · Displays artwork and feeds visual identity into the player UI.
Bitsongs/Views/Components/AlbumArtView.swift - Playback Controls · Play/pause and transport controls for local playback.
Bitsongs/Views/Components/PlaybackControlsView.swift - Search Bar · Song search input embedded in the player experience.
Bitsongs/Views/Components/SearchBarView.swift - Up Next · Shows queued and recommended follow-up tracks.
Bitsongs/Views/Components/UpNextView.swift - Dynamic BG · Background styling that adapts to album art and theme colors.
Bitsongs/Views/Components/DynamicBackgroundView.swift - Haptics · Local tactile feedback for player interactions.
Bitsongs/Utilities/HapticManager.swift - Color Extractor · Derives theme colors from artwork for dynamic presentation.
Bitsongs/Utilities/ColorExtractor.swift - Tone Generator · Local audio/tone utility used by the app.
Bitsongs/Utilities/ToneGenerator.swift
Backend Service
FastAPI API, orchestration, and recommendation engine.
- API Server · Backend entry point that exposes the mobile API and orchestrates external lookups.
Server/app.py - Reco Engine · Combines strategy logic and persistence for behavior- and content-based recommendations.
Server/recommendation/engine.py - Behavior Scoring · Scores recommendations from transition and listening behavior.
Server/recommendation/behavior.py - Content Scoring · Scores recommendations from song metadata and content similarity.
Server/recommendation/content.py - Reco Storage · Loads and updates recommendation state and counters.
Server/recommendation/storage.py - Songs Data · Primary recommendation input dataset.
Server/data/songs.json - Tally Data · Transition history and counter store for recommendation learning.
Server/data/tally_counter.json - Reco Tests · Validates recommendation behavior as an isolated subsystem.
Server/tests/test_recommendation.py
External Sources
Third-party services and system frameworks the repo depends on.
- iTunes API · Provides search and metadata lookup for songs.
- yt-dlp · Resolves audio streams and media URLs for playback.
- ffmpeg · Used for stream processing and compatibility on the server.
- LRCLIB · Provides lyrics lookup for the backend API.
- AVPlayer · Handles actual audio playback on the device.
- Now Playing · Lock-screen metadata and media controls integration.
Connections 27
- App Entry → Player Screen: launches · App entry presents the main player screen.
- Player Screen → Player VM: binds · The view is driven by centralized playback state.
- Player Screen → Album Art: composes · Main screen includes artwork presentation.
- Player Screen → Playback Controls: composes · Main screen includes playback controls.
- Player Screen → Search Bar: composes · Main screen includes search input.
- Player Screen → Up Next: composes · Main screen includes queue and follow-up tracks.
- Player Screen → Dynamic BG: styles · Main screen uses dynamic background treatment.
- Player VM → API Client: calls · View model delegates search, playback resolution, lyrics, and recommendations.
- Player VM → Song Model: uses · Tracks selected and queued songs through shared model objects.
- Player VM → Haptics: triggers · Playback interactions generate local haptic feedback.
- Player VM → Tone Generator: uses · May use local tone utilities for audio-related behavior.
- Album Art → Color Extractor: feeds · Artwork can drive extracted theme colors.
- Color Extractor → Dynamic BG: themes · Extracted colors inform the dynamic player background.
- API Client → API Server: http api · Client talks to the backend over HTTP.
- API Server → iTunes API: queries · Backend sources search and metadata from iTunes.
- API Server → yt-dlp: resolves · Backend resolves playable streams through yt-dlp.
- API Server → ffmpeg: processes · Backend uses ffmpeg for stream compatibility and processing.
- API Server → LRCLIB: fetches · Backend retrieves lyrics from LRCLIB.
- API Server → Reco Engine: delegates · Backend hands recommendation logic to the engine.
- Reco Engine → Behavior Scoring: scores · Behavior-based strategy contributes to ranking.
- Reco Engine → Content Scoring: scores · Content-based strategy contributes to ranking.
- Reco Engine → Reco Storage: persists · Engine reads and writes recommendation state.
- Reco Storage → Songs Data: reads · Uses song catalog data as recommendation input.
- Reco Storage → Tally Data: updates · Maintains transition counters and history.
- API Server → Reco Tests: validated by · Recommendation subsystem is covered by backend tests.
- Player VM → AVPlayer: controls · View model orchestrates local audio playback.
- Player VM → Now Playing: publishes · Updates system playback metadata and remote controls.