# alejandro-publius/blackbox-datahub architecture

> Architecture diagram of the GitHub repository alejandro-publius/blackbox-datahub, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alejandro-publius/blackbox-datahub
- Repository: https://github.com/alejandro-publius/blackbox-datahub

## Overview

BlackBox is an autonomous data-incident response product: an operator reports an anomaly, the agent investigates it using DataHub metadata and deterministic warehouse evidence, then pauses for repair authorization. It proposes a pipeline change, rebuilds and verifies it against invariants and baseline metrics, optionally publishes a pull request, and records the resolution in DataHub. The dashboard presents incident progress and results. Source excerpts show the evidence-gated agent/tool design and repair verification; some API, UI, and DataHub writeback connections are documented in the README rather than sampled source.

Main entry points: [`backend/blackbox/agent/tools.py`](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/agent/tools.py) (Evidence-gated tools), [`backend/blackbox/agent/investigator.py`](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/agent/investigator.py) (Investigation loop), [`backend/blackbox/repair.py`](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/repair.py) (Repair and verification), [`backend/blackbox/api.py`](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/api.py) (Backend API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Operator interface"]
  node_dashboard["Incident dashboard<br/>[Dashboard.tsx]"]
  node_stream["Incident stream"]
end

subgraph group_orchestration["Incident orchestration"]
  node_api["Backend API<br/>[api.py]"]
  node_investigator["Investigation loop<br/>[investigator.py]"]
  node_tools["Evidence-gated tools<br/>[tools.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_context["DataHub context"]
  node_datahub_client["Metadata client<br/>[client.py]"]
  node_context_kit["Embedded context kit<br/>[context_kit.py]"]
  node_mcp_bridge["MCP bridge<br/>[mcp_bridge.py]"]
  node_ingest["Metadata ingest<br/>[ingest.py]"]
  node_writeback["Resolution writeback<br/>[writeback.py]"]
  node_reset["DataHub reset<br/>[reset.py]"]
end

subgraph group_verification["Repair and verification"]
  node_warehouse[("Warehouse evidence<br/>[warehouse.py]")]
  node_repair["Repair and verification<br/>[repair.py]"]
  node_pipeline["Pipeline rebuild<br/>[run.py]"]
  node_source_generator["Demo source data"]
end

subgraph group_state["Evidence and state"]
  node_models["Incident stages<br/>[models.py]"]
  node_store[("Incident store<br/>[store.py]")]
  node_tracing["Run tracing<br/>[tracing.py]"]
end

node_operator(("Operator"))
node_claude(("Claude model"))
node_datahub[("DataHub")]
node_github["GitHub pull request"]

node_operator -.->|"reports anomaly"| node_dashboard
node_dashboard -.->|"submits incident"| node_api
node_api -.->|"starts investigation"| node_investigator
node_investigator -->|"requests strategy"| node_claude
node_investigator -->|"dispatches tools"| node_tools
node_tools -->|"reads metadata"| node_datahub_client
node_tools -.->|"gathers metrics"| node_warehouse
node_datahub_client -->|"uses embedded reads"| node_context_kit
node_datahub_client -->|"uses MCP fallback"| node_mcp_bridge
node_context_kit -.->|"queries context"| node_datahub
node_mcp_bridge -.->|"queries context"| node_datahub
node_ingest -.->|"emits metadata"| node_datahub
node_tools -->|"saves incident"| node_store
node_investigator -->|"loads and saves"| node_store
node_tools -->|"advances stages"| node_models
node_investigator -->|"records spans"| node_tracing
node_investigator -->|"captures baseline"| node_warehouse
node_api -.->|"authorizes repair"| node_repair
node_tools -->|"runs repair"| node_repair
node_repair -.->|"rebuilds warehouse"| node_pipeline
node_repair -->|"verifies invariants"| node_warehouse
node_repair -.->|"publishes PR"| node_github
node_tools -->|"records resolution"| node_writeback
node_writeback -.->|"writes resolution"| node_datahub
node_reset -.->|"scrubs state"| node_datahub
node_source_generator -.->|"generates inputs"| node_pipeline
node_stream -.->|"receives updates"| node_api
node_dashboard -.->|"renders progress"| node_stream

click node_dashboard "https://github.com/alejandro-publius/blackbox-datahub/blob/main/frontend/src/components/Dashboard.tsx"
click node_stream "https://github.com/alejandro-publius/blackbox-datahub/blob/main/frontend/src/hooks/useIncidentStream.ts"
click node_api "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/api.py"
click node_investigator "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/agent/investigator.py"
click node_tools "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/agent/tools.py"
click node_models "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/models.py"
click node_store "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/store.py"
click node_tracing "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/tracing.py"
click node_config "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/config.py"
click node_datahub_client "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/client.py"
click node_context_kit "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/context_kit.py"
click node_mcp_bridge "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/mcp_bridge.py"
click node_ingest "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/ingest.py"
click node_warehouse "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/warehouse.py"
click node_repair "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/repair.py"
click node_pipeline "https://github.com/alejandro-publius/blackbox-datahub/blob/main/pipeline/run.py"
click node_writeback "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/writeback.py"
click node_reset "https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/reset.py"
click node_source_generator "https://github.com/alejandro-publius/blackbox-datahub/blob/main/pipeline/generate_sources.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_dashboard,node_stream toneBlue
class node_api,node_investigator,node_tools,node_config,node_datahub toneAmber
class node_datahub_client,node_context_kit,node_mcp_bridge,node_ingest,node_writeback,node_reset,node_github toneMint
class node_warehouse,node_repair,node_pipeline,node_source_generator toneRose
class node_models,node_store,node_tracing,node_operator,node_claude toneIndigo
```

## Components

### Operator interface

- [Incident dashboard](https://github.com/alejandro-publius/blackbox-datahub/blob/main/frontend/src/components/Dashboard.tsx): `frontend/src/components/Dashboard.tsx`
- [Incident stream](https://github.com/alejandro-publius/blackbox-datahub/blob/main/frontend/src/hooks/useIncidentStream.ts): `frontend/src/hooks/useIncidentStream.ts`

### Incident orchestration

- [Backend API](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/api.py): `backend/blackbox/api.py`
- [Investigation loop](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/agent/investigator.py): `backend/blackbox/agent/investigator.py`
- [Evidence-gated tools](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/agent/tools.py): `backend/blackbox/agent/tools.py`
- [Runtime configuration](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/config.py): `backend/blackbox/config.py`

### DataHub context

- [Metadata client](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/client.py): `backend/blackbox/datahub/client.py`
- [Embedded context kit](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/context_kit.py): `backend/blackbox/datahub/context_kit.py`
- [MCP bridge](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/mcp_bridge.py): `backend/blackbox/datahub/mcp_bridge.py`
- [Metadata ingest](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/ingest.py): `backend/blackbox/datahub/ingest.py`
- [Resolution writeback](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/writeback.py): `backend/blackbox/datahub/writeback.py`
- [DataHub reset](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/datahub/reset.py): `backend/blackbox/datahub/reset.py`

### Repair and verification

- [Warehouse evidence](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/warehouse.py): `backend/blackbox/warehouse.py`
- [Repair and verification](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/repair.py): `backend/blackbox/repair.py`
- [Pipeline rebuild](https://github.com/alejandro-publius/blackbox-datahub/blob/main/pipeline/run.py): `pipeline/run.py`
- [Demo source data](https://github.com/alejandro-publius/blackbox-datahub/blob/main/pipeline/generate_sources.py): `pipeline/generate_sources.py`

### Evidence and state

- [Incident stages](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/models.py): `backend/blackbox/models.py`
- [Incident store](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/store.py): `backend/blackbox/store.py`
- [Run tracing](https://github.com/alejandro-publius/blackbox-datahub/blob/main/backend/blackbox/tracing.py): `backend/blackbox/tracing.py`

### Other components

- **Operator**
- **Claude model**
- **DataHub**
- **GitHub pull request**

## Connections

- Operator → Incident dashboard: reports anomaly (evidence: `README.md`)
- Incident dashboard → Backend API: submits incident (evidence: `README.md`)
- Backend API → Investigation loop: starts investigation (evidence: `README.md`)
- Investigation loop → Claude model: requests strategy (evidence: `backend/blackbox/agent/investigator.py`)
- Investigation loop → Evidence-gated tools: dispatches tools (evidence: `backend/blackbox/agent/investigator.py`)
- Evidence-gated tools → Metadata client: reads metadata (evidence: `backend/blackbox/agent/tools.py`)
- Evidence-gated tools → Warehouse evidence: gathers metrics (evidence: `README.md`)
- Metadata client → Embedded context kit: uses embedded reads (evidence: `backend/blackbox/datahub/client.py`)
- Metadata client → MCP bridge: uses MCP fallback (evidence: `backend/blackbox/datahub/client.py`)
- Embedded context kit → DataHub: queries context (evidence: `README.md`)
- MCP bridge → DataHub: queries context (evidence: `README.md`)
- Metadata ingest → DataHub: emits metadata (evidence: `README.md`)
- Evidence-gated tools → Incident store: saves incident (evidence: `backend/blackbox/agent/tools.py`)
- Investigation loop → Incident store: loads and saves (evidence: `backend/blackbox/agent/investigator.py`)
- Evidence-gated tools → Incident stages: advances stages (evidence: `backend/blackbox/agent/tools.py`)
- Investigation loop → Run tracing: records spans (evidence: `backend/blackbox/agent/investigator.py`)
- Investigation loop → Warehouse evidence: captures baseline (evidence: `backend/blackbox/agent/investigator.py`)
- Backend API → Repair and verification: authorizes repair (evidence: `README.md`)
- Evidence-gated tools → Repair and verification: runs repair (evidence: `backend/blackbox/agent/tools.py`)
- Repair and verification → Pipeline rebuild: rebuilds warehouse (evidence: `README.md`)
- Repair and verification → Warehouse evidence: verifies invariants (evidence: `backend/blackbox/repair.py`)
- Repair and verification → GitHub pull request: publishes PR (evidence: `README.md`)
- Evidence-gated tools → Resolution writeback: records resolution (evidence: `backend/blackbox/agent/tools.py`)
- Resolution writeback → DataHub: writes resolution (evidence: `README.md`)
- DataHub reset → DataHub: scrubs state (evidence: `README.md`)
- Demo source data → Pipeline rebuild: generates inputs (evidence: `README.md`)
- Incident stream → Backend API: receives updates (evidence: `README.md`)
- Incident dashboard → Incident stream: renders progress (evidence: `README.md`)
