How dbt-labs/dbt works
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: adapter_engine.rs Adapter Execution Engine · compilation_pipeline.rs Selection Schedule Pipeline · runnable Task Execution · engine.ts Browser Artifact Query
Components 22
Invocation and Planning
- dbt CLI
crates/dbt-main/src - Project Macro Loader
crates/dbt-loader/src - Project Parser
crates/dbt-parser/src - Compilation Core
crates/dbt-compilation/src - Selection Schedule Pipeline
crates/dbt-tasks-sa/src/compilation_pipeline.rs - Dependency Scheduler
crates/dbt-scheduler/src - State Run Cache
crates/dbt-state/src
Execution and Warehouse
- Task Execution
crates/dbt-tasks-sa/src/runnable - Adapter Execution Engine
crates/dbt-adapter/src/engine/adapter_engine.rs - Query Context Builder
crates/dbt-adapter/src/query_ctx.rs - ADBC Driver Manager
crates/dbt-adbc/src/driver_manager.rs - Adapter Replay Engine
crates/dbt-adapter/src/time_machine/engine.rs
Artifacts and Documentation
- Parquet Artifacts
crates/dbt-metadata-parquet/src - Documentation Server
crates/dbt-docs-server/src - Docs Browser App
crates/dbt-docs-server/web/src/queryClient.ts - Browser Artifact Query
crates/dbt-docs-server/web/src/shared/data-sources/duckdb/engine.ts - UI Preference State
crates/dbt-docs-server/web/src/shared/hooks/useLocalStorage.ts
External Systems
- Data Analyst · Initiates project parsing, compilation, and execution.
- Target Warehouse
- Artifact Static Host
- DuckDB-WASM CDN
- Browser Local Storage
Connections 19
- 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