# portolucas1/dbx-apps-genie-api architecture

> Architecture diagram of the GitHub repository portolucas1/dbx-apps-genie-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/portolucas1/dbx-apps-genie-api
- Repository: https://github.com/portolucas1/dbx-apps-genie-api

## Overview

1. **Overall shape**
   This repository is a single-process Databricks App that serves a Dash-based web UI and proxies user chat interactions to Databricks Genie Conversation APIs. The app is not a full backend/frontend split; most application logic lives in Python, with static styling in `assets/`.

2. **Runtime boundary**
   `app.py` is the entrypoint configured by `app.yaml`. In Databricks Apps, this runs inside the app container/runtime and uses environment-provided resource IDs rather than hardcoded infrastructure. The two key external dependencies are:
   - a Genie Space identified by `SPACE_ID`
   - a SQL Warehouse identified by `SQL_WAREHOUSE_ID`

3. **User interface layer**
   The UI is a Dash application with a chat-centric layout: conversation history, sidebar navigation, welcome/suggestion content, SQL display toggles, and feedback controls. `assets/style.css` provides the visual presentation, so styling is separated from the Python app logic but still part of the same deployment unit.

4. **Application orchestration**
   `app.py` is likely the central composition point. It wires together the UI, Dash callbacks, conversation state, and calls into the Genie API wrapper. From an architecture diagram perspective, it is the controller/orchestrator between browser events and Genie API operations.

5. **Genie conversation subsystem**
   `genie_room.py` appears to encapsulate Genie-specific conversation management: creating or resuming a conversation thread, sending user prompts, receiving Genie responses, and exposing data needed by the UI such as generated SQL, answer text, and conversation metadata. This is the main domain integration layer.

6. **Auth/token subsystem**
   `token_minter.py` is the authentication boundary to Databricks services. Its role is to mint or retrieve the token used by the app to call Databricks APIs from inside Databricks Apps. This is a critical boundary because it separates app session logic from workspace/service-auth concerns.

7. **Primary data flow**
   The core flow is:
   browser user input → Dash callback in `app.py` → Genie wrapper in `genie_room.py` → authenticated Databricks API call via `token_minter.py` → Genie Space / SQL Warehouse → response back to `app.py` → rendered in the browser.
   The app therefore acts as a thin conversational client over Databricks-managed services.

8. **State and conversation history**
   Conversation state is maintained on the application side and reflected in the UI as a selectable history/sidebar experience. The state boundary is important: the browser sees conversation threads and answers, while the actual authoritative conversation context is managed through Genie conversation APIs.

9. **SQL and data-access boundary**
   The app does not query datasets directly in Python. Instead, Genie generates SQL and executes it through the configured warehouse, so data access happens inside Databricks governed by workspace permissions. This means the app’s data boundary is the Genie/warehouse pair, not a local database or custom API.

10. **Security and permissions**
   The README makes clear that deployment depends on Databricks identity and resource permissions:
   - the app service principal needs `can_run` on the Genie space
   - it needs `can_use` on the SQL warehouse
   - it needs downstream privileges on catalogs/schemas/tables
   So the architecture is permission-driven and intentionally avoids separate secret management for most resource access.

11. **Deployment configuration**
   `app.yaml` defines how the container starts and injects required environment variables. This file is the deployment contract for the Databricks App and is the place where operational wiring is defined rather than in code.

12. **Infrastructure posture**
   This is a low-infra demo: Databricks handles hosting, scaling, and workspace integration. There is no separate backend service, queue, database, or object store in the repository. The main external systems are Databricks Apps, Genie, and the SQL Warehouse.

13. **What to show in an architecture diagram**
   A useful diagram would include:
   - Browser / Dash UI
   - `app.py` as the app controller
   - `genie_room.py` as the Genie conversation adapter
   - `token_minter.py` as the auth/token provider
   - Databricks Genie Space
   - Databricks SQL Warehouse
   - Workspace data assets governed by permissions
   - `assets/style.css` as static frontend styling
   - `app.yaml` as the deployment/config boundary

14. **Repository scope**
   This repo is intentionally focused on one integration path: a conversational analytics UI over Databricks-managed structured data. It is not a general-purpose platform, and its architecture is centered on one request/response loop and one external conversational data service.

