# saitokento/dlsite-browsing-companion architecture

> Architecture diagram of the GitHub repository saitokento/dlsite-browsing-companion, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saitokento/dlsite-browsing-companion
- Repository: https://github.com/saitokento/dlsite-browsing-companion

## Overview

1. **Project type and runtime boundary**
   - This is a **browser extension** called **DLsite Browsing Companion**.
   - The architecture is organized around extension contexts rather than a traditional app/server split: **background script**, **content scripts injected into DLsite pages**, and **extension UI surfaces**.

2. **Framework and build model**
   - The repo is built with **WXT** (`wxt.config.ts`), which is why the source is organized around `src/entrypoints/...`.
   - TypeScript is the main implementation language, with React used for the extension UIs.

3. **Core extension controller**
   - `src/entrypoints/background.ts` is the central non-UI runtime.
   - In extension terms, this is the place for persistent coordination: cross-tab logic, shared state, and message routing between page scripts and extension UI.

4. **Page-injected content scripts**
   - The repo has several content-script entrypoints tailored to specific DLsite pages:
     - `home.content.ts`
     - `work.content.ts`
     - `circle.content.ts`
     - `cart.content.ts`
     - `download.content.ts`
     - `userbuy.content.ts`
   - These scripts are the boundary where the extension interacts with the DLsite website DOM and page context.
   - The naming suggests page-specific augmentation rather than one generic scraper.

5. **Data flow from site pages into the extension**
   - The likely primary flow is: **DLsite page → content script → shared messaging/background → extension UI**.
   - This is reinforced by `src/utils/messaging.ts`, which indicates structured communication across extension contexts.

6. **Extension UI surfaces**
   - There are three separate UI entrypoints:
     - `popup` for the toolbar popup
     - `sidepanel` for a persistent side panel
     - `options` for configuration/settings
   - Each UI has its own `App.tsx`, `main.tsx`, HTML shell, and CSS, so they are independent entrypoints rather than routes in one SPA.

7. **Shared types and exports**
   - `src/utils/types.ts` and `src/utils/exports.ts` provide shared contracts and re-exports used across background, content scripts, and UI.
   - This is important for keeping the message payloads and domain data consistent across isolated extension contexts.

8. **Static assets**
   - `public/icon` contains extension icons and other static assets needed by the browser extension packaging pipeline.
   - There is no separate backend or API asset pipeline shown in the tree.

9. **Styling and UI implementation**
   - The UI entrypoints use plain CSS files alongside React components, which suggests a lightweight, per-surface styling approach.
   - Each surface is self-contained, so popup/sidepanel/options can evolve independently.

10. **Operational and delivery tooling**
   - The repo includes CI/release automation under `.github/workflows`, plus Husky hooks and Commitlint for commit hygiene.
   - Tooling files for ESLint, Prettier, and pnpm lockfile indicate a strongly managed TypeScript codebase, but these affect development quality more than runtime architecture.

11. **Architectural boundary summary**
   - The key architectural split is:
     - **Website context**: DLsite page-specific content scripts
     - **Extension core**: background coordinator
     - **Extension UI**: popup, sidepanel, options
   - Shared utilities connect these parts through typed messaging and common data definitions, rather than direct coupling.

12. **What to show in a diagram**
   - A useful architecture diagram would place DLsite pages on one side, the extension background in the middle, and popup/sidepanel/options on the other side.
   - Draw arrows showing content scripts reading/modifying page state and sending messages through the background to the UI surfaces.

