How pavan19047/dbt-core works
1. This is a Rust monorepo for dbt Core v2 / Fusion. The architecture is centered around shared libraries plus a small set of binaries: dbt-main is the main CLI/runtime entrypoint, with specialized tools like dbt-docs-server, dbt-metricflow, dbt-sa-cli, dbt-login, dbt-ci, and dbt-adbc.
2. The first major subsystem is project loading and validation. dbt-loader, dbt-parser, dbt-profile, dbt-cloud-config, dbt-schemas, and dbt-selector-parser read dbt projects from the filesystem (dbt_project.yml, profiles.yml, SQL/YAML resources, packages, selectors) and resolve them into typed internal structures. This is the boundary where user-authored project files become normalized dbt metadata.
3. Jinja rendering is a distinct layer, not embedded in the parser itself. The dbt-jinja-* crates provide context building, variables, filters, template evaluation, and phase-specific environments for parse/compile/run. They also implement the language surface that dbt exposes to model SQL and macros.
4. Compilation and planning are handled by dbt-compilation, dbt-dag, dbt-scheduler, dbt-defer, dbt-metadata, dbt-metadata-parquet, dbt-schema-store, and dbt-index-core. Together these crates build the DAG, hydrate schemas, determine dependencies, compute scheduling, and produce the artifact graph used downstream by execution, docs, and lineage features.
5. The execution/runtime layer is split from compilation. dbt-tasks-sa and dbt-tasks-core model runnable work units such as models, seeds, snapshots, tests, and operations. They convert compiled nodes into task execution, manage task context, and bridge into warehouse execution and run-cache behavior.
6. Database connectivity is abstracted through the adapter/engine stack in dbt-adapter and dbt-adbc. This is where dbt crosses the boundary to external warehouses and engines such as Snowflake, BigQuery, Databricks, Redshift, Postgres, DuckDB, Spark, ClickHouse, Fabric, Salesforce, Athena, and Exasol. The adapter layer also handles SQL generation, relation naming, metadata queries, retries, query comments, sidecar communication, and ADBC driver management.
7. Authentication and connection setup are separate concerns. dbt-auth and dbt-platform-auth provide credential resolution for warehouse/cloud integrations, including env-based config, cloud YAML, browser/OAuth flows, session caching, and service-specific auth helpers. dbt-cloud-api is the typed HTTP client for dbt Cloud.
8. Artifact and state management is a major architectural boundary. dbt-state, dbt-common, dbt-error, dbt-base, and dbt-metadata-parquet handle cancellation, state comparison, run caches, metadata persistence, error modeling, and serialization. The repo leans heavily on Parquet for scalable artifacts while still maintaining JSON compatibility for older consumers.
9. Local documentation is served by dbt-docs-server. It is not just a static site server; it exposes handlers for lineage, models, seeds, snapshots, tests, metrics, searches, exposures, macros, files, identities, and project data, all backed by the parsed/compiled artifacts and state stores.
10. Observability is another cross-cutting subsystem. dbt-tracing, dbt-telemetry, dbt-tui-progress, and tracing support inside dbt-common emit structured logs, spans, metrics, JSONL/Parquet/OTLP telemetry, and terminal progress. This instrumentation spans parsing, compilation, execution, and cloud interactions.
11. The repo also contains support libraries for domain-specific concerns: dbt-agate and dbt-csv for table/CSV handling, dbt-classification-types for taxonomy and tagging, dbt-features and dbt-clap-core for feature gating and CLI plumbing, dbt-env and dbt-ident for environment and identifier handling, and dbt-frontend-common for shared SQL/expression/type utilities.
12. Testing and reproducibility are built into the architecture. dbt-test-utils, dbt-test-containers, and many crate-local snapshot/integration tests provide deterministic harnesses, including containerized Postgres and warehouse-adjacent fixtures. Record/replay support appears in adbc-record-replay and the time-machine/trace subsystems to make warehouse interactions testable without always hitting live services.
13. The overall flow is: project files and auth config are loaded from disk and env, Jinja and parsing resolve them into typed resources, compilation turns resources into a DAG and artifacts, tasks execute against warehouse adapters, and the resulting run state/metadata/telemetry feeds docs, lineage, caches, and analytics surfaces.
Main entry points: dbt-main dbt-main · dbt-loader loader · dbt-compilation compilation · dbt-adapter adapter
Components 34
Binaries
CLI entrypoints and user-facing tools.
- dbt-main · Main entrypoint for Fusion/dbt commands and orchestration.
crates/dbt-main - docs server · Serves parsed and compiled project data through docs and lineage handlers.
crates/dbt-docs-server - metricflow · MetricFlow-oriented CLI and compatibility surface.
crates/dbt-metricflow - sa cli · Specialized command-line tool for static analysis and parse flows.
crates/dbt-sa-cli
Project ingest
Filesystem, config, and schema normalization.
- loader · Loads dbt projects, packages, profiles, and macro assets from disk.
crates/dbt-loader - parser · Resolves project resources, validates nodes, and builds typed parse state.
crates/dbt-parser - profile · Resolves profiles and Jinja-backed connection configuration.
crates/dbt-profile - schemas · Typed schema definitions for manifests, profiles, projects, selectors, and artifacts.
crates/dbt-schemas - selector parser · Parses node selection expressions into executable selection rules.
crates/dbt-selector-parser
Jinja layer
Template context, rendering, variables, and filters.
- jinja utils · Builds phase-specific Jinja environments and shared templating helpers.
crates/dbt-jinja-utils - jinja ctx · Constructs parse, compile, run, and load contexts for Jinja evaluation.
crates/dbt-jinja-ctx - jinja filters · dbt-specific filter implementations exposed to templates.
crates/dbt-jinja-filters - jinja vars · Resolves dbt variables and environment variables during rendering.
crates/dbt-jinja-vars
Planning
Compilation, DAG, scheduling, and metadata graph generation.
- compilation · Performs compilation, schema hydration, and schedule-oriented planning.
crates/dbt-compilation - dag · Maintains dependency graphs and scheduling relations between nodes.
crates/dbt-dag - scheduler · Turns node selection and dependencies into runnable schedules.
crates/dbt-scheduler
Execution
Task modeling and warehouse execution.
- tasks core · Defines runnable task abstractions, hooks, and run-cache lifecycle support.
crates/dbt-tasks-core - tasks sa · Converts compiled nodes into executable model, seed, snapshot, test, and operation tasks.
crates/dbt-tasks-sa
Platform
Adapters, auth, and cloud connectivity.
- adapter · Adapter and engine stack for SQL generation, metadata queries, retries, sidecars, and query comments.
crates/dbt-adapter - adbc · ADBC driver layer and database/connection management for warehouse engines.
crates/dbt-adbc - auth · Resolves warehouse credentials and service-specific authentication flows.
crates/dbt-auth - platform auth · Credential chaining, OAuth, env-based resolution, and session caching for platform integrations.
crates/dbt-platform-auth - cloud api · Typed client for dbt Cloud APIs and connection metadata endpoints.
crates/dbt-cloud-api - cloud config · Resolves dbt Cloud-specific configuration into local runtime settings.
crates/dbt-cloud-config
State & docs
Artifacts, caches, docs, and lineage surfaces.
- metadata · Tracks partial parse state, file registry, and index resolution.
crates/dbt-metadata - metadata parquet · Parquet-backed artifact encoding for parse, compile, runtime, and telemetry data.
crates/dbt-metadata-parquet - schema store · Persists schema snapshots and cached metadata for downstream consumers.
crates/dbt-schema-store - state · Run cache, metadata cache, authentication helpers, and service clients for persistent state.
crates/dbt-state - docs core · Shared docs-domain types used by the docs server and related consumers.
crates/dbt-docs-core
Support
Shared utilities, telemetry, and test scaffolding.
- common · Cross-cutting utilities for cancellation, IO, hashing, serialization, tracing glue, and artifacts.
crates/dbt-common - error · Structured error types, code locations, and tracing-friendly diagnostics.
crates/dbt-error - tracing · Structured logs, spans, OTLP/JSONL/Parquet writers, and trace infrastructure.
crates/dbt-tracing - telemetry · Generated telemetry event schemas plus JSON/Arrow serialization support.
crates/dbt-telemetry - test utils · Deterministic integration and snapshot harnesses for project, task, and telemetry flows.
crates/dbt-test-utils
Connections 41
- dbt-main → loader: loads projects · The main CLI starts by loading project files, packages, and profiles.
- dbt-main → parser: parses nodes · CLI workflows delegate resource resolution and validation to the parser.
- dbt-main → compilation: compiles graph · Compiled project state is produced for downstream execution and docs.
- dbt-main → tasks sa: runs tasks · Execution is coordinated through the task layer.
- dbt-main → state: persists state · Run cache, auth, and service state are mediated through persistent state services.
- dbt-main → tracing: emits telemetry · CLI startup and command execution are instrumented.
- loader → schemas: hydrates schemas · Loaded files are normalized into typed project/profile/manifest models.
- loader → jinja utils: renders setup · Loader-time templates and environment setup depend on Jinja utilities.
- loader → cloud config: resolves cloud config · Cloud-specific configuration is loaded alongside local project inputs.
- loader → auth: resolves creds · Loader-side configuration can require warehouse credentials.
- parser → jinja ctx: builds contexts · Parser resolution uses phase-specific Jinja contexts.
- parser → selector parser: applies selectors · Selection expressions are parsed into project traversal rules.
- parser → metadata: updates parse state · Parsed resources feed partial parse and file registry state.
- profile → jinja utils: renders profiles · Profiles are templated through the Jinja layer.
- jinja utils → jinja ctx: builds envs · Context objects are assembled into phase-specific environments.
- jinja utils → jinja filters: registers filters · dbt exposes custom filter functions to templates.
- jinja utils → jinja vars: resolves vars · Environment and dbt variables are injected into rendering.
- compilation → dag: builds dag · Compilation produces dependency graphs and artifact structure.
- compilation → scheduler: plans schedule · Compilation hands scheduling information to execution planning.
- compilation → metadata parquet: writes artifacts · Compiled state can be persisted as Parquet-backed artifacts.
- compilation → schema store: hydrates schema store · Schema information is pushed into shared caches and stores.
- dag → scheduler: orders work · Dependency relations drive execution ordering.
- scheduler → tasks core: creates tasks · Schedules are translated into task abstractions and run units.
- tasks core → tasks sa: executes task model · The core task model is specialized by the static-analysis/runtime implementation.
- tasks sa → adapter: uses adapters · Task execution ultimately crosses into warehouse adapters.
- tasks sa → state: uses run cache · Task execution consults cached run and metadata state.
- adapter → adbc: opens drivers · The adapter layer can route through ADBC-managed connections and drivers.
- adapter → auth: authenticates · Warehouse connections use adapter-specific credential resolution.
- adapter → platform auth: cloud auth · Cloud-integrated warehouses and services use platform auth flows.
- adapter → tracing: instruments queries · Adapter operations are traced for observability.
- state → metadata parquet: stores artifacts · Persistent state is serialized into scalable artifact formats.
- state → cloud api: calls cloud · State services may talk to dbt Cloud endpoints.
- docs server → docs core: serves docs · The server exposes docs-domain data structures and shared models.
- docs server → metadata parquet: reads artifacts · Docs endpoints are backed by persisted parse and runtime artifacts.
- docs server → state: reads state · Docs and lineage queries can consult live or cached state.
- docs server → dag: shows lineage · Graph and lineage handlers render dependency information.
- metricflow → dbt-main: shares runtime · MetricFlow tooling sits beside the main CLI/runtime boundary.
- sa cli → parser: static parse · The specialized CLI exercises the parsing and analysis pipeline.
- test utils → loader: fixtures projects · Test harnesses build project fixtures around the loader boundary.
- test utils → tasks sa: runs task tests · Integration tests exercise the task execution layer.
- test utils → tracing: captures traces · Tests validate structured logs and telemetry output.