# dbt-labs/dbt architecture

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

- Interactive diagram: https://gitdiagram.com/dbt-labs/dbt
- Repository: https://github.com/dbt-labs/dbt
- Video tour (about a minute): https://gitdiagram.com/dbt-labs/dbt/video

## Overview

1. **Purpose and principal workflow.** This is dbt v2.0, a Rust workspace that lets a data analyst or engineer invoke the local dbt CLI on a project of SQL models; dbt loads and resolves the project, compiles and schedules its model graph, executes warehouse SQL, and produces queryable artifacts and local documentation. The README documents parse/compile/run behavior and Parquet artifacts; sampled code confirms the scheduling and adapter-execution layers, though the top-level CLI wiring was not sampled.

2. **Components**

**Project invocation, loading, and planning**
- **Data analyst / engineer** — `null` repository path; external CLI user who initiates project parsing, compilation, and execution.
- **dbt CLI application** — `crates/dbt-main/src`; workspace application package that is the likely distributed dbt binary entry point, consistent with the README’s single self-contained binary claim, but its `main` source was not sampled.
- **Project and macro loader** — `crates/dbt-loader/src`; loads project inputs and ships dbt plus adapter-specific macro assets for Jinja-based transformation semantics.
- **Project parser and resolver** — `crates/dbt-parser/src`; parses project definitions and includes a resolution subsystem, producing the graph inputs used by compilation.
- **Compilation core** — `crates/dbt-compilation/src`; owns load and resolve phases according to the compilation-pipeline source comments and exposes `DbtLoadedProject`.
- **Selection and schedule pipeline** — `crates/dbt-tasks-sa/src/compilation_pipeline.rs`; applies selectors, prior-state/cache selection, inline-model overrides, and constructs a dependency schedule.
- **Dependency scheduler** — `crates/dbt-scheduler/src`; builds the executable graph schedule from resolved nodes, selectors, state, and scheduler arguments.
- **State-selector and run-cache state** — `crates/dbt-state/src`; evaluates state-based selection against prior artifacts and run-cache arguments.

**Execution and warehouse access**
- **Task execution layer** — `crates/dbt-tasks-sa/src/runnable`; contains runnable task implementations that consume planned dbt work; its exact dispatch from the scheduler was not sampled.
- **Adapter execution engine** — `crates/dbt-adapter/src/engine/adapter_engine.rs`; creates warehouse connections, adds query comments/labels and run metadata, configures statements, checks cancellation, executes SQL, and returns Arrow record batches or update results.
- **Adapter query context builder** — `crates/dbt-adapter/src/query_ctx.rs`; derives node, target, project/model, execution phase, and invocation identifiers from MiniJinja state into `QueryCtx`.
- **ADBC database interface and driver loading** — `crates/dbt-adbc/src/driver_manager.rs`; wraps the Arrow ADBC C interface and can initialize statically linked or dynamically loaded database drivers.
- **Target data warehouse / database driver** — `null` repository path; external destination selected by profile/adapter configuration; concrete provider choice and runtime deployment wiring are not established by the excerpts.
- **Adapter recording/replay engine** — `crates/dbt-adapter/src/time_machine/engine.rs`; records adapter-call outcomes or replays recorded results with adapter-aware event validation for compatibility/testing-style execution modes.

**Artifacts and local documentation**
- **Parquet metadata artifacts** — `crates/dbt-metadata-parquet/src`; artifact subsystem consistent with the README’s documented scalable Parquet outputs, though artifact-write call sites were not sampled.
- **Documentation server** — `crates/dbt-docs-server/src`; local docs-serving/export package documented by the repository’s revamped local documentation capability.
- **Docs browser application** — `crates/dbt-docs-server/web/src/queryClient.ts`; configures browser data fetching to avoid focus refetches and retry transient artifact/CDN failures up to three times.
- **Browser artifact query engine** — `crates/dbt-docs-server/web/src/shared/data-sources/duckdb/engine.ts`; lazily loads DuckDB-WASM, fetches generated `views.sql`, and registers Parquet artifacts on demand for client-side documentation queries.
- **Browser UI preference state** — `crates/dbt-docs-server/web/src/shared/hooks/useLocalStorage.ts`; validates, reads, and synchronously persists React UI state in browser local storage.
- **Artifact/static-site host** — `null` repository path; supplies Parquet artifacts and `views.sql` to the browser query engine.
- **DuckDB-WASM CDN** — `null` repository path; externally hosts the lazily imported WASM engine and worker.

3. **Relationships**

