# syeo66/shufflify architecture

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

- Interactive diagram: https://gitdiagram.com/syeo66/shufflify
- Repository: https://github.com/syeo66/shufflify

## Overview

##### Main Components

a) Frontend Layer:
- Svelte-based Single Page Application (SPA) as the primary user interface
- Main components hierarchy:
- App.svelte as the root component
- Header, Login, Main, Configuration, Playlists, Stats, and UserInfo components

b) State Management Layer:
- Svelte stores:
- token store (authentication)
- playlists store
- configuration store
- stats store
- availableDevice store
- savedTrackCount store

c) External Integration Layer:
- Spotify Web API integration
- Authentication flow with Spotify

d) Function Layer:
- Utility functions (chunkArray, getToken, signInWithSpotify)
- Query functions (retrievePlaylists, retrieveUserData)

**[User Browser]**
- ↓
**[Nginx Server] → [Static Assets]**
- ↓
**[Svelte Frontend]**
- ↓
**[State Management (Stores)]**
- ↓
**[Function Layer]**
- ↓
**[Spotify Web API]**

##### Important Relationships to Highlight

- Authentication Flow:
- Login.svelte → signInWithSpotify.ts → Spotify OAuth → token store
- Data Flow:
- Playlists.svelte → retrievePlaylists.ts → Spotify API → playlists store
- UserInfo.svelte → retrieveUserData.ts → Spotify API → relevant stores

##### Technical Stack Elements

- Svelte as the frontend framework
- TypeScript for type safety
- Vite as the build tool
- Nginx as the web server
- Docker for containerization

##### Additional Elements

- Version/environment indicators
- Error handling paths
- Asynchronous operations

##### The modern frontend architecture using Svelte and TypeScript

Remember to use standardized symbols for:
- Components (rectangles)
- External services (clouds)

This will create a comprehensive yet clear representation of the shufflify application's architecture, making it easy for team members to understand the system's structure and data flow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Browser
        UI[User Interface]
    end

    subgraph "Frontend Components"
        App["App Component"]
        Header["Header"]
        Login["Login"]
        Main["Main"]
        Config["Configuration"]
        Playlists["Playlists"]
        Stats["Stats"]
        UserInfo["User Info"]
    end

    subgraph "State Management"
        TokenStore[(Token Store)]
        PlaylistStore[(Playlists Store)]
        ConfigStore[(Config Store)]
        StatsStore[(Stats Store)]
        DeviceStore[(Device Store)]
        TrackStore[(Track Count Store)]
    end

    subgraph "Function Layer"
        AuthFunc["Authentication"]
        TokenFunc["Token Management"]
        UtilFunc["Utilities"]
    end

    subgraph "External Integration"
        QueryFunc["Query Functions"]
        SpotifyAPI["Spotify Web API"]
    end

    subgraph "Infrastructure"
        Nginx["Nginx Server"]
        Docker["Docker Container"]
        Vite["Vite Build"]
    end

    UI --> Nginx
    Nginx --> App
    App --> Header
    App --> Login
    App --> Main
    App --> Config
    App --> Playlists
    App --> Stats
    App --> UserInfo

    Login --> AuthFunc
    AuthFunc --> SpotifyAPI
    AuthFunc --> TokenStore

    Playlists --> QueryFunc
    UserInfo --> QueryFunc
    QueryFunc --> SpotifyAPI

    Main --> PlaylistStore
    Config --> ConfigStore
    Stats --> StatsStore
    UserInfo --> DeviceStore
    UserInfo --> TrackStore

    %% Click events for component mapping
    click App "https://github.com/syeo66/shufflify/blob/main/src/App.svelte"
    click Header "https://github.com/syeo66/shufflify/blob/main/src/lib/Header.svelte"
    click Login "https://github.com/syeo66/shufflify/blob/main/src/lib/Login.svelte"
    click Main "https://github.com/syeo66/shufflify/blob/main/src/lib/Main.svelte"
    click Config "https://github.com/syeo66/shufflify/blob/main/src/lib/Configuration.svelte"
    click Playlists "https://github.com/syeo66/shufflify/blob/main/src/lib/Playlists.svelte"
    click Stats "https://github.com/syeo66/shufflify/blob/main/src/lib/Stats.svelte"
    click UserInfo "https://github.com/syeo66/shufflify/blob/main/src/lib/UserInfo.svelte"
    click TokenStore "https://github.com/syeo66/shufflify/blob/main/src/stores/token.ts"
    click PlaylistStore "https://github.com/syeo66/shufflify/blob/main/src/stores/playlists.ts"
    click ConfigStore "https://github.com/syeo66/shufflify/blob/main/src/stores/configuration.ts"
    click StatsStore "https://github.com/syeo66/shufflify/blob/main/src/stores/stats.ts"
    click DeviceStore "https://github.com/syeo66/shufflify/blob/main/src/stores/availableDevice.ts"
    click TrackStore "https://github.com/syeo66/shufflify/blob/main/src/stores/savedTrackCount.ts"
    click AuthFunc "https://github.com/syeo66/shufflify/blob/main/src/functions/signInWithSpotify.ts"
    click TokenFunc "https://github.com/syeo66/shufflify/blob/main/src/functions/getToken.ts"
    click UtilFunc "https://github.com/syeo66/shufflify/blob/main/src/functions/chunkArray.ts"
    click QueryFunc "https://github.com/syeo66/shufflify/tree/main/src/queries"
    click Nginx "https://github.com/syeo66/shufflify/blob/main/nginx.conf"
    click Docker "https://github.com/syeo66/shufflify/tree/main/Dockerfile"
    click Vite "https://github.com/syeo66/shufflify/blob/main/vite.config.ts"

    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef store fill:#2ecc71,stroke:#27ae60,color:white
    classDef function fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white
    classDef infrastructure fill:#95a5a6,stroke:#7f8c8d,color:white

    class App,Header,Login,Main,Config,Playlists,Stats,UserInfo frontend
    class TokenStore,PlaylistStore,ConfigStore,StatsStore,DeviceStore,TrackStore store
    class AuthFunc,TokenFunc,UtilFunc,QueryFunc function
    class SpotifyAPI external
    class Nginx,Docker,Vite infrastructure
```
