# sapirkro/spotify-clone architecture

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

- Interactive diagram: https://gitdiagram.com/sapirkro/spotify-clone
- Repository: https://github.com/sapirkro/spotify-clone

## Overview

##### Detailed Component Breakdown

a) UI Layer (Blue Section):
- HomeScreen
- LibraryScreen
- LikedSongsScreen
- LoginScreen
- PlaylistInfoScreen
- SongInfoScreen
- To reusable components:
- ArtistCard
- RecentlyPlayedCard
- SongItem
- FloatingPlayer

b) State Management (Green Section):
- PlayerContext (central state management)
- AsyncStorage (local data persistence)

c) API Integration (Yellow Section):
- SpotifyApi Module
- Authentication Flow
- API Endpoints:
- Recently Played
- Playlists
- Top Artists
- Liked Songs

d) Media Playback (Purple Section):
- Expo AV Integration
- Audio Player Controls

- User interactions (green)
- API calls (blue)
- Media streaming (red)
- Authentication flow (orange)

##### External Services Integration

**Mobile App <-> Spotify Web API**
- ↑          ↑

- ┘
- Authentication Flow

##### Important Elements

- Login initiation
- OAuth2 redirect
- Token management
- Refresh token flow

- Data persistence flow:
- AsyncStorage interactions
- Caching strategy

- Media playback pipeline:
- Audio stream handling
- Player state management
- 30-second preview limitation

##### Technical Stack Callouts

- React Native/Expo
- Spotify Web API
- Expo AV
- Axios
- AsyncStorage

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Mobile["Mobile Application (React Native/Expo)"]
        subgraph UI["UI Layer"]
            HS["HomeScreen"]:::screen
            LS["LibraryScreen"]:::screen
            LKS["LikedSongsScreen"]:::screen
            LGS["LoginScreen"]:::screen
            PIS["PlaylistInfoScreen"]:::screen
            SIS["SongInfoScreen"]:::screen
            
            subgraph Components["Reusable Components"]
                AC["ArtistCard"]:::component
                RPC["RecentlyPlayedCard"]:::component
                SI["SongItem"]:::component
                FP["FloatingPlayer"]:::component
            end
        end

        subgraph State["State Management"]
            PC["PlayerContext"]:::state
            AS["AsyncStorage"]:::storage
        end

        subgraph API["API Integration"]
            SA["Spotify API Module"]:::api
            AF["Authentication Flow"]:::auth
            
            subgraph Endpoints["API Endpoints"]
                RP["Recently Played"]:::endpoint
                PL["Playlists"]:::endpoint
                TA["Top Artists"]:::endpoint
                LS2["Liked Songs"]:::endpoint
            end
        end

        subgraph Media["Media Playback"]
            EAV["Expo AV Integration"]
            APC["Audio Player Controls"]
        end

        APP["App Entry Point"]:::main
        SN["Stack Navigator"]:::nav
    end

    subgraph External["External Services"]
        SAPI["Spotify Web API"]
        AUTH["Authentication Service"]
        MCD["Media Content Delivery"]
    end

    %% Connections
    APP --> SN
    SN --> HS & LS & LKS & LGS & PIS & SIS
    Components --> |Used by| UI
    PC --> |State Management| UI
    PC --> |Controls| Media
    SA --> |Interfaces with| SAPI
    AF --> |Authenticates| AUTH
    Media --> |Streams from| MCD
    AS --> |Persists| PC

    %% Styles
    classDef screen fill:#e1f5fe,stroke:#01579b
    classDef component fill:#e8f5e9,stroke:#2e7d32
    classDef state fill:#fff3e0,stroke:#ff6f00
    classDef storage fill:#ede7f6,stroke:#4527a0
    classDef api fill:#fce4ec,stroke:#c2185b
    classDef auth fill:#f3e5f5,stroke:#7b1fa2
    classDef endpoint fill:#f1f8e9,stroke:#33691e
    classDef main fill:#bbdefb,stroke:#1565c0
    classDef nav fill:#e0f2f1,stroke:#00695c

    %% Click Events
    click HS "https://github.com/SapirKro/Spotify-Clone/blob/main/screens/HomeScreen.js"
    click LS "https://github.com/SapirKro/Spotify-Clone/blob/main/screens/LibraryScreen.js"
    click LKS "https://github.com/SapirKro/Spotify-Clone/blob/main/screens/LikedSongsScreen.js"
    click LGS "https://github.com/SapirKro/Spotify-Clone/blob/main/screens/LoginScreen.js"
    click PIS "https://github.com/SapirKro/Spotify-Clone/blob/main/screens/PlaylistInfoScreen.js"
    click SIS "https://github.com/SapirKro/Spotify-Clone/blob/main/screens/SongInfoScreen.js"
    click AC "https://github.com/SapirKro/Spotify-Clone/blob/main/components/ArtistCard.js"
    click RPC "https://github.com/SapirKro/Spotify-Clone/blob/main/components/RecentlyPlayedCard.js"
    click SI "https://github.com/SapirKro/Spotify-Clone/blob/main/components/SongItem.js"
    click FP "https://github.com/SapirKro/Spotify-Clone/blob/main/FloatingPlayer.js"
    click PC "https://github.com/SapirKro/Spotify-Clone/blob/main/PlayerContext.js"
    click SN "https://github.com/SapirKro/Spotify-Clone/blob/main/StackNavigator.js"
    click SA "https://github.com/SapirKro/Spotify-Clone/blob/main/spotifyApi.js"
    click APP "https://github.com/SapirKro/Spotify-Clone/blob/main/App.js"
```
