# chiihero/microsoft-rewards-script architecture

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

- Interactive diagram: https://gitdiagram.com/chiihero/microsoft-rewards-script
- Repository: https://github.com/chiihero/microsoft-rewards-script

## Overview

This is a TypeScript/Patchright automation bot for Microsoft Rewards, with an optional HTTP control API. Its main workflow loads account and behavior configuration, creates or reuses browser sessions, signs in, then runs search and Rewards activities and reports outcomes. Search topics can come from configurable providers; optional tasks include visual search, Read-to-Earn, and experimental API search. The README also documents a separate API and dashboard workflow for runtime control. Several activity and API implementations were not sampled, so those documented subsystems are shown without speculative internal call chains.

Main entry points: [`src/index.ts`](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/index.ts) (Bot orchestration), [`scripts/api/server.js`](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/server.js) (Control API), [`src/functions/activities/search/SearchManager.ts`](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/activities/search/SearchManager.ts) (Search orchestration), [`src/browser/auth/Login.ts`](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/browser/auth/Login.ts) (Account login)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_entry["Bot orchestration<br/>[index.ts]"]
  node_config["Configuration<br/>[Load.ts]"]
  node_account_validation["Account validation<br/>[Validator.ts]"]
  node_http_client["HTTP client<br/>[Http.ts]"]
end

subgraph group_browser["Browser and identity"]
  node_browser_lifecycle["Browser lifecycle<br/>[Browser.ts]"]
  node_browser_actions["Browser operations<br/>[BrowserFunc.ts]"]
  node_login["Account login<br/>[Login.ts]"]
  node_login_methods["Login methods"]
  node_session_store[("Session store<br/>[SessionStore.ts]")]
end

subgraph group_rewards["Rewards tasks"]
  node_search_manager["Search orchestration<br/>[SearchManager.ts]"]
  node_search_progress["Search progress<br/>[SearchProgress.ts]"]
  node_browser_search["Browser search<br/>[BrowserSearch.ts]"]
  node_query_engine["Query engine<br/>[QueryEngine.ts]"]
  node_query_queue["Query queue"]
  node_activity_runner["Activity runner<br/>[Activities.ts]"]
  node_activity_types["Rewards activities"]
  node_visual_search["Visual search<br/>[VisualSearch.ts]"]
end

subgraph group_operations["Control API"]
  node_api_server["Control API<br/>[server.js]"]
  node_process_manager["Process manager<br/>[processManager.js]"]
  node_api_accounts["Account controls<br/>[accounts.js]"]
  node_api_config["Config editor<br/>[configEditor.js]"]
  node_api_schedule[("Schedule management<br/>[scheduleStore.js]")]
  node_api_logs["Log parsing<br/>[logParser.js]"]
end

subgraph group_messaging["Logging and notices"]
  node_logger["Logger<br/>[Logger.ts]"]
  node_webhook_channels["Notification channels"]
  node_clawbot_client["ClawBot client<br/>[ClawBotClient.ts]"]
end

node_operator(("Operator"))
node_dashboard_user(("Dashboard client"))
node_microsoft(("Microsoft Rewards"))
node_query_sources(("Query sources"))
node_wechat(("WeChat iLink"))

node_operator -.->|"starts run"| node_entry
node_entry -->|"loads config"| node_config
node_entry -->|"validates accounts"| node_account_validation
node_entry -->|"manages browser"| node_browser_lifecycle
node_entry -->|"runs login"| node_login
node_login -->|"uses methods"| node_login_methods
node_login -->|"saves session"| node_session_store
node_browser_lifecycle -.->|"restores session"| node_session_store
node_login -.->|"authenticates"| node_microsoft
node_entry -->|"runs searches"| node_search_manager
node_search_manager -->|"reads quotas"| node_search_progress
node_search_manager -.->|"dispatches search"| node_browser_search
node_entry -.->|"runs activities"| node_activity_runner
node_activity_runner -.->|"dispatches tasks"| node_activity_types
node_activity_runner -.->|"dispatches optional"| node_visual_search
node_search_manager -.->|"requests topics"| node_query_queue
node_query_queue -->|"gets queries"| node_query_engine
node_query_engine -->|"fetches topics"| node_query_sources
node_search_manager -.->|"earns search points"| node_microsoft
node_dashboard_user -->|"controls bot"| node_api_server
node_api_server -->|"controls processes"| node_process_manager
node_api_server -->|"routes account actions"| node_api_accounts
node_api_server -->|"routes config edits"| node_api_config
node_api_server -->|"routes schedules"| node_api_schedule
node_api_server -.->|"routes log queries"| node_api_logs
node_entry -->|"records run"| node_logger
node_logger -->|"dispatches notices"| node_webhook_channels
node_webhook_channels -.->|"sends ClawBot"| node_clawbot_client
node_clawbot_client -->|"sends messages"| node_wechat
node_query_engine -->|"requests sources"| node_http_client
node_http_client -.->|"makes web requests"| node_microsoft

