# jesusalberto11/mymusicplayer architecture

> Architecture diagram of the GitHub repository jesusalberto11/mymusicplayer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jesusalberto11/mymusicplayer
- Repository: https://github.com/jesusalberto11/mymusicplayer

## Overview

##### Main Components
- Frontend (React SPA)
– src/ folder: UI components, pages, hooks, state (Zustand), routing (React Router), i18n.
– Audio engine: HTML5 audio element controlled by React.
- Desktop Runtime (Tauri)
– Tauri bridge (JavaScript↔Rust IPC) configured in src-tauri/tauri.conf.json.
- Backend (Rust)
– src-tauri/src/main.rs: commands exposed to the frontend.
– id3 crate: reads file metadata.
– build.rs: any build-time file operations.
- File System Storage
– Local music directory (MUSIC_PATH) containing .mp3 files.
– Cover images folder and image‐path template (SONGS_COVERS_FOLDER, SONGS_IMAGES_PATH).
- External Services (optional)
– No external web services; all data is local.

##### Relationships & Data Flows
- Startup Flow
1. React app initializes (main.tsx → App.tsx).
2. Calls Tauri command “loadSongs” via JS API.
3. Rust scans MUSIC_PATH, parses ID3 tags, returns song list with metadata & cover paths.
4. Frontend stores list in MusicPlayerStore/PlaylistsStore.
- Playback Flow
1. User clicks play in UI.
2. React invokes HTML5 audio API directly.
3. UI updates current song state via Zustand; controls (VolumeControl, ProgressBar) reactively update.
- Settings & Playlists
– UI components (SettingsPage, PlaylistsPage) read/write state in stores; persist playlists in memory or local storage if configured.

##### Architectural Patterns
- Layered Separation
– Presentation: React components & CSS.
– State: Zustand stores.
– System/API: Tauri commands (Rust).
- MVVM-like data binding via hooks (useMusicPlayer, usePlaylists)
- Local Persistence = File System (no external DB)
- IPC Boundary: clear JS ↔ Rust separation via Tauri.

##### Call Out Key Technologies
- Frontend: React, React Router, React i18Next, Zustand, Vite, TypeScript, CSS Modules.
- Backend: Rust, Tauri, id3 crate, Cargo.
- Build & Config: Cargo.toml, build.rs, tauri.conf.json, .env for paths.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "React Frontend" 
        direction TB
        A1["src/"] 
        A2["src/main.tsx"] 
        A3["index.html"] 
        subgraph "Components"
            direction TB
            B1["src/components/"] 
            B2["src/components/music player/"] 
            B3["src/components/layout/"] 
            B4["src/components/shared/"] 
        end
        subgraph "Pages & Routing"
            direction TB
            C1["src/pages/"] 
            C2["src/router/index.tsx"] 
        end
        subgraph "State & Hooks"
            direction TB
            D1["src/store/MusicPlayerStore.tsx"] 
            D2["src/store/PlaylistsStore.tsx"] 
            D3["src/hooks/"] 
        end
        subgraph "Utilities & Config"
            direction TB
            E1["src/i18n/"] 
            E2["src/helpers/musicParser.ts"] 
            E3["src/styles.css"] 
            E4["src/styles/"] 
            E5["vite.config.ts"] 
            E6["tsconfig.json"] 
            E7["tsconfig.node.json"] 
        end
        subgraph "Audio Engine"
            direction TB
            F1["MusicPlayer.tsx"] 
            F2["MusicPlayerControls.tsx"] 
            F3["ProgressBar.tsx"] 
            F4["VolumeControl.tsx"] 
        end
    end

    %% IPC Layer
    subgraph "Tauri IPC Bridge"
        direction TB
        G1["src-tauri/tauri.conf.json"] 
        G2["src-tauri/build.rs"] 
    end

    %% Backend Layer
    subgraph "Rust Backend"
        direction TB
        H1["src-tauri/Cargo.toml"] 
        H2["src-tauri/Cargo.lock"] 
        H3["src-tauri/src/main.rs"] 
    end

    %% File System
    subgraph "Local File System"
        direction TB
        I1["MUSIC_PATH (.mp3 files)"] 
        I2["SONGS_COVERS_FOLDER"] 
        I3["SONGS_IMAGES_PATH"] 
        I4["src-tauri/example.env.md"] 
    end

    %% Flows
    A2 -->|"init App"| A1
    A1 -->|"call loadSongs"| G1
    G1 -->|"invoke loadSongs"| H3
    H3 -->|"scan FS & parse ID3"| I1
    H3 -->|"load covers paths"| I2
    H3 -->|"return metadata"| G1
    G1 -->|"metadata list"| A1
    A1 -->|"store in Zustand"| D1
    A2 -->|"play command"| F1
    F1 -->|"HTML5 audio API"| F1

    %% Click events
    click A1 "https://github.com/jesusalberto11/mymusicplayer/tree/main/src/"
    click A2 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src/main.tsx"
    click A3 "https://github.com/jesusalberto11/mymusicplayer/blob/main/index.html"
    click B1 "https://github.com/jesusalberto11/mymusicplayer/tree/main/src/components/"
    click B2 "https://github.com/jesusalberto11/mymusicplayer/tree/main/src/components/music player/"
    click B3 "https://github.com/jesusalberto11/mymusicplayer/tree/main/src/components/layout/"
    click B4 "https://github.com/jesusalberto11/mymusicplayer/tree/main/src/components/shared/"
    click C1 "https://github.com/jesusalberto11/mymusicplayer/tree/main/src/pages/"
    click C2 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src/router/index.tsx"
    click D1 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src/store/MusicPlayerStore.tsx"
    click D2 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src/store/PlaylistsStore.tsx"
    click D3 "https://github.com/jesusalberto11/mymusicplayer/tree/main/src/hooks/"
    click E1 "https://github.com/jesusalberto11/mymusicplayer/tree/main/src/i18n/"
    click E2 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src/helpers/musicParser.ts"
    click E3 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src/styles.css"
    click E4 "https://github.com/jesusalberto11/mymusicplayer/tree/main/src/styles/"
    click E5 "https://github.com/jesusalberto11/mymusicplayer/blob/main/vite.config.ts"
    click E6 "https://github.com/jesusalberto11/mymusicplayer/blob/main/tsconfig.json"
    click E7 "https://github.com/jesusalberto11/mymusicplayer/blob/main/tsconfig.node.json"
    click F1 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src/components/music player/MusicPlayer.tsx"
    click F2 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src/components/music player/MusicPlayerControls.tsx"
    click F3 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src/components/music player/ProgressBar.tsx"
    click F4 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src/components/music player/VolumeControl.tsx"
    click G1 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src-tauri/tauri.conf.json"
    click G2 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src-tauri/build.rs"
    click H1 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src-tauri/Cargo.toml"
    click H2 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src-tauri/Cargo.lock"
    click H3 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src-tauri/src/main.rs"
    click I4 "https://github.com/jesusalberto11/mymusicplayer/blob/main/src-tauri/example.env.md"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000
    classDef ipc fill:#90EE90,stroke:#000
    classDef backend fill:#FFA500,stroke:#000
    classDef fs fill:#D3D3D3,stroke:#000

    class A1,A2,A3,B1,B2,B3,B4,C1,C2,D1,D2,D3,E1,E2,E3,E4,E5,E6,E7,F1,F2,F3,F4 frontend
    class G1,G2 ipc
    class H1,H2,H3 backend
    class I1,I2,I3,I4 fs
```
