How ronan-hughes74/cupid-music-player works
1. Overall shape
- This is a desktop-only music player built as an Electron shell around a React/Vite renderer.
- The app is split into two major runtime boundaries: Electron main process for OS/file/system work, and renderer UI for playback, browsing, and theming.
2. Electron main process
- electron/main.cjs is the privileged process that owns desktop concerns: window creation, frameless window behavior, app lifecycle, and any Node-side work.
- It is the natural boundary for things the renderer should not do directly, such as reading/writing app-managed local files, spawning yt-dlp, and generating Apple developer tokens.
- electron/preload.cjs likely exposes a limited, safe bridge into the renderer via IPC.
3. Renderer app
- src/main.jsx boots the React app, and src/App.jsx is the central composition layer.
- The renderer owns the visible player: playback controls, progress/seek interaction, track info, playlist browsing, settings flow, and theme switching.
- Styling is split between src/index.css and src/App.css, with heavy reliance on pixel-art assets and CSS-driven scaling.
4. Local audio subsystem
- Local playback is driven by src/useAudioPlayer.js, which wraps HTML5 Audio for source loading, play/pause, seeking, and playback state.
- Local library metadata comes from audio/playlist.json, which maps audio filenames to display metadata and optional cover art URLs.
- The repo includes an audio/ folder in source, and the README makes clear that installed builds seed a per-user audio folder on first launch; that local folder is the durable user-owned boundary.
5. Theme and visual layer
- src/useTheme.js manages the pink/blue theme choice and persistence.
- The art assets under assets/ and assets/animations/ support the animated turntable, needle transitions, and the record swap effect on song change.
- The dynamic dock/taskbar icon mentioned in the README suggests theme-aware icon selection is part of the Electron/main-process responsibilities.
6. Spotify subsystem
- src/spotify/auth.js and src/spotify/api.js handle Spotify OAuth PKCE and playlist/track metadata access.
- Playback is not via Spotify audio streaming directly; the app uses Spotify for discovery/metadata, then resolves playable audio through yt-dlp.
- src/useSpotifyPlayer.js likely orchestrates the user-facing Spotify flow: auth, playlist loading, track selection, and handoff to playback.
7. Apple Music subsystem
- src/apple/auth.js and src/apple/api.js implement MusicKit-based access to the user’s Apple Music library playlists.
- The README indicates a developer token is generated in Node using jsonwebtoken, which places Apple auth partly in the main process or another server-side boundary.
- This subsystem is for browsing library playlists; playback still aligns with the app’s broader audio model rather than a native Apple Music client.
8. YouTube subsystem
- src/youtube/auth.js, src/youtube/api.js, and src/youtube/index.js cover two modes: public playlist ingestion with no sign-in, and Google OAuth-based access to the user’s own playlists.
- Public playlist support uses YouTube Data API v3 for authenticated browsing when configured, and yt-dlp for extracting playable audio and playlist contents.
- The presence or absence of VITE_YOUTUBE_CLIENT_ID changes the UI flow, which is a key architecture toggle.
9. External playback/metadata pipeline
- A core design pattern is: provider API for discovery → track selection/metadata normalization → audio source resolution via yt-dlp or local files → HTML5 Audio playback in the renderer.
- This keeps the player UI provider-agnostic while still supporting Spotify, Apple Music, YouTube, and local files through separate adapter modules.
10. Configuration and secrets
- .env.example and the setup docs show the app is driven by environment variables for OAuth client IDs, Apple team/key IDs, and YouTube client credentials.
- These values determine which provider features appear in the UI and which auth flows are enabled.
- vite.config.js likely exposes these env vars to the renderer build where needed.
11. Build and packaging
- npm run dev uses Vite for the renderer and Electron for the desktop shell during development.
- npm run package creates desktop installers/bundles for macOS, Windows, and Linux.
- scripts/install-yt-dlp.cjs is an install-time dependency fetcher, which is important because yt-dlp is treated as a bundled runtime tool, not a user-installed prerequisite.
12. Asset and distribution boundaries
- assets/blue, assets/pink, and the animation subfolders are part of the product’s identity, not just decoration: they encode the theme states and playback animations.
- font/ and index.html support the custom pixel-art presentation.
- The repository’s README plus setup docs are part of the operational architecture because each provider has a different external dependency and onboarding path.
13. What to show in an architecture diagram
- Draw the React renderer as the central UI node.
- Surround it with four provider adapters: Local Audio, Spotify, Apple Music, and YouTube.
- Show Electron main/preload as the privileged bridge to OS features, file access, token generation, and yt-dlp execution.
- Show external dependencies separately: Spotify Web API, Apple MusicKit/Apple developer auth, YouTube Data API v3, and yt-dlp as the audio-resolution layer.
Main entry points: App.jsx App Shell · main.cjs Main Process · useSpotifyPlayer.js Spotify Flow · index.js YouTube Entry
Components 22
Desktop Shell
Electron main process and privileged bridge
- Main Process · Owns windowing, lifecycle, filesystem, and privileged Node work
electron/main.cjs - Preload Bridge · Exposes a limited API surface to the renderer
electron/preload.cjs
Renderer UI
React/Vite app and UI-side state
- App Boot · Bootstraps the renderer application
src/main.jsx - App Shell · Central composition for player, browsing, and settings
src/App.jsx - Theme State · Persists and applies pink/blue theme choice
src/useTheme.js
Provider Adapters
Local and remote music sources plus auth and metadata
- Audio Player · Loads sources and manages play, pause, seek, and state
src/useAudioPlayer.js - Spotify Flow · Coordinates Spotify auth, browsing, and track handoff
src/useSpotifyPlayer.js - Spotify Auth · Handles Spotify authorization
src/spotify/auth.js - Spotify API · Fetches Spotify playlists and track metadata
src/spotify/api.js - Apple Auth · Manages Apple Music developer and library access
src/apple/auth.js - Apple API · Reads Apple Music library playlists and metadata
src/apple/api.js - YouTube Entry · Dispatches public and OAuth-backed YouTube flows
src/youtube/index.js - YouTube Auth · Handles Google OAuth when enabled
src/youtube/auth.js - YouTube API · Fetches YouTube playlists and track data
src/youtube/api.js
Assets
Artwork, animation, and local library content
- Playlist Data · Seed metadata for bundled local audio files
audio/playlist.json - Artwork & Animations · Theme art, record swaps, needle motion, and icons
assets
Build & Config
Packaging, install scripts, and environment-driven setup
- Install yt-dlp · Fetches the yt-dlp runtime during setup or packaging
scripts/install-yt-dlp.cjs - Vite Config · Build-time environment exposure and renderer config
vite.config.js
External Services
Third-party APIs and runtime tools
- yt-dlp · Resolves playable audio from provider sources
- Spotify Web API · Remote Spotify discovery and metadata service
- Apple MusicKit · Apple Music access and developer-token-backed auth
- YouTube Data API · YouTube playlist and content lookup service
Connections 22
- App Boot → App Shell: mounts · Renderer entry mounts the app shell
- App Shell → Audio Player: controls · App shell drives playback state and transport
- App Shell → Theme State: themes · App shell applies persistent theme state
- App Shell → Spotify Flow: spotify ui · UI delegates Spotify-specific interactions
- App Shell → Apple API: apple ui · UI delegates Apple Music browsing
- App Shell → YouTube Entry: youtube ui · UI delegates YouTube browsing and selection
- App Shell → Playlist Data: local library · App shell reads bundled local library metadata
- App Shell → Artwork & Animations: renders · App shell uses animated artwork and theme assets
- Spotify Flow → Spotify Auth: auth · Spotify flow initiates OAuth PKCE login
- Spotify Flow → Spotify API: fetches · Spotify flow loads playlists and track metadata
- Spotify API → Spotify Web API: calls · Spotify API module talks to the remote service
- Apple API → Apple Auth: auth · Apple API depends on MusicKit/developer-token access
- Apple Auth → Apple MusicKit: calls · Apple auth uses MusicKit and Apple developer auth
- YouTube Entry → YouTube Auth: auth · YouTube entry switches to OAuth when configured
- YouTube Entry → YouTube API: fetches · YouTube entry loads public or authenticated playlist data
- YouTube API → YouTube Data API: calls · YouTube API module talks to the Data API
- Audio Player → yt-dlp: resolves · Audio player consumes extracted playable sources
- Main Process → Preload Bridge: bridges · Main process exposes a constrained preload surface
- Preload Bridge → App Shell: ipc · Renderer receives privileged capabilities through preload
- Main Process → Install yt-dlp: bundles · Main or packaging path ensures yt-dlp is available
- Vite Config → App Boot: builds · Vite config shapes the renderer build
- Main Process → Artwork & Animations: theme icon · Main process can select theme-aware app icons