- **Data analyst / engineer -> dbt CLI application:** invokes dbt against a project; README identifies analysts/engineers and describes dbt projects composed of SQL models.
- **dbt CLI application -> Project and macro loader:** loads project inputs and bundled macro assets; documented dbt project workflow, with top-level call site not sampled.
- **Project and macro loader -> Project parser and resolver:** supplies project files and macro definitions for parsing/resolution; subsystem ownership is evident, but exact call site was not sampled.
- **Project parser and resolver -> Compilation core:** provides resolved project graph inputs for compilation; README documents parse then compile, while concrete handoff was not sampled.
- **Compilation core -> Selection and schedule pipeline:** supplies loaded/resolved project state; the pipeline imports `DbtLoadedProject` and explicitly identifies compilation core as phases 1–2.
- **Selection and schedule pipeline -> State-selector and run-cache state:** evaluates prior-state selection; directly calls `evaluate_state_selector`.
- **Selection and schedule pipeline -> Dependency scheduler:** builds a schedule with resolved nodes, selectors, state-selector results, and cancellation token; directly calls the scheduler builder.
- **Dependency scheduler -> Task execution layer:** produces dependency-aware work for runnable tasks; intended handoff is implied by scheduler/task subsystem boundaries, but dispatch code was not sampled.
- **Task execution layer -> Adapter execution engine:** executes compiled model work through adapters; this is the documented dbt run outcome, but the direct task-to-engine call site was not sampled.
- **Adapter query context builder -> Adapter execution engine:** supplies contextual query identifiers for adapter calls; compatible types are sampled, but the invocation site was not shown.
- **Adapter execution engine -> ADBC database interface and driver loading:** uses ADBC `Connection` and `Statement` operations to configure and execute SQL.
- **ADBC database interface and driver loading -> Target data warehouse / database driver:** initializes linked or dynamically loaded ADBC drivers through FFI, as documented in the driver-manager module.
- **Adapter execution engine -> Target data warehouse / database driver:** executes statements through its configured ADBC connection and checks cancellation.
- **Adapter recording/replay engine -> Adapter execution engine:** records adapter-call results or returns replayed results in alternate time-machine modes; exact engine integration point was not sampled.
- **Task execution layer -> Parquet metadata artifacts:** emits project artifacts after work; documented README behavior, with writer call sites not sampled.
- **Docs browser application -> Browser artifact query engine:** uses browser-side artifact querying for docs data; overall UI/data-source wiring was not sampled.
- **Browser artifact query engine -> Artifact/static-site host:** fetches `views.sql` and artifact bytes, registering artifacts only when needed.
- **Browser artifact query engine -> DuckDB-WASM CDN:** dynamically imports DuckDB-WASM and starts its worker on first query.
- **Browser UI preference state -> Browser local storage:** reads validated values and synchronously writes updates; browser local storage is an external browser facility.

4. **Coverage limits.** The sample does not include the dbt CLI `main`, task dispatcher, artifact writers, docs server routes, or most package manifests, so exact command parsing, execution handoff, artifact-export timing, authentication/profile wiring, and supported warehouse-provider selection cannot be established. Provider-specific adapter directories exist, but no concrete runtime provider path was sampled.

