# najaf1705/musync architecture

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

- Interactive diagram: https://gitdiagram.com/najaf1705/musync
- Repository: https://github.com/najaf1705/musync

## Overview

##### Main Components

a. Client-Side (Frontend):
- Authentication Components (Login/Signup)
- Core Features (Playlists, Discover, Profile)
- External API Integrations (YouTube, Spotify)

b. Server-Side (Backend):
- Authentication Middleware
- Route Handlers
- API Integration Services

c. Database:
- MongoDB instance for user data and playlists

d. ML Component:
- Separate container for the Machine Learning model
- Connection to song recommendations

e. External Services:
- Spotify API
- YouTube API
- RapidAPI (for audio download)
- Google OAuth

##### Component Relationships

- Client → Backend (REST API calls)
- Backend → Database (data persistence)
- Backend → ML Model (recommendation requests)
- Backend → External APIs
- Authentication flow paths

##### Specific Implementation Details

a. Frontend Architecture:
- React Components hierarchy
- State management
- API integration points

b. Backend Architecture:
- Express middleware stack
- Authentication flow
- Route organization
- Database schemas

##### Technical Stack Indicators

Technology labels:
- Frontend: React, Bootstrap
- Backend: Node.js, Express
- Database: MongoDB, Mongoose
- Authentication: JWT, Google OAuth
- ML: Python (indicated by pickle integration)

##### Data Flow Patterns

Illustrate:
- User authentication flow
- Playlist creation and management
- Song recommendation process
- External API data fetching

##### Security Layer

Show:
- JWT token flow
- Authentication middleware
- Environment variable usage points

**[External Services Layer]**
- ↕
**[Frontend Layer]**
- ↕
**[Backend API Layer]**
- ↕
**[Authentication Layer]**
- ↕
**[Database Layer] ← → [ML Model Layer]**

Important Considerations:

1. Keep the ML model integration clearly separated but show its interaction with the main application flow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External["External Services Layer"]
        direction TB
        SPOT[Spotify API]:::external
        YT[YouTube API]:::external
        RAPID[RapidAPI]:::external
        GAUTH[Google OAuth]:::external
    end

    subgraph Front["Frontend Layer"]
        direction TB
        APP["Main App"]:::frontend
        click APP "https://github.com/Najaf1705/Musync/blob/master/client/src/App.js"
        
        subgraph Auth["Authentication Components"]
            direction TB
            LOGIN["Login"]:::auth
            click LOGIN "https://github.com/Najaf1705/Musync/blob/master/client/src/components/Login.js"
            SIGNUP["Signup"]:::auth
            click SIGNUP "https://github.com/Najaf1705/Musync/blob/master/client/src/components/Signup.js"
        end

        subgraph Features["Core Features"]
            direction TB
            PLAY["Playlists"]:::frontend
            click PLAY "https://github.com/Najaf1705/Musync/blob/master/client/src/components/Playlists.js"
            DISC["Discover"]:::frontend
            click DISC "https://github.com/Najaf1705/Musync/blob/master/client/src/components/Discover.js"
            PROF["Profile"]:::frontend
            click PROF "https://github.com/Najaf1705/Musync/blob/master/client/src/components/Profile.js"
            CREATE["Create Playlist"]:::frontend
            click CREATE "https://github.com/Najaf1705/Musync/blob/master/client/src/components/CreatePlaylist.js"
        end
    end

    subgraph Back["Backend Layer"]
        direction TB
        SERVER["Express Server"]:::backend
        click SERVER "https://github.com/Najaf1705/Musync/blob/master/server/app.js"
        
        subgraph Routes["Route Handlers"]
            direction TB
            AUTHROUTE["Auth Routes"]:::backend
            click AUTHROUTE "https://github.com/Najaf1705/Musync/blob/master/server/router/auth.js"
            SPOTROUTE["Spotify Routes"]:::backend
            click SPOTROUTE "https://github.com/Najaf1705/Musync/blob/master/server/router/spotapi.js"
            PLAYROUTE["Playlist Routes"]:::backend
            click PLAYROUTE "https://github.com/Najaf1705/Musync/blob/master/server/router/createplaylist.js"
            LIKEROUTE["Liked Songs Routes"]:::backend
            click LIKEROUTE "https://github.com/Najaf1705/Musync/blob/master/server/router/likedsongs.js"
            RECROUTE["Recommendation Routes"]:::backend
            click RECROUTE "https://github.com/Najaf1705/Musync/blob/master/server/router/recommend.js"
        end

        AUTHMID["Auth Middleware"]:::backend
        click AUTHMID "https://github.com/Najaf1705/Musync/blob/master/server/middleware/authenticate.js"
    end

    subgraph Data["Data Layer"]
        direction TB
        DB["MongoDB"]:::database
        click DB "https://github.com/Najaf1705/Musync/blob/master/server/db/conn.js"
        
        subgraph Schema["Database Schemas"]
            direction TB
            USCHEMA["User Schema"]:::database
            click USCHEMA "https://github.com/Najaf1705/Musync/blob/master/server/models/userSchema.js"
            DSCHEMA["Data Schema"]:::database
            click DSCHEMA "https://github.com/Najaf1705/Musync/blob/master/server/models/dataSchema.js"
        end
    end

    subgraph ML["ML Layer"]
        direction TB
        MODEL["ML Model"]:::ml
        click MODEL "https://github.com/Najaf1705/Musync/tree/master/ML_model/"
        MODELJSON["Model JSON"]:::ml
        click MODELJSON "https://github.com/Najaf1705/Musync/blob/master/ML_model/songsmodel.json"
        TRAINDATA["Training Data"]:::ml
        click TRAINDATA "https://github.com/Najaf1705/Musync/blob/master/ML_model/songs.csv"
    end

    %% Connections
    External --> Front
    Front --> Back
    Back --> Data
    Back --> ML
    AUTHMID --> Routes
    Routes --> DB

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef auth fill:#f1c40f,stroke:#f39c12,color:black
    classDef ml fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
```
