# handel-hub/bettingautomation architecture

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

- Interactive diagram: https://gitdiagram.com/handel-hub/bettingautomation
- Repository: https://github.com/handel-hub/bettingautomation

## Overview

#### Purpose and Runtime
Node.js 18+ Playwright automation engine for coordinated betting actions across one visible Master browser and multiple background Slave browsers. It loads encrypted account credentials, optional proxies, and INI settings; actions are recorded or replayed as macros, with an independent cashout path. Process entry point: `index.mjs`; shared configuration and browser utilities: `src/config.mjs`, `src/utils/playwright.mjs`.

#### Bootstrap, Credentials, and Network Identity
Startup reads settings, decrypts `accounts.enc` using `MASTER_KEY`, and assigns accounts/proxies to browser instances. Plaintext account import is encrypted for persistence; proxy and stealth facilities isolate or reduce detection exposure. Key boundaries: local secrets/config versus external betting sites.
Paths: `src/utils/crypto.mjs`, `src/detection/proxyManager.mjs`, `src/detection/stealth.mjs`.

#### Browser Fleet Control
`AutomationController` is the top-level browser orchestration façade. It routes incoming operator commands, maintains browser registration and lifecycle, resolves targets, tracks health, manages sessions, and locks accounts during exclusive operations such as cashout.
Paths: `src/browser/AutomationController.mjs`, `src/browser/CommandRouter.mjs`, `src/browser/coordination/BrowserLifecycleManager.mjs`.

#### Command Execution and Workflows
Commands enter a scheduler/receiver pipeline, gain an execution context, resolve locators, and are dispatched as real actions or simulated validation actions. `MacroEngine` replays sequence JSON across eligible slaves; `WorkflowEngine` hosts higher-level workflows, including cashout rather than relying on master mirroring.
Paths: `src/browser/execution/ExecutionScheduler.mjs`, `src/browser/execution/MacroEngine.mjs`, `src/browser/workflows/CashoutWorkflow.mjs`.

#### Master Capture and Slave Playback
Master-browser activity is captured by injected page-side JavaScript and stored as reusable sequences. On hotkey playback, the system broadcasts macro steps to ready slaves; validation mode substitutes action simulation/DOM checks for clicks. Sequence files are the durable boundary between capture and replay.
Paths: `injected.js`, `src/browser/execution/ActionDispatcher.mjs`, `sequences/login.json`.

#### Locator Intelligence Pipeline
Locator resolution is a dedicated pipeline: extract target features, generate ARIA/data/role/text/structural candidates, deduplicate, validate against the live DOM, rank candidates, serialize the selected locator, and emit telemetry. This isolates volatile betting-site DOMs from macro/workflow logic.
Paths: `src/browser/execution/locatorIntelligence/engine/LocatorIntelligenceEngine.mjs`, `src/browser/execution/locatorIntelligence/generation/CandidateGenerator.mjs`, `src/browser/execution/locatorIntelligence/ranking/RankingEngine.mjs`.

#### Synchronization, Recovery, and Observability
A capability-based synchronization subsystem observes connection, DOM, navigation, frames, viewport, and scrolling. It compares actual browser state with required consistency profiles, coordinates barriers, and executes recovery plans. This is separate from action execution so fleet readiness and recovery can gate work.
Paths: `src/browser/synchronization/SynchronizationManager.mjs`, `src/browser/synchronization/coordination/SynchronizationCoordinator.mjs`, `src/browser/synchronization/providers/frame/FrameCapabilityProvider.mjs`.

