# dante098t/music-app architecture

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

- Interactive diagram: https://gitdiagram.com/dante098t/music-app
- Repository: https://github.com/dante098t/music-app

## Overview

1. **Overall shape**
   - This is an iOS music streaming app built in **Swift/SwiftUI** using an **MVVM + Service** layering style.
   - The repo is organized around clear boundaries: **Views** for presentation, **ViewModels** for UI state/orchestration, **Services** for backend/audio/persistence operations, and **Models** for data structures.

2. **App bootstrap and routing**
   - The entry point is **`doan_nhom6App.swift`**, with **`ContentView.swift`** acting as the top shell.
   - **`Views/RootView.swift`** is the main route switchboard: it decides whether the user sees authentication, home, premium, artist, or admin areas based on session/app state.
   - **`Managers/AppState.swift`** holds shared reactive state such as login/session and player-related global state.

3. **Presentation layer by role**
   - The UI is split into role-driven surfaces:
     - **Auth:** `LoginView`, `ResigterView`
     - **Standard user/home:** `HomeView`, `SideMenuView`, `ProfileView`
     - **Player:** `PlayerView`, `QueueView`, `AlbumDetailView`, `RecentlyPlayedView`, `FavoriteSongsView`
     - **Premium:** `PremiumHomeView`, `PremiumView`, `PremiumPlayerView`, `SearchResultView`
     - **Artist:** `ArtistDashboardView`
     - **Admin:** `AdminView`
   - This suggests the app is not just a consumer player; it has separate operational surfaces for users, creators, and platform staff.

4. **Reusable UI components**
   - The `Components` folder contains small reusable UI pieces such as **`AlbumCard`**, **`SongCard`**, **`PremiumBanner`**, and **`AnimatedBackgroundView`**.
   - These are visual building blocks used across multiple screens to keep the larger views thin and consistent.

5. **ViewModels as the orchestration layer**
   - The `ViewModels` folder contains the stateful bridge between SwiftUI and services:
     - **`AuthViewModel`** for sign-in/sign-up flows
     - **`HomeViewModel`** for feed/discovery content
     - **`PlayerViewModel`** for playback state and queue control
     - **`SongViewModel`** for track-level data shaping
     - **`SideMenuViewModel`** for navigation/menu state
   - In diagram terms, these are the main consumer of services and the main source of data binding into the UI.

6. **Service layer and domain operations**
   - The `Services` folder is the business/integration layer. Key services include:
     - **`AuthService` / `AuthManager`** for authentication and session handling
     - **`SupabaseService`** as the backend client gateway
     - **`SongService`**, **`ArtistService`**, **`PlaylistService`** for catalog/content retrieval
     - **`AudioPlayerService`** for actual playback
     - **`StorageService`** for media asset storage access
     - **`AnalyticsService`** for reports/metrics
     - **`FavoriteAlbumService`**, **`RecentlyPlayedService`**, and related managers for user interaction history
   - This layer is where most cross-cutting logic lives, keeping the views and view models relatively clean.

7. **Playback pipeline**
   - Audio playback is handled through **`AVFoundation`** via **`AudioPlayerService`**.
   - The data path is typically: UI interaction → `PlayerViewModel` → `AudioPlayerService` → remote audio asset fetched through storage/backend.
   - `QueueView`, `PlayerListView`, and `PremiumPlayerView` indicate the app supports structured playback control, not just single-track streaming.

8. **Local persistence and offline-friendly data**
   - The app includes **Core Data** via **`Persistence.swift`** and the **`doan_nhom6.xcdatamodeld`** model.
   - This is used for locally retaining user-centric data such as favorites and recently played items, through managers like **`FavoriteManager`** and **`RecentlyPlayedManager`**.
   - The local store acts as an offline-resilient cache for interaction history and preferences, separate from the cloud catalog.

