Introducing a new way to review your PRs.

Read the announcement

bruin-data / dac

DaC is a dashboard-as-code tool. Build interactive dashboards using YAML and JSX. Built-in semantic layer. Get your agents to build standardized, reviewable dashboards.

View on GitHub

20 documents · Updated Nov 23, 2026

docs / local-server-api-and-live-reload

Local server APIs and live reload

The local server is the runtime bridge between a DAC project and its web dashboard. It validates the project before listening, serves the embedded frontend, turns dashboard requests into query work, and reports file changes so an engineer can edit definitions and see fresh results without restarting the workflow. Read server and frontend for the larger boundary, frontend dashboard experience for browser behavior, and frontend widgets and export for rendering and export.

Service boundary

The dac serve command creates one HTTP service for dashboard files, query access, themes, and optional administration. The command passes the selected project environment, host, port, template, configuration, and embedded frontend into the service so the local workflow uses one consistent runtime boundary.

Startup contract

The service loads dashboard metadata and validates all loaded dashboards before it starts listening. It wraps the query backend in a five-minute cache, then starts a file watcher when the dashboard, semantic, and theme directories are available. If the requested port is busy, it tries later ports within a bounded range.

This startup order gives the browser a usable contract: a listening service has passed its initial dashboard checks, but later file edits can still produce request errors that the API returns to the page.

References: cmd/serve.go• L13-78 pkg/…/server.go• L18-39 pkg/…/server.go• L95-142 pkg/…/server.go• L214-246 pkg/…/cache.go• L11-65

Cross-origin access

The service adds permissive CORS headers to its HTTP handler. This allows a frontend hosted in a different origin, such as a VS Code webview or the Vite development server, to call the same API. It also answers browser preflight requests before they reach an API handler.

References: pkg/…/server.go• L200-212 frontend/vite.config.ts• L8-16

API surface

The versioned /api/v1 API gives the frontend separate resources for discovery, dashboard definitions, filter options, data, display settings, and live events. JSON errors use an error field; successful responses use resource-specific JSON shapes.

Dashboard resources

Dashboard resources support the two stages of browsing. The list endpoint returns lightweight summaries, while the detail endpoint returns one parsed dashboard definition. The raw endpoint returns the source text for inspection and labels it as YAML or TypeScript according to the source format.

MethodPathPurpose
GET/api/v1/dashboardsDiscover dashboards through summaries and counts
GET/api/v1/dashboards/{name}Load one parsed dashboard definition
GET/api/v1/dashboards/{name}/rawRead the source file for that dashboard

Dashboard names are path values. The browser encodes them before it builds a request, so names with spaces or reserved URL characters remain addressable. Loading a dashboard definition does not run its query-backed filter option queries; the browser requests those options only when it needs them.

References: pkg/…/server.go• L144-156 pkg/…/api.go• L71-103 pkg/…/api.go• L105-131 pkg/…/api_test.go• L93-146 frontend/…/client.ts• L44-64

Filter option resources

Filter option resources supply values for select filters without running the dashboard’s widget queries. The request carries the current filter state, so dependent option queries can use dashboard defaults and current selections.

MethodPathPurpose
POST/api/v1/dashboards/{name}/filters/{filter}/optionsResolve the available values for one select filter

The server validates and normalizes the supplied filter state before it resolves options. Configured static values are returned without a backend call. Query-backed options use the filter’s connection when present, otherwise the dashboard connection, and return distinct scalar values from the first result column. The request cannot replace the configured option query or connection, and resolving options does not change the stored dashboard definition.

References: pkg/…/server.go• L144-156 pkg/…/filter_options.go• L11-62 pkg/…/api.go• L85-103 pkg/…/filter_options_test.go• L17-120 pkg/…/filter_options_test.go• L122-190 pkg/…/filter_options_test.go• L193-278

Query resources

Query resources turn the current filter state into widget data. The frontend can request a full dashboard as one JSON response, receive widget results as newline-delimited JSON while work completes, or request one widget when it needs independent loading. A separate query endpoint runs supplied SQL against a named connection.

MethodPathPurpose
POST/api/v1/dashboards/{name}/dataRun all data-bearing widgets and return a widget map
POST/api/v1/dashboards/{name}/streamStream each completed widget result
POST/api/v1/dashboards/{name}/widgets/{widgetId}/queryRun one widget query
POST/api/v1/queryRun one direct SQL request

Dashboard data requests accept a filters map. The server starts with dashboard defaults, overlays request values, and resolves each widget from that combined state. Text and divider widgets do not need query work. Data-bearing widgets can use regular SQL, semantic definitions, or inline static data; static data returns without a backend call. The server runs query work concurrently with a limit, keeps query failures attached to the affected widget, and lets other results complete.

