# joeanamier/tiktokdownloader architecture

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

- Interactive diagram: https://gitdiagram.com/joeanamier/tiktokdownloader
- Repository: https://github.com/joeanamier/tiktokdownloader

## Overview

1. **What this repo is**
   DouK-Downloader is a Python 3.12 data-collection and media-downloading tool for Douyin/TikTok. Its core job is to take user input such as links, account IDs, search terms, or live-room IDs, resolve them into platform requests, fetch metadata/media URLs, and then either download files or persist structured records.

2. **Top-level entry and runtime modes**
   `main.py` is the primary entrypoint, and the `src/application` package appears to route startup into different execution modes: terminal interaction, server/API mode, and monitoring mode. The repository also contains separate frontends for CLI, TUI, and a GUI/web-oriented edition, though the README notes the Web UI code is not currently up to date.

3. **Presentation layer boundaries**
   The repo is organized around adapters for how users interact with it:
   - `src/cli_edition` for command-line flow
   - `src/tui_edition` for terminal UI
   - `src/gui_edition` and `src/application/main_server.py` for web-facing functionality
   - `src/application/main_monitor.py` for background monitoring behavior
   These layers should be drawn as thin shells over the same backend pipeline rather than separate business logic.

4. **Request and link-resolution layer**
   `src/link` and `src/extract` handle link parsing and request preparation. This is the boundary where raw Douyin/TikTok share links or URLs are normalized into canonical identifiers and request targets. `src/link/requester.py` is likely the HTTP abstraction, while `src/link/extractor.py` and `src/extract/extractor.py` turn remote responses into usable IDs, URLs, and page data.

5. **Platform-specific interface adapters**
   The `src/interface` package is the main feature surface. It is split by content type and platform:
   - general modules like account, comment, detail, live, mix, search, hot, user, hashtag, slides
   - TikTok-specific counterparts such as `*_tiktok.py`
   This suggests a dispatcher that routes each operation type to a dedicated parser/collector rather than one monolithic scraper.

6. **Core domain models**
   `src/models` defines the structured data passed between layers: account, comment, detail, live, mix, search, share, reply, response, settings. These are the contracts between network parsing, storage, and output generation. In an architecture diagram, these are the shared DTO/domain objects that keep the downloader, recorder, and storage code decoupled.

7. **Download and media handling**
   `src/downloader/download.py` is the file-transfer engine. It likely takes resolved media URLs and streams them to disk, with support for retries, resumable downloads, file-size limits, temporary staging, and duplicate skipping as described in the README. `src/module/ffmpeg.py` is the special-case path for live-stream recording/downloading, where the pipeline hands off to ffmpeg for transport-stream capture or remuxing.

8. **Persistence and storage outputs**
   The storage boundary lives in `src/storage`, which supports multiple export targets:
   - CSV
   - XLSX
   - SQLite
   - plain text
   `src/storage/manager.py` likely selects the backend, while `src/manager/database.py`, `cache.py`, and `recorder.py` coordinate persistence, deduplication, and progress/statistics tracking. The README’s “save collected data persistently” feature maps directly to this subsystem.

9. **State, caching, and recordkeeping**
   The `src/manager` package is the stateful service layer. It appears to centralize database access, cache lookup, and recording of downloaded IDs or statistics. This is the boundary where the tool avoids re-downloading known items and preserves incremental runs across sessions.

10. **Authentication, browser integration, and anti-bot tokens**
   `src/module/cookie.py`, `src/tools/browser.py`, and the `src/encrypt` package form the authentication and request-signing boundary. The encryption helpers (`xBogus`, `aBogus`, `xGnarly`, `verifyFp`, `msToken`, `ttWid`, `device_id`, `webID`) indicate the tool generates or manages platform-specific anti-scraping/request-validation parameters. Cookie acquisition from clipboard or browser is an important external dependency, especially for higher-quality downloads and private-content access.

11. **Shared utilities and cross-cutting concerns**
   `src/tools` contains the generic infrastructure used everywhere else: retries, progress reporting, file/folder management, formatting, console I/O, temporary files, truncation/renaming compatibility, and error handling. These are not business features; they are the supporting services that keep the pipelines resilient and cross-platform.

12. **Localization and configuration**
   `src/translation` and `locale` provide i18n for the UI/messages, while `src/config` and `src/models/settings.py` handle persisted configuration such as proxy settings, cookie values, download rules, and runtime options. This is the main configuration boundary between user-controlled settings and the downloader runtime.

13. **External dependencies that materially shape the architecture**
   The tool depends on HTTPX for network access, ffmpeg for live-stream handling, and storage libraries for XLSX/SQLite output. Docker is supported via the included `Dockerfile`, and the GitHub Actions workflows build executable releases and Docker images. These deployment paths matter because the runtime can be used as a local Python app, a packaged binary, or a containerized service.

