# iuroc/bilidown architecture

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

- Interactive diagram: https://gitdiagram.com/iuroc/bilidown
- Repository: https://github.com/iuroc/bilidown

## Overview

##### Main Components
- Client (Frontend):
- Built with HTML, TypeScript/JavaScript (index.ts, header.ts, and multiple feature-specific modules like login, task, setting, work)
- Uses external libraries (VanJS, Bootstrap, p-queue for concurrency, and routing utilities like vanjs-router)
- Organized in several submodules (login, task, work, setting, and shared elements like error handling and SCSS styling)
- Built and bundled using Vite and configured via tsconfig and vite.config.ts
- Server (Backend):
- Developed in Go with a modular structure
- Contains functional packages such as:
▪ bilibili – handling Bilibili-specific API interactions and video parsing logic (including testing files)
▪ router – defines HTTP routes and endpoints (login, task, video)
▪ task – manages background processing and queued tasks
▪ util and common – shared utility functions (for database operations, error responses, concurrency control, etc.)
- Uses external dependencies like SQLite (through modernc.org/sqlite) and systray for system tray integration
- Build and cross-compilation tools are included (with Docker and goreleaser support)

##### Relationships and Interactions
- The Client sends HTTP requests to the Server’s API endpoints (as defined in the router directory)
- The Server processes tasks such as login, video parsing, and task management through dedicated Go packages (bilibili for video parsing, task package for work processing)
- Utility modules support the overall operations (e.g., db.go for database interaction and semaphore.go for concurrency)
- External tools (e.g., FFmpeg) and libraries are required for media processing and merging

##### Important Architectural Patterns
- Separation of Concerns: Clear division between the user interface and backend services
- Modular Design: Both client and server are broken down into features and function-specific modules
- Concurrency Control: The use of p-queue on the client side and semaphore utilities on the server side
- Cross-Compilation and Containerization: The server is designed to be easily built for multiple architectures using tools like goreleaser and Docker

- Main UI (index.html, index.ts)
- Feature modules (Login, Task, Setting, Work)
- Supporting libraries (VanJS, Bootstrap, p-queue)
- Main entrypoint (main.go) that orchestrates the API requests.
- Submodules:
▪ Router: Handles different routes – login, task, video endpoints.
▪ Bilibili Package: Video parsing logic and communication with Bilibili API.
▪ Task Package: Manages asynchronous video parsing or downloading tasks.
▪ Util & Common Modules: Utility functions, database management, and error handling.
- Use of external libraries (SQLite, systray, go-qrcode) near or inside the relevant server modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Subgraph
    subgraph "Client"
        A["Main UI (index.html, index.ts)"]:::client
        B["Login Module"]:::client
        C["Task Module"]:::client
        D["Work Module"]:::client
        E["Setting Module"]:::client
        F["Shared/Styling Modules"]:::client
    end

    %% Server Subgraph
    subgraph "Server"
        G["Main Application (main.go)"]:::server
        H["Router Module"]:::server
        I["Bilibili Package (Video Parsing)"]:::server
        J["Task Management Module"]:::server
        K["Utility & Common Modules"]:::server
    end

    %% External Dependencies
    L["SQLite"]:::external
    M["FFmpeg"]:::external
    N["Docker & Goreleaser"]:::external

    %% Connections from Client to Server
    A -->|"APIcalls"| H
    B -->|"TriggersLogin"| H
    C -->|"ManagesTasks"| H
    D -->|"WorkActions"| H
    E -->|"UpdatesSettings"| H
    F -->|"ProvidesShared"| A

    %% Internal Server Relationships
    G -->|"Initializes"| H
    H -->|"HandlesVideo"| I
    H -->|"DelegatesTask"| J
    H -->|"UsesUtil"| K
    I -->|"QueuesTask"| J
    I -->|"CallsFFmpeg"| M
    K -->|"DBAccess"| L
    G -->|"Deployment"| N

    %% Click Events for Client Components
    click A "https://github.com/iuroc/bilidown/blob/main/client/index.html"
    click B "https://github.com/iuroc/bilidown/tree/main/client/src/login"
    click C "https://github.com/iuroc/bilidown/tree/main/client/src/task"
    click D "https://github.com/iuroc/bilidown/tree/main/client/src/work"
    click E "https://github.com/iuroc/bilidown/tree/main/client/src/setting"
    click F "https://github.com/iuroc/bilidown/blob/main/client/src/header.ts"

    %% Click Events for Server Components
    click G "https://github.com/iuroc/bilidown/blob/main/server/main.go"
    click H "https://github.com/iuroc/bilidown/tree/main/server/router"
    click I "https://github.com/iuroc/bilidown/tree/main/server/bilibili"
    click J "https://github.com/iuroc/bilidown/tree/main/server/task"
    click K "https://github.com/iuroc/bilidown/tree/main/server/common"

    %% Class Definitions for Colors
    classDef client fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef server fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
