Generating & Serving Documentation
Relevant source files
The following files were used as context for generating this wiki page:
The meltano-dbt-ext utility facilitates the lifecycle of dbt documentation by wrapping the standard dbt CLI commands within a Meltano extension framework. This allows users to generate technical documentation from their dbt models and serve that documentation through a local web server, all while leveraging Meltano's configuration management and environment variables.
The extension manages these processes through two primary commands: docs-generate and docs-serve. These commands interact with the underlying dbt project structure, utilizing specified project and profile directories to ensure documentation reflects the current state of the data warehouse.
Sources: README.md:118-121, dbt_ext/extension.py:18-36
Documentation Architecture
The documentation system relies on the dbt class, which inherits from ExtensionBase. This class handles the execution of dbt commands via an Invoker. Documentation generation is a two-step process: first, metadata is extracted from the project and warehouse to create static files; second, those files are served via a web server.
Command Workflow
When a user executes a documentation command through Meltano, the extension follows a specific execution flow:
The diagram shows the logic flow from user command to dbt execution, including the optional pre-invoke steps that ensure dependencies are current.
Sources: dbt_ext/extension.py:53-90, tests/test_dbt_ext.py:20-43
Generating Documentation (docs-generate)
The docs-generate command is responsible for compiling the dbt project and producing the index.html and manifest.json files required for documentation.
- Logic: The command maps to the dbt CLI argument
docs generate. - Target Directory: Compiled files are written to the directory specified by
target-pathindbt_project.yml, which defaults totarget. - Automation: Unless
DBT_EXT_SKIP_PRE_INVOKEis set totrue, the extension automatically runsdbt cleananddbt depsbefore generation to ensure a clean build environment.
| Command | dbt Argument | Description |
|---|---|---|
docs-generate | docs generate | Generates documentation for your project. |
Sources: README.md:118-119, dbt_ext/extension.py:53-73, dbt_ext/dbt_files/bundle/transform/dbt_project.yml:19
Serving Documentation (docs-serve)
The docs-serve command starts a local web server to display the documentation generated in the previous step.
- Dependency: Users must run
docs-generatesuccessfully before runningdocs-serve. - Execution: The command maps to the dbt CLI argument
docs serve. - Process Management: The
dbtclass usesself.dbt_invoker.run_and_logto execute the command, which captures and logs the server output to the Meltano log stream.
| Command | dbt Argument | Description |
|---|---|---|
docs-serve | docs serve | Serve documentation for your project. |
Sources: README.md:120-121, dbt_ext/extension.py:84-95
Configuration and Environment
Documentation commands are influenced by the extension's environment variables and settings defined in the Meltano project.
Relevant Settings
| Setting | Environment Variable | Default | Description |
|---|---|---|---|
project_dir | DBT_PROJECT_DIR | transform | The directory where the dbt project resides. |
skip_pre_invoke | DBT_EXT_SKIP_PRE_INVOKE | false | Skips dbt clean and dbt deps before generation. |
type | DBT_EXT_TYPE | N/A (Required) | Determines the connection profile (e.g., postgres, snowflake). |
Invocation via Meltano
Users typically interact with these features using the meltano invoke command:
# Generate the documentation
meltano invoke dbt-postgres:docs-generate
# Serve the documentation
meltano invoke dbt-postgres:docs-serve
Sources: README.md:19-35, dbt_ext/extension.py:38-51
Internal Implementation
The extension utilizes the meltano.edk.process.Invoker to bridge Meltano and the dbt CLI.
# dbt_ext/extension.py:46-47
self.dbt_invoker = Invoker(self.dbt_bin, cwd=self.dbt_project_dir)
# dbt_ext/extension.py:94
self.dbt_invoker.run_and_log(command_name, *command_args)
The Invoker ensures that the commands are executed within the correct cwd (Working Directory), which is critical for dbt to locate the dbt_project.yml and the target/ folder containing the documentation.
Sources: dbt_ext/extension.py:46-47, dbt_ext/extension.py:94
Summary
Generating and serving documentation in meltano-dbt-ext is a streamlined wrapper around standard dbt functionality. By integrating these commands into the Meltano extension, the project ensures that documentation processes are consistent with the rest of the data transformation pipeline, respecting the same environment variables and project structures used for data modeling and testing.
Sources: README.md:118-121, dbt_ext/extension.py:10-15