# rohit-db/bi-hub-app architecture

> Architecture diagram of the GitHub repository rohit-db/bi-hub-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rohit-db/bi-hub-app
- Repository: https://github.com/rohit-db/bi-hub-app

## Overview

BI Hub is a Chainlit business-intelligence chat app with two selectable answer paths: an in-app reasoning agent using Genie MCP, or a Multi-Agent Supervisor endpoint. A message is authenticated, combined with bounded chat history, routed to the selected agent, normalized into streaming events, and rendered to the user; table output can be formatted from pipe tables. Lakebase backs durable chat history, with app-owned Chainlit tables. The README also documents Unity Catalog governance and MAS trace logging; their runtime wiring is not shown in the sampled sources, so those links are marked unverified.

Main entry points: [`src/app/routes.py`](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/routes.py) (Message router), [`src/app/auth/identity.py`](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/auth/identity.py) (Identity and tokens), [`src/app/app.py`](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/app.py) (Chainlit app), [`src/app/agent/reasoning_agent.py`](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/agent/reasoning_agent.py) (Reasoning agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chat["Chat and presentation"]
  node_chainlit["Chainlit app<br/>[app.py]"]
  node_router["Message router<br/>[routes.py]"]
  node_history["History builder<br/>[routes.py]"]
  node_normalizer["Event normalizer<br/>[mas_normalizer.py]"]
  node_stream_renderer["Stream renderer<br/>[renderer.py]"]
  node_table_parser["Table parser<br/>[table_parser.py]"]
end

subgraph group_agents["Agent execution"]
  node_reasoner["Reasoning agent<br/>[reasoning_agent.py]"]
  node_genie_client["Genie MCP client<br/>[genie_mcp.py]"]
  node_mas_client["MAS client<br/>[mas_client.py]"]
end

subgraph group_identity["Identity and access"]
  node_identity_check["Identity validation<br/>[ensure_identity.py]"]
  node_header_auth["Header authentication<br/>[header.py]"]
  node_identity["Identity and tokens<br/>[identity.py]"]
  node_settings["App configuration<br/>[config.py]"]
end

subgraph group_persistence["Persistence"]
  node_data_layer["Chainlit data layer<br/>[layer.py]"]
  node_lakebase[("Lakebase PostgreSQL")]
  node_db_credentials["Lakebase credentials<br/>[credentials.py]"]
  node_schema["Durable schema<br/>[schema.py]"]
  node_schema_setup["Schema setup"]
end

node_user(("BI user"))
node_genie_mcp{{"Managed Genie MCP"}}
node_mas_endpoint{{"MAS endpoint"}}
node_unity_catalog{{"Unity Catalog governance"}}
node_trace_logging["MAS trace logging"]

node_user -->|"sends chat"| node_chainlit
node_chainlit -->|"registers handlers"| node_router
node_router -->|"validates identity"| node_identity_check
node_header_auth -->|"creates identity"| node_identity
node_identity_check -->|"constructs tokens"| node_identity
node_identity_check -->|"reads auth settings"| node_settings
node_router -->|"builds context"| node_history
node_router -->|"routes Genie One"| node_reasoner
node_router -->|"routes supervisor"| node_mas_client
node_reasoner -->|"opens tool server"| node_genie_client
node_genie_client -->|"queries space"| node_genie_mcp
node_reasoner -->|"reads bearer token"| node_identity
node_mas_client -->|"reads bearer token"| node_identity
node_mas_client -->|"streams invocations"| node_mas_endpoint
node_router -->|"normalizes events"| node_normalizer
node_router -->|"renders stream"| node_stream_renderer
node_stream_renderer -->|"parses tables"| node_table_parser
node_chainlit -->|"configures persistence"| node_data_layer
node_data_layer -->|"persists chat"| node_lakebase
node_data_layer -->|"injects credentials"| node_db_credentials
node_schema -->|"creates tables"| node_lakebase
node_schema -->|"connects with credentials"| node_db_credentials
node_schema_setup -->|"grants schema access"| node_lakebase
node_genie_mcp -.->|"governed data access"| node_unity_catalog
node_mas_endpoint -.->|"governed data access"| node_unity_catalog
node_mas_endpoint -.->|"logs traces"| node_trace_logging

click node_chainlit "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/app.py"
click node_router "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/routes.py"
click node_history "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/routes.py"
click node_normalizer "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/services/mas_normalizer.py"
click node_stream_renderer "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/services/renderer.py"
click node_table_parser "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/services/table_parser.py"
click node_reasoner "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/agent/reasoning_agent.py"
click node_genie_client "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/agent/genie_mcp.py"
click node_mas_client "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/services/mas_client.py"
click node_identity_check "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/auth/ensure_identity.py"
click node_header_auth "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/auth/header.py"
click node_identity "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/auth/identity.py"
click node_settings "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/config.py"
click node_data_layer "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/memory/layer.py"
click node_db_credentials "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/memory/credentials.py"
click node_schema "https://github.com/rohit-db/bi-hub-app/blob/main/src/app/memory/schema.py"
click node_schema_setup "https://github.com/rohit-db/bi-hub-app/blob/main/src/scripts/setup_chainlit_schema.py"

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_chainlit,node_router,node_history,node_normalizer,node_stream_renderer,node_table_parser,node_user toneBlue
class node_reasoner,node_genie_client,node_mas_client toneAmber
class node_identity_check,node_header_auth,node_identity,node_settings toneMint
class node_data_layer,node_lakebase,node_db_credentials,node_schema,node_schema_setup toneRose
class node_genie_mcp,node_mas_endpoint,node_unity_catalog,node_trace_logging toneIndigo
```

## Components

### Chat and presentation

- [Chainlit app](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/app.py): `src/app/app.py`
- [Message router](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/routes.py): `src/app/routes.py`
- [History builder](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/routes.py): `src/app/routes.py`
- [Event normalizer](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/services/mas_normalizer.py): `src/app/services/mas_normalizer.py`
- [Stream renderer](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/services/renderer.py): `src/app/services/renderer.py`
- [Table parser](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/services/table_parser.py): `src/app/services/table_parser.py`

### Agent execution

- [Reasoning agent](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/agent/reasoning_agent.py): `src/app/agent/reasoning_agent.py`
- [Genie MCP client](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/agent/genie_mcp.py): `src/app/agent/genie_mcp.py`
- [MAS client](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/services/mas_client.py): `src/app/services/mas_client.py`

### Identity and access

- [Identity validation](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/auth/ensure_identity.py): `src/app/auth/ensure_identity.py`
- [Header authentication](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/auth/header.py): `src/app/auth/header.py`
- [Identity and tokens](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/auth/identity.py): `src/app/auth/identity.py`
- [App configuration](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/config.py): `src/app/config.py`

### Persistence

- [Chainlit data layer](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/memory/layer.py): `src/app/memory/layer.py`
- **Lakebase PostgreSQL**
- [Lakebase credentials](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/memory/credentials.py): `src/app/memory/credentials.py`
- [Durable schema](https://github.com/rohit-db/bi-hub-app/blob/main/src/app/memory/schema.py): `src/app/memory/schema.py`
- [Schema setup](https://github.com/rohit-db/bi-hub-app/blob/main/src/scripts/setup_chainlit_schema.py): `src/scripts/setup_chainlit_schema.py`

### Other components

- **BI user**
- **Managed Genie MCP**
- **MAS endpoint**
- **Unity Catalog governance**
- **MAS trace logging**

## Connections

- BI user → Chainlit app: sends chat (evidence: `README.md`)
- Chainlit app → Message router: registers handlers (evidence: `src/app/app.py`)
- Message router → Identity validation: validates identity (evidence: `src/app/routes.py`)
- Header authentication → Identity and tokens: creates identity (evidence: `src/app/auth/header.py`)
- Identity validation → Identity and tokens: constructs tokens (evidence: `src/app/auth/ensure_identity.py`)
- Identity validation → App configuration: reads auth settings (evidence: `src/app/auth/ensure_identity.py`)
- Message router → History builder: builds context (evidence: `src/app/routes.py`)
- Message router → Reasoning agent: routes Genie One (evidence: `src/app/routes.py`)
- Message router → MAS client: routes supervisor (evidence: `src/app/routes.py`)
- Reasoning agent → Genie MCP client: opens tool server (evidence: `src/app/agent/reasoning_agent.py`)
- Genie MCP client → Managed Genie MCP: queries space (evidence: `README.md`)
- Reasoning agent → Identity and tokens: reads bearer token (evidence: `src/app/agent/reasoning_agent.py`)
- MAS client → Identity and tokens: reads bearer token (evidence: `src/app/services/mas_client.py`)
- MAS client → MAS endpoint: streams invocations (evidence: `src/app/services/mas_client.py`)
- Message router → Event normalizer: normalizes events (evidence: `src/app/routes.py`)
- Message router → Stream renderer: renders stream (evidence: `src/app/routes.py`)
- Stream renderer → Table parser: parses tables (evidence: `src/app/services/renderer.py`)
- Chainlit app → Chainlit data layer: configures persistence (evidence: `src/app/app.py`)
- Chainlit data layer → Lakebase PostgreSQL: persists chat (evidence: `README.md`)
- Chainlit data layer → Lakebase credentials: injects credentials
- Durable schema → Lakebase PostgreSQL: creates tables (evidence: `README.md`)
- Durable schema → Lakebase credentials: connects with credentials (evidence: `src/app/memory/schema.py`)
- Schema setup → Lakebase PostgreSQL: grants schema access (evidence: `README.md`)
- Managed Genie MCP → Unity Catalog governance: governed data access (evidence: `README.md`)
- MAS endpoint → Unity Catalog governance: governed data access (evidence: `README.md`)
- MAS endpoint → MAS trace logging: logs traces (evidence: `README.md`)
