# guozhigq/pilipala architecture

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

- Interactive diagram: https://gitdiagram.com/guozhigq/pilipala
- Repository: https://github.com/guozhigq/pilipala

## Overview

##### Main Components
- Frontend (Flutter UI)
– The majority of the app’s presentation lives in the lib/pages directory, which is organized by features (e.g., home, video, dynamic, login, member, etc.)
– lib/common also contains shared widgets and utility components.
- Business Logic & State Management
– Controllers inside each page directory orchestrate user interactions, data fetching, and navigation flows.
– The project uses providers/service locators (see lib/services/service_locator.dart) for dependency management.
- Data Access Layer
– HTTP API communications are abstracted in lib/http (API endpoints for bangumi, dynamics, video, user, login, etc.).
– Data models are well-organized in lib/models which mirror the domain objects that come from BiliBili APIs.
- Plugins & Custom Modules
– Custom plugins in lib/plugin (e.g., pl_gallery, pl_player, pl_popup, pl_socket) encapsulate reusable functionality like custom media viewing and socket communication.
- Platform Integrations
– Directories for android, ios, macos, linux, windows contain native project configurations and platform-specific code.
- Assets & Resources
– Assets folder holds fonts, images, and JSON files that support theming and media in the UI.
- Build, CI/CD and Deployment
– .github/workflows, fastlane and pubspec files indicate automated build and release processes.

##### Relationships and Interactions
- Controllers call upon service classes in lib/services and HTTP helper classes (lib/http) to fetch data from external APIs (BiliBili official endpoints as mentioned in the README).
- The data retrieved is then transformed into model objects (in lib/models) and passed back to the UI.
- Custom plugins (lib/plugin) are invoked by both UI and service layers to provide enhanced functionalities such as video playback, popup dialogs, or socket events.
- External API Services: Even if not maintained internally, a note should be drawn that the mobile client interacts with BiliBili’s API endpoints.

##### Architectural Patterns and Design Principles
- Modularization: The clear separation of pages, models, controllers, services, and plugins allows independent development and testing.
- Layered/MVC Pattern:
- The “View” is implemented in Flutter’s UI (pages, widgets)
- “Controllers” manage user actions and data flows.
- “Models” represent structured data from API calls.
- Dependency Injection: (Service Locator in lib/services/service_locator.dart) simplifies testing and enhances modular design.
- Responsive Design: The project’s multiple directories (android, ios, web, desktop) indicate that the app is built for cross-platform support.

– Ensure every component is clearly labeled.
– Create additional callouts for builds/CI systems (e.g., GitHub Actions, Fastlane) if needed.
– The high level should not overwhelm minor details – focus on showing how many components collaborate to provide the features listed (e.g., video playback controls, dynamic feed, blacklisting, live streaming support).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI/Presentation Layer
    subgraph "UI/Presentation"
        A["UI - Pages"]:::frontend
        B["UI - Widgets"]:::frontend
    end

    %% Business Logic & State Management
    subgraph "Business Logic"
        C["Controllers"]:::business
        D["Service Locator"]:::business
    end

    %% Data Access Layer
    subgraph "Data Access"
        E["HTTP API"]:::data
        F["Data Models"]:::data
    end

    %% Plugins & Custom Modules
    subgraph "Plugins & Custom Modules"
        G["Plugins"]:::plugins
    end

    %% External API Services
    Q["External API: BiliBili"]:::external

    %% Build, CI/CD and Deployment
    subgraph "Build & Deployment"
        N["GitHub Workflows"]:::cicd
        O["Fastlane"]:::cicd
        P["Pubspec Files"]:::cicd
    end

    %% Platform-Specific Integrations
    subgraph "Platform Integrations"
        H["Android"]:::platform
        I["iOS"]:::platform
        J["macOS"]:::platform
        K["Linux"]:::platform
        L["Windows"]:::platform
    end

    %% Assets & Resources
    M["Assets & Resources"]:::assets

    %% Flow Connections
    %% UI interactions trigger business logic
    A -->|"UserEvent"| C
    B -->|"UserEvent"| C

    %% UI loads assets
    A -->|"Loads"| M

    %% Business Logic calls data access
    C -->|"DataFetch"| E
    D -->|"DependencyInjection"| E

    %% Data access parses data and calls external API
    E -->|"ParseData"| F
    E -->|"APIRequest"| Q

    %% UI and Business Logic invoking Plugins
    A -->|"Uses"| G
    D -->|"Invokes"| G

    %% CI/CD deploys the application (triggering UI for deployment)
    N -->|"Deploy"| A
    O -->|"Deploy"| A
    P -->|"Deploy"| A

    %% Platform integrations provide native support to UI
    H ---|"NativeSupport"| A
    I ---|"NativeSupport"| A
    J ---|"NativeSupport"| A
    K ---|"NativeSupport"| A
    L ---|"NativeSupport"| A

    %% Legend Subgraph
    subgraph "Legend"
        L1["UI/Presentation: Blue (#AED6F1)"]
        L2["Business Logic: Green (#A9DFBF)"]
        L3["Data Access: Yellow (#F9E79F)"]
        L4["Plugins: Orange (#FAD7A0)"]
        L5["Platform: Purple (#D7BDE2)"]
        L6["CI/CD: Gray (#D5DBDB)"]
        L7["Assets: Light Orange (#FDEBD0)"]
        L8["External API: Sky Blue (#85C1E9)"]
    end

    %% Click Events
    click A "https://github.com/guozhigq/pilipala/tree/main/lib/pages"
    click B "https://github.com/guozhigq/pilipala/tree/main/lib/common/widgets"
    click C "https://github.com/guozhigq/pilipala/blob/main/lib/pages/*/controller.dart"
    click D "https://github.com/guozhigq/pilipala/blob/main/lib/services/service_locator.dart"
    click E "https://github.com/guozhigq/pilipala/tree/main/lib/http"
    click F "https://github.com/guozhigq/pilipala/tree/main/lib/models"
    click G "https://github.com/guozhigq/pilipala/tree/main/lib/plugin"
    click H "https://github.com/guozhigq/pilipala/tree/main/android"
    click I "https://github.com/guozhigq/pilipala/tree/main/ios"
    click J "https://github.com/guozhigq/pilipala/tree/main/macos"
    click K "https://github.com/guozhigq/pilipala/tree/main/linux"
    click L "https://github.com/guozhigq/pilipala/tree/main/windows"
    click M "https://github.com/guozhigq/pilipala/tree/main/assets"
    click N "https://github.com/guozhigq/pilipala/tree/main/.github/workflows"
    click O "https://github.com/guozhigq/pilipala/tree/main/fastlane"
    click P "https://github.com/guozhigq/pilipala/blob/main/pubspec.yaml"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef business fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef data fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef plugins fill:#FAD7A0,stroke:#B9770E,stroke-width:2px;
    classDef external fill:#85C1E9,stroke:#2874A6,stroke-width:2px;
    classDef cicd fill:#D5DBDB,stroke:#7B7D7D,stroke-width:2px;
    classDef platform fill:#D7BDE2,stroke:#884EA0,stroke-width:2px;
    classDef assets fill:#FDEBD0,stroke:#D35400,stroke-width:2px;
```
