CLI platform and command architecture
DAC is a command-line platform for creating, checking, serving, querying, and exporting dashboard projects. The executable presents one command tree and carries shared project, configuration, and runtime context into the system that owns each operation.
Command surface
Command tree
The command surface is a hierarchy built with urfave/cli v3 in cmd/root.go; the current code does not use Cobra. NewApp registers the top-level commands and gives users one consistent entry point named dac.
The command groups map to these user goals:
| Goal | Commands | Result |
|---|---|---|
| Start or inspect a project | init, ls, validate, check | Create project files or assess dashboard health |
| Work with a dashboard | serve, build, export slides | View, package, or publish dashboard output |
| Work with data | query, connections | Run SQL or test configured data links |
| Move dashboard content | import metabase | Convert an external dashboard into DAC files |
| Manage the CLI and agent support | version, upgrade, skills | Inspect or update the CLI and bundled authoring skills |
The detailed command behavior is described in project lifecycle commands, data-access commands, and dashboard-oriented commands. A hidden skill refresh command supports upgrade flows but is not part of the normal command surface.
References: cmd/root.go• L59-104 cmd/help_golden_test.go• L13-80 cmd/…/standalone_help.golden• L1-329 cmd/export.go• L12-19
Shared invocation context
The root command supplies settings that affect more than one operation. --config selects a Bruin configuration file, --environment selects the target environment, and --debug enables debug logging for commands that use it. The command framework also carries the process context so long-running work can stop when the process is cancelled.
Operational subcommands receive telemetry hooks at registration time. These hooks run for real subcommands and do not add command events to help or version output. Build information also carries the Bruin executable path and whether DAC runs as bruin dac.
References: cmd/root.go• L19-57 cmd/root.go• L59-104 cmd/host_test.go• L111-137
Operation handoff
Each command validates its own input, builds a small operation configuration, and calls the package that owns the work. This keeps command-line concerns at the edge while the dashboard loader, query backend, server, and output systems share the same project context.
The main handoff follows this path:
flowchart LR
A[ dac executable ] --> B[ command tree ]
B --> C[ shared flags and project path ]
C --> D[ command action ]
D --> E[ dashboard loader ]
D --> F[ Bruin query backend ]
D --> G[ server, renderer, importer, or exporter ]
E --> F
G --> F
The same build context selects the Bruin binary for data work and passes the embedded frontend to the development server.
References: cmd/root.go• L107-115 cmd/common.go• L53-72 cmd/build.go• L41-65 cmd/serve.go• L45-78 cmd/host_test.go• L140-205
Project and configuration context
Configuration resolution
The .bruin.yml file defines environments and named data connections. Commands that need data resolve this file from --config or discover it from the dashboard directory. A selected environment controls which connection definitions the Bruin-backed query system uses.
Commands differ in whether configuration is required. Data checks and direct queries fail when no configuration can be found. Serving, building, and exporting can start with an optional configuration path, but data work still needs a usable connection when a dashboard requires live results.
References: cmd/common.go• L20-59 pkg/…/config.go• L11-19 pkg/…/config.go• L31-86 cmd/query.go• L53-61 cmd/check.go• L35-45
Dashboard project paths
The shared --dir option identifies the dashboard project or its dashboard directory. Project path resolution treats a project with a dashboards directory as a unit and also finds nearby semantic and themes directories. This lets commands use the same project layout even when the user points directly at dashboards.
Most commands accept either --dir or one directory argument. They reject both forms together so that one command invocation has one clear source of project context.
References: cmd/common.go• L12-18 cmd/common.go• L73-84 pkg/…/project.go• L15-53
Dashboard loading boundary
Dashboard loading turns YAML and TSX definitions into a common dashboard model. The loader also brings semantic models into the project context and can execute TSX load-time queries when a command supplies a query function.
Commands use this boundary in different ways. Listing and metadata checks avoid query execution. Full checks, direct widget queries, serving, and export work resolve data-bearing widgets into jobs that can use the Bruin backend.
References: pkg/…/loader.go• L14-56 pkg/…/loader.go• L59-90 pkg/…/project.go• L60-75 pkg/…/server.go• L41-92
Executable lifecycle
Process startup
The executable prepares process-wide services before it runs a command. It reads telemetry choices from build values or environment variables, starts a non-blocking update check, passes embedded frontend files to the command layer, and supplies version and commit information.
This startup work supports the command surface without changing the project operation itself. The update check is allowed to finish briefly after a successful command and does not delay command output beyond its short exit wait.
References: main.go• L25-53 main.go• L63-82
Hosted invocation
The executable can run under the Bruin CLI as bruin dac. In this mode it uses the host-provided Bruin binary, presents bruin dac in help and user guidance, and removes commands that belong to standalone DAC installation management.
This mode keeps dashboard work available while avoiding a second version or upgrade path. Only the exact value DAC_HOST=bruin enables hosted behavior. Other values leave the normal standalone command surface unchanged.
References: cmd/root.go• L23-48 cmd/root.go• L73-86 cmd/host_test.go• L324-427
Command execution and exit behavior
cmd.Run stores the embedded frontend for serve, constructs the command tree, and runs it with the process context and argument list. A successful command returns normally. A command error is printed to standard error and ends the process with a non-zero status.
Machine-readable command results stay on standard output. Notices from skill checks and upgrade work use standard error so they do not mix with query or export data. Help output is treated as a stable user contract and is checked for every visible command.
References: main.go• L50-60 cmd/root.go• L107-115 cmd/skills.go• L266-305 cmd/skills.go• L317-356 cmd/help_golden_test.go• L37-81
Query backend boundary
The command platform uses a query.Backend boundary for data access. The main backend runs the selected Bruin CLI and converts its JSON result into a common query result. The same boundary supports live execution and dry-run checks.
This boundary lets commands focus on intent. query asks for rows, validate can ask whether read-only SQL is valid, and check or the server can execute widget jobs without knowing the details of each connection type.
References: pkg/…/backend.go• L5-14 pkg/…/bruin.go• L11-16 pkg/…/bruin.go• L42-100 cmd/query.go• L90-105 cmd/host_test.go• L140-321
Command operation families
Project lifecycle commands
Project lifecycle commands create a usable project and assess its state. init creates a project from a starter, SQL, semantic, or TSX template and initializes Git so Bruin can find the project root. It also adds the bundled authoring skill and prints the next validation and serve steps. validate checks dashboard structure and can add read-only database dry runs. check goes further by executing data-bearing widget queries. ls gives a compact view of valid dashboards.
validate --with-database checks both queries loaded by dashboard code and queries resolved from widgets. It accepts only one read-only SQL statement for each dry run, so validation cannot use its database check as a write path. check reports static widgets without a query and runs query-bearing widgets in a way that limits contention on the same connection while allowing separate connections to make progress together.
Read cli-project-lifecycle.md for the lifecycle flow and its command contracts.
References: cmd/init.go• L27-52 cmd/init.go• L55-133 cmd/init.go• L168-203 cmd/validate.go• L24-139 cmd/validate.go• L143-245 cmd/check.go• L29-145 cmd/check.go• L149-175 cmd/init_test.go• L13-58
Data-access commands
Data-access commands connect dashboard intent to configured data sources. query accepts inline SQL, a SQL file, or a dashboard widget and prints table, JSON, or CSV results. A widget can be selected by its full label, a unique tab name, or its stable job ID; an ambiguous tab name returns the matching choices instead of selecting one silently. A tabbed widget also returns a hint when the container name is used without a tab name. connections tests every named connection in the selected environment with a small read-only query and reports all results together.
Query output is designed for both people and tools. Table output is readable in a terminal. JSON preserves structured results. CSV writes null values as empty fields while preserving a single-column null row as a valid record.
Read cli-data-access.md for query sources, output contracts, and connection checks.
References: cmd/query.go• L22-107 cmd/query.go• L127-159 cmd/query.go• L161-223 cmd/query.go• L245-300 cmd/query_test.go• L14-103 cmd/connections.go• L13-87 cmd/host_test.go• L140-185
Dashboard-oriented commands
Dashboard-oriented commands turn definitions into user-facing results. serve starts the local development server with live reload and can expose protected management endpoints when a password is set. build creates a static dashboard with query results included. export slides sends a dashboard to Google Slides. import metabase converts an external dashboard into DAC YAML and can also create semantic model files.
Read cli-dashboard-operations.md for serving, rendering, importing, and exporting flows.
References: cmd/serve.go• L13-80 cmd/build.go• L12-67 cmd/export.go• L22-73 cmd/host_test.go• L170-204
CLI support commands
Support commands manage the executable and its authoring aids rather than dashboard data. version reports build information. upgrade installs a newer CLI from the selected release channel and then asks the new binary to refresh installed skills. skills lists, installs, and updates the bundled dashboard authoring skill for supported agent tools. Hosted mode omits version, upgrade, and update because Bruin owns those functions.
The bundled create-dashboard skill is embedded in the CLI and carries its own version. Its current guidance covers dashboard authoring, project layout, data connections, direct SQL, semantic models, and CLI validation workflows. The bundled skill is version 16. The CLI compares the installed version with the bundled version: normal work can report or refresh stale installs, while dac skills update or dac upgrade can replace the installed copy explicitly. Claude receives the skill file directly and Codex uses a link to that file, so one update serves both supported agent paths. Skill notices find the project root from a dashboard subdirectory.
References: cmd/version.go• L10-25 cmd/upgrade.go• L19-40 cmd/upgrade.go• L44-127 cmd/skills.go• L16-119 cmd/skills.go• L131-236 cmd/skills.go• L266-375 cmd/skills_test.go• L11-157 cmd/skills_test.go• L180-324 cmd/…/SKILL.md• L1-48
Change checklist
When these files or sections are changed, remember to consider these:
- Add each new user-facing command to the registration in cmd/root.go and decide whether its telemetry hooks should run.
- Keep standalone and
bruin daccommand lists, help names, and next-step hints aligned when changing hosted mode. - Keep root flags and command-local flags aligned with the config and directory paths passed to downstream packages.
- Preserve the distinction between required configuration commands and commands that can load project metadata without a config file.
- When changing project path rules, check dashboard loading, semantic model loading, theme loading, and the default output path used by imports.
- Keep machine-readable output on standard output and send advisory notices to standard error.
- When changing bundled skill content or its version format, check direct installs, stale-copy refreshes, the Codex link, and the post-upgrade refresh performed by the new binary.
- When changing visible command names, usage text, or flags, update the standalone help golden output and hosted-help expectations together.
- When changing query widget matching or output formats, check tab labels, stable widget IDs, ambiguous-name errors, and null rows in CSV output.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No .bruin.yml is found for a data operation | Query, connection checks, or database validation stop before data work | Pass --config or place the command directory inside a project with discoverable configuration |
| The selected environment is missing or has no required connection | Bruin cannot resolve the requested data source | Set --environment or the config default and use the exact connection name from that environment |
A dashboard path is supplied both as an argument and through --dir | The command rejects the ambiguous project context | Use one directory form only |
| Dashboard structure or semantic references are invalid | Validation fails and serving or data operations cannot safely proceed | Run dac validate before live checks or serving |
| The Bruin executable is unavailable or returns an error | Query results, widget checks, and live dashboard data fail | Install Bruin or set its host-provided path, then confirm the configured connection with dac connections |
A project target contains scaffold files without --force | init stops rather than overwriting project files | Review the conflicts or use --force when replacement is intended |
| The configured server port range is occupied | serve cannot start after trying its allowed ports | Free a port or choose another starting port with --port |
| An installed skill is stale or conflicts with local content | Automatic refresh may report or replace stale content, while an install can stop on an overwrite conflict | Use dac skills update for the bundled skill or dac skills install --force when replacement is intended |
| A widget tab name matches more than one tab | query --dashboard ... --widget ... stops instead of running an unintended query | Use the full Widget / Tab label or the returned widget ID |
| A tabbed widget is addressed only by its container name | Query selection stops and lists the valid tab names | Pass a tab name, full label, or stable tab ID |
DAC runs with DAC_HOST=bruin but a command assumes standalone DAC | Help or next-step guidance points to commands that the host does not expose | Use the hosted program name and keep hosted command registration separate from standalone registration |
| A visible command or help flag changes without a golden update | The help contract test fails even when command execution still works | Regenerate cmd/testdata/standalone_help.golden only for an intended help change |
Key files
| File | Why to read it |
|---|---|
| main.go | Shows process startup, telemetry and update setup, frontend handoff, and exit behavior |
| cmd/root.go | Defines the command tree, root flags, build metadata, hosted mode, and command execution entry point |
| cmd/common.go | Defines shared dashboard-directory and configuration resolution used by many commands |
| pkg/…/config.go | Defines environment selection and named connection lookup |
| pkg/…/project.go | Explains how a dashboard directory maps to project, semantic, and theme paths |
| pkg/…/loader.go | Shows the common boundary from project files to dashboard models |
| pkg/…/backend.go | Defines the data-access contract used by commands and the server |
| pkg/…/bruin.go | Shows how DAC delegates query execution and dry runs to Bruin |
| pkg/…/server.go | Shows how serve assembles the local dashboard server and its shared backend |
| pkg/…/api.go | Shows how dashboard widgets become query jobs and results |
| cmd/init.go | Illustrates project creation, templates, Git setup, and initial project guidance |
| cmd/query.go | Illustrates direct SQL and dashboard-widget data-access paths and result formats |
| cmd/skills.go | Defines bundled skill registration, installation targets, version checks, root discovery, and refresh |
| cmd/skills_test.go | Verifies skill registration, installation targets, overwrite rules, version refresh, and CLI wiring |
| cmd/…/SKILL.md | States the current authoring guidance distributed by the CLI |
| cmd/host_test.go | Verifies hosted invocation, Bruin binary selection, command hiding, help naming, and host-specific guidance |
| cmd/query_test.go | Verifies widget-tab selection, ambiguity handling, stable IDs, and CSV null output |
| cmd/help_golden_test.go | Verifies stable help output for every visible standalone command |
cmd/testdata/standalone_help.golden | Records the expected standalone command and flag help surface |