Main entry points: [`src/browser/AutomationController.mjs`](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/AutomationController.mjs) (Automation Controller), [`src/browser/execution/ExecutionScheduler.mjs`](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/ExecutionScheduler.mjs) (Execution Scheduler), [`src/browser/execution/ActionDispatcher.mjs`](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/ActionDispatcher.mjs) (Action Dispatcher), [`src/browser/execution/locatorIntelligence/engine/LocatorIntelligenceEngine.mjs`](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/locatorIntelligence/engine/LocatorIntelligenceEngine.mjs) (Locator Engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bootstrap["Bootstrap &amp; Identity"]
  node_entry["Process Entry<br/>Node.js entry<br/>[index.mjs]"]
  node_config["Settings Loader<br/>configuration<br/>[config.mjs]"]
  node_accounts[("Encrypted Accounts<br/>credential store<br/>[accounts.enc]")]
  node_crypto{{"Credential Crypto<br/>secrets service<br/>[crypto.mjs]"}}
  node_proxy_stealth["Proxy &amp; Stealth<br/>identity controls<br/>[proxyManager.mjs]"]
end

subgraph group_fleet["Browser Fleet"]
  node_controller["Automation Controller<br/>orchestration facade"]
  node_router["Command Router<br/>command routing<br/>[CommandRouter.mjs]"]
  node_lifecycle["Browser Lifecycle<br/>fleet lifecycle"]
end

subgraph group_execution["Execution &amp; Macros"]
  node_scheduler["Execution Scheduler<br/>command pipeline"]
  node_macro["Macro Engine<br/>macro playback<br/>[MacroEngine.mjs]"]
  node_cashout["Cashout Workflow<br/>exclusive workflow"]
  node_dispatcher["Action Dispatcher<br/>browser actions"]
  node_capture["Master Activity Capture<br/>injected page script<br/>[injected.js]"]
  node_sequences[("Sequence Files<br/>macro store<br/>[login.json]")]
end

subgraph group_locator["Locator Intelligence"]
  node_locator_engine["Locator Engine<br/>locator resolution"]
  node_candidate_generator["Candidate Generator<br/>locator generation"]
  node_ranking["Ranking Engine<br/>locator ranking<br/>[RankingEngine.mjs]"]
end

subgraph group_sync["Synchronization"]
  node_sync_manager["Synchronization Manager<br/>readiness and recovery"]
  node_sync_coordinator["Synchronization Coordinator<br/>barrier coordination"]
  node_frame_provider["Frame Capability Provider<br/>state provider"]
end

node_operator(("Operator<br/>command source"))
node_betting_sites{{"Betting Sites<br/>external websites"}}

node_entry -->|"loads"| node_config
node_entry -->|"initializes"| node_crypto
node_crypto -->|"decrypts and persists"| node_accounts
node_config -->|"configures"| node_controller
node_accounts -->|"supplies accounts"| node_controller
node_proxy_stealth -->|"applies identity controls"| node_lifecycle
node_operator -->|"commands"| node_controller
node_controller -->|"routes commands"| node_router
node_controller -->|"manages"| node_lifecycle
node_router -->|"submits work"| node_scheduler
node_scheduler -->|"dispatches macro replay"| node_macro
node_scheduler -->|"dispatches cashout"| node_cashout
node_macro -->|"loads steps"| node_sequences
node_capture -->|"records"| node_sequences
node_macro -->|"broadcasts steps"| node_dispatcher
node_cashout -->|"executes actions"| node_dispatcher
node_dispatcher -->|"resolves targets"| node_locator_engine
node_locator_engine -->|"generates candidates"| node_candidate_generator
node_candidate_generator -->|"submits candidates"| node_ranking
node_ranking -->|"selects locator"| node_locator_engine
node_scheduler -->|"checks readiness"| node_sync_manager
node_sync_manager -->|"coordinates barriers"| node_sync_coordinator
node_sync_coordinator -->|"queries capability"| node_frame_provider
node_lifecycle -->|"opens browsers to"| node_betting_sites
node_dispatcher -->|"acts on"| node_betting_sites
node_locator_engine -.->|"validates against DOM"| node_betting_sites

click node_entry "https://github.com/handel-hub/bettingautomation/blob/main/index.mjs"
click node_config "https://github.com/handel-hub/bettingautomation/blob/main/src/config.mjs"
click node_accounts "https://github.com/handel-hub/bettingautomation/blob/main/accounts.enc"
click node_crypto "https://github.com/handel-hub/bettingautomation/blob/main/src/utils/crypto.mjs"
click node_proxy_stealth "https://github.com/handel-hub/bettingautomation/blob/main/src/detection/proxyManager.mjs"
click node_controller "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/AutomationController.mjs"
click node_router "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/CommandRouter.mjs"
click node_lifecycle "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/coordination/BrowserLifecycleManager.mjs"
click node_scheduler "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/ExecutionScheduler.mjs"
click node_macro "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/MacroEngine.mjs"
click node_cashout "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/workflows/CashoutWorkflow.mjs"
click node_dispatcher "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/ActionDispatcher.mjs"
click node_capture "https://github.com/handel-hub/bettingautomation/blob/main/injected.js"
click node_sequences "https://github.com/handel-hub/bettingautomation/blob/main/sequences/login.json"
click node_locator_engine "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/locatorIntelligence/engine/LocatorIntelligenceEngine.mjs"
click node_candidate_generator "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/locatorIntelligence/generation/CandidateGenerator.mjs"
click node_ranking "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/locatorIntelligence/ranking/RankingEngine.mjs"
click node_sync_manager "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/synchronization/SynchronizationManager.mjs"
click node_sync_coordinator "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/synchronization/coordination/SynchronizationCoordinator.mjs"
click node_frame_provider "https://github.com/handel-hub/bettingautomation/blob/main/src/browser/synchronization/providers/frame/FrameCapabilityProvider.mjs"

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_accounts,node_crypto,node_proxy_stealth toneBlue
class node_controller,node_router,node_lifecycle toneAmber
class node_scheduler,node_macro,node_cashout,node_dispatcher,node_capture,node_sequences toneMint
class node_locator_engine,node_candidate_generator,node_ranking toneRose
class node_sync_manager,node_sync_coordinator,node_frame_provider toneIndigo
class node_operator,node_betting_sites toneNeutral
```

## Components

### Bootstrap & Identity

Local settings, encrypted accounts, and browser identity controls.

- [Process Entry](https://github.com/handel-hub/bettingautomation/blob/main/index.mjs): Node.js entry · `index.mjs`
- [Settings Loader](https://github.com/handel-hub/bettingautomation/blob/main/src/config.mjs): configuration · Loads INI settings and shared browser configuration. · `src/config.mjs`
- [Encrypted Accounts](https://github.com/handel-hub/bettingautomation/blob/main/accounts.enc): credential store · Encrypted account credentials persisted locally. · `accounts.enc`
- [Credential Crypto](https://github.com/handel-hub/bettingautomation/blob/main/src/utils/crypto.mjs): secrets service · Decrypts accounts with MASTER_KEY and encrypts imports. · `src/utils/crypto.mjs`
- [Proxy & Stealth](https://github.com/handel-hub/bettingautomation/blob/main/src/detection/proxyManager.mjs): identity controls · Assigns proxies and reduces browser detection exposure. · `src/detection/proxyManager.mjs`

### Browser Fleet

Operator command routing and browser lifecycle control.

- [Automation Controller](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/AutomationController.mjs): orchestration facade · Registers browsers, resolves targets, tracks health, sessions, and account locks. · `src/browser/AutomationController.mjs`
- [Command Router](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/CommandRouter.mjs): command routing · `src/browser/CommandRouter.mjs`
- [Browser Lifecycle](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/coordination/BrowserLifecycleManager.mjs): fleet lifecycle · Launches and manages visible master and background slave browsers. · `src/browser/coordination/BrowserLifecycleManager.mjs`

### Execution & Macros

Action scheduling, playback, and cashout workflows.

- [Execution Scheduler](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/ExecutionScheduler.mjs): command pipeline · Builds execution context and schedules browser work. · `src/browser/execution/ExecutionScheduler.mjs`
- [Macro Engine](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/MacroEngine.mjs): macro playback · Replays recorded sequences across eligible ready slaves. · `src/browser/execution/MacroEngine.mjs`
- [Cashout Workflow](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/workflows/CashoutWorkflow.mjs): exclusive workflow · Runs independent cashout actions with account locking. · `src/browser/workflows/CashoutWorkflow.mjs`
- [Action Dispatcher](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/ActionDispatcher.mjs): browser actions · Executes real actions or validation-mode DOM simulations. · `src/browser/execution/ActionDispatcher.mjs`
- [Master Activity Capture](https://github.com/handel-hub/bettingautomation/blob/main/injected.js): injected page script · Captures visible master-browser activity as reusable steps. · `injected.js`
- [Sequence Files](https://github.com/handel-hub/bettingautomation/blob/main/sequences/login.json): macro store · Durable capture-to-replay boundary. · `sequences/login.json`

### Locator Intelligence

Live-DOM locator generation and ranking pipeline.

- [Locator Engine](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/locatorIntelligence/engine/LocatorIntelligenceEngine.mjs): locator resolution · Extracts target features, validates live DOM candidates, and serializes the selected locator. · `src/browser/execution/locatorIntelligence/engine/LocatorIntelligenceEngine.mjs`
- [Candidate Generator](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/locatorIntelligence/generation/CandidateGenerator.mjs): locator generation · Produces ARIA, data, role, text, and structural candidates. · `src/browser/execution/locatorIntelligence/generation/CandidateGenerator.mjs`
- [Ranking Engine](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/execution/locatorIntelligence/ranking/RankingEngine.mjs): locator ranking · `src/browser/execution/locatorIntelligence/ranking/RankingEngine.mjs`

### Synchronization

Readiness barriers and browser-state recovery.

- [Synchronization Manager](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/synchronization/SynchronizationManager.mjs): readiness and recovery · Gates work on required browser consistency profiles. · `src/browser/synchronization/SynchronizationManager.mjs`
- [Synchronization Coordinator](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/synchronization/coordination/SynchronizationCoordinator.mjs): barrier coordination · Coordinates fleet barriers and recovery plans. · `src/browser/synchronization/coordination/SynchronizationCoordinator.mjs`
- [Frame Capability Provider](https://github.com/handel-hub/bettingautomation/blob/main/src/browser/synchronization/providers/frame/FrameCapabilityProvider.mjs): state provider · Supplies frame capability state for synchronization. · `src/browser/synchronization/providers/frame/FrameCapabilityProvider.mjs`

### Other components

- **Operator**: command source
- **Betting Sites**: external websites · Volatile external site DOM and betting endpoints.

## Connections

- Process Entry → Settings Loader: loads
- Process Entry → Credential Crypto: initializes
- Credential Crypto → Encrypted Accounts: decrypts and persists
- Settings Loader → Automation Controller: configures
- Encrypted Accounts → Automation Controller: supplies accounts
- Proxy & Stealth → Browser Lifecycle: applies identity controls
- Operator → Automation Controller: commands
- Automation Controller → Command Router: routes commands
- Automation Controller → Browser Lifecycle: manages
- Command Router → Execution Scheduler: submits work
- Execution Scheduler → Macro Engine: dispatches macro replay
- Execution Scheduler → Cashout Workflow: dispatches cashout
- Macro Engine → Sequence Files: loads steps
- Master Activity Capture → Sequence Files: records
- Macro Engine → Action Dispatcher: broadcasts steps
- Cashout Workflow → Action Dispatcher: executes actions
- Action Dispatcher → Locator Engine: resolves targets
- Locator Engine → Candidate Generator: generates candidates
- Candidate Generator → Ranking Engine: submits candidates
- Ranking Engine → Locator Engine: selects locator
- Execution Scheduler → Synchronization Manager: checks readiness
- Synchronization Manager → Synchronization Coordinator: coordinates barriers
- Synchronization Coordinator → Frame Capability Provider: queries capability
- Browser Lifecycle → Betting Sites: opens browsers to
- Action Dispatcher → Betting Sites: acts on
- Locator Engine → Betting Sites: validates against DOM
