# databox/databox-cli architecture

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

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

## Overview

1. **Overall shape**
   - This is a **Node.js/TypeScript CLI** for the Databox public API.
   - The repository is organized around **command handlers** under `src/commands`, with shared utilities in `src/lib`, and executable entrypoints in `bin/`.

2. **CLI entrypoints**
   - `bin/run.js` and `bin/dev.js` are the runtime launchers for the CLI.
   - The project appears to use an **oclif-style command framework**: each file in `src/commands/**` maps to a subcommand exposed on the `databox` binary.

3. **Command layer by domain**
   - Commands are grouped into clear functional domains:
     - `auth` for API key setup/validation
     - `account` for account discovery and resource listing
     - `data-source` for data source lifecycle and inspection
     - `dataset` for dataset lifecycle, ingestion, and ingestion status
     - `analyze` for Genie AI queries over datasets
   - This is the main architectural boundary for the repo: **each command is a thin adapter around a specific API workflow**.

4. **Shared command base**
   - `src/base-command.ts` is likely the common superclass for all commands.
   - It probably centralizes cross-cutting behavior such as config loading, API client creation, JSON vs table output selection, and error handling.

5. **API integration boundary**
   - `src/lib/api-client.ts` is the main boundary to external Databox services.
   - All CRUD/listing/ingestion operations likely go through this client rather than direct network calls in each command.
   - The CLI therefore separates **user interaction and argument parsing** from **HTTP/API access**.

6. **Configuration and authentication flow**
   - `src/lib/config.ts` manages persisted CLI state, especially the API key.
   - The README says `auth login` stores credentials in `~/.config/databox-cli/config.json`.
   - Most commands depend on that stored key; `auth login` is the exception because it bootstraps access.

7. **Output and user interaction**
   - `src/lib/output.ts` handles presentation concerns, especially the default human-readable tables versus `--json` output.
   - `src/lib/prompt.ts` supports interactive flows such as confirming destructive actions or requesting missing auth input.
   - This keeps command modules focused on business action rather than formatting or prompting logic.

8. **Main data flows**
   - **Account/resource discovery**: `account list`, `account datasets`, `account data-sources`, `account timezones` fetch reference data from Databox and render it.
   - **Resource lifecycle**: `data-source create/delete`, `dataset create/delete/purge` perform mutations against the API.
   - **Data ingestion**: `dataset ingest` accepts inline JSON, file input, or stdin-style usage and sends records to Databox.
   - **Ingestion monitoring**: `dataset ingestion` and `dataset ingestions` query job/status metadata after ingestion.
   - **Analysis**: `analyze ask-genie` sends dataset questions to a separate Genie/agentic service.

9. **External service boundary for analysis**
   - Most commands talk to the Databox API, but `analyze ask-genie` also depends on an **agentic service**.
   - The README shows a distinct base URL defaulting to `https://agentic-service.databox.com`, configurable via `--service-url` or `DATABOX_AGENTIC_SERVICE_URL`.
   - That makes analysis a separate subsystem from the core CRUD/ingestion API path.

10. **Destructive command safeguards**
   - Commands like delete and purge support `--force`, implying interactive confirmation is otherwise required.
   - This is a safety boundary in the CLI UX: mutation commands are designed to prevent accidental irreversible actions unless explicitly overridden.

11. **Skills distribution as a secondary artifact**
   - The `skills/` directory contains packaged `SKILL.md` files for agent tooling:
     - `databox-auth`
     - `databox-accounts`
     - `databox-data-sources`
     - `databox-datasets`
     - `databox-analyze`
   - These are not runtime dependencies of the CLI itself, but they are an important **distribution layer** for AI agents that use the CLI autonomously.

12. **Testing structure mirrors the command tree**
   - `test/commands/**` mirrors `src/commands/**`, which suggests each command has focused unit tests.
   - There is also `test/env-concurrency.test.ts`, indicating coverage for shared environment/config behavior, likely around parallel execution or shared state.
   - `test/helpers.ts` provides common test setup/mocking, probably around API client and filesystem/config isolation.

