# ronan-hughes74/cupid-music-player architecture

> Architecture diagram of the GitHub repository ronan-hughes74/cupid-music-player, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ronan-hughes74/cupid-music-player
- Repository: https://github.com/ronan-hughes74/cupid-music-player

## Overview

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: [`src/App.jsx`](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/App.jsx) (App Shell), [`electron/main.cjs`](https://github.com/ronan-hughes74/cupid-music-player/blob/main/electron/main.cjs) (Main Process), [`src/useSpotifyPlayer.js`](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/useSpotifyPlayer.js) (Spotify Flow), [`src/youtube/index.js`](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/youtube/index.js) (YouTube Entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop_shell["Desktop Shell"]
  node_electron_main["Main Process<br/>electron shell<br/>[main.cjs]"]
  node_electron_preload["Preload Bridge<br/>ipc bridge<br/>[preload.cjs]"]
end

subgraph group_renderer_ui["Renderer UI"]
  node_app_boot["App Boot<br/>react entry<br/>[main.jsx]"]
  node_app_shell["App Shell<br/>react composer<br/>[App.jsx]"]
  node_theme(("Theme State<br/>ui theme hook<br/>[useTheme.js]"))
end

subgraph group_providers["Provider Adapters"]
  node_audio_player(("Audio Player<br/>HTML5 audio hook<br/>[useAudioPlayer.js]"))
  node_spotify_flow(("Spotify Flow<br/>player flow"))
  node_spotify_auth["Spotify Auth<br/>oauth pkce<br/>[auth.js]"]
  node_spotify_api["Spotify API<br/>metadata api<br/>[api.js]"]
  node_apple_auth["Apple Auth<br/>music kit auth<br/>[auth.js]"]
  node_apple_api["Apple API<br/>library api<br/>[api.js]"]
  node_youtube_entry["YouTube Entry<br/>provider entry<br/>[index.js]"]
  node_youtube_auth["YouTube Auth<br/>oauth flow<br/>[auth.js]"]
  node_youtube_api["YouTube API<br/>data api<br/>[api.js]"]
end

subgraph group_assets["Assets"]
  node_playlist_data["Playlist Data<br/>local library<br/>[playlist.json]"]
  node_art_assets["Artwork & Animations<br/>visual assets"]
end

subgraph group_build["Build & Config"]
  node_install_yt_dlp["Install yt-dlp<br/>install script<br/>[install-yt-dlp.cjs]"]
  node_vite_config["Vite Config<br/>build config<br/>[vite.config.js]"]
end

subgraph group_external["External Services"]
  node_yt_dlp["yt-dlp<br/>runtime tool"]
  node_spotify_web["Spotify Web API<br/>external api"]
  node_apple_musickit["Apple MusicKit<br/>external api"]
  node_youtube_data["YouTube Data API<br/>external api"]
end

node_app_boot -->|"mounts"| node_app_shell
node_app_shell -->|"controls"| node_audio_player
node_app_shell -->|"themes"| node_theme
node_app_shell -->|"spotify ui"| node_spotify_flow
node_app_shell -->|"apple ui"| node_apple_api
node_app_shell -->|"youtube ui"| node_youtube_entry
node_app_shell -->|"local library"| node_playlist_data
node_app_shell -->|"renders"| node_art_assets
node_spotify_flow -->|"auth"| node_spotify_auth
node_spotify_flow -->|"fetches"| node_spotify_api
node_spotify_api -->|"calls"| node_spotify_web
node_apple_api -->|"auth"| node_apple_auth
node_apple_auth -->|"calls"| node_apple_musickit
node_youtube_entry -->|"auth"| node_youtube_auth
node_youtube_entry -->|"fetches"| node_youtube_api
node_youtube_api -->|"calls"| node_youtube_data
node_audio_player -->|"resolves"| node_yt_dlp
node_electron_main -->|"bridges"| node_electron_preload
node_electron_preload -->|"ipc"| node_app_shell
node_electron_main -->|"bundles"| node_install_yt_dlp
node_vite_config -->|"builds"| node_app_boot
node_electron_main -.->|"theme icon"| node_art_assets

click node_electron_main "https://github.com/ronan-hughes74/cupid-music-player/blob/main/electron/main.cjs"
click node_electron_preload "https://github.com/ronan-hughes74/cupid-music-player/blob/main/electron/preload.cjs"
click node_app_boot "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/main.jsx"
click node_app_shell "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/App.jsx"
click node_audio_player "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/useAudioPlayer.js"
click node_theme "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/useTheme.js"
click node_spotify_flow "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/useSpotifyPlayer.js"
click node_spotify_auth "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/spotify/auth.js"
click node_spotify_api "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/spotify/api.js"
click node_apple_auth "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/apple/auth.js"
click node_apple_api "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/apple/api.js"
click node_youtube_entry "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/youtube/index.js"
click node_youtube_auth "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/youtube/auth.js"
click node_youtube_api "https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/youtube/api.js"
click node_playlist_data "https://github.com/ronan-hughes74/cupid-music-player/blob/main/audio/playlist.json"
click node_art_assets "https://github.com/ronan-hughes74/cupid-music-player/tree/main/assets"
click node_install_yt_dlp "https://github.com/ronan-hughes74/cupid-music-player/blob/main/scripts/install-yt-dlp.cjs"
click node_vite_config "https://github.com/ronan-hughes74/cupid-music-player/blob/main/vite.config.js"

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_electron_main,node_electron_preload toneBlue
class node_app_boot,node_app_shell,node_theme toneAmber
class node_audio_player,node_spotify_flow,node_spotify_auth,node_spotify_api,node_apple_auth,node_apple_api,node_youtube_entry,node_youtube_auth,node_youtube_api toneMint
class node_playlist_data,node_art_assets toneRose
class node_install_yt_dlp,node_vite_config toneIndigo
class node_yt_dlp,node_spotify_web,node_apple_musickit,node_youtube_data toneTeal
```

## Components

### Desktop Shell

Electron main process and privileged bridge

- [Main Process](https://github.com/ronan-hughes74/cupid-music-player/blob/main/electron/main.cjs): electron shell · Owns windowing, lifecycle, filesystem, and privileged Node work · `electron/main.cjs`
- [Preload Bridge](https://github.com/ronan-hughes74/cupid-music-player/blob/main/electron/preload.cjs): ipc bridge · Exposes a limited API surface to the renderer · `electron/preload.cjs`

### Renderer UI

React/Vite app and UI-side state

- [App Boot](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/main.jsx): react entry · Bootstraps the renderer application · `src/main.jsx`
- [App Shell](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/App.jsx): react composer · Central composition for player, browsing, and settings · `src/App.jsx`
- [Theme State](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/useTheme.js): ui theme hook · Persists and applies pink/blue theme choice · `src/useTheme.js`

### Provider Adapters

Local and remote music sources plus auth and metadata

- [Audio Player](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/useAudioPlayer.js): HTML5 audio hook · Loads sources and manages play, pause, seek, and state · `src/useAudioPlayer.js`
- [Spotify Flow](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/useSpotifyPlayer.js): player flow · Coordinates Spotify auth, browsing, and track handoff · `src/useSpotifyPlayer.js`
- [Spotify Auth](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/spotify/auth.js): oauth pkce · Handles Spotify authorization · `src/spotify/auth.js`
- [Spotify API](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/spotify/api.js): metadata api · Fetches Spotify playlists and track metadata · `src/spotify/api.js`
- [Apple Auth](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/apple/auth.js): music kit auth · Manages Apple Music developer and library access · `src/apple/auth.js`
- [Apple API](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/apple/api.js): library api · Reads Apple Music library playlists and metadata · `src/apple/api.js`
- [YouTube Entry](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/youtube/index.js): provider entry · Dispatches public and OAuth-backed YouTube flows · `src/youtube/index.js`
- [YouTube Auth](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/youtube/auth.js): oauth flow · Handles Google OAuth when enabled · `src/youtube/auth.js`
- [YouTube API](https://github.com/ronan-hughes74/cupid-music-player/blob/main/src/youtube/api.js): data api · Fetches YouTube playlists and track data · `src/youtube/api.js`

### Assets

Artwork, animation, and local library content

- [Playlist Data](https://github.com/ronan-hughes74/cupid-music-player/blob/main/audio/playlist.json): local library · Seed metadata for bundled local audio files · `audio/playlist.json`
- [Artwork & Animations](https://github.com/ronan-hughes74/cupid-music-player/tree/main/assets): visual assets · Theme art, record swaps, needle motion, and icons · `assets`

### Build & Config

Packaging, install scripts, and environment-driven setup

- [Install yt-dlp](https://github.com/ronan-hughes74/cupid-music-player/blob/main/scripts/install-yt-dlp.cjs): install script · Fetches the yt-dlp runtime during setup or packaging · `scripts/install-yt-dlp.cjs`
- [Vite Config](https://github.com/ronan-hughes74/cupid-music-player/blob/main/vite.config.js): build config · Build-time environment exposure and renderer config · `vite.config.js`

### External Services

Third-party APIs and runtime tools

- **yt-dlp**: runtime tool · Resolves playable audio from provider sources
- **Spotify Web API**: external api · Remote Spotify discovery and metadata service
- **Apple MusicKit**: external api · Apple Music access and developer-token-backed auth
- **YouTube Data API**: external api · YouTube playlist and content lookup service

## Connections

- 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