9. **Cloud backend and storage**
   - The backend is **Supabase** with PostgreSQL, accessed through **`SupabaseService`**.
   - The app appears to use Supabase for:
     - Authentication/session management
     - Catalog and relational data queries
     - Role-based access control for standard users, premium users, artists, and admins
     - Storage-backed media assets through `StorageService`
   - This is the main external system boundary in the architecture.

10. **Domain model layer**
   - The `Models` folder contains the app’s core entities: **Song, Album, Artist, Playlist, Profile, Subscription, Report, Analytics, FavoriteAlbum, RecentlyPlayed, User**.
   - These models mirror both backend records and local app state, giving the app a shared vocabulary across UI, services, and persistence.
   - They are important for any architecture diagram because they sit between cloud data, Core Data, and view models.

11. **Admin, artist, and premium business sub-systems**
   - The presence of **`AdminView` / `AdminViewModel`**, **`ArtistDashboardView`**, and premium-specific views indicates separate business flows:
     - **Admin:** moderation, catalog governance, reporting, analytics
     - **Artist:** dashboard-style content/insight access
     - **Premium:** subscription-gated playback and discovery
   - These are not separate apps, but separate feature boundaries inside the same client.

12. **Key architectural flow to draw**
   - A good diagram would show:
     - **SwiftUI views** at the top
     - **ViewModels** in the middle
     - **Services** below them
     - **Supabase/PostgreSQL + Storage** on one side as remote infrastructure
     - **Core Data** on the other side as local persistence
     - **AVFoundation** as the playback engine behind `AudioPlayerService`
   - The most important data movement is: **user action → View → ViewModel → Service → backend/local store/audio engine → updated state back to UI**.

