# brandonyuyu/douyin-archiver architecture

> Architecture diagram of the GitHub repository brandonyuyu/douyin-archiver, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/brandonyuyu/douyin-archiver
- Repository: https://github.com/brandonyuyu/douyin-archiver

## Overview

Douyin Liked / Favorites Archiver is a browser extension that archives the signed-in user’s liked and favorited videos. The main workflow runs a page-side response hook while the content script scrolls virtualized lists, validates and normalizes captured data, then sends records to the service worker for deduplicated persistent storage. Users can monitor runs, export JSON/CSV, and import or clear archives. The README and source index support the main flow; some internal wiring is documented rather than visible in the sampled excerpts.

Main entry points: [`extension/content/content.js`](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/content/content.js) (Capture controller), [`extension/popup/popup.js`](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/popup/popup.js) (Run controls and status), [`extension/pages/manage.js`](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/pages/manage.js) (Archive management), [`extension/background/service-worker.js`](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/background/service-worker.js) (Background service worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Capture and scrolling"]
  node_hook["Network response hook<br/>[hook.js]"]
  node_content["Capture controller<br/>[content.js]"]
  node_capture_parse["API response parser<br/>[capture.js]"]
  node_normalize["Record normalization<br/>[normalize.js]"]
  node_dom["DOM fallback harvester<br/>[domHarvest.js]"]
  node_scroll["Scroll and run loop<br/>[scroll.js]"]
  node_interruptions["Interruption detection<br/>[interruptions.js]"]
  node_targets["Douyin site rules<br/>[targets.js]"]
end

subgraph group_archive["Archive and settings"]
  node_worker["Background service worker<br/>[service-worker.js]"]
  node_store[("Persistent archive<br/>[store.js]")]
  node_dedup["Record merge and dedup<br/>[dedup.js]"]
  node_settings["Run settings<br/>[settings.js]"]
  node_stoprules["Stop and pause rules<br/>[stopRules.js]"]
end

subgraph group_interface["User interface"]
  node_popup["Run controls and status<br/>[popup.js]"]
  node_manage["Archive management<br/>[manage.js]"]
end

subgraph group_exchange["Import and export"]
  node_exchange["JSON archive format<br/>[exchange.js]"]
  node_csv["CSV formatter<br/>[csv.js]"]
  node_download["File download<br/>[download.js]"]
end

node_user(("Archive user"))
node_douyin(("Douyin page"))

node_user -->|"starts run"| node_popup
node_popup -->|"controls run"| node_content
node_content -.->|"drives scrolling"| node_scroll
node_douyin -->|"serves list responses"| node_hook
node_hook -->|"forwards response copy"| node_content
node_content -.->|"validates responses"| node_capture_parse
node_capture_parse -->|"normalizes items"| node_normalize
node_capture_parse -->|"uses site rules"| node_targets
node_content -.->|"harvests fallback"| node_dom
node_dom -->|"normalizes items"| node_normalize
node_dom -->|"uses selectors"| node_targets
node_scroll -->|"evaluates run state"| node_stoprules
node_scroll -->|"uses run settings"| node_settings
node_content -.->|"detects interruptions"| node_interruptions
node_content -->|"sends captured records"| node_worker
node_worker -->|"persists archive"| node_store
node_store -->|"merges records"| node_dedup
node_worker -->|"normalizes settings"| node_settings
node_popup -->|"requests state and records"| node_worker
node_manage -->|"requests archive actions"| node_worker
node_manage -->|"parses imports"| node_exchange
node_exchange -->|"sanitizes imported records"| node_normalize
node_popup -->|"builds JSON export"| node_exchange
node_popup -->|"formats CSV export"| node_csv
node_manage -->|"formats CSV export"| node_csv
node_popup -->|"downloads exports"| node_download
node_manage -->|"downloads exports"| node_download
node_user -->|"imports or clears"| node_manage

click node_hook "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/content/hook.js"
click node_content "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/content/content.js"
click node_capture_parse "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/capture.js"
click node_normalize "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/normalize.js"
click node_dom "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/domHarvest.js"
click node_scroll "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/scroll.js"
click node_interruptions "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/interruptions.js"
click node_targets "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/targets.js"
click node_worker "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/background/service-worker.js"
click node_store "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/store.js"
click node_dedup "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/dedup.js"
click node_settings "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/settings.js"
click node_stoprules "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/stopRules.js"
click node_popup "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/popup/popup.js"
click node_manage "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/pages/manage.js"
click node_exchange "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/exchange.js"
click node_csv "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/csv.js"
click node_download "https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/download.js"

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_hook,node_content,node_capture_parse,node_normalize,node_dom,node_scroll,node_interruptions,node_targets,node_user toneBlue
class node_worker,node_store,node_dedup,node_settings,node_stoprules toneAmber
class node_popup,node_manage toneMint
class node_exchange,node_csv,node_download toneRose
class node_douyin toneIndigo
```

## Components

### Capture and scrolling

- [Network response hook](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/content/hook.js): `extension/content/hook.js`
- [Capture controller](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/content/content.js): `extension/content/content.js`
- [API response parser](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/capture.js): `extension/lib/capture.js`
- [Record normalization](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/normalize.js): `extension/lib/normalize.js`
- [DOM fallback harvester](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/domHarvest.js): `extension/lib/domHarvest.js`
- [Scroll and run loop](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/scroll.js): `extension/lib/scroll.js`
- [Interruption detection](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/interruptions.js): `extension/lib/interruptions.js`
- [Douyin site rules](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/targets.js): `extension/lib/targets.js`

### Archive and settings

- [Background service worker](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/background/service-worker.js): `extension/background/service-worker.js`
- [Persistent archive](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/store.js): `extension/lib/store.js`
- [Record merge and dedup](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/dedup.js): `extension/lib/dedup.js`
- [Run settings](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/settings.js): `extension/lib/settings.js`
- [Stop and pause rules](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/stopRules.js): `extension/lib/stopRules.js`

### User interface

- [Run controls and status](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/popup/popup.js): `extension/popup/popup.js`
- [Archive management](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/pages/manage.js): `extension/pages/manage.js`

### Import and export

- [JSON archive format](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/exchange.js): `extension/lib/exchange.js`
- [CSV formatter](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/csv.js): `extension/lib/csv.js`
- [File download](https://github.com/brandonyuyu/douyin-archiver/blob/main/extension/lib/download.js): `extension/lib/download.js`

### Other components

- **Archive user**
- **Douyin page**

## Connections

- Archive user → Run controls and status: starts run (evidence: `README.md`)
- Run controls and status → Capture controller: controls run (evidence: `README.md`)
- Capture controller → Scroll and run loop: drives scrolling
- Douyin page → Network response hook: serves list responses (evidence: `README.md`)
- Network response hook → Capture controller: forwards response copy (evidence: `README.md`)
- Capture controller → API response parser: validates responses
- API response parser → Record normalization: normalizes items (evidence: `extension/lib/capture.js`)
- API response parser → Douyin site rules: uses site rules (evidence: `extension/lib/capture.js`)
- Capture controller → DOM fallback harvester: harvests fallback (evidence: `README.md`)
- DOM fallback harvester → Record normalization: normalizes items (evidence: `extension/lib/domHarvest.js`)
- DOM fallback harvester → Douyin site rules: uses selectors (evidence: `extension/lib/domHarvest.js`)
- Scroll and run loop → Stop and pause rules: evaluates run state (evidence: `extension/lib/scroll.js`)
- Scroll and run loop → Run settings: uses run settings (evidence: `extension/lib/scroll.js`)
- Capture controller → Interruption detection: detects interruptions
- Capture controller → Background service worker: sends captured records (evidence: `README.md`)
- Background service worker → Persistent archive: persists archive (evidence: `extension/background/service-worker.js`)
- Persistent archive → Record merge and dedup: merges records (evidence: `extension/lib/store.js`)
- Background service worker → Run settings: normalizes settings (evidence: `extension/background/service-worker.js`)
- Run controls and status → Background service worker: requests state and records (evidence: `extension/popup/popup.js`)
- Archive management → Background service worker: requests archive actions (evidence: `extension/pages/manage.js`)
- Archive management → JSON archive format: parses imports (evidence: `extension/pages/manage.js`)
- JSON archive format → Record normalization: sanitizes imported records (evidence: `extension/lib/exchange.js`)
- Run controls and status → JSON archive format: builds JSON export (evidence: `extension/popup/popup.js`)
- Run controls and status → CSV formatter: formats CSV export (evidence: `extension/popup/popup.js`)
- Archive management → CSV formatter: formats CSV export (evidence: `extension/pages/manage.js`)
- Run controls and status → File download: downloads exports (evidence: `extension/popup/popup.js`)
- Archive management → File download: downloads exports (evidence: `extension/pages/manage.js`)
- Archive user → Archive management: imports or clears (evidence: `README.md`)
