# renmu123/bililive-tools architecture

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

- Interactive diagram: https://gitdiagram.com/renmu123/bililive-tools
- Repository: https://github.com/renmu123/bililive-tools

## Overview

- Monorepo Core: Show that the project is managed as a monorepo using a PNPM workspace (indicated by “pnpm-lock.yaml” and “pnpm-workspace.yaml”).
- Recording Libraries: Separate packages (e.g., BilibiliRecorder, DouYinRecorder, DouYuRecorder, HuYaRecorder, and also huya-danmu) function as the core modules for handling platform-specific recording, danmu processing, and stream management.
- CLI Module: The “CLI” package encapsulates the command-line interface functionalities.
- Desktop Application: The “app” package is clearly the Electron-based desktop client. Inside it you have split responsibilities (main process, renderer process) for handling application logic and UI components.
- HTTP/API Service: The “http” package defines middleware, routes, and services to accept webhook calls and API requests.
- Shared/Common Utilities: The “shared” and “types” packages include common code (utilities, database models, presets, configuration) used across modules.
- Live Manager & Others: The “liveManager” package further orchestrates live stream recording and processing.
- Docker & Deployment Components: The “docker” folder (and associated GitHub workflows) indicates containerized versions of the backend API, web UI, and third-party recorder integration (e.g., BililiveRecorder/recorder).

##### Relationships and Interactions
- That the Desktop App (Electron UI) and the CLI interact with the underlying recording libraries and shared utilities.
- The HTTP/API service (backend) exposes routes such as webhook endpoints (e.g., for BililiveRecorder, blrec, DDTV, custom webhooks) that trigger processing in the recording modules.
- The Shared package is used by multiple components (CLI, HTTP API, Live Manager, Desktop App) to maintain consistency in presets, configuration, and type definitions.

##### Architectural Patterns and Design Principles
- Modular Design: Clearly illustrate each package/module as an independent component within the monorepo while noting their reusability (like shared utilities and types).
- Separation of Concerns: Distinguish between the UI layers (Desktop App, WebUI), service layers (HTTP/mock API service), and core domain libraries (recorders, live management).
- Microservices Components (in Docker): Note the separation between the “frontend” container (web UI) and “backend” container (API server) in a Docker Compose environment.
- Extensibility: Indicate that the design supports plugin-like recording modules for platforms, making it easy to add more in the future.

##### Detail the Technologies, Frameworks, or Libraries Involved
- Electron is used for the desktop application (packages/app).
- Likely Vue (or a similar framework) is used in the renderer process for building the UI (as seen from the “src/renderer” structure and .vue components).
- Node.js is the runtime environment (with a defined .node-version).
- Tools like ffmpeg, DanmakuFactory, and possibly better-sqlite3 (for danmu analysis) are integrated as binary dependencies.
- Docker is used for containerized deployments, and GitHub Actions streamline CI/CD.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Monorepo Core
    subgraph "Monorepo Core"
        PNWS("pnpm-workspace.yaml"):::config
        PNLock("pnpm-lock.yaml"):::config
        DA("Desktop App (Electron)"):::ui
        CLI("CLI Module"):::cli
        HTTP("HTTP/API Service"):::api
        LM("Live Manager"):::lm
        subgraph "Recording Libraries"
            BR("BilibiliRecorder Module"):::recorder
            DY("DouYinRecorder Module"):::recorder
            DYU("DouYuRecorder Module"):::recorder
            HH("HuYaRecorder Module"):::recorder
            HD("Huya Danmu Library"):::recorder
        end
        subgraph "Shared Modules"
            SU("Shared Utilities"):::shared
            ST("Shared Types"):::shared
        end
    end

    %% Deployment and CI/CD
    subgraph "Deployment (Docker & CI/CD)"
        APICont("Backend API Container"):::docker
        WebUICont("WebUI Container"):::docker
        DockerCfg("Docker Configuration"):::docker
        Compose("Docker Compose"):::docker
        GitHubWF("GitHub Workflows"):::ci
    end

    %% External Integrations
    EX("External Webhooks/Integrations"):::external

    %% Connections between External and Application Layer
    EX -->|"triggers"| HTTP

    %% Connections within Monorepo
    DA -->|"uses"| SU
    CLI -->|"uses"| SU

    DA -->|"uses"| BR
    DA -->|"uses"| DY
    DA -->|"uses"| DYU
    DA -->|"uses"| HH
    DA -->|"uses"| HD

    CLI -->|"uses"| BR
    CLI -->|"uses"| DY
    CLI -->|"uses"| DYU
    CLI -->|"uses"| HH
    CLI -->|"uses"| HD

    HTTP -->|"calls"| BR
    HTTP -->|"calls"| DY
    HTTP -->|"calls"| DYU
    HTTP -->|"calls"| HH
    HTTP -->|"calls"| HD

    LM -->|"orchestrates"| BR
    LM -->|"orchestrates"| DY
    LM -->|"orchestrates"| DYU
    LM -->|"orchestrates"| HH
    LM -->|"orchestrates"| HD

    %% Deployment connections
    WebUICont -->|"REST"| APICont
    GitHubWF -->|"triggers"| DockerCfg
    DockerCfg -->|"defines"| Compose
    HTTP -.-> APICont

    %% Click Events
    click PNWS "https://github.com/renmu123/bililive-tools/blob/master/pnpm-workspace.yaml"
    click PNLock "https://github.com/renmu123/bililive-tools/blob/master/pnpm-lock.yaml"
    click DA "https://github.com/renmu123/bililive-tools/tree/master/packages/app"
    click CLI "https://github.com/renmu123/bililive-tools/tree/master/packages/CLI"
    click HTTP "https://github.com/renmu123/bililive-tools/tree/master/packages/http"
    click BR "https://github.com/renmu123/bililive-tools/tree/master/packages/BilibiliRecorder"
    click DY "https://github.com/renmu123/bililive-tools/tree/master/packages/DouYinRecorder"
    click DYU "https://github.com/renmu123/bililive-tools/tree/master/packages/DouYuRecorder"
    click HH "https://github.com/renmu123/bililive-tools/tree/master/packages/HuYaRecorder"
    click HD "https://github.com/renmu123/bililive-tools/tree/master/packages/huya-danmu"
    click SU "https://github.com/renmu123/bililive-tools/tree/master/packages/shared"
    click ST "https://github.com/renmu123/bililive-tools/tree/master/packages/types"
    click LM "https://github.com/renmu123/bililive-tools/tree/master/packages/liveManager"
    click DockerCfg "https://github.com/renmu123/bililive-tools/tree/master/docker"
    click Compose "https://github.com/renmu123/bililive-tools/blob/master/docker/docker-compose.yml"
    click GitHubWF "https://github.com/renmu123/bililive-tools/blob/master/.github/workflows/docker.yml"

    %% Styles
    classDef config fill:#FFF3B0,stroke:#D49A07,stroke-width:2px;
    classDef ui fill:#C8E6F5,stroke:#039BE5,stroke-width:2px;
    classDef cli fill:#D0F0C0,stroke:#4CAF50,stroke-width:2px;
    classDef api fill:#FFCDD2,stroke:#E53935,stroke-width:2px;
    classDef lm fill:#FFE082,stroke:#FB8C00,stroke-width:2px;
    classDef recorder fill:#F8BBD0,stroke:#C2185B,stroke-width:2px;
    classDef shared fill:#C5CAE9,stroke:#303F9F,stroke-width:2px;
    classDef docker fill:#E0E0E0,stroke:#616161,stroke-width:2px;
    classDef ci fill:#FFECB3,stroke:#FF9800,stroke-width:2px;
    classDef external fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
```
