# yichengchen/atv-bilibili-demo architecture

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

- Interactive diagram: https://gitdiagram.com/yichengchen/atv-bilibili-demo
- Repository: https://github.com/yichengchen/atv-bilibili-demo

## Overview

##### Main Components and Their Groupings
- TVOS Client Application: This is the “BilibiliLive” app that includes the entire client.
- UI / Presentation Layer:
- Base components like AppDelegate, BLTabBarViewController, and numerous View Controllers (FeedViewController, LivePlayerViewController, PersonalViewController, etc.).
- Storyboards (Main.storyboard and LaunchScreen.storyboard) which define UI layouts.
- Feature-Specific Modules:
- Feed Module: Includes components under Feed (FeedCollectionViewController, StandardVideoCollectionViewController, TitleSupplementaryView, etc.).
- Player Module: Contains player-related classes, video resource loader, video player view controller, and an assortment of plugins (e.g., DebugPlugin, SpeedChangerPlugin, etc.).
- Video Module: Covers video detail, mask providers, video clips, and plugins related to video handling.
- Live Module: Houses live streaming functionality with LivePlayerViewController, LiveViewController, and related provider classes.
- Personal and other modules: These include controllers for user data such as HistoryViewController, SettingsViewController, and so on.
- DLNA Module: Handles cloud casting functionalities with UPnP / DLNA protocols (<Module/DLNA> directory).
- Networking/Request Layer:
- Defined in the “Request” folder, including classes for API requests, cookie management, WebRequest signing (wbi), and protobuf-based network definitions (dm.pb.swift, dmView.pb.swift).
- Extensions & Utilities:
- Numerous extension files that extend native types and UI classes (e.g., String.swift, DateFormatter.swift, UIView+Layout.swift).
- Logger, Keys, and configuration files.
- Supporting Files and Assets:

##### Relationships and Data Flow
- The UI layer communicates with the Request layer (APIRequest, WebRequest, etc.) to fetch data, which is then passed to the respective modules (Feed, Live, Video, Personal).
- Video and Live modules incorporate the Player module components to facilitate smooth video playback and manage interactive plugins. The Video module even showcases an abstraction with plugins to add, for example, masking, playback control, or additional information.
- The DLNA module represents an external service integration for casting, interacting with the native player to allow cloud streaming functionalities.

##### Architectural Patterns and Design Principles
- Modularity: The project separates concerns by isolating features (Feed, Player, Live, etc.) into dedicated directories and modules.
- Plugin Architecture: The Player and Video components use a plugin system to allow flexible extensions (e.g., Danmu, SpeedChanger, SponsorSkip plugins).
- Layered Architecture: There is a clear separation between the UI (presentation), business logic and request/network layer, and supporting utility extensions.
- Use of MVC/MVVM: Given the presence of View Controllers and ViewModels (e.g., NewVideoPlayerViewModel, LivePlayerViewModel), the design likely follows MVC or a variant with MVVM patterns.

