# Where Is the Primary dbt Directory Located in dbt-labs/dbt-core? Complete Guide to the Rust Source Structure

> Discover the primary dbt directory in dbt-labs/dbt-core at crates/dbt-main/. Understand the Rust source structure powering the dbt CLI and core library.

- Repository: [dbt Labs/dbt-core](https://github.com/dbt-labs/dbt-core)
- Tags: how-to-guide
- Published: 2026-06-28

---

**The primary dbt directory is located at `crates/dbt-main/` in the dbt-labs/dbt-core repository, serving as the central Rust crate that powers the dbt command-line tool and core library.**

The dbt-labs/dbt-core repository houses the foundational engine for dbt (data build tool), which has migrated from a Python-centric architecture to a Rust-based system organized into modular crates. Understanding the exact location of the primary dbt directory is essential for developers contributing to core logic, debugging CLI behavior, or integrating with the dbt ecosystem.

## Locating the Primary dbt Directory in the Repository Structure

The dbt-labs/dbt-core repository organizes its Rust codebase using a Cargo workspace structure where individual crates handle specific responsibilities. The primary dbt directory containing the central implementation is **`crates/dbt-main/`**, which functions as the entry point for the dbt CLI and the integration layer for all other dbt components.

This directory houses the main library code and the binary executable that users invoke when running `dbt` commands. Unlike the specialized helper crates such as `dbt-loader` or `dbt-parser`, the `dbt-main` crate coordinates the entire execution flow.

## Key Files Inside the Primary dbt Directory

### Cargo.toml Manifest

The **[`crates/dbt-main/Cargo.toml`](https://github.com/dbt-labs/dbt-core/blob/main/crates/dbt-main/Cargo.toml)** file defines the crate metadata, dependencies, and compilation targets for the primary dbt package. This manifest declares the crate name and its relationship to other workspace members, establishing the foundation for how the dbt CLI is built and distributed.

### Library Root: [`dbt_lib.rs`](https://github.com/dbt-labs/dbt-core/blob/main/dbt_lib.rs)

The core library logic resides in **[`crates/dbt-main/src/dbt_lib.rs`](https://github.com/dbt-labs/dbt-core/blob/main/crates/dbt-main/src/dbt_lib.rs)**, which exports the `run()` function that initializes the dbt execution environment. This file handles configuration loading, command routing, and the orchestration of the dbt pipeline.

```rust
// crates/dbt-main/src/dbt_lib.rs
pub fn run() -> Result<()> {
    // Initialise logging, configuration, etc.
    let config = dbt_config::load()?;
    // Execute the requested command (run, test, compile, …)
    dbt_commands::execute(&config)
}

```

### Binary Entry Point: [`dbt_main.rs`](https://github.com/dbt-labs/dbt-core/blob/main/dbt_main.rs)

The CLI executable entry point is defined in **[`crates/dbt-main/src/bin/dbt_main.rs`](https://github.com/dbt-labs/dbt-core/blob/main/crates/dbt-main/src/bin/dbt_main.rs)**, which imports the library from [`dbt_lib.rs`](https://github.com/dbt-labs/dbt-core/blob/main/dbt_lib.rs) and handles process-level concerns such as error codes and exit status.

```rust
// crates/dbt-main/src/bin/dbt_main.rs
fn main() {
    if let Err(e) = dbt_main::run() {
        eprintln!("Error: {}", e);
        std::process::exit(1);
    }
}

```

## Relationship Between `dbt-main` and Other Crates

The primary dbt directory at `crates/dbt-main/` depends on several specialized crates that provide distinct functionality:

- **`dbt-loader`** – Handles parsing and loading of [`dbt_project.yml`](https://github.com/dbt-labs/dbt-core/blob/main/dbt_project.yml) files and project assets
- **`dbt-parser`** – Processes SQL and Jinja templates used in dbt models
- **`dbt-schemas`** – Manages schema definitions and validation logic

These sub-components are imported as dependencies in the [`Cargo.toml`](https://github.com/dbt-labs/dbt-core/blob/main/Cargo.toml) of `dbt-main`, allowing the primary directory to orchestrate the complete dbt workflow while maintaining clean separation of concerns.

## Summary

- The primary dbt directory in dbt-labs/dbt-core is **`crates/dbt-main/`**
- **[`crates/dbt-main/Cargo.toml`](https://github.com/dbt-labs/dbt-core/blob/main/crates/dbt-main/Cargo.toml)** defines the crate configuration and workspace dependencies
- **[`crates/dbt-main/src/dbt_lib.rs`](https://github.com/dbt-labs/dbt-core/blob/main/crates/dbt-main/src/dbt_lib.rs)** contains the core `run()` function and library logic
- **[`crates/dbt-main/src/bin/dbt_main.rs`](https://github.com/dbt-labs/dbt-core/blob/main/crates/dbt-main/src/bin/dbt_main.rs)** serves as the CLI entry point that invokes the library
- The crate coordinates with specialized crates like `dbt-loader` and `dbt-parser` to execute the full dbt pipeline

## Frequently Asked Questions

### Is the primary dbt directory still written in Python?

No, the primary dbt directory located at `crates/dbt-main/` is implemented in Rust. The dbt-labs/dbt-core repository has migrated from Python to a Rust-based architecture, though Python adapters and bindings may still exist in separate repositories or legacy integration points.

### What is the purpose of the `dbt-main` crate?

The `dbt-main` crate serves as the central integration point and entry point for the dbt CLI. It coordinates the execution of dbt commands by importing functionality from specialized crates like `dbt-loader` and `dbt-parser`, handling configuration initialization through `dbt_config::load()`, and managing the overall execution flow through the `run()` function in [`dbt_lib.rs`](https://github.com/dbt-labs/dbt-core/blob/main/dbt_lib.rs).

### Where is the CLI entry point defined?

The CLI entry point is defined in **[`crates/dbt-main/src/bin/dbt_main.rs`](https://github.com/dbt-labs/dbt-core/blob/main/crates/dbt-main/src/bin/dbt_main.rs)**. This file contains the `main()` function that invokes `dbt_main::run()` from the library, handles error propagation, and sets the process exit code, making it the executable that runs when users type `dbt` in their terminal.

### How do other crates interact with the primary dbt directory?

Specialized crates such as `dbt-loader`, `dbt-parser`, and `dbt-schemas` are declared as dependencies in the [`Cargo.toml`](https://github.com/dbt-labs/dbt-core/blob/main/Cargo.toml) of `dbt-main`. The primary directory imports and calls their public APIs to perform specific tasks like project file loading and SQL parsing, while the `dbt-main` crate itself focuses on orchestration and CLI integration.