Main entry points: [`app.py`](https://github.com/portolucas1/dbx-apps-genie-api/blob/main/app.py) (app.py), [`genie_room.py`](https://github.com/portolucas1/dbx-apps-genie-api/blob/main/genie_room.py) (genie_room.py), [`token_minter.py`](https://github.com/portolucas1/dbx-apps-genie-api/blob/main/token_minter.py) (token_minter.py), [`app.yaml`](https://github.com/portolucas1/dbx-apps-genie-api/blob/main/app.yaml) (app.yaml)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client & UI"]
  node_browser(("Browser<br/>user client"))
  node_style_css["style.css<br/>static styles<br/>[style.css]"]
end

subgraph group_app["App Runtime"]
  node_app_py["app.py<br/>Dash app<br/>[app.py]"]
  node_genie_room["genie_room.py<br/>Genie adapter<br/>[genie_room.py]"]
  node_token_minter["token_minter.py<br/>auth helper<br/>[token_minter.py]"]
  node_app_yaml["app.yaml<br/>deploy config<br/>[app.yaml]"]
end

subgraph group_databricks["Databricks Services"]
  node_dash_runtime[("Databricks App<br/>runtime")]
  node_genie_space{{"Genie Space<br/>conversation service"}}
  node_sql_warehouse[("SQL Warehouse<br/>query engine")]
end

subgraph group_data["Governed Data"]
  node_workspace_data[("Workspace Data<br/>governed assets")]
end

node_browser -->|"chat input / view"| node_app_py
node_app_py -->|"responses"| node_browser
node_app_py -->|"loads styles"| node_style_css
node_app_yaml -->|"starts app"| node_dash_runtime
node_dash_runtime -->|"runs"| node_app_py
node_app_py -->|"orchestrates"| node_genie_room
node_genie_room -->|"gets token"| node_token_minter
node_token_minter -->|"workspace auth"| node_dash_runtime
node_genie_room -->|"sends prompt"| node_genie_space
node_genie_space -->|"executes SQL"| node_sql_warehouse
node_sql_warehouse -->|"queries"| node_workspace_data
node_genie_room -->|"results"| node_app_py
node_app_py -.->|"configured by"| node_app_yaml

click node_app_py "https://github.com/portolucas1/dbx-apps-genie-api/blob/main/app.py"
click node_genie_room "https://github.com/portolucas1/dbx-apps-genie-api/blob/main/genie_room.py"
click node_token_minter "https://github.com/portolucas1/dbx-apps-genie-api/blob/main/token_minter.py"
click node_app_yaml "https://github.com/portolucas1/dbx-apps-genie-api/blob/main/app.yaml"
click node_style_css "https://github.com/portolucas1/dbx-apps-genie-api/blob/main/assets/style.css"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser,node_style_css toneBlue
class node_app_py,node_genie_room,node_token_minter,node_app_yaml toneAmber
class node_dash_runtime,node_genie_space,node_sql_warehouse toneMint
class node_workspace_data toneRose
```

## Components

### Client & UI

Browser-facing chat experience and styling.

- **Browser**: user client · User interacts with the chat UI in the browser.
- [style.css](https://github.com/portolucas1/dbx-apps-genie-api/blob/main/assets/style.css): static styles · Dash asset that provides the app’s visual styling. · `assets/style.css`

### App Runtime

Databricks App entrypoint and Python orchestration.

- [app.py](https://github.com/portolucas1/dbx-apps-genie-api/blob/main/app.py): Dash app · Main entrypoint and callback/controller for the chat experience. · `app.py`
- [genie_room.py](https://github.com/portolucas1/dbx-apps-genie-api/blob/main/genie_room.py): Genie adapter · Conversation management and Genie API integration layer. · `genie_room.py`
- [token_minter.py](https://github.com/portolucas1/dbx-apps-genie-api/blob/main/token_minter.py): auth helper · Mints or retrieves Databricks access tokens for service calls. · `token_minter.py`
- [app.yaml](https://github.com/portolucas1/dbx-apps-genie-api/blob/main/app.yaml): deploy config · Deployment contract and startup configuration for the Databricks App. · `app.yaml`

### Databricks Services

Managed services the app calls at runtime.

- **Databricks App**: runtime · Managed container/runtime where the app process runs.
- **Genie Space**: conversation service · Databricks Genie space that receives prompts and returns answers.
- **SQL Warehouse**: query engine · Warehouse used to execute SQL generated through Genie.

### Governed Data

Workspace data accessed through Genie and SQL permissions.

- **Workspace Data**: governed assets · Catalogs, schemas, and tables accessed under Databricks permissions.

## Connections

- Browser → app.py: chat input / view · Browser events and rendered UI flow into the Dash controller.
- app.py → Browser: responses · The app renders conversation history, suggestions, SQL, and feedback controls.
- app.py → style.css: loads styles · Dash serves static styling from the assets directory.
- app.yaml → Databricks App: starts app · Deployment config defines how the app process is launched.
- Databricks App → app.py: runs · The Databricks App runtime executes the Python entrypoint.
- app.py → genie_room.py: orchestrates · The controller delegates conversational work to the Genie adapter.
- genie_room.py → token_minter.py: gets token · The adapter obtains authentication for Databricks API calls.
- token_minter.py → Databricks App: workspace auth · Authentication is tied to the Databricks App/runtime identity.
- genie_room.py → Genie Space: sends prompt · User prompts are forwarded to the Genie conversation API.
- Genie Space → SQL Warehouse: executes SQL · Genie uses the configured warehouse for SQL-backed answers.
- SQL Warehouse → Workspace Data: queries · Warehouse reads governed catalog, schema, and table data.
- genie_room.py → app.py: results · Conversation metadata, answer text, and SQL return to the UI layer.
- app.py → app.yaml: configured by · The entrypoint and environment wiring are defined by deployment config.
