# btjawa/bilitools architecture

> Architecture diagram of the GitHub repository btjawa/bilitools, 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/btjawa/bilitools
- Repository: https://github.com/btjawa/bilitools

## Overview

##### Project Type & Core Purpose
- This is a full-stack desktop application combining a modern Vue/TypeScript frontend with a Rust-powered backend (via Tauri). Its main purpose is to serve as a toolbox for downloading and parsing multimedia content from Bilibili.
- The README emphasizes functionalities such as video/audio support, different login methods, and integration with auxiliary tools (ffmpeg, aria2, DanmakuFactory), which must be represented in the design.

##### Key Components
a. Frontend (User Interface):
- Located in the “src” directory.
- Contains Vue components (e.g., App.vue, various view files, and reusable components like ContextMenu, TitleBar, and Updater).
- Includes internationalization files under “src/i18n” and “src/locales” for supporting multiple languages.
- Uses a router (under “src/router”) and a state management system (“src/store”) to manage app navigation and state.

b. Backend (Tauri/Rust Layer):
- Found in the “src-tauri” directory.
- Uses Rust to implement native functionalities.
- Contains modules for commands, services (for handling aria2c, ffmpeg, login, etc.), and storage management.
- Manages integration with external binaries (e.g., ffmpeg, aria2c, DanmakuFactory) that are embedded and available in precompiled formats.
- Includes configuration files such as tauri.conf.json and platform-specific variants.

c. External Services & Binaries:
- External engines like ffmpeg, aria2c, and DanmakuFactory are part of the “src-tauri/binaries” which perform media processing, efficient downloading, and subtitle transformations.
- They are connected through Rust “services” (e.g., src-tauri/src/services/) that manage the interfacing between the application’s logic and these binaries.

d. Data Storage:
- Uses SQLite for local storage (as mentioned in the README) for caching cookies, login data, download history, and configuration.
- This persistence layer as an independent storage component interacting with the backend.

##### Relationships and Interactions
- The backend, upon receiving commands, may invoke external binaries (ffmpeg, aria2c) and internal services (e.g., for login or parsing) to process multimedia data.
- Persistent storage (SQLite) sits under the backend domain and is used for caching user data and configurations.
- Additionally, configuration files and localized resources can be depicted as supporting components that inform both backend logic and frontend UI.

##### Architectural Patterns & Design Principles
- The frontend uses standard patterns with reusable components, centralized state management (store), and routing for navigation.
- The backend modules implement a service-oriented design where each service (ffmpeg, aria2c, login, storage, etc.) is encapsulated within its module.
- The system underscores a clear separation of concerns, where the UI layer is decoupled from the native functionalities provided by Rust/Tauri.
- Integration with external binaries (via patching and precompiled binaries) reflects modular design that can be updated or extended independently.

##### Detailed Elements
- Clear labels for:
- UI Components: “Main App”, “Components (SideBar, TitleBar, etc.)”, “Views (Search, Download, Settings)”
- Frontend Services: “Router”, “State Management (Vuex/Pinia)”, “i18n Modules”
- Tauri Bridge: representing the inter-layer communication between JS and Rust.
- Backend Services: “Download Manager Service”, “Media Parsing Service”, “Login/Auth Service”, “External Command Invoker”
- External Binaries: “ffmpeg”, “aria2c”, “DanmakuFactory”
- Data Storage: “SQLite Database (Local Storage)”
- UI invoking Tauri commands.
- Backend services invoking respective external processes.
- Data returning from external resources to the UI display via the backend.
- Presentation layer (frontend)
- Business logic layer (backend)
- External integration (third-party binaries/services)
- Data layer (SQLite storage)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        F1["Main App (Vue & TS)"]:::frontend
        F2["main.ts"]:::frontend
        F3["Components (UI)"]:::frontend
        F4["Views (UI)"]:::frontend
        F5["i18n"]:::frontend
        F6["Locales"]:::frontend
        F7["Router (Navigation)"]:::frontend
        F8["State Management (Store)"]:::frontend
    end

    %% Tauri Bridge
    TB["Tauri Bridge (Command API)"]:::bridge

    %% Backend Layer
    subgraph "Backend Layer"
        B1["Rust Backend (Tauri)"]:::backend
        B2["Backend Services"]:::backend
    end

    %% External Services
    subgraph "External Services"
        E1["ffmpeg"]:::external
        E2["aria2c"]:::external
        E3["DanmakuFactory"]:::external
    end

    %% Data Persistence Layer
    subgraph "Data Persistence"
        D1["SQLite Database (Local Storage)"]:::data
    end

    %% Connections from Frontend to Bridge
    F1 --> TB
    F2 --> TB
    F3 --> TB
    F4 --> TB
    F5 --> TB
    F6 --> TB
    F7 --> TB
    F8 --> TB

    %% Bridge to Backend
    TB --> B1
    B1 --> B2

    %% Backend Services to External Services and Data Storage
    B2 --> E1
    B2 --> E2
    B2 --> E3
    B2 --> D1

    %% Click Events for Frontend
    click F1 "https://github.com/btjawa/bilitools/blob/master/src/App.vue"
    click F2 "https://github.com/btjawa/bilitools/blob/master/src/main.ts"
    click F3 "https://github.com/btjawa/bilitools/tree/master/src/components/"
    click F4 "https://github.com/btjawa/bilitools/tree/master/src/views/"
    click F5 "https://github.com/btjawa/bilitools/tree/master/src/i18n/"
    click F6 "https://github.com/btjawa/bilitools/tree/master/src/locales/"
    click F7 "https://github.com/btjawa/bilitools/blob/master/src/router/index.ts"
    click F8 "https://github.com/btjawa/bilitools/tree/master/src/store/"

    %% Click Events for Backend
    click B1 "https://github.com/btjawa/bilitools/tree/master/src-tauri/"
    click B2 "https://github.com/btjawa/bilitools/tree/master/src-tauri/src/services/"

    %% Click Events for External Services
    click E1 "https://github.com/btjawa/bilitools/tree/master/src-tauri/binaries/"
    click E2 "https://github.com/btjawa/bilitools/tree/master/src-tauri/binaries/"
    click E3 "https://github.com/btjawa/bilitools/tree/master/src-tauri/binaries/"

    %% Click Event for Data Storage
    click D1 "https://github.com/btjawa/bilitools/tree/master/src-tauri/src/storage/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef bridge fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef data fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