click node_entry "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/index.ts"
click node_config "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/util/Load.ts"
click node_account_validation "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/util/Validator.ts"
click node_browser_lifecycle "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/browser/Browser.ts"
click node_browser_actions "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/browser/BrowserFunc.ts"
click node_login "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/browser/auth/Login.ts"
click node_login_methods "https://github.com/chiihero/microsoft-rewards-script/tree/V4-china/src/browser/auth/methods"
click node_session_store "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/util/SessionStore.ts"
click node_search_manager "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/activities/search/SearchManager.ts"
click node_search_progress "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/activities/search/SearchProgress.ts"
click node_browser_search "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/activities/search/BrowserSearch.ts"
click node_query_engine "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/QueryEngine.ts"
click node_query_queue "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/SearchQueryQueue.ts"
click node_activity_runner "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/Activities.ts"
click node_activity_types "https://github.com/chiihero/microsoft-rewards-script/tree/V4-china/src/functions/activities"
click node_visual_search "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/activities/visualSearch/VisualSearch.ts"
click node_api_server "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/server.js"
click node_process_manager "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/processManager.js"
click node_api_accounts "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/accounts.js"
click node_api_config "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/configEditor.js"
click node_api_schedule "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/scheduleStore.js"
click node_api_logs "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/logParser.js"
click node_logger "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/logging/Logger.ts"
click node_webhook_channels "https://github.com/chiihero/microsoft-rewards-script/tree/V4-china/src/logging"
click node_clawbot_client "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/util/ClawBotClient.ts"
click node_http_client "https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/util/Http.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_entry,node_config,node_account_validation,node_http_client,node_dashboard_user toneBlue
class node_browser_lifecycle,node_browser_actions,node_login,node_login_methods,node_session_store toneAmber
class node_search_manager,node_search_progress,node_browser_search,node_query_engine,node_query_queue,node_activity_runner,node_activity_types,node_visual_search toneMint
class node_api_server,node_process_manager,node_api_accounts,node_api_config,node_api_schedule,node_api_logs toneRose
class node_logger,node_webhook_channels,node_clawbot_client,node_operator,node_microsoft,node_query_sources,node_wechat toneIndigo
```

## Components

### Bot runtime

- [Bot orchestration](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/index.ts): `src/index.ts`
- [Configuration](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/util/Load.ts): `src/util/Load.ts`
- [Account validation](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/util/Validator.ts): `src/util/Validator.ts`
- [HTTP client](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/util/Http.ts): `src/util/Http.ts`

### Browser and identity

- [Browser lifecycle](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/browser/Browser.ts): `src/browser/Browser.ts`
- [Browser operations](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/browser/BrowserFunc.ts): `src/browser/BrowserFunc.ts`
- [Account login](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/browser/auth/Login.ts): `src/browser/auth/Login.ts`
- [Login methods](https://github.com/chiihero/microsoft-rewards-script/tree/V4-china/src/browser/auth/methods): `src/browser/auth/methods`
- [Session store](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/util/SessionStore.ts): `src/util/SessionStore.ts`

### Rewards tasks

- [Search orchestration](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/activities/search/SearchManager.ts): `src/functions/activities/search/SearchManager.ts`
- [Search progress](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/activities/search/SearchProgress.ts): `src/functions/activities/search/SearchProgress.ts`
- [Browser search](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/activities/search/BrowserSearch.ts): `src/functions/activities/search/BrowserSearch.ts`
- [Query engine](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/QueryEngine.ts): `src/functions/QueryEngine.ts`
- [Query queue](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/SearchQueryQueue.ts): `src/functions/SearchQueryQueue.ts`
- [Activity runner](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/Activities.ts): `src/functions/Activities.ts`
- [Rewards activities](https://github.com/chiihero/microsoft-rewards-script/tree/V4-china/src/functions/activities): `src/functions/activities`
- [Visual search](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/functions/activities/visualSearch/VisualSearch.ts): `src/functions/activities/visualSearch/VisualSearch.ts`

### Control API

- [Control API](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/server.js): `scripts/api/server.js`
- [Process manager](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/processManager.js): `scripts/api/processManager.js`
- [Account controls](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/accounts.js): `scripts/api/accounts.js`
- [Config editor](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/configEditor.js): `scripts/api/configEditor.js`
- [Schedule management](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/scheduleStore.js): `scripts/api/scheduleStore.js`
- [Log parsing](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/scripts/api/logParser.js): `scripts/api/logParser.js`

### Logging and notices

- [Logger](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/logging/Logger.ts): `src/logging/Logger.ts`
- [Notification channels](https://github.com/chiihero/microsoft-rewards-script/tree/V4-china/src/logging): `src/logging`
- [ClawBot client](https://github.com/chiihero/microsoft-rewards-script/blob/V4-china/src/util/ClawBotClient.ts): `src/util/ClawBotClient.ts`

### Other components

- **Operator**
- **Dashboard client**
- **Microsoft Rewards**
- **Query sources**
- **WeChat iLink**

## Connections

- Operator → Bot orchestration: starts run (evidence: `README.md`)
- Bot orchestration → Configuration: loads config (evidence: `src/index.ts`)
- Bot orchestration → Account validation: validates accounts (evidence: `src/index.ts`)
- Bot orchestration → Browser lifecycle: manages browser (evidence: `src/index.ts`)
- Bot orchestration → Account login: runs login (evidence: `src/index.ts`)
- Account login → Login methods: uses methods (evidence: `src/browser/auth/Login.ts`)
- Account login → Session store: saves session (evidence: `src/browser/auth/Login.ts`)
- Browser lifecycle → Session store: restores session
- Account login → Microsoft Rewards: authenticates (evidence: `README.md`)
- Bot orchestration → Search orchestration: runs searches (evidence: `src/index.ts`)
- Search orchestration → Search progress: reads quotas (evidence: `src/functions/activities/search/SearchManager.ts`)
- Search orchestration → Browser search: dispatches search (evidence: `README.md`)
- Bot orchestration → Activity runner: runs activities (evidence: `README.md`)
- Activity runner → Rewards activities: dispatches tasks (evidence: `README.md`)
- Activity runner → Visual search: dispatches optional (evidence: `README.md`)
- Search orchestration → Query queue: requests topics (evidence: `README.md`)
- Query queue → Query engine: gets queries (evidence: `src/functions/SearchQueryQueue.ts`)
- Query engine → Query sources: fetches topics (evidence: `src/functions/QueryEngine.ts`)
- Search orchestration → Microsoft Rewards: earns search points (evidence: `README.md`)
- Dashboard client → Control API: controls bot (evidence: `README.md`)
- Control API → Process manager: controls processes (evidence: `scripts/api/server.js`)
- Control API → Account controls: routes account actions (evidence: `scripts/api/server.js`)
- Control API → Config editor: routes config edits (evidence: `scripts/api/server.js`)
- Control API → Schedule management: routes schedules (evidence: `scripts/api/server.js`)
- Control API → Log parsing: routes log queries (evidence: `scripts/api/server.js`)
- Bot orchestration → Logger: records run (evidence: `src/index.ts`)
- Logger → Notification channels: dispatches notices (evidence: `src/logging/Logger.ts`)
- Notification channels → ClawBot client: sends ClawBot (evidence: `src/logging/ClawBot.ts`)
- ClawBot client → WeChat iLink: sends messages (evidence: `src/util/ClawBotClient.ts`)
- Query engine → HTTP client: requests sources (evidence: `src/functions/QueryEngine.ts`)
- HTTP client → Microsoft Rewards: makes web requests (evidence: `README.md`)