##### Final Recommendations
- Begin at the highest level (entire tvOS app) and then break it down to show each module’s internal components.
- Modular and extensible nature (especially in the Player and Video sections) to communicate flexibility and separation of responsibilities.

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI / Presentation Layer
    subgraph "UI / Presentation Layer"
        AD["AppDelegate"]:::ui
        TAB["BLTabBarViewController"]:::ui
        MS["Main Storyboard"]:::ui
        LS["LaunchScreen Storyboard"]:::ui
        GV["General View Components"]:::ui
    end

    %% Modules
    subgraph "Modules"
        %% Feed Module
        subgraph "Feed Module"
            FEED["Feed Components"]:::module
        end
        %% Player Module
        subgraph "Player Module"
            CP["Core Player"]:::module
            PP["Player Plugins"]:::module
            PU["Player Utilities"]:::module
        end
        %% Video Module
        subgraph "Video Module"
            VC["Video Components"]:::module
            MP["Mask Providers"]:::module
            VP["Video Plugins"]:::module
            VM["Video ViewModel"]:::module
        end
        %% Live Module
        subgraph "Live Module"
            LIVE["Live Components"]:::module
        end
        %% Personal Module
        subgraph "Personal Module"
            PERSONAL["Personal & User Controllers"]:::module
        end
        %% DLNA Module
        subgraph "DLNA Module"
            DLNA["DLNA Casting"]:::external
        end
    end

    %% Networking/Request Layer
    subgraph "Networking/Request Layer"
        NET["API & WebRequest"]:::network
    end

    %% Extensions & Utilities
    subgraph "Extensions & Utilities"
        EXT["Extensions"]:::utility
        LK["Logger & Keys"]:::utility
    end

    %% Supporting Files & Assets
    subgraph "Supporting Files & Assets"
        ASSET["Assets & Localizations"]:::support
    end

    %% Data Flow Connections
    AD -->|"initializes"| TAB
    TAB -->|"navigates to"| FEED
    TAB -->|"navigates to"| LIVE
    TAB -->|"navigates to"| PERSONAL
    TAB -->|"triggers video playback"| VC

    %% UI components communicate with networking for data retrieval
    TAB -->|"fetches data"| NET
    FEED -->|"requests"| NET
    VC -->|"requests"| NET
    LIVE -->|"requests"| NET
    PERSONAL -->|"requests"| NET

    %% Video and Live modules use Player module components
    VC -->|"uses"| CP
    LIVE -->|"uses"| CP
    CP -->|"extensible via"| PP

    %% Video Module internal components
    VC -->|"integrates with"| VP
    VC -->|"applies"| MP
    VC -->|"binds with"| VM

    %% General View Components support UI layer
    GV --> TAB

    %% Networking/Request Layer feeds data to Modules
    NET --> FEED
    NET --> VC
    NET --> LIVE
    NET --> PERSONAL

    %% Extensions assist UI and Modules
    EXT --> GV
    EXT --> VC
    EXT --> LIVE
    LK --> GV

    %% DLNA integration with Player for casting functionality
    DLNA --- CP

    %% Supporting Files for overall assets
    ASSET --> GV
    ASSET --> MS
    ASSET --> LS

    %% Click Events
    click AD "https://github.com/yichengchen/atv-bilibili-demo/blob/main/BilibiliLive/AppDelegate.swift"
    click TAB "https://github.com/yichengchen/atv-bilibili-demo/blob/main/BilibiliLive/BLTabBarViewController.swift"
    click MS "https://github.com/yichengchen/atv-bilibili-demo/blob/main/BilibiliLive/Base.lproj/Main.storyboard"
    click LS "https://github.com/yichengchen/atv-bilibili-demo/blob/main/BilibiliLive/Supporting Files/Base.lproj/LaunchScreen.storyboard"
    click GV "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Component/View"
    click FEED "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Component/Feed"
    click CP "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Component/Player"
    click PP "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Component/Player/Plugins"
    click PU "https://github.com/yichengchen/atv-bilibili-demo/blob/main/BilibiliLive/Component/Player/SidxParseUtil.swift"
    click VC "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Component/Video"
    click MP "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Component/Video/MaskProvider"
    click VP "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Component/Video/Plugins"
    click VM "https://github.com/yichengchen/atv-bilibili-demo/blob/main/BilibiliLive/Component/Video/NewVideoPlayerViewModel.swift"
    click LIVE "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Module/Live"
    click PERSONAL "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Module/Personal"
    click DLNA "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Module/DLNA"
    click NET "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Request"
    click EXT "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Extensions"
    click LK "https://github.com/yichengchen/atv-bilibili-demo/blob/main/BilibiliLive/Logger.swift"
    click ASSET "https://github.com/yichengchen/atv-bilibili-demo/tree/main/BilibiliLive/Supporting Files"

    %% Styles
    classDef ui fill:#CDEBFF,stroke:#1f78b4,stroke-width:2px;
    classDef module fill:#D5F5E3,stroke:#27ae60,stroke-width:2px;
    classDef network fill:#FCF8E3,stroke:#f1c40f,stroke-width:2px;
    classDef utility fill:#FADBD8,stroke:#e74c3c,stroke-width:2px;
    classDef support fill:#E8DAEF,stroke:#8e44ad,stroke-width:2px;
    classDef external fill:#FDEBD0,stroke:#d35400,stroke-width:2px;
```
