Technology Stack
Frontend Framework
React 18 with Vite for fast builds and hot module replacement
Routing
React Router DOM for declarative client-side routing
UI Library
Material-UI (MUI) with Emotion for styling
State Management
Nanostores for lightweight, reactive global state
System Architecture
Project Structure
All source code is organized under the
src/ directory with clear separation by concern.Core Design Patterns
1. Container/Presentational Pattern
Components are organized into smart containers (pages) and presentational components:- Pages (
src/pages/): Handle data fetching, routing params, and business logic - Components (
src/components/): Receive props and render UI, accessing stores when needed
2. Reactive State Management
Nanostores provide a lightweight pub/sub pattern where components subscribe to specific state slices:3. Shared Audio Element
A singleHTMLAudioElement instance (src/audioEl.js) is shared across the application to maintain consistent playback state:
- Single source of truth for playback
- Efficient memory usage
- Consistent event handling
4. Media Session Integration
The player integrates with the browser’s Media Session API to provide native OS-level controls:See
src/stores/playerStore.js:209-221 for the Media Session API implementationData Flow
User Interaction Flow
- User interacts with UI (clicks play, adds to queue, etc.)
- Component calls an action from the appropriate store
- Store updates state and triggers side effects (API calls, audio playback)
- Audio element fires events that update store state
- Components subscribed to the store automatically re-render
Key Features
Music Playback & Streaming
Music Playback & Streaming
Audio streaming is handled through a custom API proxy system. Track URLs are fetched from the YouTube API and proxied to avoid CORS issues. The
audioEl.js singleton manages playback state.Queue Management
Queue Management
The playback queue is managed entirely in
playerStore.js. Users can:- Add tracks to the end of the queue
- Play next (insert after current track)
- View and navigate the queue via
QueueDrawer
Search System
Search System
Multi-faceted search allows users to find:
- Tracks
- Albums
- Artists
searchStore.js with dedicated result components for each type.Persistent Data
Persistent Data
IndexedDB stores user data locally:
- Liked tracks
- Recently played songs
- Playback history
src/lib/idb.js for the storage implementation.Routing Architecture
The application uses a nested routing structure defined insrc/routes.jsx:
All routes render inside the
<Outlet /> in App.jsx, maintaining the persistent player and navigation.Layout System
TheApp.jsx component establishes a fixed layout structure:
Next Steps
State Management
Learn how Nanostores power reactive state
Component Structure
Explore the component hierarchy and patterns