Main entry points: [`crates/dbt-adapter/src/engine/adapter_engine.rs`](https://github.com/dbt-labs/dbt/blob/main/crates/dbt-adapter/src/engine/adapter_engine.rs) (Adapter Execution Engine), [`crates/dbt-tasks-sa/src/compilation_pipeline.rs`](https://github.com/dbt-labs/dbt/blob/main/crates/dbt-tasks-sa/src/compilation_pipeline.rs) (Selection Schedule Pipeline), [`crates/dbt-tasks-sa/src/runnable`](https://github.com/dbt-labs/dbt/tree/main/crates/dbt-tasks-sa/src/runnable) (Task Execution), [`crates/dbt-docs-server/web/src/shared/data-sources/duckdb/engine.ts`](https://github.com/dbt-labs/dbt/blob/main/crates/dbt-docs-server/web/src/shared/data-sources/duckdb/engine.ts) (Browser Artifact Query)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_invocation_planning["Invocation and Planning"]
  node_cli["dbt CLI"]
  node_loader["Project Macro Loader"]
  node_parser["Project Parser"]
  node_compilation["Compilation Core<br/>compiler"]
  node_pipeline["Selection Schedule Pipeline"]
  node_scheduler["Dependency Scheduler"]
  node_state[("State Run Cache<br/>state selector")]
end

subgraph group_execution_warehouse["Execution and Warehouse"]
  node_tasks["Task Execution<br/>task runner"]
  node_adapter_engine["Adapter Execution Engine<br/>[adapter_engine.rs]"]
  node_query_context["Query Context Builder<br/>[query_ctx.rs]"]
  node_adbc["ADBC Driver Manager<br/>database interface"]
  node_replay["Adapter Replay Engine<br/>recording engine"]
end

subgraph group_artifacts_docs["Artifacts and Documentation"]
  node_parquet[("Parquet Artifacts<br/>artifact store")]
  node_docs_server["Documentation Server"]
  node_docs_browser["Docs Browser App<br/>web application"]
  node_query_engine["Browser Artifact Query<br/>query engine"]
  node_ui_state["UI Preference State<br/>browser state"]
end

subgraph group_external_systems["External Systems"]
  node_analyst(("Data Analyst<br/>external user"))
  node_warehouse[("Target Warehouse<br/>external database")]
  node_artifact_host["Artifact Static Host<br/>external host"]
  node_duckdb_cdn["DuckDB-WASM CDN<br/>external CDN"]
  node_browser_storage[("Browser Local Storage<br/>browser facility")]
end

node_analyst -->|"invokes dbt"| node_cli
node_cli -->|"loads project"| node_loader
node_loader -->|"supplies inputs"| node_parser
node_parser -->|"provides graph"| node_compilation
node_compilation -->|"supplies project"| node_pipeline
node_pipeline -->|"evaluates state"| node_state
node_pipeline -->|"builds schedule"| node_scheduler
node_scheduler -->|"produces work"| node_tasks
node_tasks -->|"executes models"| node_adapter_engine
node_query_context -->|"supplies context"| node_adapter_engine
node_adapter_engine -->|"executes via ADBC"| node_adbc
node_adbc -->|"loads driver"| node_warehouse
node_adapter_engine -->|"executes SQL"| node_warehouse
node_replay -->|"records or replays"| node_adapter_engine
node_tasks -->|"emits artifacts"| node_parquet
node_docs_browser -->|"queries artifacts"| node_query_engine
node_query_engine -->|"fetches artifacts"| node_artifact_host
node_query_engine -->|"loads DuckDB"| node_duckdb_cdn
node_ui_state -->|"persists preferences"| node_browser_storage

click node_cli "https://github.com/dbt-labs/dbt/tree/main/crates/dbt-main/src"
click node_loader "https://github.com/dbt-labs/dbt/tree/main/crates/dbt-loader/src"
click node_parser "https://github.com/dbt-labs/dbt/tree/main/crates/dbt-parser/src"
click node_compilation "https://github.com/dbt-labs/dbt/tree/main/crates/dbt-compilation/src"
click node_pipeline "https://github.com/dbt-labs/dbt/blob/main/crates/dbt-tasks-sa/src/compilation_pipeline.rs"
click node_scheduler "https://github.com/dbt-labs/dbt/tree/main/crates/dbt-scheduler/src"
click node_state "https://github.com/dbt-labs/dbt/tree/main/crates/dbt-state/src"
click node_tasks "https://github.com/dbt-labs/dbt/tree/main/crates/dbt-tasks-sa/src/runnable"
click node_adapter_engine "https://github.com/dbt-labs/dbt/blob/main/crates/dbt-adapter/src/engine/adapter_engine.rs"
click node_query_context "https://github.com/dbt-labs/dbt/blob/main/crates/dbt-adapter/src/query_ctx.rs"
click node_adbc "https://github.com/dbt-labs/dbt/blob/main/crates/dbt-adbc/src/driver_manager.rs"
click node_replay "https://github.com/dbt-labs/dbt/blob/main/crates/dbt-adapter/src/time_machine/engine.rs"
click node_parquet "https://github.com/dbt-labs/dbt/tree/main/crates/dbt-metadata-parquet/src"
click node_docs_server "https://github.com/dbt-labs/dbt/tree/main/crates/dbt-docs-server/src"
click node_docs_browser "https://github.com/dbt-labs/dbt/blob/main/crates/dbt-docs-server/web/src/queryClient.ts"
click node_query_engine "https://github.com/dbt-labs/dbt/blob/main/crates/dbt-docs-server/web/src/shared/data-sources/duckdb/engine.ts"
click node_ui_state "https://github.com/dbt-labs/dbt/blob/main/crates/dbt-docs-server/web/src/shared/hooks/useLocalStorage.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_cli,node_loader,node_parser,node_compilation,node_pipeline,node_scheduler,node_state toneBlue
class node_tasks,node_adapter_engine,node_query_context,node_adbc,node_replay toneAmber
class node_parquet,node_docs_server,node_docs_browser,node_query_engine,node_ui_state toneMint
class node_analyst,node_warehouse,node_artifact_host,node_duckdb_cdn,node_browser_storage toneRose
```

## Components

### Invocation and Planning

- [dbt CLI](https://github.com/dbt-labs/dbt/tree/main/crates/dbt-main/src): application · `crates/dbt-main/src`
- [Project Macro Loader](https://github.com/dbt-labs/dbt/tree/main/crates/dbt-loader/src): loader · `crates/dbt-loader/src`
- [Project Parser](https://github.com/dbt-labs/dbt/tree/main/crates/dbt-parser/src): parser · `crates/dbt-parser/src`
- [Compilation Core](https://github.com/dbt-labs/dbt/tree/main/crates/dbt-compilation/src): compiler · `crates/dbt-compilation/src`
- [Selection Schedule Pipeline](https://github.com/dbt-labs/dbt/blob/main/crates/dbt-tasks-sa/src/compilation_pipeline.rs): pipeline · `crates/dbt-tasks-sa/src/compilation_pipeline.rs`
- [Dependency Scheduler](https://github.com/dbt-labs/dbt/tree/main/crates/dbt-scheduler/src): scheduler · `crates/dbt-scheduler/src`
- [State Run Cache](https://github.com/dbt-labs/dbt/tree/main/crates/dbt-state/src): state selector · `crates/dbt-state/src`

### Execution and Warehouse

- [Task Execution](https://github.com/dbt-labs/dbt/tree/main/crates/dbt-tasks-sa/src/runnable): task runner · `crates/dbt-tasks-sa/src/runnable`
- [Adapter Execution Engine](https://github.com/dbt-labs/dbt/blob/main/crates/dbt-adapter/src/engine/adapter_engine.rs): execution engine · `crates/dbt-adapter/src/engine/adapter_engine.rs`
- [Query Context Builder](https://github.com/dbt-labs/dbt/blob/main/crates/dbt-adapter/src/query_ctx.rs): context builder · `crates/dbt-adapter/src/query_ctx.rs`
- [ADBC Driver Manager](https://github.com/dbt-labs/dbt/blob/main/crates/dbt-adbc/src/driver_manager.rs): database interface · `crates/dbt-adbc/src/driver_manager.rs`
- [Adapter Replay Engine](https://github.com/dbt-labs/dbt/blob/main/crates/dbt-adapter/src/time_machine/engine.rs): recording engine · `crates/dbt-adapter/src/time_machine/engine.rs`

### Artifacts and Documentation

- [Parquet Artifacts](https://github.com/dbt-labs/dbt/tree/main/crates/dbt-metadata-parquet/src): artifact store · `crates/dbt-metadata-parquet/src`
- [Documentation Server](https://github.com/dbt-labs/dbt/tree/main/crates/dbt-docs-server/src): server · `crates/dbt-docs-server/src`
- [Docs Browser App](https://github.com/dbt-labs/dbt/blob/main/crates/dbt-docs-server/web/src/queryClient.ts): web application · `crates/dbt-docs-server/web/src/queryClient.ts`
- [Browser Artifact Query](https://github.com/dbt-labs/dbt/blob/main/crates/dbt-docs-server/web/src/shared/data-sources/duckdb/engine.ts): query engine · `crates/dbt-docs-server/web/src/shared/data-sources/duckdb/engine.ts`
- [UI Preference State](https://github.com/dbt-labs/dbt/blob/main/crates/dbt-docs-server/web/src/shared/hooks/useLocalStorage.ts): browser state · `crates/dbt-docs-server/web/src/shared/hooks/useLocalStorage.ts`

### External Systems

- **Data Analyst**: external user · Initiates project parsing, compilation, and execution.
- **Target Warehouse**: external database
- **Artifact Static Host**: external host
- **DuckDB-WASM CDN**: external CDN
- **Browser Local Storage**: browser facility

## Connections

- Data Analyst → dbt CLI: invokes dbt
- dbt CLI → Project Macro Loader: loads project
- Project Macro Loader → Project Parser: supplies inputs
- Project Parser → Compilation Core: provides graph
- Compilation Core → Selection Schedule Pipeline: supplies project
- Selection Schedule Pipeline → State Run Cache: evaluates state
- Selection Schedule Pipeline → Dependency Scheduler: builds schedule
- Dependency Scheduler → Task Execution: produces work
- Task Execution → Adapter Execution Engine: executes models
- Query Context Builder → Adapter Execution Engine: supplies context
- Adapter Execution Engine → ADBC Driver Manager: executes via ADBC
- ADBC Driver Manager → Target Warehouse: loads driver
- Adapter Execution Engine → Target Warehouse: executes SQL
- Adapter Replay Engine → Adapter Execution Engine: records or replays
- Task Execution → Parquet Artifacts: emits artifacts
- Docs Browser App → Browser Artifact Query: queries artifacts
- Browser Artifact Query → Artifact Static Host: fetches artifacts
- Browser Artifact Query → DuckDB-WASM CDN: loads DuckDB
- UI Preference State → Browser Local Storage: persists preferences
