# vatsrounak/audiohives architecture

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

- Interactive diagram: https://gitdiagram.com/vatsrounak/audiohives
- Repository: https://github.com/vatsrounak/audiohives

## Overview

##### Project Type & Purpose
- The project is a lightweight command-line Node.js application. Its main function is to download audio tracks from a Spotify playlist by querying YouTube for the corresponding videos.
- It integrates with two external APIs: Spotify for playlist and track details and YouTube for audio/video search and download.
- The README clearly explains that after starting the process, it guides the user through obtaining an access token, running several scripts, and finally downloading songs into the “songs” directory.

##### Analyzing the File Structure
- The top-level files include:
- index.js: Likely the primary entry point for handling authentication and launching the web server (listening on port 8888 for Spotify login).
- config.js: Contains configuration details (Spotify credentials and YouTube API key).
- automate.js, getMe.js: Likely utility scripts handling automated tasks and API requests (token fetching, possibly post-login processing).
- spotify.js and youtube.js: Modules responsible for interacting respectively with the Spotify and YouTube APIs.
- The “songs” folder: Destination where the downloaded audio files are stored.
- The presence of configuration and separate modules indicates a separation of concerns, i.e., one module focuses on Spotify integration while another handles YouTube functionality.

##### Key System Components
- User Interface / Client Interaction:
- A simple web UI endpoint (http://localhost:8888/login) for Spotify OAuth authentication.
- Backend Controller:
- index.js acting as the server which handles login and token retrieval.
- getMe.js as a utility script for processing tokens and likely interfacing with Spotify’s API to fetch playlist information.
- Configuration & Credential Management:
- config.js managing API keys and client secrets for both Spotify and YouTube.
- Spotify Integration:
- The spotify.js module, which communicates with Spotify Web API to fetch playlist details and track metadata.
- YouTube Integration:
- The youtube.js module, which handles the searching and downloading process from YouTube based on track details.
- Storage:
- The songs/ directory where downloaded audio files are saved.

##### Establishing Component Interactions
- User accesses the login endpoint via browser → index.js triggers Spotify OAuth flow.
- Once authenticated, the retrieved access token is displayed in the terminal.
- The token is then manually inserted into the getMe.js script.
- Running getMe.js:
- Uses the token to query the Spotify API via functions in spotify.js.
- For each track received, it sends a request to youtube.js to search for and download the corresponding audio.
- The downloaded audio files are written to the songs directory.

##### Significant Architectural Patterns & Design Principles
- Separation of Concerns:
- Each functionality is broken down into separate modules (config, Spotify API integration, YouTube API integration).
- Modular Design:
- The clear division into multiple scripts (index.js, getMe.js, spotify.js, youtube.js) facilitates maintainability.
- API Integration:
- Emphasis on interacting with external services (Spotify API and YouTube API) which should be clearly represented.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Nodes
    U["User Browser (http://localhost:8888/login)"]:::internal
    I["Backend Controller (index.js)"]:::internal
    T["Token Processor (getMe.js)"]:::internal
    S["Spotify Module (spotify.js)"]:::internal
    Y["YouTube Module (youtube.js)"]:::internal
    C["Configuration (config.js)"]:::configstyle
    SPAPI["Spotify API"]:::external
    YTAPI["YouTube API"]:::external
    F["Downloaded Songs (songs)"]:::storage

    %% Flow Paths
    U -->|"LoginRequest"| I
    I -->|"ReturnsAccessToken"| T
    T -->|"FetchPlaylistDetails"| S
    S -->|"QueryPlaylist"| SPAPI
    T -->|"TriggerAudioDownload"| Y
    Y -->|"SearchAndDownload"| YTAPI
    Y -->|"StoreAudio"| F

    %% Config Dependencies (dashed lines)
    S -.->|"uses_config"| C
    Y -.->|"uses_config"| C

    %% Click Events
    click I "https://github.com/vatsrounak/audiohives/blob/main/index.js"
    click T "https://github.com/vatsrounak/audiohives/blob/main/getMe.js"
    click C "https://github.com/vatsrounak/audiohives/blob/main/config.js"
    click S "https://github.com/vatsrounak/audiohives/blob/main/spotify.js"
    click Y "https://github.com/vatsrounak/audiohives/blob/main/youtube.js"
    click F "https://github.com/vatsrounak/audiohives/tree/main/songs"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef external fill:#FFC0CB,stroke:#000,stroke-width:2px;
    classDef configstyle fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef storage fill:#FFB6C1,stroke:#000,stroke-width:2px;
```