The result contract uses columns and rows for every data-bearing widget. That lets table columns render ordinary values, images, or compact sparkline series while chart widgets use the same query result. The server also restores dashboard-facing names when a query backend changes the case of result columns, including aliases created for semantic joins. The browser accepts image values only when they are absolute HTTPS URLs on another origin; Vega-Lite charts use the returned rows as their dashboard dataset and do not fetch a separate data URL.

The stream response uses application/x-ndjson. Each line identifies one widget and carries its result, so the browser can render useful data before the full dashboard finishes. The single-widget route uses the same filter and result rules. Tabbed widgets include the tab name in the widget ID, so tab order changes do not assign old data to a new tab. The direct query route is broader than a dashboard widget request and should be treated as a data-access surface rather than a dashboard definition lookup.

References: pkg/…/server.go• L146-152 pkg/…/api.go• L148-223 pkg/…/api.go• L255-379 pkg/…/api.go• L393-522 pkg/…/api_test.go• L148-230 pkg/…/api_test.go• L232-348 pkg/…/api_test.go• L368-461 pkg/…/filter_security_test.go• L70-117 frontend/…/client.ts• L66-177 frontend/…/dashboard.ts• L292-301 frontend/…/TableWidget.tsx• L727-740 frontend/…/sparkline.ts• L1-49 frontend/…/dashboardImage.ts• L1-26 frontend/…/VegaLiteChart.tsx• L88-151

Display resources

Display resources let the frontend choose its visual contract without bundling that choice into each dashboard. Configuration returns the selected template and, for a user-defined theme, its design tokens. Theme endpoints expose the available names and the full theme selected by name.

MethodPathPurpose
GET/api/v1/configReturn template selection, theme tokens, and admin availability
GET/api/v1/themesList available theme names
GET/api/v1/themes/{name}Return one theme definition

The frontend loads configuration before it renders dashboard content. This keeps the server-selected visual template and any user theme tokens in the same initial contract as the dashboard API.

References: pkg/…/api.go• L225-253 pkg/…/server.go• L153-155 frontend/…/client.ts• L32-42 frontend/…/client.ts• L179-186 frontend/…/App.tsx• L50-67

Administration

Administration is an optional API for connection settings in the selected environment. It is intended for local use through the browser’s admin page and is separate from normal dashboard reads and query requests.

Connection management

The server registers admin routes only when --password is set. Login checks the supplied password. Each protected request then needs the same value as a bearer token in the Authorization header.

MethodPathPurpose
POST/api/v1/admin/loginCheck the admin password
GET/api/v1/admin/connectionsList connections grouped by type
POST/api/v1/admin/connectionsAdd a connection
PUT/api/v1/admin/connections/{type}/{name}Update connection fields
DELETE/api/v1/admin/connections/{type}/{name}Remove a connection
POST/api/v1/admin/connections/{type}/{name}/testTest a connection with a basic query

The handlers load the project configuration, apply the change to the selected environment, and save it back to the configuration file. The browser keeps the password in session storage, offers guided fields for common connection types, and falls back to key-value fields for other types. An unauthorized response clears the browser session and returns the user to login.

References: pkg/…/server.go• L158-166 pkg/…/admin.go• L11-52 pkg/…/admin.go• L54-147 pkg/…/admin.go• L149-276 frontend/…/client.ts• L188-281 frontend/…/Admin.tsx• L518-695

Semantic query path

Semantic dashboards use the same dashboard data API as SQL-backed dashboards. A semantic widget describes metrics, dimensions, filters, segments, and sort rules; the server turns that description into SQL before it calls the configured query backend.

Semantic widget resolution

The dashboard layer first decides whether a widget uses a named semantic query or direct semantic fields. It resolves the model and connection, then passes the job to the semantic engine. A dashboard project can provide a set of models, so a dimension from a related model can add a join to the generated query.

This path has no separate HTTP endpoint. The distinction stays inside the data routes, which means the frontend only needs one widget result shape for ordinary SQL, semantic SQL, and inline static data. Cross-model dimensions produce joins while single-model queries remain join-free. The result layer maps engine aliases back to dashboard-facing dimension names, including granularity aliases, and matches backend column names without depending on their case. Widgets can therefore use the names in their definitions across query warehouses.

References: pkg/…/semantic_query.go• L9-73 pkg/…/api.go• L255-379 pkg/…/semantic.go• L15-105 pkg/…/semantic_join_test.go• L11-126 pkg/…/semantic_null_test.go• L15-89 pkg/…/api_test.go• L232-254 pkg/…/api_test.go• L297-337

Filter rendering

The server applies dashboard defaults and request values through one filter contract before it renders ordinary SQL or semantic model and query fields. It rejects undeclared filters, invalid types, unsafe values, and values with a shape that the selected semantic operator cannot use before any backend call. An empty multi-select removes its semantic condition instead of producing an empty constraint.

