# Where Is the Primary dbt Directory in dbt-labs/dbt-core?

> Locate the primary dbt directory in dbt-labs/dbt-core at crates/dbt-main/. Discover the central Rust crate housing the CLI entry point and core logic.

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

---

**The primary `dbt` directory in the `dbt-labs/dbt-core` repository is `crates/dbt-main/`, which functions as the central Rust crate containing the CLI entry point and core library logic.**

The `dbt-labs/dbt-core` repository houses the core implementation of dbt (data build tool), organized as a Rust workspace with multiple specialized crates. Locating the primary `dbt` directory is essential for developers contributing to the CLI or integrating with the core library, as this folder contains the executable binary and the public API that orchestrates commands like `run`, `test`, and `compile`.

## Locating the Primary dbt Directory

The main implementation resides in the **`crates/dbt-main/`** directory at the repository root. This crate serves as the entry point for the `dbt` command-line tool and aggregates functionality from other workspace crates such as `dbt-loader` and `dbt-parser`. The architecture centers on this Rust crate for high-level orchestration, making it the definitive "main" dbt directory in the codebase.

## Key Files and Subdirectories

### 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 binary targets. This manifest declares how the `dbt` executable is built and which internal crates (e.g., `dbt-schemas`, `dbt-config`) are linked as dependencies for the build process.

### Core Library Source (dbt_lib.rs)

The heart of the library lives in **[`crates/dbt-main/src/dbt_lib.rs`](https://github.com/dbt-labs/dbt-core/blob/main/crates/dbt-main/src/dbt_lib.rs)**. This file exposes the public `run()` function that initializes configuration, sets up logging, and dispatches commands to appropriate handlers. Both the CLI binary and programmatic consumers rely on this module as the primary interface to dbt's execution engine.

### CLI Binary Entry Point (dbt_main.rs)

The executable entry point is located at **[`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 minimal wrapper calls into the library's `run()` function and handles process exit codes. When users invoke the `dbt` command, this binary is the actual code that executes on the system.

## Architecture Overview

The `dbt-main` crate imports functionality from specialized sub-crates to perform specific tasks:

- **`crates/dbt-loader/src/`** – Handles parsing of [`dbt_project.yml`](https://github.com/dbt-labs/dbt-core/blob/main/dbt_project.yml) files and project asset discovery
- **`crates/dbt-parser/src/`** – Responsible for SQL and Jinja template parsing used throughout the project
- **`crates/dbt-schemas/`** – Manages artifact schemas and validation logic

These components are imported by `dbt-main` while the primary directory maintains the high-level orchestration logic that ties them together.

## Code Examples

The core library initialization in [`dbt_lib.rs`](https://github.com/dbt-labs/dbt-core/blob/main/dbt_lib.rs) sets up the execution environment by loading configuration and executing commands:

```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)
}

```

The CLI binary in [`dbt_main.rs`](https://github.com/dbt-labs/dbt-core/blob/main/dbt_main.rs) provides the minimal wrapper required for system execution:

```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);
    }
}

```

## Summary

- The primary `dbt` directory is **`crates/dbt-main/`** in the `dbt-labs/dbt-core` repository
- **[`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 public API surface
- **[`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 executable entry point
- The crate aggregates functionality from sub-components like `dbt-loader` and `dbt-parser` to provide unified orchestration

## Frequently Asked Questions

### Where is the main dbt package located in dbt-core?

The main dbt package is located at `crates/dbt-main/` within the repository root. This Rust crate serves as the central hub for CLI functionality and core library exports, following standard Rust workspace conventions for the project's architecture.

### What programming language is the primary dbt directory written in?

The primary dbt directory is implemented in **Rust**. The `crates/dbt-main/` path contains `.rs` source files and a [`Cargo.toml`](https://github.com/dbt-labs/dbt-core/blob/main/Cargo.toml) manifest, reflecting the repository's migration to a Rust-based architecture for core functionality.

### How does dbt-main relate to other crates in the repository?

The `dbt-main` crate acts as the orchestration layer that imports and coordinates specialized crates such as `dbt-loader` for project configuration parsing and `dbt-parser` for SQL processing. It aggregates these capabilities to provide the unified CLI interface that end users interact with when running dbt commands.

### What is the entry point for the dbt CLI executable?

The entry point is [`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 defines the `main()` function. This binary file calls `dbt_main::run()` from the library code in [`dbt_lib.rs`](https://github.com/dbt-labs/dbt-core/blob/main/dbt_lib.rs) and manages process termination, serving as the actual executable launched when users type `dbt` in their terminal.