Main entry points: [`src/entrypoints/background.ts`](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/background.ts) (Background), [`wxt.config.ts`](https://github.com/saitokento/dlsite-browsing-companion/blob/main/wxt.config.ts) (WXT config), [`src/utils/messaging.ts`](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/utils/messaging.ts) (Messaging), [`src/utils/exports.ts`](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/utils/exports.ts) (Exports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime_pages["DLsite pages"]
  node_home_content["Home script<br/>content script<br/>[home.content.ts]"]
  node_work_content["Work script<br/>content script<br/>[work.content.ts]"]
  node_circle_content["Circle script<br/>content script<br/>[circle.content.ts]"]
  node_cart_content["Cart script<br/>content script<br/>[cart.content.ts]"]
  node_download_content["Download script<br/>content script"]
  node_userbuy_content["Purchase script<br/>content script<br/>[userbuy.content.ts]"]
end

subgraph group_runtime_core["Extension core"]
  node_background(("Background<br/>extension core<br/>[background.ts]"))
end

subgraph group_runtime_ui["Extension UI"]
  node_popup_app["Popup app<br/>react UI<br/>[App.tsx]"]
  node_popup_main["Popup entry<br/>ui bootstrap<br/>[main.tsx]"]
  node_sidepanel_app["Sidepanel app<br/>react UI<br/>[App.tsx]"]
  node_sidepanel_main["Sidepanel entry<br/>ui bootstrap<br/>[main.tsx]"]
  node_options_app["Options app<br/>react UI<br/>[App.tsx]"]
  node_options_main["Options entry<br/>ui bootstrap<br/>[main.tsx]"]
end

subgraph group_shared_build["Shared and build"]
  node_wxt["WXT config<br/>build config<br/>[wxt.config.ts]"]
  node_shared_types["Shared types<br/>contracts<br/>[types.ts]"]
  node_shared_messaging["Messaging<br/>channel<br/>[messaging.ts]"]
  node_shared_exports["Exports<br/>barrel<br/>[exports.ts]"]
end

node_wxt -->|"builds"| node_background
node_wxt -->|"builds"| node_home_content
node_wxt -->|"builds"| node_work_content
node_wxt -->|"builds"| node_circle_content
node_wxt -->|"builds"| node_cart_content
node_wxt -->|"builds"| node_download_content
node_wxt -->|"builds"| node_userbuy_content
node_wxt -->|"builds"| node_popup_main
node_wxt -->|"builds"| node_sidepanel_main
node_wxt -->|"builds"| node_options_main
node_home_content -->|"messages"| node_background
node_work_content -->|"messages"| node_background
node_circle_content -->|"messages"| node_background
node_cart_content -->|"messages"| node_background
node_download_content -->|"messages"| node_background
node_userbuy_content -->|"messages"| node_background
node_background -->|"updates"| node_popup_app
node_background -->|"updates"| node_sidepanel_app
node_background -->|"updates"| node_options_app
node_shared_messaging -->|"used by"| node_background
node_shared_messaging -->|"used by"| node_home_content
node_shared_messaging -->|"used by"| node_work_content
node_shared_messaging -->|"used by"| node_circle_content
node_shared_messaging -->|"used by"| node_cart_content
node_shared_messaging -->|"used by"| node_download_content
node_shared_messaging -->|"used by"| node_userbuy_content
node_shared_types -->|"defines"| node_shared_messaging
node_shared_exports -->|"re-exports"| node_shared_types
node_shared_exports -->|"re-exports"| node_shared_messaging
node_shared_exports -->|"imports"| node_background
node_shared_exports -->|"imports"| node_popup_app
node_shared_exports -->|"imports"| node_sidepanel_app
node_shared_exports -->|"imports"| node_options_app

click node_wxt "https://github.com/saitokento/dlsite-browsing-companion/blob/main/wxt.config.ts"
click node_shared_types "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/utils/types.ts"
click node_shared_messaging "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/utils/messaging.ts"
click node_shared_exports "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/utils/exports.ts"
click node_background "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/background.ts"
click node_home_content "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/home.content.ts"
click node_work_content "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/work.content.ts"
click node_circle_content "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/circle.content.ts"
click node_cart_content "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/cart.content.ts"
click node_download_content "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/download.content.ts"
click node_userbuy_content "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/userbuy.content.ts"
click node_popup_app "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/popup/App.tsx"
click node_popup_main "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/popup/main.tsx"
click node_sidepanel_app "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/sidepanel/App.tsx"
click node_sidepanel_main "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/sidepanel/main.tsx"
click node_options_app "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/options/App.tsx"
click node_options_main "https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/options/main.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_home_content,node_work_content,node_circle_content,node_cart_content,node_download_content,node_userbuy_content toneBlue
class node_background toneAmber
class node_popup_app,node_popup_main,node_sidepanel_app,node_sidepanel_main,node_options_app,node_options_main toneMint
class node_wxt,node_shared_types,node_shared_messaging,node_shared_exports toneRose
```

## Components

### DLsite pages

Website contexts augmented by page-specific content scripts

- [Home script](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/home.content.ts): content script · Injected into DLsite home pages · `src/entrypoints/home.content.ts`
- [Work script](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/work.content.ts): content script · Injected into DLsite work pages · `src/entrypoints/work.content.ts`
- [Circle script](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/circle.content.ts): content script · Injected into DLsite circle pages · `src/entrypoints/circle.content.ts`
- [Cart script](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/cart.content.ts): content script · Injected into DLsite cart pages · `src/entrypoints/cart.content.ts`
- [Download script](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/download.content.ts): content script · Injected into DLsite download pages · `src/entrypoints/download.content.ts`
- [Purchase script](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/userbuy.content.ts): content script · Injected into DLsite purchase history pages · `src/entrypoints/userbuy.content.ts`

### Extension core

Persistent background coordination and message routing

- [Background](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/background.ts): extension core · Persistent coordinator for state and routing · `src/entrypoints/background.ts`

### Extension UI

Independent browser extension surfaces

- [Popup app](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/popup/App.tsx): react UI · Toolbar popup interface · `src/entrypoints/popup/App.tsx`
- [Popup entry](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/popup/main.tsx): ui bootstrap · Popup mount and startup · `src/entrypoints/popup/main.tsx`
- [Sidepanel app](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/sidepanel/App.tsx): react UI · Persistent side panel interface · `src/entrypoints/sidepanel/App.tsx`
- [Sidepanel entry](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/sidepanel/main.tsx): ui bootstrap · Sidepanel mount and startup · `src/entrypoints/sidepanel/main.tsx`
- [Options app](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/options/App.tsx): react UI · Extension settings interface · `src/entrypoints/options/App.tsx`
- [Options entry](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/entrypoints/options/main.tsx): ui bootstrap · Options mount and startup · `src/entrypoints/options/main.tsx`

### Shared and build

Contracts, messaging, and WXT entrypoint wiring

- [WXT config](https://github.com/saitokento/dlsite-browsing-companion/blob/main/wxt.config.ts): build config · Extension build and entrypoint wiring · `wxt.config.ts`
- [Shared types](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/utils/types.ts): contracts · Common domain and message types · `src/utils/types.ts`
- [Messaging](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/utils/messaging.ts): channel · Cross-context message helpers · `src/utils/messaging.ts`
- [Exports](https://github.com/saitokento/dlsite-browsing-companion/blob/main/src/utils/exports.ts): barrel · Shared re-exports for extension contexts · `src/utils/exports.ts`

## Connections

- WXT config → Background: builds · Registers the background entrypoint
- WXT config → Home script: builds · Registers page injection
- WXT config → Work script: builds · Registers page injection
- WXT config → Circle script: builds · Registers page injection
- WXT config → Cart script: builds · Registers page injection
- WXT config → Download script: builds · Registers page injection
- WXT config → Purchase script: builds · Registers page injection
- WXT config → Popup entry: builds · Registers popup surface
- WXT config → Sidepanel entry: builds · Registers side panel surface
- WXT config → Options entry: builds · Registers options surface
- Home script → Background: messages · Sends page-derived events and state
- Work script → Background: messages · Sends page-derived events and state
- Circle script → Background: messages · Sends page-derived events and state
- Cart script → Background: messages · Sends page-derived events and state
- Download script → Background: messages · Sends page-derived events and state
- Purchase script → Background: messages · Sends page-derived events and state
- Background → Popup app: updates · Feeds popup state and actions
- Background → Sidepanel app: updates · Feeds side panel state and actions
- Background → Options app: updates · Feeds settings state and actions
- Messaging → Background: used by · Shared message channel helpers
- Messaging → Home script: used by · Shared message channel helpers
- Messaging → Work script: used by · Shared message channel helpers
- Messaging → Circle script: used by · Shared message channel helpers
- Messaging → Cart script: used by · Shared message channel helpers
- Messaging → Download script: used by · Shared message channel helpers
- Messaging → Purchase script: used by · Shared message channel helpers
- Shared types → Messaging: defines · Typed payload contracts
- Exports → Shared types: re-exports · Shared surface for common contracts
- Exports → Messaging: re-exports · Shared surface for message helpers
- Exports → Background: imports · Common extension helpers
- Exports → Popup app: imports · Common extension helpers
- Exports → Sidepanel app: imports · Common extension helpers
- Exports → Options app: imports · Common extension helpers
