# rithik-b/playlistmanager architecture

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

- Interactive diagram: https://gitdiagram.com/rithik-b/playlistmanager
- Repository: https://github.com/rithik-b/playlistmanager

## Overview

##### Project Type & Purpose
- The project is a game mod for Beat Saber that manages playlists. It allows users to view, modify, and download songs for playlists by hooking into Beat Saber via Harmony patches.
- External dependencies include SongCore, BeatSaverSharp, BeatSaberMarkupLanguage (BSML), SiraUtil, and BeatSaberPlaylistsLib. These are critical as they indicate points where the mod integrates with the Beat Saber ecosystem.

##### Analyzing the File Structure
- Core Logic and Plugin Entry:
- Files like Plugin.cs and PlaylistManager.csproj are central. They represent the mod’s entry point and overall project configuration.
- Dependency Injection and Installers:
- The Installers folder (PlaylistManagerAppInstaller.cs, PlaylistManagerGameInstaller.cs, PlaylistManagerMenuInstaller.cs) sets up the mod’s components using Zenject, binding interfaces and classes for runtime DI.
- Runtime Patching:
- The HarmonyPatches and AffinityPatches folders contain classes that patch Beat Saber’s native behavior (like UI updates and level refreshing). These illustrate the modification layers that the mod uses.
- Business Logic and Management:
- The Managers folder (PlaylistDataManager.cs, PlaylistUIManager.cs) contains the core logic for CRUD operations on playlists, acting as the intermediary between data and UI.
- Downloading and Synchronization:
- The Downloaders folder (PlaylistSequentialDownloader.cs) and parts of the Utilities folder manage download logic for missing songs.
- User Interface Layer:
- The UI folder, along with its sub-folders for Views and ViewControllers, houses BSML files and controllers that render and handle mod UI interactions. Components like PlaylistManagerFlowCoordinator and various modal controllers form the UI layer.
- Domain Models:
- The Types folder holds models (Contributor, CoverImage, DownloadQueueEntry, etc.) which encapsulate the data structure for playlists, songs, and other metadata.
- Configuration and Helpers:
- The Configuration folder and Utilities folder add configuration capabilities and common helper functions across the project.

a. Main Components to Include:
- Plugin Entry & Mod Initialization: Represented by Plugin.cs, initiating the mod and hooking into Beat Saber.
- Dependency Injection Installers: Separate installer components that wire up dependencies (App, Game, Menu installers).
- Harmony & Affinity Patches: Representing runtime modifications that hook the game’s behavior.
- Business Logic Managers: Such as PlaylistDataManager and PlaylistUIManager that handle playlist operations and data/state management.
- Downloaders & Utilities: A module for handling song downloads and supporting utilities.
- Data Models: Types representing contributors, cover images, download queue entries, etc.
- External Integrations: Mark external services and libraries such as SongCore, BeatSaverSharp, BSML, SiraUtil, and BeatSaberPlaylistsLib.

b. Relationships and Interactions:
- Data flow/direction from the Plugin (initialization) to the Installers that configure all managers and UI components.

c. Architectural Patterns and Design Principles:
- Use of Dependency Injection (via Zenject installers) as a core principle.
- Separation of concerns between UI (view controllers and BSML files) and business logic (managers and interfaces).
- Use of aspect-oriented programming with Harmony patches to modify behavior without altering base code.

