# uxiaohan/douyinspark architecture

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

- Interactive diagram: https://gitdiagram.com/uxiaohan/douyinspark
- Repository: https://github.com/uxiaohan/douyinspark

## Overview

DouyinSpark is a local Douyin direct-message automation engine with a web admin console. The main workflow is account configuration → randomized daily scheduling or manual start → per-account browser login → target friend matching and message send/confirmation → persisted run results and optional notification. The console also manages credentials, accounts, friends, message pools, settings, logs, and runtime status. Edges reflect only README statements or shown references/calls; unsampled frontend/API details are represented conservatively.

Main entry points: [`src/web/index.ts`](https://github.com/uxiaohan/douyinspark/blob/main/src/web/index.ts) (Admin API), [`src/runner.ts`](https://github.com/uxiaohan/douyinspark/blob/main/src/runner.ts) (Run Coordinator), [`src/scheduler.ts`](https://github.com/uxiaohan/douyinspark/blob/main/src/scheduler.ts) (Daily Scheduler), [`web/src/api.ts`](https://github.com/uxiaohan/douyinspark/blob/main/web/src/api.ts) (Console API Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Admin Console"]
  node_console["Web Console<br/>[routes.ts]"]
  node_webapi["Admin API<br/>[index.ts]"]
  node_auth["Session Auth<br/>[auth.ts]"]
  node_uiapi["Console API Client<br/>[api.ts]"]
  node_accounts["Accounts, Friends, Messages<br/>[AccountsPage.vue]"]
  node_settingsui["Settings &amp; Dashboard<br/>[SettingsPage.vue]"]
  node_runui["Run History &amp; Logs<br/>[LogsPage.vue]"]
end

subgraph group_schedule["Run Orchestration"]
  node_entry["Runtime Entrypoints<br/>[index.ts]"]
  node_webentry["Web Service Startup<br/>[web-server.ts]"]
  node_scheduler["Daily Scheduler<br/>[scheduler.ts]"]
  node_child["Isolated Run Process<br/>[run-child.ts]"]
  node_runner["Run Coordinator<br/>[runner.ts]"]
end

subgraph group_automation["Douyin Automation"]
  node_browser["Browser Session<br/>[browser.ts]"]
  node_douyin["Chat &amp; Message Actions<br/>[douyin.ts]"]
  node_selectors["DOM Selectors<br/>[selectors.ts]"]
  node_cache["Memory Cache Eviction<br/>[cache-evict.ts]"]
end

subgraph group_data["Local Data"]
  node_config["Runtime Configuration<br/>[config.ts]"]
  node_repo["Data Access<br/>[repo.ts]"]
  node_sqlite[("SQLite Store<br/>[db.ts]")]
  node_notify["Run Notifications<br/>[notify.ts]"]
end

node_admin(("Operator"))
node_douyinservice["Douyin Web"]
node_pushdeer["PushDeer"]

node_admin -->|"uses"| node_console
node_console -.->|"requests"| node_uiapi
node_uiapi -.->|"calls API"| node_webapi
node_webapi -->|"authenticates"| node_auth
node_webapi -->|"manages records"| node_repo
node_webapi -->|"reads settings"| node_config
node_webapi -->|"wakes scheduler"| node_scheduler
node_webapi -->|"tests notification"| node_notify
node_webentry -->|"serves API"| node_webapi
node_entry -->|"starts loop"| node_scheduler
node_entry -->|"runs batch"| node_runner
node_webentry -->|"starts loop"| node_scheduler
node_scheduler -->|"loads schedule"| node_config
node_scheduler -->|"dispatches run"| node_child
node_child -->|"runs isolated"| node_runner
node_child -->|"evicts memory"| node_cache
node_runner -->|"loads run config"| node_config
node_runner -->|"records results"| node_repo
node_runner -->|"opens accounts"| node_browser
node_runner -->|"drives messaging"| node_douyin
node_runner -->|"notifies run"| node_notify
node_browser -->|"logs in"| node_douyinservice
node_douyin -->|"uses selectors"| node_selectors
node_douyin -->|"sends messages"| node_douyinservice
node_notify -->|"sends push"| node_pushdeer
node_config -->|"loads and saves"| node_repo
node_repo -->|"queries"| node_sqlite
node_auth -->|"stores sessions"| node_repo
node_accounts -.->|"manages data"| node_uiapi
node_settingsui -.->|"updates settings"| node_uiapi
node_runui -.->|"views history"| node_uiapi

click node_console "https://github.com/uxiaohan/douyinspark/blob/main/web/src/app/routes.ts"
click node_webapi "https://github.com/uxiaohan/douyinspark/blob/main/src/web/index.ts"
click node_auth "https://github.com/uxiaohan/douyinspark/blob/main/src/web/auth.ts"
click node_uiapi "https://github.com/uxiaohan/douyinspark/blob/main/web/src/api.ts"
click node_accounts "https://github.com/uxiaohan/douyinspark/blob/main/web/src/pages/AccountsPage.vue"
click node_settingsui "https://github.com/uxiaohan/douyinspark/blob/main/web/src/pages/SettingsPage.vue"
click node_runui "https://github.com/uxiaohan/douyinspark/blob/main/web/src/pages/LogsPage.vue"
click node_entry "https://github.com/uxiaohan/douyinspark/blob/main/index.ts"
click node_webentry "https://github.com/uxiaohan/douyinspark/blob/main/web-server.ts"
click node_scheduler "https://github.com/uxiaohan/douyinspark/blob/main/src/scheduler.ts"
click node_child "https://github.com/uxiaohan/douyinspark/blob/main/src/run-child.ts"
click node_runner "https://github.com/uxiaohan/douyinspark/blob/main/src/runner.ts"
click node_browser "https://github.com/uxiaohan/douyinspark/blob/main/src/browser.ts"
click node_douyin "https://github.com/uxiaohan/douyinspark/blob/main/src/douyin.ts"
click node_selectors "https://github.com/uxiaohan/douyinspark/blob/main/src/selectors.ts"
click node_cache "https://github.com/uxiaohan/douyinspark/blob/main/src/cache-evict.ts"
click node_config "https://github.com/uxiaohan/douyinspark/blob/main/src/config.ts"
click node_repo "https://github.com/uxiaohan/douyinspark/blob/main/src/repo.ts"
click node_sqlite "https://github.com/uxiaohan/douyinspark/blob/main/src/db.ts"
click node_notify "https://github.com/uxiaohan/douyinspark/blob/main/src/notify.ts"

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_webapi,node_auth,node_uiapi,node_accounts,node_settingsui,node_runui toneBlue
class node_entry,node_webentry,node_scheduler,node_child,node_runner toneAmber
class node_browser,node_douyin,node_selectors,node_cache toneMint
class node_config,node_repo,node_sqlite,node_notify toneRose
class node_admin,node_douyinservice,node_pushdeer toneIndigo
```

## Components

### Admin Console

- [Web Console](https://github.com/uxiaohan/douyinspark/blob/main/web/src/app/routes.ts): `web/src/app/routes.ts`
- [Admin API](https://github.com/uxiaohan/douyinspark/blob/main/src/web/index.ts): `src/web/index.ts`
- [Session Auth](https://github.com/uxiaohan/douyinspark/blob/main/src/web/auth.ts): `src/web/auth.ts`
- [Console API Client](https://github.com/uxiaohan/douyinspark/blob/main/web/src/api.ts): `web/src/api.ts`
- [Accounts, Friends, Messages](https://github.com/uxiaohan/douyinspark/blob/main/web/src/pages/AccountsPage.vue): `web/src/pages/AccountsPage.vue`
- [Settings & Dashboard](https://github.com/uxiaohan/douyinspark/blob/main/web/src/pages/SettingsPage.vue): `web/src/pages/SettingsPage.vue`
- [Run History & Logs](https://github.com/uxiaohan/douyinspark/blob/main/web/src/pages/LogsPage.vue): `web/src/pages/LogsPage.vue`

### Run Orchestration

- [Runtime Entrypoints](https://github.com/uxiaohan/douyinspark/blob/main/index.ts): `index.ts`
- [Web Service Startup](https://github.com/uxiaohan/douyinspark/blob/main/web-server.ts): `web-server.ts`
- [Daily Scheduler](https://github.com/uxiaohan/douyinspark/blob/main/src/scheduler.ts): `src/scheduler.ts`
- [Isolated Run Process](https://github.com/uxiaohan/douyinspark/blob/main/src/run-child.ts): `src/run-child.ts`
- [Run Coordinator](https://github.com/uxiaohan/douyinspark/blob/main/src/runner.ts): `src/runner.ts`

### Douyin Automation

- [Browser Session](https://github.com/uxiaohan/douyinspark/blob/main/src/browser.ts): `src/browser.ts`
- [Chat & Message Actions](https://github.com/uxiaohan/douyinspark/blob/main/src/douyin.ts): `src/douyin.ts`
- [DOM Selectors](https://github.com/uxiaohan/douyinspark/blob/main/src/selectors.ts): `src/selectors.ts`
- [Memory Cache Eviction](https://github.com/uxiaohan/douyinspark/blob/main/src/cache-evict.ts): `src/cache-evict.ts`

### Local Data

- [Runtime Configuration](https://github.com/uxiaohan/douyinspark/blob/main/src/config.ts): `src/config.ts`
- [Data Access](https://github.com/uxiaohan/douyinspark/blob/main/src/repo.ts): `src/repo.ts`
- [SQLite Store](https://github.com/uxiaohan/douyinspark/blob/main/src/db.ts): `src/db.ts`
- [Run Notifications](https://github.com/uxiaohan/douyinspark/blob/main/src/notify.ts): `src/notify.ts`

### Other components

- **Operator**
- **Douyin Web**
- **PushDeer**

## Connections

- Operator → Web Console: uses (evidence: `README.md`)
- Web Console → Console API Client: requests
- Console API Client → Admin API: calls API
- Admin API → Session Auth: authenticates (evidence: `src/web/index.ts`)
- Admin API → Data Access: manages records (evidence: `src/web/index.ts`)
- Admin API → Runtime Configuration: reads settings (evidence: `src/web/index.ts`)
- Admin API → Daily Scheduler: wakes scheduler (evidence: `src/web/index.ts`)
- Admin API → Run Notifications: tests notification (evidence: `src/web/index.ts`)
- Web Service Startup → Admin API: serves API (evidence: `web-server.ts`)
- Runtime Entrypoints → Daily Scheduler: starts loop (evidence: `index.ts`)
- Runtime Entrypoints → Run Coordinator: runs batch (evidence: `README.md`)
- Web Service Startup → Daily Scheduler: starts loop (evidence: `README.md`)
- Daily Scheduler → Runtime Configuration: loads schedule (evidence: `src/scheduler.ts`)
- Daily Scheduler → Isolated Run Process: dispatches run (evidence: `src/scheduler.ts`)
- Isolated Run Process → Run Coordinator: runs isolated (evidence: `src/run-child.ts`)
- Isolated Run Process → Memory Cache Eviction: evicts memory (evidence: `src/run-child.ts`)
- Run Coordinator → Runtime Configuration: loads run config (evidence: `src/runner.ts`)
- Run Coordinator → Data Access: records results (evidence: `src/runner.ts`)
- Run Coordinator → Browser Session: opens accounts (evidence: `src/runner.ts`)
- Run Coordinator → Chat & Message Actions: drives messaging (evidence: `src/runner.ts`)
- Run Coordinator → Run Notifications: notifies run (evidence: `src/runner.ts`)
- Browser Session → Douyin Web: logs in (evidence: `README.md`)
- Chat & Message Actions → DOM Selectors: uses selectors (evidence: `src/douyin.ts`)
- Chat & Message Actions → Douyin Web: sends messages (evidence: `README.md`)
- Run Notifications → PushDeer: sends push (evidence: `README.md`)
- Runtime Configuration → Data Access: loads and saves (evidence: `src/config.ts`)
- Data Access → SQLite Store: queries (evidence: `src/repo.ts`)
- Session Auth → Data Access: stores sessions (evidence: `src/web/auth.ts`)
- Accounts, Friends, Messages → Console API Client: manages data
- Settings & Dashboard → Console API Client: updates settings
- Run History & Logs → Console API Client: views history