13. **Architecture summary for a diagram**
   - Draw the system as:
     - **User/terminal input**
     - → **CLI command modules**
     - → **shared base/helpers**
     - → **Databox API** for account/data source/dataset operations
     - → **separate agentic service** for Genie analysis
     - with **config storage** in the local filesystem and **prompt/output utilities** as cross-cutting supporting components.

Main entry points: [`src/base-command.ts`](https://github.com/databox/databox-cli/blob/main/src/base-command.ts) (Base Cmd), [`skills`](https://github.com/databox/databox-cli/tree/main/skills) (Skills), [`src/lib/api-client.ts`](https://github.com/databox/databox-cli/blob/main/src/lib/api-client.ts) (API Client), [`src/lib/config.ts`](https://github.com/databox/databox-cli/blob/main/src/lib/config.ts) (Config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_bin_run["run.js<br/>launcher<br/>[run.js]"]
  node_bin_dev["dev.js<br/>launcher<br/>[dev.js]"]
end

subgraph group_commands["Commands"]
  node_auth{{"Auth<br/>command family"}}
  node_account{{"Account<br/>command family"}}
  node_data_source{{"Data Source<br/>command family"}}
  node_dataset{{"Dataset<br/>command family"}}
  node_analyze{{"Analyze<br/>command family"}}
end

subgraph group_shared["Shared Lib"]
  node_base_command["Base Cmd<br/>command base<br/>[base-command.ts]"]
  node_api_client["API Client<br/>databox api<br/>[api-client.ts]"]
  node_config["Config<br/>state store<br/>[config.ts]"]
  node_output["Output<br/>renderer<br/>[output.ts]"]
  node_prompt["Prompt<br/>ux helper<br/>[prompt.ts]"]
end

subgraph group_external["External"]
  node_user(("User<br/>terminal"))
  node_databox_api[("Databox API<br/>remote service")]
  node_agentic_service[("Genie Service<br/>remote service")]
  node_local_fs["Config File<br/>local storage"]
end

subgraph group_distribution["Skills"]
  node_skills_pack["Skills<br/>distribution"]
end

node_user -->|"invokes"| node_bin_run
node_user -->|"invokes"| node_bin_dev
node_bin_run -->|"boots"| node_base_command
node_bin_dev -->|"boots"| node_base_command
node_base_command -->|"loads"| node_config
node_base_command -->|"formats"| node_output
node_base_command -->|"prompts"| node_prompt
node_auth -->|"extends"| node_base_command
node_account -->|"extends"| node_base_command
node_data_source -->|"extends"| node_base_command
node_dataset -->|"extends"| node_base_command
node_analyze -->|"extends"| node_base_command
node_auth -->|"stores key"| node_config
node_auth -->|"validates"| node_api_client
node_account -->|"reads"| node_api_client
node_data_source -->|"mutates"| node_api_client
node_dataset -->|"mutates"| node_api_client
node_dataset -->|"confirms"| node_prompt
node_data_source -->|"confirms"| node_prompt
node_analyze -->|"queries"| node_agentic_service
node_api_client -->|"calls"| node_databox_api
node_config -->|"persists"| node_local_fs
node_skills_pack -.->|"packages"| node_auth
node_skills_pack -.->|"packages"| node_account
node_skills_pack -.->|"packages"| node_data_source
node_skills_pack -.->|"packages"| node_dataset
node_skills_pack -.->|"packages"| node_analyze

click node_bin_run "https://github.com/databox/databox-cli/blob/main/bin/run.js"
click node_bin_dev "https://github.com/databox/databox-cli/blob/main/bin/dev.js"
click node_base_command "https://github.com/databox/databox-cli/blob/main/src/base-command.ts"
click node_api_client "https://github.com/databox/databox-cli/blob/main/src/lib/api-client.ts"
click node_config "https://github.com/databox/databox-cli/blob/main/src/lib/config.ts"
click node_output "https://github.com/databox/databox-cli/blob/main/src/lib/output.ts"
click node_prompt "https://github.com/databox/databox-cli/blob/main/src/lib/prompt.ts"
click node_skills_pack "https://github.com/databox/databox-cli/tree/main/skills"

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_bin_run,node_bin_dev toneBlue
class node_auth,node_account,node_data_source,node_dataset,node_analyze toneAmber
class node_base_command,node_api_client,node_config,node_output,node_prompt toneMint
class node_user,node_databox_api,node_agentic_service,node_local_fs toneRose
class node_skills_pack toneIndigo
```

## Components

### Runtime

CLI launchers and user entrypoints

- [run.js](https://github.com/databox/databox-cli/blob/main/bin/run.js): launcher · Production CLI entrypoint · `bin/run.js`
- [dev.js](https://github.com/databox/databox-cli/blob/main/bin/dev.js): launcher · Development CLI entrypoint · `bin/dev.js`

### Commands

Domain command families exposed by the databox binary

- **Auth**: command family · Login and token validation
- **Account**: command family · Account discovery and reference listing
- **Data Source**: command family · Data source lifecycle and inspection
- **Dataset**: command family · Dataset lifecycle, ingestion, and status
- **Analyze**: command family · Genie query workflow

### Shared Lib

Common command base and reusable CLI helpers

- [Base Cmd](https://github.com/databox/databox-cli/blob/main/src/base-command.ts): command base · Shared superclass for CLI commands · `src/base-command.ts`
- [API Client](https://github.com/databox/databox-cli/blob/main/src/lib/api-client.ts): databox api · Main Databox API integration boundary · `src/lib/api-client.ts`
- [Config](https://github.com/databox/databox-cli/blob/main/src/lib/config.ts): state store · Persisted CLI configuration and API key · `src/lib/config.ts`
- [Output](https://github.com/databox/databox-cli/blob/main/src/lib/output.ts): renderer · Table and JSON rendering · `src/lib/output.ts`
- [Prompt](https://github.com/databox/databox-cli/blob/main/src/lib/prompt.ts): ux helper · Interactive confirmation and input handling · `src/lib/prompt.ts`

### External

Remote services and local state boundaries

- **User**: terminal · Person running the CLI
- **Databox API**: remote service · Primary backend for CRUD, listing, and ingestion
- **Genie Service**: remote service · Separate analysis service for ask-genie
- **Config File**: local storage · Filesystem-backed CLI state under the user config directory

### Skills

Packaged agent skill artifacts

- [Skills](https://github.com/databox/databox-cli/tree/main/skills): distribution · Packaged SKILL.md artifacts for autonomous agents · `skills`

## Connections

- User → run.js: invokes · User runs the CLI
- User → dev.js: invokes · User runs the CLI in development mode
- run.js → Base Cmd: boots · Runtime launcher initializes the command framework
- dev.js → Base Cmd: boots · Dev launcher initializes the command framework
- Base Cmd → Config: loads · Commands share persisted configuration and auth state
- Base Cmd → Output: formats · Centralizes human-readable and JSON output
- Base Cmd → Prompt: prompts · Centralizes interactive confirmation and input flows
- Auth → Base Cmd: extends · Auth commands build on the shared base command
- Account → Base Cmd: extends · Account commands build on the shared base command
- Data Source → Base Cmd: extends · Data source commands build on the shared base command
- Dataset → Base Cmd: extends · Dataset commands build on the shared base command
- Analyze → Base Cmd: extends · Analyze command builds on the shared base command
- Auth → Config: stores key · Login persists API credentials locally
- Auth → API Client: validates · Validate uses the Databox API client
- Account → API Client: reads · Account discovery and listings go through the API client
- Data Source → API Client: mutates · Create, delete, and list operations use the Databox API
- Dataset → API Client: mutates · Dataset lifecycle, ingestion, and status operations use the Databox API
- Dataset → Prompt: confirms · Destructive dataset actions can require confirmation
- Data Source → Prompt: confirms · Destructive data source actions can require confirmation
- Analyze → Genie Service: queries · ask-genie sends questions to a separate service
- API Client → Databox API: calls · HTTP boundary to Databox backend services
- Config → Config File: persists · Config is stored in the local user configuration directory
- Skills → Auth: packages · Skill artifact mirrors the auth workflow
- Skills → Account: packages · Skill artifact mirrors the account workflow
- Skills → Data Source: packages · Skill artifact mirrors the data source workflow
- Skills → Dataset: packages · Skill artifact mirrors the dataset workflow
- Skills → Analyze: packages · Skill artifact mirrors the analysis workflow