Main entry points: [`doan_nhom6/Views/RootView.swift`](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/RootView.swift) (Root view), [`doan_nhom6/ViewModels/PlayerViewModel.swift`](https://github.com/dante098t/music-app/blob/main/doan_nhom6/ViewModels/PlayerViewModel.swift) (Player VM), [`doan_nhom6/Services/SupabaseService.swift`](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/SupabaseService.swift) (Supabase), [`doan_nhom6/Models/Song.swift`](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Models/Song.swift) (Domain models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_root["Root view<br/>route shell<br/>[RootView.swift]"]
  node_content["Content view<br/>shell view<br/>[ContentView.swift]"]
  node_adminvm["Admin VM<br/>view model"]
  node_login["Login<br/>auth screen<br/>[LoginView.swift]"]
  node_register["Register<br/>auth screen<br/>[ResigterView.swift]"]
  node_home["Home<br/>main screen<br/>[HomeView.swift]"]
  node_menu["Side menu<br/>navigation UI<br/>[SideMenuView.swift]"]
  node_player["Player<br/>playback screen<br/>[PlayerView.swift]"]
  node_queue["Queue<br/>playback screen<br/>[QueueView.swift]"]
  node_premium["Premium home<br/>premium screen"]
  node_admin["Admin<br/>[AdminView.swift]"]
  node_artistdash["Artist dash<br/>artist screen"]
end

subgraph group_orchestration["Orchestration"]
  node_app["App entry<br/>SwiftUI app"]
  node_appstate["App state<br/>shared state<br/>[AppState.swift]"]
  node_authvm["Auth VM<br/>view model"]
  node_homevm["Home VM<br/>view model"]
  node_playervm["Player VM<br/>view model"]
  node_sidevm["Menu VM<br/>view model"]
  node_songvm["Song VM<br/>view model"]
end

subgraph group_services["Services"]
  node_authsvc["Auth service<br/>auth backend<br/>[AuthService.swift]"]
  node_supabase[("Supabase<br/>backend gateway")]
  node_audio{{"Audio engine<br/>playback service"}}
  node_catalog["Catalog services<br/>content services<br/>[SongService.swift]"]
  node_storage[("Storage")]
  node_metrics["Analytics<br/>reporting service"]
  node_fav["Favorites<br/>interaction store"]
  node_recent["Recents<br/>history store"]
end

subgraph group_data["Data"]
  node_persistence[("Core Data<br/>local store<br/>[Persistence.swift]")]
  node_models["Domain models<br/>entities<br/>[Song.swift]"]
end

node_app -->|"launches"| node_content
node_content -->|"hosts"| node_root
node_root -->|"routes to"| node_login
node_root -->|"routes to"| node_home
node_root -->|"routes to"| node_premium
node_root -->|"routes to"| node_artistdash
node_root -->|"routes to"| node_admin
node_root -->|"reads state"| node_appstate
node_login -->|"binds to"| node_authvm
node_register -->|"binds to"| node_authvm
node_home -->|"binds to"| node_homevm
node_home -->|"uses"| node_sidevm
node_player -->|"binds to"| node_playervm
node_queue -->|"binds to"| node_playervm
node_premium -->|"uses"| node_playervm
node_admin -->|"binds to"| node_adminvm
node_artistdash -->|"uses"| node_metrics
node_authvm -->|"calls"| node_authsvc
node_authsvc -->|"uses"| node_supabase
node_homevm -->|"calls"| node_catalog
node_songvm -->|"calls"| node_catalog
node_playervm -->|"controls"| node_audio
node_audio -->|"streams from"| node_storage
node_catalog -->|"queries"| node_supabase
node_metrics -->|"reports to"| node_supabase
node_fav -->|"stores"| node_persistence
node_recent -->|"stores"| node_persistence
node_persistence -->|"persists"| node_models
node_supabase -->|"serves"| node_models
node_appstate -->|"shares state"| node_playervm
node_homevm -->|"uses"| node_models
node_playervm -->|"uses"| node_models

click node_app "https://github.com/dante098t/music-app/blob/main/doan_nhom6/doan_nhom6App.swift"
click node_root "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/RootView.swift"
click node_content "https://github.com/dante098t/music-app/blob/main/doan_nhom6/ContentView.swift"
click node_appstate "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Managers/AppState.swift"
click node_authvm "https://github.com/dante098t/music-app/blob/main/doan_nhom6/ViewModels/AuthViewModel.swift"
click node_homevm "https://github.com/dante098t/music-app/blob/main/doan_nhom6/ViewModels/HomeViewModel.swift"
click node_playervm "https://github.com/dante098t/music-app/blob/main/doan_nhom6/ViewModels/PlayerViewModel.swift"
click node_sidevm "https://github.com/dante098t/music-app/blob/main/doan_nhom6/ViewModels/SideMenuViewModel.swift"
click node_songvm "https://github.com/dante098t/music-app/blob/main/doan_nhom6/ViewModels/SongViewModel.swift"
click node_adminvm "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Admin/AdminViewModel.swift"
click node_login "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Auth /LoginView.swift"
click node_register "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Auth /ResigterView.swift"
click node_home "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Home/HomeView.swift"
click node_menu "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Home/SideMenuView.swift"
click node_player "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Player/PlayerView.swift"
click node_queue "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Player/QueueView.swift"
click node_premium "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/User Premium/PremiumHomeView.swift"
click node_admin "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Admin/AdminView.swift"
click node_artistdash "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Artist /ArtistDashboardView.swift"
click node_authsvc "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/AuthService.swift"
click node_supabase "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/SupabaseService.swift"
click node_audio "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/AudioPlayerService.swift"
click node_catalog "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/SongService.swift"
click node_storage "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/StorageService.swift"
click node_metrics "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/AnalyticsService.swift"
click node_fav "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/FavoriteManager.swift"
click node_recent "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/RecentlyPlayedManager.swift"
click node_persistence "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Persistence.swift"
click node_models "https://github.com/dante098t/music-app/blob/main/doan_nhom6/Models/Song.swift"

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_root,node_content,node_adminvm,node_login,node_register,node_home,node_menu,node_player,node_queue,node_premium,node_admin,node_artistdash toneBlue
class node_app,node_appstate,node_authvm,node_homevm,node_playervm,node_sidevm,node_songvm toneAmber
class node_authsvc,node_supabase,node_audio,node_catalog,node_storage,node_metrics,node_fav,node_recent toneMint
class node_persistence,node_models toneRose
```

## Components

### Presentation

SwiftUI screens and reusable UI components

- [Root view](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/RootView.swift): route shell · Top-level route switchboard for auth, home, premium, artist, and admin areas · `doan_nhom6/Views/RootView.swift`
- [Content view](https://github.com/dante098t/music-app/blob/main/doan_nhom6/ContentView.swift): shell view · Primary app container view · `doan_nhom6/ContentView.swift`
- [Admin VM](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Admin/AdminViewModel.swift): view model · Supports admin dashboard workflows · `doan_nhom6/Views/Admin/AdminViewModel.swift`
- [Login](https://github.com/dante098t/music-app/blob/HEAD/doan_nhom6/Views/Auth%20/LoginView.swift): auth screen · Sign-in screen · `doan_nhom6/Views/Auth /LoginView.swift`
- [Register](https://github.com/dante098t/music-app/blob/HEAD/doan_nhom6/Views/Auth%20/ResigterView.swift): auth screen · Account creation screen · `doan_nhom6/Views/Auth /ResigterView.swift`
- [Home](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Home/HomeView.swift): main screen · Primary user home screen · `doan_nhom6/Views/Home/HomeView.swift`
- [Side menu](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Home/SideMenuView.swift): navigation UI · App navigation drawer and shortcuts · `doan_nhom6/Views/Home/SideMenuView.swift`
- [Player](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Player/PlayerView.swift): playback screen · Now-playing controls and track playback UI · `doan_nhom6/Views/Player/PlayerView.swift`
- [Queue](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Player/QueueView.swift): playback screen · Playback queue and upcoming tracks · `doan_nhom6/Views/Player/QueueView.swift`
- [Premium home](https://github.com/dante098t/music-app/blob/HEAD/doan_nhom6/Views/User%20Premium/PremiumHomeView.swift): premium screen · Premium user landing and subscription-facing UI · `doan_nhom6/Views/User Premium/PremiumHomeView.swift`
- [Admin](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Views/Admin/AdminView.swift): admin screen · Administrative operations and moderation surface · `doan_nhom6/Views/Admin/AdminView.swift`
- [Artist dash](https://github.com/dante098t/music-app/blob/HEAD/doan_nhom6/Views/Artist%20/ArtistDashboardView.swift): artist screen · Creator dashboard surface · `doan_nhom6/Views/Artist /ArtistDashboardView.swift`

### Orchestration

App state and view models that coordinate UI flow

- [App entry](https://github.com/dante098t/music-app/blob/main/doan_nhom6/doan_nhom6App.swift): SwiftUI app · Bootstraps the application and initial environment · `doan_nhom6/doan_nhom6App.swift`
- [App state](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Managers/AppState.swift): shared state · Global reactive app and player state · `doan_nhom6/Managers/AppState.swift`
- [Auth VM](https://github.com/dante098t/music-app/blob/main/doan_nhom6/ViewModels/AuthViewModel.swift): view model · Coordinates sign-in and registration flows · `doan_nhom6/ViewModels/AuthViewModel.swift`
- [Home VM](https://github.com/dante098t/music-app/blob/main/doan_nhom6/ViewModels/HomeViewModel.swift): view model · Drives home feed and discovery state · `doan_nhom6/ViewModels/HomeViewModel.swift`
- [Player VM](https://github.com/dante098t/music-app/blob/main/doan_nhom6/ViewModels/PlayerViewModel.swift): view model · Controls playback state and queue orchestration · `doan_nhom6/ViewModels/PlayerViewModel.swift`
- [Menu VM](https://github.com/dante098t/music-app/blob/main/doan_nhom6/ViewModels/SideMenuViewModel.swift): view model · Handles side menu and navigation state · `doan_nhom6/ViewModels/SideMenuViewModel.swift`
- [Song VM](https://github.com/dante098t/music-app/blob/main/doan_nhom6/ViewModels/SongViewModel.swift): view model · Shapes track-level song data for the UI · `doan_nhom6/ViewModels/SongViewModel.swift`

### Services

Backend, playback, and persistence integrations

- [Auth service](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/AuthService.swift): auth backend · Authentication and session management · `doan_nhom6/Services/AuthService.swift`
- [Supabase](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/SupabaseService.swift): backend gateway · Client gateway to cloud data and auth · `doan_nhom6/Services/SupabaseService.swift`
- [Audio engine](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/AudioPlayerService.swift): playback service · AVFoundation-backed audio playback · `doan_nhom6/Services/AudioPlayerService.swift`
- [Catalog services](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/SongService.swift): content services · Song, artist, and playlist retrieval · `doan_nhom6/Services/SongService.swift`
- [Storage](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/StorageService.swift): media storage · Remote media asset access · `doan_nhom6/Services/StorageService.swift`
- [Analytics](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/AnalyticsService.swift): reporting service · Metrics and reporting operations · `doan_nhom6/Services/AnalyticsService.swift`
- [Favorites](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/FavoriteManager.swift): interaction store · Favorite album and song interaction logic · `doan_nhom6/Services/FavoriteManager.swift`
- [Recents](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Services/RecentlyPlayedManager.swift): history store · Recently played tracking and retrieval · `doan_nhom6/Services/RecentlyPlayedManager.swift`

### Data

Domain models and local persistence

- [Core Data](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Persistence.swift): local store · Local persistence layer and data model container · `doan_nhom6/Persistence.swift`
- [Domain models](https://github.com/dante098t/music-app/blob/main/doan_nhom6/Models/Song.swift): entities · Songs, albums, artists, playlists, profiles, subscriptions, reports, and history models · `doan_nhom6/Models/Song.swift`

## Connections

- App entry → Content view: launches · App bootstraps the main content shell
- Content view → Root view: hosts · Content view embeds the route switchboard
- Root view → Login: routes to · Shows auth flow when session is missing
- Root view → Home: routes to · Shows standard user home area
- Root view → Premium home: routes to · Shows premium experience
- Root view → Artist dash: routes to · Shows artist dashboard surface
- Root view → Admin: routes to · Shows admin surface
- Root view → App state: reads state · Uses global session and player state for routing
- Login → Auth VM: binds to · Login UI is driven by auth view model
- Register → Auth VM: binds to · Registration UI is driven by auth view model
- Home → Home VM: binds to · Home screen consumes discovery and feed state
- Home → Menu VM: uses · Home screen integrates navigation menu state
- Player → Player VM: binds to · Player UI is controlled by playback view model
- Queue → Player VM: binds to · Queue UI shares playback state
- Premium home → Player VM: uses · Premium playback views reuse the player orchestration
- Admin → Admin VM: binds to · Admin UI is backed by admin-specific orchestration
- Artist dash → Analytics: uses · Artist surface consumes reporting and insight data
- Auth VM → Auth service: calls · Authentication flow delegates to auth service
- Auth service → Supabase: uses · Auth operations go through the cloud gateway
- Home VM → Catalog services: calls · Home content comes from catalog services
- Song VM → Catalog services: calls · Song shaping depends on catalog data
- Player VM → Audio engine: controls · Playback state drives the audio engine
- Audio engine → Storage: streams from · Audio engine fetches media assets from storage
- Catalog services → Supabase: queries · Catalog data is sourced from backend records
- Analytics → Supabase: reports to · Analytics data is stored or fetched through the backend
- Favorites → Core Data: stores · Favorites are retained locally
- Recents → Core Data: stores · Recently played history is retained locally
- Core Data → Domain models: persists · Core Data stores domain entities
- Supabase → Domain models: serves · Backend data maps to shared domain entities
- App state → Player VM: shares state · Global player state feeds playback orchestration
- Home VM → Domain models: uses · Home state is shaped from domain models
- Player VM → Domain models: uses · Playback state references song and queue models