14. **Overall data flow**
   The main flow is: user input or API request → command/UI layer → link resolution/request setup → platform-specific interface parser → model objects → downloader or storage manager → local files / SQLite / CSV / XLSX / text output. Auxiliary flows branch off for cookie retrieval, token/signature generation, live-stream ffmpeg recording, and incremental state updates in the cache/database layer.

Main entry points: [`src/interface/template.py`](https://github.com/joeanamier/tiktokdownloader/blob/master/src/interface/template.py) (Interface router), [`main.py`](https://github.com/joeanamier/tiktokdownloader/blob/master/main.py) (main.py), [`src/application/main_terminal.py`](https://github.com/joeanamier/tiktokdownloader/blob/master/src/application/main_terminal.py) (Terminal app), [`src/interface`](https://github.com/joeanamier/tiktokdownloader/tree/master/src/interface) (Core interfaces)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Entry & UIs"]
  node_n1["main.py<br/>entrypoint<br/>[main.py]"]
  node_n2["Terminal app<br/>runtime shell<br/>[main_terminal.py]"]
  node_n3["Server mode<br/>web runtime<br/>[main_server.py]"]
  node_n4["Monitor mode<br/>background runtime<br/>[main_monitor.py]"]
  node_n5["CLI edition<br/>cli frontend<br/>[main_cli.py]"]
  node_n6["TUI edition<br/>terminal frontend<br/>[app.py]"]
  node_n7["GUI edition<br/>web/ui shell"]
end

subgraph group_g2["Fetch Pipeline"]
  node_n8["Link resolve<br/>link parsing<br/>[extractor.py]"]
  node_n9["HTTP requester<br/>request layer<br/>[requester.py]"]
  node_n10["Extractor core<br/>page parser<br/>[extractor.py]"]
  node_n11["Interface router<br/>platform dispatcher<br/>[template.py]"]
  node_n12["TikTok adapters<br/>platform adapters<br/>[detail_tiktok.py]"]
  node_n13["Core interfaces<br/>content collectors"]
end

subgraph group_g3["Domain & State"]
  node_n14[("Models<br/>domain dtos")]
  node_n15[("Cache & record<br/>state service")]
end

subgraph group_g4["Media & Storage"]
  node_n16["Download engine<br/>file transfer<br/>[download.py]"]
  node_n17[("Storage manager<br/>export router<br/>[manager.py]")]
  node_n18[("SQLite/exports<br/>persistence backends<br/>[sqlite.py]")]
  node_n19["Live ffmpeg<br/>recording bridge<br/>[ffmpeg.py]"]
end

subgraph group_g5["Auth & Platform"]
  node_n20{{"Auth & signing<br/>anti-bot/auth"}}
  node_n21["Cookie tools<br/>credential helper<br/>[cookie.py]"]
  node_n22["Browser tools<br/>browser bridge<br/>[browser.py]"]
end

subgraph group_g6["Utilities"]
  node_n23["Shared tools<br/>utility layer"]
  node_n24["Config & i18n<br/>settings/localization<br/>[settings.py]"]
end

node_n1 -->|"starts"| node_n2
node_n1 -->|"starts"| node_n3
node_n1 -->|"starts"| node_n4
node_n1 -->|"uses"| node_n5
node_n1 -->|"uses"| node_n6
node_n1 -->|"uses"| node_n7
node_n2 -->|"resolves"| node_n8
node_n3 -->|"resolves"| node_n8
node_n5 -->|"dispatches"| node_n11
node_n6 -->|"dispatches"| node_n11
node_n7 -->|"dispatches"| node_n11
node_n8 -->|"fetches"| node_n9
node_n9 -->|"feeds"| node_n10
node_n10 -->|"normalizes"| node_n11
node_n11 -->|"specializes"| node_n12
node_n11 -->|"implements"| node_n13
node_n11 -->|"produces"| node_n14
node_n14 -->|"persists"| node_n15
node_n13 -->|"downloads"| node_n16
node_n14 -->|"exports"| node_n17
node_n17 -->|"writes"| node_n18
node_n13 -->|"records"| node_n19
node_n11 -->|"signs"| node_n20
node_n20 -->|"uses"| node_n21
node_n20 -->|"uses"| node_n22
node_n2 -->|"relies on"| node_n23
node_n11 -->|"relies on"| node_n23
node_n16 -->|"relies on"| node_n23
node_n24 -.->|"configures"| node_n2

click node_n1 "https://github.com/joeanamier/tiktokdownloader/blob/master/main.py"
click node_n2 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/application/main_terminal.py"
click node_n3 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/application/main_server.py"
click node_n4 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/application/main_monitor.py"
click node_n5 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/cli_edition/main_cli.py"
click node_n6 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/tui_edition/app.py"
click node_n7 "https://github.com/joeanamier/tiktokdownloader/tree/master/src/gui_edition"
click node_n8 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/link/extractor.py"
click node_n9 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/link/requester.py"
click node_n10 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/extract/extractor.py"
click node_n11 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/interface/template.py"
click node_n12 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/interface/detail_tiktok.py"
click node_n13 "https://github.com/joeanamier/tiktokdownloader/tree/master/src/interface"
click node_n14 "https://github.com/joeanamier/tiktokdownloader/tree/master/src/models"
click node_n15 "https://github.com/joeanamier/tiktokdownloader/tree/master/src/manager"
click node_n16 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/downloader/download.py"
click node_n17 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/storage/manager.py"
click node_n18 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/storage/sqlite.py"
click node_n19 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/module/ffmpeg.py"
click node_n20 "https://github.com/joeanamier/tiktokdownloader/tree/master/src/encrypt"
click node_n21 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/module/cookie.py"
click node_n22 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/tools/browser.py"
click node_n23 "https://github.com/joeanamier/tiktokdownloader/tree/master/src/tools"
click node_n24 "https://github.com/joeanamier/tiktokdownloader/blob/master/src/config/settings.py"

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_n1,node_n2,node_n3,node_n4,node_n5,node_n6,node_n7 toneBlue
class node_n8,node_n9,node_n10,node_n11,node_n12,node_n13 toneAmber
class node_n14,node_n15 toneMint
class node_n16,node_n17,node_n18,node_n19 toneRose
class node_n20,node_n21,node_n22 toneIndigo
class node_n23,node_n24 toneTeal
```

## Components

### Entry & UIs

User-facing startup modes and interaction shells.

- [main.py](https://github.com/joeanamier/tiktokdownloader/blob/master/main.py): entrypoint · Primary application entrypoint. · `main.py`
- [Terminal app](https://github.com/joeanamier/tiktokdownloader/blob/master/src/application/main_terminal.py): runtime shell · Routes startup into terminal-oriented workflows. · `src/application/main_terminal.py`
- [Server mode](https://github.com/joeanamier/tiktokdownloader/blob/master/src/application/main_server.py): web runtime · Web-facing/API-oriented application entry. · `src/application/main_server.py`
- [Monitor mode](https://github.com/joeanamier/tiktokdownloader/blob/master/src/application/main_monitor.py): background runtime · Background monitoring and polling execution path. · `src/application/main_monitor.py`
- [CLI edition](https://github.com/joeanamier/tiktokdownloader/blob/master/src/cli_edition/main_cli.py): cli frontend · Command-line interaction layer. · `src/cli_edition/main_cli.py`
- [TUI edition](https://github.com/joeanamier/tiktokdownloader/blob/master/src/tui_edition/app.py): terminal frontend · Terminal UI presentation layer. · `src/tui_edition/app.py`
- [GUI edition](https://github.com/joeanamier/tiktokdownloader/tree/master/src/gui_edition): web/ui shell · GUI/web-oriented edition shell. · `src/gui_edition`

### Fetch Pipeline

Resolve links, dispatch platform parsers, and normalize results.

- [Link resolve](https://github.com/joeanamier/tiktokdownloader/blob/master/src/link/extractor.py): link parsing · Normalizes shared links and URLs into canonical requests. · `src/link/extractor.py`
- [HTTP requester](https://github.com/joeanamier/tiktokdownloader/blob/master/src/link/requester.py): request layer · HTTP abstraction for platform calls and fetches. · `src/link/requester.py`
- [Extractor core](https://github.com/joeanamier/tiktokdownloader/blob/master/src/extract/extractor.py): page parser · Extracts IDs, page data, and usable targets from responses. · `src/extract/extractor.py`
- [Interface router](https://github.com/joeanamier/tiktokdownloader/blob/master/src/interface/template.py): platform dispatcher · Dispatches account, search, detail, live, hot, and other content flows. · `src/interface/template.py`
- [TikTok adapters](https://github.com/joeanamier/tiktokdownloader/blob/master/src/interface/detail_tiktok.py): platform adapters · TikTok-specific interface implementations. · `src/interface/detail_tiktok.py`
- [Core interfaces](https://github.com/joeanamier/tiktokdownloader/tree/master/src/interface): content collectors · General content collectors for accounts, comments, live, search, mix, and related views. · `src/interface`

### Domain & State

Shared models plus incremental cache/database state.

- [Models](https://github.com/joeanamier/tiktokdownloader/tree/master/src/models): domain dtos · Shared structured records passed between fetch, storage, and output layers. · `src/models`
- [Cache & record](https://github.com/joeanamier/tiktokdownloader/tree/master/src/manager): state service · Deduplication, persistence coordination, and run-state tracking. · `src/manager`

### Media & Storage

File downloads and persistent export targets.

- [Download engine](https://github.com/joeanamier/tiktokdownloader/blob/master/src/downloader/download.py): file transfer · Streams resolved media to disk with retries and download controls. · `src/downloader/download.py`
- [Storage manager](https://github.com/joeanamier/tiktokdownloader/blob/master/src/storage/manager.py): export router · Selects and coordinates CSV, XLSX, SQLite, text, and SQL persistence. · `src/storage/manager.py`
- [SQLite/exports](https://github.com/joeanamier/tiktokdownloader/blob/master/src/storage/sqlite.py): persistence backends · Representative persistent output backends. · `src/storage/sqlite.py`
- [Live ffmpeg](https://github.com/joeanamier/tiktokdownloader/blob/master/src/module/ffmpeg.py): recording bridge · ffmpeg-based live capture and remux path. · `src/module/ffmpeg.py`

### Auth & Platform

Cookie, browser, signing, and TikTok-specific helpers.

- [Auth & signing](https://github.com/joeanamier/tiktokdownloader/tree/master/src/encrypt): anti-bot/auth · Cookie handling, browser integration, and request-signing helpers. · `src/encrypt`
- [Cookie tools](https://github.com/joeanamier/tiktokdownloader/blob/master/src/module/cookie.py): credential helper · Cookie acquisition and session setup support. · `src/module/cookie.py`
- [Browser tools](https://github.com/joeanamier/tiktokdownloader/blob/master/src/tools/browser.py): browser bridge · Browser-assisted cookie/session capture utilities. · `src/tools/browser.py`

### Utilities

Cross-cutting support code used across the repo.

- [Shared tools](https://github.com/joeanamier/tiktokdownloader/tree/master/src/tools): utility layer · Retry, formatting, file, console, progress, and cleanup helpers. · `src/tools`
- [Config & i18n](https://github.com/joeanamier/tiktokdownloader/blob/master/src/config/settings.py): settings/localization · Runtime settings and translation resources. · `src/config/settings.py`

## Connections

- main.py → Terminal app: starts · Main entry can launch terminal runtime.
- main.py → Server mode: starts · Main entry can launch server runtime.
- main.py → Monitor mode: starts · Main entry can launch monitoring runtime.
- main.py → CLI edition: uses · CLI edition is one user-facing entry path.
- main.py → TUI edition: uses · TUI edition is one user-facing entry path.
- main.py → GUI edition: uses · GUI/web edition is another presentation shell.
- Terminal app → Link resolve: resolves · Terminal workflows normalize user-provided links first.
- Server mode → Link resolve: resolves · Server requests also pass through link normalization.
- CLI edition → Interface router: dispatches · CLI routes commands into the interface layer.
- TUI edition → Interface router: dispatches · TUI routes selections into the interface layer.
- GUI edition → Interface router: dispatches · GUI shell routes interactions into the same backend.
- Link resolve → HTTP requester: fetches · Link resolution depends on HTTP requests.
- HTTP requester → Extractor core: feeds · Fetched responses are parsed into usable targets.
- Extractor core → Interface router: normalizes · Parsed page data is handed to platform collectors.
- Interface router → TikTok adapters: specializes · TikTok-specific adapters handle platform nuances.
- Interface router → Core interfaces: implements · Core collectors cover account, comment, detail, live, search, and related flows.
- Interface router → Models: produces · Collectors populate shared domain models.
- Models → Cache & record: persists · State and deduplication services store run metadata.
- Core interfaces → Download engine: downloads · Content collectors hand resolved media to the downloader.
- Models → Storage manager: exports · Structured records flow into storage selection.
- Storage manager → SQLite/exports: writes · One major storage backend is SQLite and related exports.
- Core interfaces → Live ffmpeg: records · Live collectors may hand off to ffmpeg capture.
- Interface router → Auth & signing: signs · Requests may require anti-bot parameters and cookies.
- Auth & signing → Cookie tools: uses · Cookie helpers support authenticated access.
- Auth & signing → Browser tools: uses · Browser-assisted cookie capture feeds signing/auth.
- Terminal app → Shared tools: relies on · Runtime shells share utility helpers.
- Interface router → Shared tools: relies on · Collectors use retry, formatting, and filesystem helpers.
- Download engine → Shared tools: relies on · Downloader uses file, retry, and progress utilities.
- Config & i18n → Terminal app: configures · Settings and translations shape user-facing runtime behavior.