The filter contract preserves typed null values as distinct from the string "null". For in and not_in filters, the semantic engine turns a null member into SQL null checks while it keeps text values as text. This lets dashboard filters include or exclude database nulls without changing literal values.

The same validation boundary protects filter-option requests. It renders every model in the project so joined expressions use the same filter state as the primary model. The semantic engine escapes author-written literals, while values changed by request templates pass the server’s SQL safety checks. The generated result keeps dashboard-facing names when the semantic engine changes names for qualified dimensions.

This preserves one safe filter contract across the browser and query layer: the browser sends values, the server validates and applies them, and the backend receives executable SQL rather than template markers. The batch, stream, single-widget, and filter-option routes use the same rejection boundary.

References: pkg/…/api.go• L255-335 pkg/…/filter_options.go• L28-39 pkg/…/semantic.go• L15-56 pkg/…/semantic.go• L153-271 pkg/…/semantic_null_test.go• L91-128 pkg/…/filter_security_test.go• L70-204 pkg/…/filter_options_test.go• L193-278 pkg/…/api_test.go• L206-230

Embedded frontend delivery

The Go binary carries the built React application and passes it to the server as a file system. The server serves an asset when its path exists and returns the application entry page for other paths, which lets client-side dashboard and admin routes work from direct browser navigation.

Embedded asset path

The build places frontend assets in frontend/dist. Go embeds that directory, narrows the embedded file system to the distribution root, and passes it through command startup to server.Config.Frontend. When this value is present, the server adds the frontend handler at / beside the API routes.

The frontend uses relative /api/v1 requests in normal local mode. During separate frontend development, Vite proxies /api to the Go service on port 8321, so the browser-facing API contract remains the same while the asset source changes.

Query data that represents an image is still subject to a browser-side boundary. Table images, image widgets, and Vega-Lite image marks render only safe absolute HTTPS URLs on another origin; Vega-Lite receives query rows through the API instead of loading an external dataset. This keeps embedded and development frontend modes under the same data and URL rules.

References: frontend/README.md• L1-22 embed.go• L1-14 main.go• L45-52 cmd/root.go• L11-12 cmd/root.go• L67-69 cmd/serve.go• L53-62 pkg/…/server.go• L168-198 frontend/…/client.ts• L1-5 frontend/vite.config.ts• L8-16 frontend/…/dashboardImage.ts• L1-26 frontend/…/WidgetFrame.tsx• L33-100 frontend/…/VegaLiteChart.tsx• L36-67 frontend/…/VegaLiteChart.tsx• L88-151

Live reload

Live reload connects file edits to fresh browser state. The server watches project directories, invalidates query results, and sends a small event to each connected browser; the frontend responds by refetching definitions and data without changing the current route.

File change events

The watcher monitors the dashboard directory and any project semantic or theme directories. Write, create, and remove events are treated as changes. For each change it clears registered query caches and broadcasts a full_reload event with the changed file name.

The events endpoint is a Server-Sent Events stream. It stays open for each browser subscriber, flushes each event as it arrives, and removes the subscriber when the request ends. If watcher setup fails, the server still serves ordinary API and frontend traffic, but the events endpoint reports that live reload is unavailable.

References: pkg/…/project.go• L15-53 pkg/…/server.go• L217-228 pkg/…/watcher.go• L13-83 pkg/…/watcher.go• L85-113 pkg/…/watcher.go• L115-145

Browser refresh behavior

The frontend does not open an event stream in static mode. In server mode, a full_reload event invalidates cached dashboard state and restarts active dashboard data streams. The old stream is cancelled first, so results from a prior file version do not replace results for the new one. The browser’s EventSource also reconnects after a connection error.

This makes a file save a full dashboard refresh rather than a partial widget update. It is important because one edit can change a definition, a semantic model, a theme, or the SQL produced for several widgets at once.

Event conditionBrowser action
full_reload received by the appInvalidate query state and refresh active dashboard data
Dashboard or filter changes during a streamAbort the old stream and start the new request
Event connection errorLet EventSource reconnect
Static payload is presentDo not open the event stream