d. Relevant Technologies & Frameworks:
- Zenject (for DI)
- Harmony (for patching)
- BSML (for UI rendering)
- External libraries: SongCore, BeatSaverSharp, BeatSaberPlaylistsLib, and SiraUtil

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Initialization
    subgraph "Core Initialization"
        Plugin["Plugin (Entry)"]:::core
        ProjectConfig["Project Config"]:::core
    end

    %% Dependency Injection Installers
    subgraph "Dependency Injection (Installers)"
        AppInstaller["App Installer"]:::di
        GameInstaller["Game Installer"]:::di
        MenuInstaller["Menu Installer"]:::di
    end

    %% Runtime Patching
    subgraph "Runtime Patching"
        subgraph "Harmony Patches"
            HarmonyPatchA["AnnotatedBeatmapLevelCollectionCell_RefreshAvailabilityAsync"]:::patch
            HarmonyPatchB["SongCore_RefreshLevelPacks"]:::patch
        end
        subgraph "Affinity Patches"
            AffinityPatchA["AnnotatedBeatmapLevelCollectionsUIPatches"]:::patch
            AffinityPatchB["LevelCollectionCellSetDataPatch"]:::patch
        end
    end

    %% Business Logic Managers
    subgraph "Business Logic Managers"
        PlaylistDataManager["PlaylistDataManager"]:::manager
        PlaylistUIManager["PlaylistUIManager"]:::manager
    end

    %% User Interface Layer
    subgraph "User Interface Layer"
        subgraph "UI Controllers"
            AddPlaylistModalController["AddPlaylistModalController"]:::ui
            PlaylistDetailsViewController["PlaylistDetailsViewController"]:::ui
        end
        subgraph "BSML Views"
            AddPlaylistModalView["AddPlaylistModalView"]:::ui
            PlaylistDetailsView["PlaylistDetailsView"]:::ui
        end
        UIFlowCoordinator["PlaylistManagerFlowCoordinator"]:::ui
    end

    %% Downloading & Utilities
    subgraph "Downloading & Utilities"
        PlaylistSequentialDownloader["PlaylistSequentialDownloader"]:::downloader
        subgraph "Common Helpers"
            Accessors["Accessors"]:::helper
            DownloadPauser["DownloadPauser"]:::helper
            PlaylistDownloader["PlaylistDownloader"]:::helper
        end
    end

    %% Domain Models
    subgraph "Domain Models"
        Contributor["Contributor"]:::model
        CoverImage["CoverImage"]:::model
        DownloadQueueEntry["DownloadQueueEntry"]:::model
    end

    %% Configuration
    subgraph "Configuration"
        PluginConfig["PluginConfig"]:::config
    end

    %% External Dependencies
    subgraph "External Dependencies"
        SongCore["SongCore"]:::external
        BeatSaverSharp["BeatSaverSharp"]:::external
        BSML["BSML"]:::external
        SiraUtil["SiraUtil"]:::external
        BeatSaberPlaylistsLib["BeatSaberPlaylistsLib"]:::external
        BeatSaberCore["Beat Saber Core"]:::external
    end

    %% Connections
    Plugin -->|"initializes"| AppInstaller
    Plugin -->|"initializes"| GameInstaller
    Plugin -->|"initializes"| MenuInstaller
    ProjectConfig --- Plugin

    AppInstaller -->|"injects"| PlaylistDataManager
    AppInstaller -->|"injects"| PlaylistUIManager
    GameInstaller -->|"injects"| PlaylistDataManager
    GameInstaller -->|"injects"| PlaylistUIManager
    MenuInstaller -->|"injects"| UIFlowCoordinator

    UIFlowCoordinator -->|"manages"| AddPlaylistModalController
    UIFlowCoordinator -->|"manages"| PlaylistDetailsViewController
    AddPlaylistModalController -->|"triggers"| PlaylistUIManager
    PlaylistDetailsViewController -->|"triggers"| PlaylistUIManager

    PlaylistUIManager -->|"updates"| PlaylistSequentialDownloader
    PlaylistDataManager -->|"handles"| PlaylistSequentialDownloader

    %% Patching interactions with Beat Saber Core
    HarmonyPatchA ---|"modifies"| BeatSaberCore
    HarmonyPatchB ---|"modifies"| BeatSaberCore
    AffinityPatchA ---|"modifies"| BeatSaberCore
    AffinityPatchB ---|"modifies"| BeatSaberCore

    %% External dependency connections
    AppInstaller ---|"depends_on"| SongCore
    AppInstaller ---|"depends_on"| BeatSaverSharp
    AppInstaller ---|"depends_on"| BSML
    AppInstaller ---|"depends_on"| SiraUtil
    AppInstaller ---|"depends_on"| BeatSaberPlaylistsLib

    PlaylistUIManager ---|"uses"| BSML
    PlaylistSequentialDownloader ---|"uses"| BeatSaverSharp

    %% Click Events
    click Plugin "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Plugin.cs"
    click ProjectConfig "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/PlaylistManager.csproj"
    
    click AppInstaller "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Installers/PlaylistManagerAppInstaller.cs"
    click GameInstaller "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Installers/PlaylistManagerGameInstaller.cs"
    click MenuInstaller "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Installers/PlaylistManagerMenuInstaller.cs"

    click HarmonyPatchA "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/HarmonyPatches/AnnotatedBeatmapLevelCollectionCell_RefreshAvailabilityAsync.cs"
    click HarmonyPatchB "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/HarmonyPatches/SongCore_RefreshLevelPacks.cs"
    click AffinityPatchA "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/AffinityPatches/AnnotatedBeatmapLevelCollectionsUIPatches.cs"
    click AffinityPatchB "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/AffinityPatches/LevelCollectionCellSetDataPatch.cs"

    click PlaylistDataManager "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Managers/PlaylistDataManager.cs"
    click PlaylistUIManager "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Managers/PlaylistUIManager.cs"

    click AddPlaylistModalController "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/UI/ViewControllers/AddPlaylistModalController.cs"
    click PlaylistDetailsViewController "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/UI/ViewControllers/PlaylistDetailsViewController.cs"
    click AddPlaylistModalView "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/UI/Views/AddPlaylistModal.bsml"
    click PlaylistDetailsView "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/UI/Views/PlaylistDetailsView.bsml"
    click UIFlowCoordinator "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/UI/PlaylistManagerFlowCoordinator.cs"

    click PlaylistSequentialDownloader "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Downloaders/PlaylistSequentialDownloader.cs"
    click Accessors "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Utilities/Accessors.cs"
    click DownloadPauser "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Utilities/DownloadPauser.cs"
    click PlaylistDownloader "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Utilities/PlaylistDownloader.cs"

    click Contributor "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Types/Contributor.cs"
    click CoverImage "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Types/CoverImage.cs"
    click DownloadQueueEntry "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Types/DownloadQueueEntry.cs"

    click PluginConfig "https://github.com/rithik-b/playlistmanager/blob/master/PlaylistManager/Configuration/PluginConfig.cs"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef di fill:#C1E1C1,stroke:#333,stroke-width:2px;
    classDef patch fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef manager fill:#FFFACD,stroke:#333,stroke-width:2px;
    classDef ui fill:#F4A460,stroke:#333,stroke-width:2px;
    classDef downloader fill:#FFDAB9,stroke:#333,stroke-width:2px;
    classDef helper fill:#FFEFD5,stroke:#333,stroke-width:2px;
    classDef model fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef config fill:#E0FFFF,stroke:#333,stroke-width:2px;
    classDef external fill:#E6E6FA,stroke:#333,stroke-width:2px;
```
