# ramismat/spotifier architecture

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

- Interactive diagram: https://gitdiagram.com/ramismat/spotifier
- Repository: https://github.com/ramismat/spotifier

## Overview

##### Main System Components

a) Client Layer (to be implemented, but important to show):
- As a frontend block that will interact with the API
- Planned features: music player, search interface, playlist management

b) API Layer (Core Backend):
- Express.js REST API server (server.js)
- Authentication system (using Passport.js)
- Route handlers (userRoute.js, songRoutes.js)

c) Service Layer:
- User Service (user management, following)
- Song Service (music management)
- Download Service (YouTube integration)

d) Data Layer:
- MongoDB database
- Models (User, Song)

e) External Services:
- YouTube API (for song downloads)
- Spotify API (for song search)

##### Component Relationships

**[Client] ←→ [API Layer] ←→ [Service Layer] ←→ [Data Layer]**
- ↑               ↑

- [Authentication]  [External APIs]

##### Specific Implementation Details

Technical aspects:

a) Authentication Flow:
- JWT-based authentication
- Google OAuth integration
- Session management

b) Core Features:
- User management (registration, profiles, following)
- Song management (search, download, playback)
- Playlist organization
- Download management

##### Important Architectural Patterns to Highlight

a) MVC Pattern:
- Controllers (downloadController, songController, userController)
- Models (songModel, userModel)
- Views (future frontend implementation)

b) Service Layer Pattern:
- Separate business logic in services
- Clear separation of concerns

##### Technical Stack Indicators

- Node.js/Express.js
- MongoDB
- Passport.js
- JWT
- YouTube API
- Spotify API

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#E0E0E0,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
    classDef api fill:#B3E0FF,stroke:#333,stroke-width:2px
    classDef service fill:#FFE0B3,stroke:#333,stroke-width:2px
    classDef data fill:#D1D1D1,stroke:#333,stroke-width:2px
    classDef external fill:#B3FFB3,stroke:#333,stroke-width:2px
    classDef auth fill:#FFE0B3,stroke:#333,stroke-width:2px
    classDef config fill:#E6E6FA,stroke:#333,stroke-width:2px

    %% Client Layer (Future)
    subgraph ClientLayer["Client Layer (Future Implementation)"]
        Client["Web Client"]
        Player["Music Player"]
        Search["Search Interface"]
        PlaylistMgmt["Playlist Management"]
    end
    
    %% API Layer
    subgraph APILayer["API Layer"]
        Server["Express Server"]
        UserRoutes["User Routes"]
        SongRoutes["Song Routes"]
    end
    
    %% Service Layer
    subgraph ServiceLayer["Service Layer"]
        UserService["User Service"]
        SongService["Song Service"]
        DownloadService["Download Service"]
    end
    
    %% Controller Layer
    subgraph ControllerLayer["Controller Layer"]
        UserController["User Controller"]
        SongController["Song Controller"]
        DownloadController["Download Controller"]
    end
    
    %% Data Layer
    subgraph DataLayer["Data Layer"]
        Database["MongoDB"]
        UserModel["User Model"]
        SongModel["Song Model"]
        Downloads["Downloads Storage"]
    end
    
    %% Authentication
    subgraph AuthLayer["Authentication"]
        PassportConfig["Passport.js"]
        JWT["JWT"]
        GoogleOAuth["Google OAuth"]
    end
    
    %% External Services
    subgraph ExternalServices["External Services"]
        YouTubeAPI["YouTube API"]
        SpotifyAPI["Spotify API"]
    end
    
    %% Configuration
    subgraph ConfigLayer["Configuration"]
        DBConfig["Database Config"]
        AppConfig["App Config"]
    end

    %% Connections
    ClientLayer --> APILayer
    Server --> ServiceLayer
    ServiceLayer --> ControllerLayer
    ControllerLayer --> DataLayer
    AuthLayer --> Server
    ServiceLayer --> ExternalServices
    ConfigLayer --> Server

    %% Click Events
    click Server "https://github.com/RamiSmat/Spotifier/blob/main/api/server.js"
    click UserRoutes "https://github.com/RamiSmat/Spotifier/blob/main/api/routes/userRoute.js"
    click SongRoutes "https://github.com/RamiSmat/Spotifier/blob/main/api/routes/songRoutes.js"
    click UserService "https://github.com/RamiSmat/Spotifier/blob/main/api/services/userService.js"
    click SongService "https://github.com/RamiSmat/Spotifier/blob/main/api/services/songService.js"
    click DownloadService "https://github.com/RamiSmat/Spotifier/blob/main/api/services/downloadService.js"
    click UserController "https://github.com/RamiSmat/Spotifier/blob/main/api/controllers/userController.js"
    click SongController "https://github.com/RamiSmat/Spotifier/blob/main/api/controllers/songController.js"
    click DownloadController "https://github.com/RamiSmat/Spotifier/blob/main/api/controllers/downloadController.js"
    click UserModel "https://github.com/RamiSmat/Spotifier/blob/main/api/models/userModel.js"
    click SongModel "https://github.com/RamiSmat/Spotifier/blob/main/api/models/songModel.js"
    click DBConfig "https://github.com/RamiSmat/Spotifier/blob/main/api/config/db.mjs"
    click PassportConfig "https://github.com/RamiSmat/Spotifier/blob/main/api/config/passport.js"
    click Downloads "https://github.com/RamiSmat/Spotifier/tree/main/api/downloads"
    click ConfigLayer "https://github.com/RamiSmat/Spotifier/tree/main/api/config"

    %% Styling
    class ClientLayer,Client,Player,Search,PlaylistMgmt frontend
    class Server,UserRoutes,SongRoutes api
    class UserService,SongService,DownloadService service
    class Database,UserModel,SongModel,Downloads data
    class YouTubeAPI,SpotifyAPI external
    class PassportConfig,JWT,GoogleOAuth auth
    class DBConfig,AppConfig config
```
