# brightdata/cli architecture

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

- Interactive diagram: https://gitdiagram.com/brightdata/cli
- Repository: https://github.com/brightdata/cli

## Overview

#### Purpose and Entrypoint
Bright Data CLI is a Node.js (≥20) terminal client for Bright Data APIs: web scraping, SERP/search, AI discovery, dataset pipelines, scraper lifecycle management, account administration, and persistent remote-browser control. `src/index.ts` is the command-line composition/dispatch entrypoint; command implementations live under `src/commands/`.

#### Command Layer
Commands translate parsed CLI arguments into product-specific API requests and output contracts. Major domains include scraping/search/discovery (`src/commands/scrape.ts`, `src/commands/search.ts`, `src/commands/discover.ts`), dataset pipelines (`src/commands/dataset.ts`), and AI scraper creation/run/heal/approval (`src/commands/scraper.ts`). Account/setup operations are separated into `src/commands/login.ts`, `src/commands/init.ts`, `src/commands/zones.ts`, and `src/commands/budget.ts`.

#### Shared API, Auth, and Configuration Boundary
All remote-service access is centralized behind the reusable client and credential/config utilities: `src/utils/client.ts`, `src/utils/auth.ts`, and `src/utils/config.ts`. Credentials may come from command flags, environment, or persisted OS-local files; this is the boundary between user-local state and Bright Data’s authenticated HTTP APIs. `src/utils/polling.ts` supports asynchronous job workflows, while `src/utils/output.ts` enforces terminal, JSON, and file-oriented response delivery.

#### Asynchronous Data Product Flows
Scrape, datasets, discovery, and scraper execution may submit server-side jobs then poll for results. Commands own product request/response shaping, shared polling owns wait/timeout behavior, and domain types document payload contracts in `src/types/scrape.ts`, `src/types/dataset.ts`, `src/types/discover.ts`, and `src/types/scraper.ts`. Scraper operations implement a longer control flow: trigger AI generation or refactoring, retry/back off on capacity limits, poll progress, and optionally stop at or continue through a human approval gate.

#### Persistent Browser Subsystem
Browser control is architecturally distinct from ordinary request/response commands. A local daemon retains Scraping Browser connections and session state between CLI invocations: `src/browser/daemon.ts`, `src/browser/ipc.ts`, and `src/browser/lifecycle.ts`. The browser command front end delegates navigation and interaction through IPC (`src/browser/entrypoint.ts`, `src/browser/interaction.ts`), while specialized modules create accessibility snapshots, screenshots, and per-daemon authentication tokens (`src/browser/snapshot.ts`, `src/browser/screenshot.ts`, `src/browser/token.ts`). This isolates local process/socket lifecycle from the remote browser service.

#### Agent and Integration Installation
The CLI can modify external coding-agent configuration rather than merely call Bright Data APIs. MCP registration is handled by `src/commands/add-mcp.ts` and `src/utils/mcp-config.ts`, writing Bright Data MCP server definitions into Claude Code, Cursor, or Codex config locations. AI-agent skill discovery and installation are handled by `src/commands/skill.ts` plus `src/utils/skill-installer/installer.ts` and `src/utils/skill-installer/agents.ts`.

#### Runtime and External Dependencies
The distributable is an npm TypeScript CLI, with release automation in `.github/workflows/release.yml` and shell installation via `install.sh`. Its material external systems are Bright Data’s authenticated APIs—Web Unlocker, SERP, Web Scraper/datasets, Scraper Studio AI flows, account/zone APIs, and Scraping Browser—as well as optional GitHub CLI/browser-based login and local configuration files.

