dbt-lineage

A fast Rust CLI tool for visualizing dbt model lineage. Parses SQL files directly to extract ref() and source() dependencies, builds a DAG, and renders it as ASCII art, Graphviz DOT, or an interactive terminal UI.
No dbt compilation, manifest, or Python runtime required for graph building — just point it at a dbt project directory.
Features
- Direct SQL parsing — extracts
ref()andsource()calls via regex, nodbt compileneeded - Interactive TUI — navigate, search, and explore lineage in a terminal UI (ratatui) with Unicode box-drawing nodes, orthogonal edge routing, and full mouse support
- Run dbt from TUI — execute
dbt run/dbt teston selected models with scope control (+upstream,downstream+,+all+) via keyboard menu or right-click context menu - Run status tracking — color-coded nodes show success (green), error (red), outdated (yellow), or never-run (default)
- Collapsible node list — directory-grouped, expandable/collapsible sidebar panel
- Multiple output formats — colored ASCII boxes or Graphviz DOT for static output
- Filtering — focus on a single model with configurable upstream/downstream depth
- Node type support — models, sources, seeds, snapshots, tests, exposures
Installation
From crates.io
From source
The binary is installed to ~/.cargo/bin/dbt-lineage.
Usage
Static output
# Full lineage of current directory's dbt project
# Focus on a specific model
# Point at a different project directory
# Show 2 levels upstream, 1 downstream
# Include seeds, tests, snapshots, exposures
# Graphviz DOT output (pipe to `dot -Tpng` etc.)
Interactive TUI
CLI Reference
Usage: dbt-lineage [OPTIONS] [MODEL]
Arguments:
[MODEL] Model name to focus on (shows full lineage if omitted)
Options:
-p, --project-dir <PATH> Path to dbt project directory [default: .]
-u, --upstream <N> Upstream levels to show (default: all)
-d, --downstream <N> Downstream levels to show (default: all)
-i, --interactive Launch interactive TUI mode
-o, --output <FORMAT> Output format: ascii, dot [default: ascii]
--include-tests Include test nodes
--include-seeds Include seed nodes
--include-snapshots Include snapshot nodes
--include-exposures Include exposure nodes
-h, --help Print help
TUI Keybindings
Navigation
| Key | Action |
|---|---|
h j k l / arrow keys |
Navigate between nodes (left/down/up/right) |
H J K L |
Pan the viewport |
+ / - |
Zoom in / out (adjusts spacing) |
Tab / Shift+Tab |
Cycle through nodes sequentially |
r |
Reset view (center + zoom) |
Mouse
| Action | Target | Effect |
|---|---|---|
| Left click | Node on graph | Select node (no viewport jump) |
| Left click | Empty graph area | Begin drag to pan |
| Drag | Graph area | Pan the viewport |
| Scroll up / down | Graph area | Zoom in / out |
| Left click | Node list entry | Select node and center viewport |
| Left click | Group header | Collapse / expand group |
| Right click | Node on graph | Open context menu (run options) |
Search
| Key | Action |
|---|---|
/ |
Open search |
Tab |
Next search result |
Esc / Enter |
Close search |
Node list panel
| Key | Action |
|---|---|
n |
Toggle node list sidebar |
c |
Collapse/expand directory group |
Running dbt
| Key | Action |
|---|---|
x |
Open run menu for selected node |
| Right click | Open context menu on a node (same run options) |
o |
View last run output |
Run menu / context menu options:
| Key | Command |
|---|---|
r |
dbt run (this model) |
u |
dbt run +upstream |
d |
dbt run downstream+ |
a |
dbt run +all+ |
t |
dbt test |
General
| Key | Action |
|---|---|
q |
Quit |
Ctrl+C |
Quit (any mode) |
Node colors in TUI
By run status (when target/run_results.json exists):
| Color | Meaning |
|---|---|
| Green | Last run succeeded |
| Red | Last run failed |
| Yellow | Outdated (source file modified after last run) |
| DarkGray | Skipped |
By node type (when never run):
| Color | Type |
|---|---|
| Blue | Model |
| Green | Source |
| Yellow | Seed |
| Magenta | Snapshot |
| Cyan | Test |
| Red | Exposure |
| DarkGray | Phantom (unresolved ref) |
How it works
- Parse
dbt_project.ymlto find model/seed/snapshot paths - Walk those directories, collecting
.sqland.ymlfiles - Extract
ref('model')andsource('schema', 'table')from SQL via regex - Parse YAML schema files for sources, model descriptions, and exposures
- Build a directed acyclic graph (petgraph) where edges flow from dependency to dependent
- Filter by focus model and depth, prune by node type
- Layout using a Sugiyama-style layered algorithm (longest-path layering + barycenter ordering)
- Render as ASCII, DOT, or interactive TUI
uv / virtualenv support
When running dbt from the TUI, the tool auto-detects whether to use uv run dbt or plain dbt:
- If
uv.lockorpyproject.tomlexists in the dbt project directory, usesuv run dbt - Otherwise, if
dbtis on PATH, uses it directly - If
dbtis not on PATH butuvis, falls back touv run dbt
Building without TUI
The TUI is enabled by default. To build a minimal binary with only static output:
License
MIT