References: frontend/…/useLiveReload.ts• L7-32 frontend/…/useDashboardData.ts• L17-39 frontend/…/useDashboardData.ts• L41-102 frontend/…/App.tsx• L12-30 frontend/…/client.ts• L87-159

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep route paths and response shapes aligned between pkg/server and frontend/…/client.ts. A route can remain reachable while a changed field leaves the page without data.
  • Keep the three dashboard data paths consistent: batch, NDJSON stream, and single-widget requests must use the same filter, widget ID, and validation rules.
  • Keep filter-option requests separate from dashboard loading. Static option values must not trigger a backend call, and query-backed options must use the configured query and connection.
  • Keep the filter-option result contract aligned with dependent filters. The request must carry current defaults and selections without changing the loaded dashboard definition.
  • Keep the distinction between query-backed and inline widgets in all data paths. Static widgets must not require a connection or backend execution.
  • When semantic model or query fields change, check generated SQL and output column names for joined dimensions. The browser depends on dashboard-facing names and case-independent result matching.
  • When semantic filter values change, preserve the distinction between database null and the string "null" across YAML, JSON, templates, and generated SQL.
  • When filter rules or template handling change, preserve rejection before backend execution and avoid returning generated SQL for invalid input.
  • When data-bearing widget forms such as images or sparklines change, keep the generic columns-and-rows contract aligned with the browser’s parsing, size limits, and URL checks.
  • When frontend build or embedding paths change, keep frontend/dist, the embedded file-system root, and SPA fallback in agreement.
  • When admin fields or environment selection change, keep the browser form, request payload, configuration save, and query connection lookup aligned.
  • When serve flags or server startup inputs change, keep command values aligned with the service configuration and the local workflow’s expected host, port, template, environment, frontend, and admin behavior.
  • When file watch scope or event names change, update cache invalidation and both frontend reload listeners together.

Important failure modes

TriggerConsequenceGuard
A dashboard fails the initial validationThe service returns an error before it listensValidate the initial dashboard set during server creation
A watched directory cannot be openedThe service still runs, but browser refresh events and cache invalidation do not occurTreat watcher startup as optional and expose the unavailable events path
A dashboard data request contains an invalid or unsafe filter valueThe request fails before widget results or generated SQL are returnedValidate filter values and semantic operator shapes before backend execution
A semantic filter loses the type of a null memberThe query treats database null as text or builds the wrong null predicatePreserve typed values through serialization and let the semantic engine emit null checks
A filter-option request uses an unknown filter or a non-select filterThe browser cannot load options and no option query runsResolve only the named select filter after validating the request state
A filter option query returns a backend error or non-scalar first-column valueThe option request fails instead of returning unusable valuesRequire a successful result with scalar values in its first column
One widget query failsThat widget carries an error while other batch or stream results can completeKeep errors in the per-widget result contract
A static widget is sent to the query backendA widget with inline data can fail even though it needs no connectionResolve inline data as a result before backend execution
A semantic engine output name differs from the dashboard dimension name or result caseA widget cannot find the returned columnRemap qualified and granularity aliases and compare backend column names without case dependence
A query result contains a relative, same-origin, or non-HTTPS image URLThe browser refuses the image instead of allowing query data to call the local server or execute active contentPass image values through the shared dashboard image URL check
A Vega-Lite spec supplies an external data URLThe chart does not render the specLoad chart rows through the API dataset and reject external data URLs
The embedded distribution is missing an asset or entry pageThe browser cannot load the app or a direct client routeBuild the frontend into frontend/dist and retain the SPA fallback
Admin password is absent or wrongAdmin routes are unavailable or protected requests are rejectedRegister admin routes only with an explicit password and require the bearer value

Key files

FileWhy to read it
cmd/serve.goDefines local serve flags and maps command context into server startup.
pkg/…/server.goDefines startup checks, route groups, CORS, frontend serving, and watcher setup.
pkg/…/api.goDefines dashboard discovery, filter resolution, query jobs, widget results, themes, and config behavior.
pkg/…/filter_options.goDefines the focused API for resolving one select filter’s options.
pkg/…/api_test.goShows the API contract for regular SQL, semantic, inline, tabbed, and data-bearing widget flows.
pkg/…/filter_options_test.goShows option loading, dependent filters, static allowlists, scalar values, and validation behavior.
pkg/…/filter_security_test.goShows the filter contract that blocks unsafe or invalid values before backend execution.
pkg/…/admin.goDefines password checks and configuration changes for connection administration.
pkg/…/semantic.goExplains how semantic jobs become executable query work, safe filter values, joins, and result names.
pkg/…/semantic_join_test.goShows the contract for cross-model joins, single-model queries, and joined granularity names.
pkg/…/semantic_null_test.goShows how semantic filters preserve database nulls and distinguish them from the string null.
pkg/…/watcher.goDefines the file-change event source and the live-reload stream.
embed.goShows how the built frontend becomes a file system available to the Go binary.
frontend/…/client.tsDefines the browser contract for normal, streamed, static, option, and admin requests.
frontend/…/dashboard.tsDefines the shared dashboard and widget data shapes used by the API consumer.
frontend/…/dashboardImage.tsDefines the URL boundary for image values returned by dashboard queries.
frontend/…/VegaLiteChart.tsxShows how query rows enter Vega-Lite and how external data and image URLs are constrained.
frontend/…/useLiveReload.tsShows how the app invalidates cached state after a file event.
frontend/…/useDashboardData.tsShows how active streamed widget data restarts after a file event.
frontend/…/App.tsxShows the distinction between server-backed, embedded, and static frontend modes.