# evil0ctal/douyin_tiktok_download_api architecture

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

- Interactive diagram: https://gitdiagram.com/evil0ctal/douyin_tiktok_download_api
- Repository: https://github.com/evil0ctal/douyin_tiktok_download_api

## Overview

DTK is a self-hosted Douyin/TikTok data API with a web console and MCP interface. A typical request enters through an API or console, becomes asynchronous work when queued, and is executed by the worker through platform-specific fetching, identity selection and scheduling; results and operational records are kept in PostgreSQL. The repository also includes identity minting, archive/watchlist operations, and browser and media sidecars. Several links below are documented or referenced by the source index; unsampled runtime wiring is omitted or marked unverified.

Main entry points: [`src/dtk/services/fetch.py`](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/services/fetch.py) (Fetch service), [`src/dtk/identity/pool.py`](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/identity/pool.py) (Identity pool), [`src/dtk/api`](https://github.com/evil0ctal/douyin_tiktok_download_api/tree/main/src/dtk/api) (REST API), [`src/dtk/services/tasks.py`](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/services/tasks.py) (Task queue)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_console["Web console"]
  node_api["REST API"]
  node_mcp["MCP server"]
  node_task_api["Task endpoints<br/>[tasks.py]"]
end

subgraph group_execution["Fetch execution"]
  node_task_service["Task queue<br/>[tasks.py]"]
  node_worker["Task worker<br/>[main.py]"]
  node_fetch["Fetch service<br/>[fetch.py]"]
  node_pipeline["Direct probe pipeline<br/>[pipeline.py]"]
  node_platforms["Platform adapters"]
end

subgraph group_identity["Identity and scheduling"]
  node_identity_pool["Identity pool<br/>[pool.py]"]
  node_scheduler["Request scheduler<br/>[scheduler.py]"]
end

subgraph group_state["State and operations"]
  node_database[("PostgreSQL data<br/>[models.py]")]
  node_repositories["Data repositories<br/>[repositories.py]"]
  node_archive["Archive services<br/>[archive.py]"]
  node_watchlist["Watchlist services<br/>[watchlist.py]"]
end

subgraph group_integrations["Sidecar integrations"]
  node_browser_rpc["Browser RPC<br/>[main.py]"]
  node_downloader["Media downloader"]
end

node_user(("API client"))
node_platform(("Douyin / TikTok"))

node_user -->|"sends requests"| node_api
node_console -->|"calls API"| node_api
node_api -->|"routes tasks"| node_task_api
node_task_api -->|"submits and collects"| node_task_service
node_task_service -->|"stores task state"| node_database
node_worker -->|"claims and finishes"| node_task_service
node_worker -->|"runs fetch"| node_fetch
node_fetch -->|"selects identities"| node_identity_pool
node_fetch -->|"requests leases"| node_scheduler
node_fetch -->|"dispatches requests"| node_platforms
node_platforms -->|"fetches platform data"| node_platform
node_identity_pool -->|"reads identity records"| node_database
node_identity_pool -.->|"mints identities"| node_browser_rpc
node_pipeline -->|"selects identity"| node_identity_pool
node_pipeline -->|"uses platform registry"| node_platforms
node_repositories -.->|"reads and writes"| node_database
node_archive -.->|"uses persistence"| node_repositories
node_watchlist -.->|"uses persistence"| node_repositories
node_mcp -->|"serves tool requests"| node_user
node_downloader -->|"downloads media"| node_platform

click node_console "https://github.com/evil0ctal/douyin_tiktok_download_api/tree/main/web/src"
click node_api "https://github.com/evil0ctal/douyin_tiktok_download_api/tree/main/src/dtk/api"
click node_mcp "https://github.com/evil0ctal/douyin_tiktok_download_api/tree/main/src/dtk/mcp"
click node_task_api "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/api/routes/tasks.py"
click node_task_service "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/services/tasks.py"
click node_worker "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/worker/main.py"
click node_fetch "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/services/fetch.py"
click node_pipeline "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/ops/pipeline.py"
click node_platforms "https://github.com/evil0ctal/douyin_tiktok_download_api/tree/main/src/dtk/platforms"
click node_identity_pool "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/identity/pool.py"
click node_scheduler "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/scheduler/scheduler.py"
click node_browser_rpc "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/docker/browser_rpc/main.py"
click node_database "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/db/models.py"
click node_repositories "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/db/repositories.py"
click node_archive "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/services/archive.py"
click node_watchlist "https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/services/watchlist.py"
click node_downloader "https://github.com/evil0ctal/douyin_tiktok_download_api/tree/main/docker/downloader"

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_console,node_api,node_mcp,node_task_api,node_user toneBlue
class node_task_service,node_worker,node_fetch,node_pipeline,node_platforms toneAmber
class node_identity_pool,node_scheduler toneMint
class node_database,node_repositories,node_archive,node_watchlist toneRose
class node_browser_rpc,node_downloader,node_platform toneIndigo
```

## Components

### User interfaces

- [Web console](https://github.com/evil0ctal/douyin_tiktok_download_api/tree/main/web/src): `web/src`
- [REST API](https://github.com/evil0ctal/douyin_tiktok_download_api/tree/main/src/dtk/api): `src/dtk/api`
- [MCP server](https://github.com/evil0ctal/douyin_tiktok_download_api/tree/main/src/dtk/mcp): `src/dtk/mcp`
- [Task endpoints](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/api/routes/tasks.py): `src/dtk/api/routes/tasks.py`

### Fetch execution

- [Task queue](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/services/tasks.py): `src/dtk/services/tasks.py`
- [Task worker](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/worker/main.py): `src/dtk/worker/main.py`
- [Fetch service](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/services/fetch.py): `src/dtk/services/fetch.py`
- [Direct probe pipeline](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/ops/pipeline.py): `src/dtk/ops/pipeline.py`
- [Platform adapters](https://github.com/evil0ctal/douyin_tiktok_download_api/tree/main/src/dtk/platforms): `src/dtk/platforms`

### Identity and scheduling

- [Identity pool](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/identity/pool.py): `src/dtk/identity/pool.py`
- [Request scheduler](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/scheduler/scheduler.py): `src/dtk/scheduler/scheduler.py`

### State and operations

- [PostgreSQL data](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/db/models.py): `src/dtk/db/models.py`
- [Data repositories](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/db/repositories.py): `src/dtk/db/repositories.py`
- [Archive services](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/services/archive.py): `src/dtk/services/archive.py`
- [Watchlist services](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/src/dtk/services/watchlist.py): `src/dtk/services/watchlist.py`

### Sidecar integrations

- [Browser RPC](https://github.com/evil0ctal/douyin_tiktok_download_api/blob/main/docker/browser_rpc/main.py): `docker/browser_rpc/main.py`
- [Media downloader](https://github.com/evil0ctal/douyin_tiktok_download_api/tree/main/docker/downloader): `docker/downloader`

### Other components

- **API client**
- **Douyin / TikTok**

## Connections

- API client → REST API: sends requests (evidence: `README.md`)
- Web console → REST API: calls API (evidence: `README.md`)
- REST API → Task endpoints: routes tasks (evidence: `src/dtk/api/app.py`)
- Task endpoints → Task queue: submits and collects (evidence: `src/dtk/api/routes/tasks.py`)
- Task queue → PostgreSQL data: stores task state (evidence: `src/dtk/services/tasks.py`)
- Task worker → Task queue: claims and finishes (evidence: `src/dtk/worker/main.py`)
- Task worker → Fetch service: runs fetch (evidence: `src/dtk/worker/main.py`)
- Fetch service → Identity pool: selects identities (evidence: `src/dtk/services/fetch.py`)
- Fetch service → Request scheduler: requests leases (evidence: `src/dtk/services/fetch.py`)
- Fetch service → Platform adapters: dispatches requests (evidence: `src/dtk/services/fetch.py`)
- Platform adapters → Douyin / TikTok: fetches platform data (evidence: `README.md`)
- Identity pool → PostgreSQL data: reads identity records (evidence: `src/dtk/identity/pool.py`)
- Identity pool → Browser RPC: mints identities
- Direct probe pipeline → Identity pool: selects identity (evidence: `src/dtk/ops/pipeline.py`)
- Direct probe pipeline → Platform adapters: uses platform registry (evidence: `src/dtk/ops/pipeline.py`)
- Data repositories → PostgreSQL data: reads and writes
- Archive services → Data repositories: uses persistence
- Watchlist services → Data repositories: uses persistence
- MCP server → API client: serves tool requests (evidence: `README.md`)
- Media downloader → Douyin / TikTok: downloads media (evidence: `README.md`)
