# norinorin/anime_rpc architecture

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

- Interactive diagram: https://gitdiagram.com/norinorin/anime_rpc
- Repository: https://github.com/norinorin/anime_rpc

## Overview

##### Main Components
- Core Application Module: Represented by the anime_rpc directory, which contains the core modules:
– __main__.py: The entry point that bootstraps the application.
– cli.py: Handles command-line interactions and possibly initial configuration.
– config.py and formatting.py: Manage the reading and formatting of the configuration file (rpc.config).
– asyncio_helper.py and monkey_patch.py: Provide asynchronous utilities and runtime modifications.
– presence.py: Manages the communication with Discord (sending rich presence updates).
– scraper.py: Likely responsible for extracting metadata “on the fly” from media sources.
– states.py and ux.py: Maintain application state and user experience logic.
- Pollers: Located in the anime_rpc/pollers directory:
– base_poller.py: Defines a generic interface or common logic.
– mpc_poller.py and mpv_poller.py: Specialized modules to poll data from MPC and MPV media players.
– (Extended support for other platforms like bilibili.tv is hinted in the README and via the extension modules.)
- Web Server: The webserver.py module sets up a local server for providing a web interface or API endpoints.
- Browser Extension: The extension folder contains files (HTML, CSS, JS, and manifest) aimed at integrating with browsers for additional functionalities or notifications.
- Additional Scripts:
– launcher.py: Likely a helper or alternative entry point for starting the application.
– hook-anime_rpc.monkey_patch.py: Provides an entry for applying monkey patches on the fly, possibly for integration purposes.

##### Out Relationships and Interactions
- Entry Points: Start with the CLI or the Python module (__main__.py) that initializes the system.
- Configuration Flow: The config module reads a “rpc.config” file (or its proxy using example.rpc.config) from the media folder. This configuration is used by downstream components to determine behavior (e.g., what format to display, which poller to use).
- Polling Mechanism:
– Pollers (e.g., mpv and mpc pollers) continuously monitor their respective media players or sites, using distinctive protocols like native IPC sockets (for mpv) or web APIs (for MPC).
- Data Processing and State Management: Modules like scraper, states, and formatting process the polled data and prepare it in the expected format.
- Communication Path to Discord: The presence module takes the processed data and sends it to Discord as Rich Presence updates.
- Web Server & Browser Extension:
– The webserver acts as an interface or an intermediary to provide a REST API (or similar) for external tools.
– The browser extension (found under the extension folder) acts as another integration point that may interact with Anime RPC (especially for sites like bilibili.tv).

##### Architectural Patterns or Design Principles
- Extensibility: The presence of multiple poller modules and a browser extension indicates a plug-in style architecture where new integrations can be added without altering the core system drastically.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Entry Points"
        main["__main__.py"]:::entry
        cli["cli.py"]:::entry
        launcher["launcher.py"]:::entry
    end

    subgraph "Core Application Module"
        config["config.py"]:::core
        formatting["formatting.py"]:::core
        asyncHelper["asyncio_helper.py"]:::core
        monkeyPatch["monkey_patch.py"]:::core
        presence["presence.py"]:::core
        scraper["scraper.py"]:::core
        states["states.py"]:::core
        ux["ux.py"]:::core
    end

    subgraph "Pollers"
        basePoller["base_poller.py"]:::poller
        mpcPoller["mpc_poller.py"]:::poller
        mpvPoller["mpv_poller.py"]:::poller
    end

    subgraph "Additional Scripts"
        hook["hook-anime_rpc.monkey_patch.py"]:::additional
    end

    subgraph "External Interfaces"
        webserver["webserver.py"]:::external
        browserExt["Browser Extension"]:::external
        discord["Discord\nRich Presence"]:::external
    end

    %% Entry Points connections to Core Application
    main --> cli
    main --> launcher
    cli --> config
    launcher --> config

    %% Pollers feeding data into the Core Processing via scraper
    basePoller --> scraper
    mpcPoller --> scraper
    mpvPoller --> scraper

    %% Data processing flow within Core Application
    scraper --> formatting
    formatting --> states
    states --> ux

    %% Configuration influences scraper and presence modules
    config --> scraper
    config --> presence

    %% Asynchronous utilities support core modules
    asyncHelper --> scraper
    asyncHelper --> presence

    %% Monkey patch applies modifications to asyncHelper and presence
    monkeyPatch --> asyncHelper
    monkeyPatch --> presence

    %% Presence module sends updates to Discord
    presence -->|"update"| discord

    %% Webserver interfaces with core state management
    webserver --> states

    %% Browser extension interacts with the UX component
    browserExt --> ux

    %% Additional hook script ties into monkey patch mechanism
    hook --> monkeyPatch

    %% Click Events for Core Application Module
    click main "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/__main__.py"
    click cli "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/cli.py"
    click config "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/config.py"
    click formatting "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/formatting.py"
    click asyncHelper "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/asyncio_helper.py"
    click monkeyPatch "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/monkey_patch.py"
    click presence "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/presence.py"
    click scraper "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/scraper.py"
    click states "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/states.py"
    click ux "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/ux.py"

    %% Click Events for Pollers
    click basePoller "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/pollers/base_poller.py"
    click mpcPoller "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/pollers/mpc_poller.py"
    click mpvPoller "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/pollers/mpv_poller.py"

    %% Click Event for Web Server
    click webserver "https://github.com/norinorin/anime_rpc/blob/main/anime_rpc/webserver.py"

    %% Click Event for Browser Extension
    click browserExt "https://github.com/norinorin/anime_rpc/tree/main/extension/"

    %% Click Events for Additional Scripts
    click launcher "https://github.com/norinorin/anime_rpc/blob/main/launcher.py"
    click hook "https://github.com/norinorin/anime_rpc/blob/main/hook-anime_rpc.monkey_patch.py"

    %% Styles
    classDef entry fill:#f9bf3b,stroke:#333,stroke-width:2px;
    classDef core fill:#a2d5f2,stroke:#333,stroke-width:2px;
    classDef poller fill:#e2f0cb,stroke:#333,stroke-width:2px;
    classDef external fill:#f7c6c7,stroke:#333,stroke-width:2px;
    classDef additional fill:#d3c0cd,stroke:#333,stroke-width:2px;
```
