# chaumanh/ie104-music architecture

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

- Interactive diagram: https://gitdiagram.com/chaumanh/ie104-music
- Repository: https://github.com/chaumanh/ie104-music

## Overview

##### Project Type & Purpose
- This is a full-stack music streaming web app with a clear separation of concerns between the Frontend and the Backend. The frontend is built in ReactJS (styled with TailwindCSS) and the backend is developed using Node.js with Express.js. The application uses MongoDB as its database and integrates external services like Spotify API (for music playback) and Cloudinary (likely for media asset management), with Firebase configuration on the frontend.

##### Analyzing the File Structure
- Frontend:
- Contains directories like /src with components, pages, context providers, assets, and routes.
- Uses a Vite configuration for building and bundling assets.
- Has service modules for API calls (adminApi, authApi, albumApi, etc.) indicating communication with the backend.
- Uses environment configuration (.env example) for Firebase and likely other settings.

- Backend:
- Organized in an MVC-like structure with folders for controllers, models, routes, middleware, services, configuration, and utility functions.
- Integration with third-party services is apparent: Spotify (config files and token management) and Cloudinary.
- Contains a separate file for DB configuration connecting to MongoDB and for initializing things such as the admin using utility scripts.

##### Components & Relationships
- Frontend (Client Side):
- UI Components: Pages (e.g., AlbumPage, ArtistPage, PlaylistPage), Layout components (Player, TopNav, Sidebar), and utility components for search, login popup, queue, etc.
- Context Providers: For managing states like the Player and Queue.
- Service Layer: Responsible for making HTTP requests to the backend (e.g., authApi, songApi).
- Configuration: Environment setups for Firebase to manage authentication or additional functionalities.

- Backend (Server Side):
- API Server: Exposes endpoints via routes defined for authentication, album, artist, playlist, song management, etc.
- Controllers: Handle business logic and request processing.
- Models: Define MongoDB schemas (users, song, playlist, album, artist).
- Middleware: Security/authentication (adminAuth, auth).
- Services: Encapsulate common logic (authService, userService, Spotify token management via webPlayBackSDK).
- External Integrations: Spotify API interactions and Cloudinary for media handling.
- Database: MongoDB accessed via Mongoose (utility and configuration files).

- External Services:
- Spotify API: Used for online music playback, managing tokens, and retrieving music data.
- Cloudinary: Likely used for image/file uploads.
- Firebase (Frontend): For configuration purposes (authentication or push notifications).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        Pages["Pages\n(AlbumPage.jsx, ArtistPage.jsx, PlaylistPage.jsx)"]:::frontend
        Components["General Components\n(AlbumItem.jsx, ArtistItem.jsx, SongItem.jsx)"]:::frontend
        Layout["Layout Components\n(Player, TopNav, Sidebar)"]:::frontend
        DefaultLayout["Default Layout"]:::frontend
        PlayerContext["PlayerContext"]:::frontend
        QueueContext["QueueContext"]:::frontend
        APIServices["API Service Layer"]:::frontend
        Firebase["Firebase Config"]:::frontend
        EnvConfig["Environment Config"]:::frontend
    end

    subgraph "Backend"
        APIServer["API Server"]:::backend
        Routes["Routes"]:::backend
        Controllers["Controllers"]:::backend
        Middleware["Middleware"]:::backend
        BackendServices["Services"]:::backend
        Models["Models"]:::backend
        DBConfig["Database Config"]:::backend
        Cloudinary["Cloudinary Integration"]:::backend
        SpotifyToken["Spotify Token Service"]:::backend
        SpotifySDK["Spotify WebPlaybackSDK Service"]:::backend
        Utility["Utility Functions & Admin Setup"]:::backend
    end

    subgraph "External/Database"
        MongoDB["MongoDB"]:::database
        ExtSpotify["Spotify API"]:::external
        ExtCloudinary["Cloudinary"]:::external
    end

    %% Frontend Relationships
    Pages --> APIServices
    Components --> APIServices
    Layout --> Pages
    DefaultLayout --> Layout
    PlayerContext --> Pages
    QueueContext --> Pages
    Firebase --> Pages
    EnvConfig --> Pages

    %% Frontend calls Backend
    APIServices -->|"HTTPRequests"| APIServer

    %% Backend Relationships
    APIServer --> Routes
    Routes --> Controllers
    Routes --> Middleware
    Controllers --> BackendServices
    Controllers --> Models
    BackendServices --> Models
    Models -->|"DataPersistence"| MongoDB
    DBConfig --> MongoDB
    Middleware --> Controllers
    BackendServices --> SpotifyToken
    BackendServices --> SpotifySDK
    SpotifyToken -->|"TokenRequest"| ExtSpotify
    SpotifySDK -->|"PlaybackSDK"| ExtSpotify
    BackendServices --> Cloudinary
    Cloudinary -->|"MediaUpload"| ExtCloudinary
    Utility --> APIServer

    %% Click Events for Frontend
    click Pages "https://github.com/chaumanh/ie104-music/tree/main/Frontend/src/pages"
    click Components "https://github.com/chaumanh/ie104-music/tree/main/Frontend/src/components"
    click Layout "https://github.com/chaumanh/ie104-music/tree/main/Frontend/src/Layout/Components"
    click DefaultLayout "https://github.com/chaumanh/ie104-music/blob/main/Frontend/src/Layout/DefaultLayout/DefaultLayout.jsx"
    click PlayerContext "https://github.com/chaumanh/ie104-music/blob/main/Frontend/src/context/PlayerContext.jsx"
    click QueueContext "https://github.com/chaumanh/ie104-music/blob/main/Frontend/src/context/QueueContext.jsx"
    click APIServices "https://github.com/chaumanh/ie104-music/tree/main/Frontend/src/services"
    click Firebase "https://github.com/chaumanh/ie104-music/blob/main/Frontend/src/config/firebase.js"
    click EnvConfig "https://github.com/chaumanh/ie104-music/blob/main/Frontend/.env.example"

    %% Click Events for Backend
    click APIServer "https://github.com/chaumanh/ie104-music/blob/main/Backend/src/server.js"
    click Routes "https://github.com/chaumanh/ie104-music/tree/main/Backend/src/routes"
    click Controllers "https://github.com/chaumanh/ie104-music/tree/main/Backend/src/controllers"
    click Middleware "https://github.com/chaumanh/ie104-music/tree/main/Backend/src/middleware"
    click BackendServices "https://github.com/chaumanh/ie104-music/tree/main/Backend/src/services"
    click Models "https://github.com/chaumanh/ie104-music/tree/main/Backend/src/models"
    click DBConfig "https://github.com/chaumanh/ie104-music/blob/main/Backend/src/config/db/db.js"
    click Cloudinary "https://github.com/chaumanh/ie104-music/blob/main/Backend/src/config/cloudinary/cloudinary_config.js"
    click SpotifyToken "https://github.com/chaumanh/ie104-music/blob/main/Backend/src/config/spotify/getTokenSpotify.js"
    click SpotifySDK "https://github.com/chaumanh/ie104-music/blob/main/Backend/src/config/spotify/getWebPlaybackSDKToken.js"
    click Utility "https://github.com/chaumanh/ie104-music/tree/main/Backend/src/util"

    %% Styles
    classDef frontend fill:#a7d7c5,stroke:#333,stroke-width:2px;
    classDef backend fill:#f9d5b5,stroke:#333,stroke-width:2px;
    classDef external fill:#ffb347,stroke:#333,stroke-width:2px;
    classDef database fill:#ffd1dc,stroke:#333,stroke-width:2px;
```