Main entry points: [`src/index.ts`](https://github.com/brightdata/cli/blob/main/src/index.ts) (CLI composition & dispatch), [`src/utils/client.ts`](https://github.com/brightdata/cli/blob/main/src/utils/client.ts) (Authenticated API client), [`src/commands/scrape.ts`](https://github.com/brightdata/cli/blob/main/src/commands/scrape.ts) (Scrape, search & discovery), [`src/commands/dataset.ts`](https://github.com/brightdata/cli/blob/main/src/commands/dataset.ts) (Dataset pipelines)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI command layer"]
  node_entrypoint["CLI composition &amp; dispatch<br/>Node.js CLI<br/>[index.ts]"]
  node_product_commands["Scrape, search &amp; discovery<br/>command handlers<br/>[scrape.ts]"]
  node_dataset_commands["Dataset pipelines<br/>command handlers<br/>[dataset.ts]"]
  node_scraper_commands["AI scraper lifecycle<br/>command handlers<br/>[scraper.ts]"]
  node_account_commands["Setup &amp; account commands<br/>command handlers<br/>[login.ts]"]
end

subgraph group_shared["Shared runtime"]
  node_api_client["Authenticated API client<br/>HTTP client<br/>[client.ts]"]
  node_credentials["Credentials &amp; configuration<br/>local state utility<br/>[auth.ts]"]
  node_polling["Async job polling<br/>workflow utility<br/>[polling.ts]"]
  node_output["Output delivery<br/>output utility<br/>[output.ts]"]
end

subgraph group_browser["Persistent browser"]
  node_browser_frontend["Browser command frontend<br/>browser commands<br/>[entrypoint.ts]"]
  node_browser_ipc["Daemon IPC<br/>local IPC<br/>[ipc.ts]"]
  node_browser_daemon["Persistent browser daemon<br/>local daemon<br/>[daemon.ts]"]
  node_browser_artifacts["Snapshots &amp; screenshots<br/>browser artifacts<br/>[snapshot.ts]"]
end

subgraph group_integration["Agent integrations"]
  node_mcp_install["MCP registration<br/>integration command<br/>[add-mcp.ts]"]
  node_skill_install["Agent skill installation<br/>integration command<br/>[skill.ts]"]
end

subgraph group_external["External and local systems"]
  node_local_files[("OS-local files &amp; agent configs<br/>local filesystem")]
  node_brightdata_apis{{"Bright Data APIs<br/>authenticated remote services"}}
  node_remote_jobs["Server-side jobs<br/>asynchronous jobs"]
end

node_entrypoint -->|"dispatches"| node_product_commands
node_entrypoint -->|"dispatches"| node_dataset_commands
node_entrypoint -->|"dispatches"| node_scraper_commands
node_entrypoint -->|"dispatches"| node_account_commands
node_entrypoint -->|"dispatches"| node_browser_frontend
node_entrypoint -->|"dispatches"| node_mcp_install
node_entrypoint -->|"dispatches"| node_skill_install
node_product_commands -->|"API requests"| node_api_client
node_dataset_commands -->|"API requests"| node_api_client
node_scraper_commands -->|"AI lifecycle requests"| node_api_client
node_account_commands -->|"account requests"| node_api_client
node_api_client -->|"gets credentials"| node_credentials
node_credentials -->|"reads and persists"| node_local_files
node_api_client -->|"authenticated HTTP"| node_brightdata_apis
node_product_commands -->|"waits for jobs"| node_polling
node_dataset_commands -->|"waits for jobs"| node_polling
node_scraper_commands -->|"progress and retry"| node_polling
node_polling -->|"polls"| node_remote_jobs
node_product_commands -->|"renders results"| node_output
node_dataset_commands -->|"renders results"| node_output
node_scraper_commands -->|"renders results"| node_output
node_browser_frontend -->|"navigation &amp; interaction"| node_browser_ipc
node_browser_ipc -->|"local messages"| node_browser_daemon
node_browser_daemon -->|"browser sessions"| node_brightdata_apis
node_browser_daemon -->|"captures"| node_browser_artifacts
node_mcp_install -->|"writes MCP config"| node_local_files
node_skill_install -->|"installs skills"| node_local_files

click node_entrypoint "https://github.com/brightdata/cli/blob/main/src/index.ts"
click node_product_commands "https://github.com/brightdata/cli/blob/main/src/commands/scrape.ts"
click node_dataset_commands "https://github.com/brightdata/cli/blob/main/src/commands/dataset.ts"
click node_scraper_commands "https://github.com/brightdata/cli/blob/main/src/commands/scraper.ts"
click node_account_commands "https://github.com/brightdata/cli/blob/main/src/commands/login.ts"
click node_api_client "https://github.com/brightdata/cli/blob/main/src/utils/client.ts"
click node_credentials "https://github.com/brightdata/cli/blob/main/src/utils/auth.ts"
click node_polling "https://github.com/brightdata/cli/blob/main/src/utils/polling.ts"
click node_output "https://github.com/brightdata/cli/blob/main/src/utils/output.ts"
click node_browser_frontend "https://github.com/brightdata/cli/blob/main/src/browser/entrypoint.ts"
click node_browser_ipc "https://github.com/brightdata/cli/blob/main/src/browser/ipc.ts"
click node_browser_daemon "https://github.com/brightdata/cli/blob/main/src/browser/daemon.ts"
click node_browser_artifacts "https://github.com/brightdata/cli/blob/main/src/browser/snapshot.ts"
click node_mcp_install "https://github.com/brightdata/cli/blob/main/src/commands/add-mcp.ts"
click node_skill_install "https://github.com/brightdata/cli/blob/main/src/commands/skill.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_entrypoint,node_product_commands,node_dataset_commands,node_scraper_commands,node_account_commands toneBlue
class node_api_client,node_credentials,node_polling,node_output toneAmber
class node_browser_frontend,node_browser_ipc,node_browser_daemon,node_browser_artifacts toneMint
class node_mcp_install,node_skill_install toneRose
class node_local_files,node_brightdata_apis,node_remote_jobs toneIndigo
```

## Components

### CLI command layer

- [CLI composition & dispatch](https://github.com/brightdata/cli/blob/main/src/index.ts): Node.js CLI · `src/index.ts`
- [Scrape, search & discovery](https://github.com/brightdata/cli/blob/main/src/commands/scrape.ts): command handlers · Shapes requests and asynchronous result contracts. · `src/commands/scrape.ts`
- [Dataset pipelines](https://github.com/brightdata/cli/blob/main/src/commands/dataset.ts): command handlers · `src/commands/dataset.ts`
- [AI scraper lifecycle](https://github.com/brightdata/cli/blob/main/src/commands/scraper.ts): command handlers · Creates, runs, heals, and approves AI scrapers. · `src/commands/scraper.ts`
- [Setup & account commands](https://github.com/brightdata/cli/blob/main/src/commands/login.ts): command handlers · `src/commands/login.ts`

### Shared runtime

- [Authenticated API client](https://github.com/brightdata/cli/blob/main/src/utils/client.ts): HTTP client · `src/utils/client.ts`
- [Credentials & configuration](https://github.com/brightdata/cli/blob/main/src/utils/auth.ts): local state utility · Resolves flags, environment, and persisted OS-local credentials. · `src/utils/auth.ts`
- [Async job polling](https://github.com/brightdata/cli/blob/main/src/utils/polling.ts): workflow utility · `src/utils/polling.ts`
- [Output delivery](https://github.com/brightdata/cli/blob/main/src/utils/output.ts): output utility · Produces terminal, JSON, or file output. · `src/utils/output.ts`

### Persistent browser

- [Browser command frontend](https://github.com/brightdata/cli/blob/main/src/browser/entrypoint.ts): browser commands · Delegates navigation and interaction to the retained daemon. · `src/browser/entrypoint.ts`
- [Daemon IPC](https://github.com/brightdata/cli/blob/main/src/browser/ipc.ts): local IPC · `src/browser/ipc.ts`
- [Persistent browser daemon](https://github.com/brightdata/cli/blob/main/src/browser/daemon.ts): local daemon · Retains browser connections and session state across CLI invocations. · `src/browser/daemon.ts`
- [Snapshots & screenshots](https://github.com/brightdata/cli/blob/main/src/browser/snapshot.ts): browser artifacts · `src/browser/snapshot.ts`

### Agent integrations

- [MCP registration](https://github.com/brightdata/cli/blob/main/src/commands/add-mcp.ts): integration command · Writes Bright Data MCP definitions into supported coding-agent configuration. · `src/commands/add-mcp.ts`
- [Agent skill installation](https://github.com/brightdata/cli/blob/main/src/commands/skill.ts): integration command · `src/commands/skill.ts`

### External and local systems

- **OS-local files & agent configs**: local filesystem
- **Bright Data APIs**: authenticated remote services · Includes Unlocker, SERP, datasets, Scraper Studio, account APIs, and Scraping Browser.
- **Server-side jobs**: asynchronous jobs · Scrape, dataset, discovery, and scraper executions may run asynchronously.

## Connections

- CLI composition & dispatch → Scrape, search & discovery: dispatches
- CLI composition & dispatch → Dataset pipelines: dispatches
- CLI composition & dispatch → AI scraper lifecycle: dispatches
- CLI composition & dispatch → Setup & account commands: dispatches
- CLI composition & dispatch → Browser command frontend: dispatches
- CLI composition & dispatch → MCP registration: dispatches
- CLI composition & dispatch → Agent skill installation: dispatches
- Scrape, search & discovery → Authenticated API client: API requests
- Dataset pipelines → Authenticated API client: API requests
- AI scraper lifecycle → Authenticated API client: AI lifecycle requests
- Setup & account commands → Authenticated API client: account requests
- Authenticated API client → Credentials & configuration: gets credentials
- Credentials & configuration → OS-local files & agent configs: reads and persists
- Authenticated API client → Bright Data APIs: authenticated HTTP
- Scrape, search & discovery → Async job polling: waits for jobs
- Dataset pipelines → Async job polling: waits for jobs
- AI scraper lifecycle → Async job polling: progress and retry
- Async job polling → Server-side jobs: polls
- Scrape, search & discovery → Output delivery: renders results
- Dataset pipelines → Output delivery: renders results
- AI scraper lifecycle → Output delivery: renders results
- Browser command frontend → Daemon IPC: navigation & interaction
- Daemon IPC → Persistent browser daemon: local messages
- Persistent browser daemon → Bright Data APIs: browser sessions
- Persistent browser daemon → Snapshots & screenshots: captures
- MCP registration → OS-local files & agent configs: writes MCP config
- Agent skill installation → OS-local files & agent configs: installs skills
