# acelikesghosts/ytm-rpc architecture

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

- Interactive diagram: https://gitdiagram.com/acelikesghosts/ytm-rpc
- Repository: https://github.com/acelikesghosts/ytm-rpc

## Overview

##### Core Components
- Browser Extension (Chrome/Firefox)
- Server Component
- Discord Client Integration
- Client Modifications (BetterDiscord/Replugged)

##### Connection Flows

- Browser Extension → Server (Song data)
- Server → Discord (RPC/WebSocket)
- Server → Client Mods (WebSocket when USING_WS is true)

- Blue: Browser components
- Green: Server components
- Purple: Discord components
- Orange: Data flow paths

##### Detailed Component Breakdown

Server (packages/server):
**┌─ Server Component ─────────────┐**
- RPCServer                  │
- WSServer                   │
- Song Management           │
- ┘

Extension (packages/extension):
**┌─ Browser Extension ────────────┐**
- Content Script             │
- Popup Interface           │
- Polyfill                  │
- ┘

Client Mods:
**┌─ Discord Integration ──────────┐**
- Native RPC                 │
- BetterDiscord Plugin      │
- Replugged Plugin          │
- ┘

##### Additional Elements

- Connection types (WebSocket/RPC)
- State indicators (Playing/Paused)
- Data flow directions
- Component responsibilities

##### Technical Details to Note

Annotations for:
- Port configurations
- Environment variables
- Supported browsers
- Required Node.js version (v18.17.1 LTS)

##### Implementation Notes

- The modular package structure
- The separation between native RPC and client mod approaches
- The central role of the server component
- The extension's content script interaction with Youtube Music

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Browser
        YTM[Youtube Music Tab]
        subgraph Extension
            CS["Content Script"]:::extension
            PI["Popup Interface"]:::extension
            PF["Polyfill"]:::extension
            BG["Extension Background"]:::extension
        end
    end

    subgraph Server
        direction TB
        SB["Server Base"]:::server
        subgraph ServerComponents
            direction TB
            RPC["RPC Server"]:::server
            WS["WebSocket Server"]:::server
            SMS["Song Management System"]:::server
            US["Update System"]:::server
        end
    end

    subgraph Discord
        direction TB
        DRPC["Native Discord RPC"]:::discord
        subgraph ClientMods
            direction TB
            BD["BetterDiscord Plugin"]:::discord
            RP["Replugged Plugin"]:::discord
            VC["Vencord Plugin"]:::discord
        end
    end

    YTM --> CS
    CS --> BG
    BG --> SB
    SB --> ServerComponents
    RPC --> DRPC
    WS --> ClientMods
    SMS --> RPC
    SMS --> WS

    classDef extension fill:#3498db,stroke:#2980b9,color:white
    classDef server fill:#2ecc71,stroke:#27ae60,color:white
    classDef discord fill:#9b59b6,stroke:#8e44ad,color:white

    click CS "https://github.com/acelikesghosts/ytm-rpc/blob/master/packages/extension/content.js"
    click PI "https://github.com/acelikesghosts/ytm-rpc/blob/master/packages/extension/popup.html"
    click PF "https://github.com/acelikesghosts/ytm-rpc/blob/master/packages/extension/polyfill.js"
    click Extension "https://github.com/acelikesghosts/ytm-rpc/tree/master/packages/extension/"
    click RPC "https://github.com/acelikesghosts/ytm-rpc/blob/master/packages/server/src/servers/RPCServer.ts"
    click WS "https://github.com/acelikesghosts/ytm-rpc/blob/master/packages/server/src/servers/WSServer.ts"
    click SMS "https://github.com/acelikesghosts/ytm-rpc/blob/master/packages/server/src/utils/Song.ts"
    click SB "https://github.com/acelikesghosts/ytm-rpc/blob/master/packages/server/src/servers/Server.ts"
    click US "https://github.com/acelikesghosts/ytm-rpc/blob/master/packages/server/src/updater/index.ts"
    click BD "https://github.com/acelikesghosts/ytm-rpc/blob/master/packages/BetterDiscord/src/index.jsx"
    click RP "https://github.com/acelikesghosts/ytm-rpc/blob/master/packages/replugged/src/index.ts"
    click VC "https://github.com/acelikesghosts/ytm-rpc/tree/master/packages/vencord/"

    %% Legend
    subgraph Legend
        L1["Browser Components"]:::extension
        L2["Server Components"]:::server
        L3["Discord Components"]:::discord
    end
```
