# david20571015/pixiv-downloader architecture

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

- Interactive diagram: https://gitdiagram.com/david20571015/pixiv-downloader
- Repository: https://github.com/david20571015/pixiv-downloader

## Overview

##### Main Components
- Extension Entry Points – The project clearly separates its functionality into different “entrypoints”:
- Background Script (src/entrypoints/background/index.ts): This handles persistent/background tasks, such as managing downloads and possibly coordinating with other scripts.
- Content Script (src/entrypoints/content/DownloadButton.vue and src/entrypoints/content/index.ts): Injected into Pixiv pages, this script is responsible for adding a “Download” button and handling UI interactions on the site.
- Options Page (src/entrypoints/options/OptionsPage.vue, constant.ts, index.html, main.ts): This is the configuration UI built using Vue 3 and Vuetify, allowing users to customize filename templates, choose image sizes, and set up conflict handling modes.

##### Supporting Utilities and Assets
- Utils (src/utils/downloader.ts and src/utils/options-store.ts): These utility modules contain core functionalities such as download logic (e.g., handling image sizes, conflict resolution) and managing the options/settings storage for the extension.

##### Interactions and Relationships
- Data Flow:
- The Content Script on a Pixiv illustration page “listens” for user actions (click on the Download button) and communicates with the Background Script to initiate downloads.
- The Background Script, upon receiving signals, leverages the downloader utility to process image data and the options store to load user preferences.
- The Options Page provides a user interface for configuring various settings. Changes here should persist (and be consumed by the downloader) via the options-store utility.
- External Services:
- The extension supports a proxy (https://pixiv.cat/) to bypass hotlink protection. This should be represented as an external dependency the Background Script or downloader invokes when necessary.

- Content Script (UI on Pixiv pages)
- Background Script (Core logic and download management)
- Options Page (Settings UI built with Vue 3 + Vuetify)
- Utility Modules (Downloader and Options Store)
- External Proxy Service (pixiv.cat)
- External systems (Pixiv website, Proxy service) might have a third distinct style or border.

##### Detailed Steps for the Principal Software Engineer
○ Content Script – Displaying the “Download” button on Pixiv pages.
○ Background Script – Managing background operations and data processes.
○ Options Page – Providing a settings UI for customization.
○ External Services – Pixiv website (where illustrations reside) and Proxy Service (pixiv.cat).
○ User interactions triggering content script actions.
○ Content Script forwarding download requests to Background Script.
○ Background Script invoking utilities (Downloader and Options Store) for handling image downloads and user-defined settings.
○ Background Script contacting the external proxy and Pixiv service as needed.
- Use annotations or callouts to indicate important technologies (e.g., Vue 3 & Vuetify for the Options Page, TypeScript for the core scripts).

– Emphasize directional flows and interactions between scripts and external services.
– Tailor the details so that the division of responsibilities (content, background, options, utils) is immediately apparent.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Chrome Extension Container
    subgraph "Chrome Extension"
        %% Entrypoints Subgraph
        subgraph "Entrypoints"
            BS["Background Script"]:::logic
            subgraph "Content Script"
                CS1["DownloadButton.vue"]:::ui
                CS2["Content/index.ts"]:::ui
            end
            subgraph "Options Page"
                OP1["OptionsPage.vue"]:::ui
                OP2["constant.ts"]:::ui
                OP3["index.html"]:::ui
                OP4["main.ts"]:::ui
            end
        end

        %% Utilities and Assets Subgraph
        subgraph "Utilities and Assets"
            DU["Downloader Utility"]:::logic
            OS["Options Store Utility"]:::logic
            AS["Assets (UI Resources)"]:::ui
        end
    end

    %% External Services Container
    subgraph "External Services"
        PW["Pixiv Website"]:::external
        PC["pixiv.cat Proxy"]:::external
    end

    %% Interactions and Relationships
    %% Content Script initiates download request to Background Script
    CS1 -->|"DownloadRequest"| BS
    CS2 -->|"DownloadRequest"| BS

    %% Background Script leverages utilities
    BS -->|"ProcessDownload"| DU
    BS -->|"LoadUserSettings"| OS

    %% Options Page interacts with Options Store Utility (bidirectional sync)
    OP1 <-->|"SettingsSync"| OS

    %% Downloader Utility calls external proxy for downloads
    DU -->|"ProxyCall"| PC

    %% Background Script fetches data from Pixiv Website
    BS -->|"FetchData"| PW

    %% Content Script also injects UI into Pixiv Website
    CS1 -->|"UIInjection"| PW

    %% Click Events for Mapped Components
    click BS "https://github.com/david20571015/pixiv-downloader/blob/main/src/entrypoints/background/index.ts"
    click CS1 "https://github.com/david20571015/pixiv-downloader/blob/main/src/entrypoints/content/DownloadButton.vue"
    click CS2 "https://github.com/david20571015/pixiv-downloader/blob/main/src/entrypoints/content/index.ts"
    click OP1 "https://github.com/david20571015/pixiv-downloader/blob/main/src/entrypoints/options/OptionsPage.vue"
    click OP2 "https://github.com/david20571015/pixiv-downloader/blob/main/src/entrypoints/options/constant.ts"
    click OP3 "https://github.com/david20571015/pixiv-downloader/blob/main/src/entrypoints/options/index.html"
    click OP4 "https://github.com/david20571015/pixiv-downloader/blob/main/src/entrypoints/options/main.ts"
    click DU "https://github.com/david20571015/pixiv-downloader/blob/main/src/utils/downloader.ts"
    click OS "https://github.com/david20571015/pixiv-downloader/blob/main/src/utils/options-store.ts"
    click AS "https://github.com/david20571015/pixiv-downloader/tree/main/src/assets"

    %% Styling for UI, Logic, and External Components
    classDef ui fill:#A7C7E7,stroke:#333,stroke-width:2px;
    classDef logic fill:#F9D57A,stroke:#333,stroke-width:2px;
    classDef external fill:#F08080,stroke:#333,stroke-width:2px;
```
