Project guide

Project Guide | Nexus Hive

Free governed analytics readiness worksheet for NL-to-SQL and warehouse adapter reviews. This guide organizes the repository's original implementation notes for data platform leads and analytics engineers.

Reviewed 2026-07-28. This page is derived from checked-in repository evidence and links back to its source.

## <h1 align="center">Nexus-Hive</h1>

<p align="center"> <strong>Multi-agent NL-to-SQL copilot with governed analytics, audit trails, and multi-warehouse support</strong> </p>

<p align="center"> <a href="https://github.com/KIM3310/Nexus-Hive/actions/workflows/ci.yml"><img src="https://github.com/KIM3310/Nexus-Hive/actions/workflows/ci.yml/badge.svg" alt="CI"></a> <a href="https://codecov.io/gh/KIM3310/Nexus-Hive"><img src="https://codecov.io/gh/KIM3310/Nexus-Hive/branch/main/graph/badge.svg" alt="codecov"></a> <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.11%2B-blue.svg" alt="Python 3.11+"></a> <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-green.svg" alt="License: MIT"></a> <a href="https://fastapi.tiangolo.com"><img src="https://img.shields.io/badge/FastAPI-0.115+-009688.svg" alt="FastAPI"></a> </p>

---

Nexus-Hive turns natural-language business questions into audited SQL, executes them safely against a warehouse, and returns chart-ready answers with a full agent trace. Every step -- translation, policy check, execution, visualization -- is independently inspectable, testable, and governed.

Why this matters: Most NL-to-SQL tools generate SQL and run it. Nexus-Hive inserts a policy engine, audit trail, and retry loop between generation and execution -- making it safe for environments where data access requires governance.

---

System Overview

LensCurrent answer
UsersData platform, analytics, BI, and internal operations teams that need governed self-service questions.
Technical pathValidate the demo, README, architecture notes, and quality gate before deeper workflow review.
System scopeNL-to-SQL state graph, policy engine, audit trail, approval bundles, warehouse adapters, and chart output.
Operating boundarySQLite demo is active by default; Snowflake and Databricks live modes are environment-gated.
Evaluation pathmake verify, seeded local SQLite demo, governance endpoints, and adapter abstraction docs.

Evaluation Path

---

Architecture Notes

Architecture

flowchart TB
    User["Business User / Analyst"]
    User -->|"Natural language question"| API["FastAPI Runtime\n/api/ask"]

    subgraph AgentPipeline["LangGraph Multi-Agent Pipeline"]
        direction TB
        T["Agent 1: Translator\nNL --> SQL via Ollama/LLM\n+ heuristic fallback"]
        E["Agent 2: Executor\nPolicy engine + read-only SQL execution"]
        V["Agent 3: Visualizer\nChart.js config generation"]
        T --> E
        E -->|"error + retry budget > 0"| T
        E -->|"success"| V
    end

    API --> AgentPipeline

    subgraph Governance["Governance Layer"]
        direction LR
        PE["Policy Engine\nDeny / Review / Allow"]
        AT["Audit Trail\nJSONL + query tags"]
        GE["Gold Eval Suite\nSQL quality scoring"]
    end

    E --- PE
    E --- AT

    subgraph Warehouses["Warehouse Adapters"]
        direction LR
        SQLite["SQLite\n(demo, active by default)"]
        SF["Snowflake\n(live when configured)"]
        DB["Databricks\n(live when configured)"]
    end

    E --> Warehouses
    V --> UI["Frontend\nChart.js + agent trace viewer"]

The pipeline is built with LangGraph as a compiled state graph. Each agent is a node with typed state (AgentState), connected by edges with conditional routing. When the Executor rejects SQL (policy denial or execution error), the graph routes back to the Translator for correction -- up to 3 retries -- without re-running the Visualizer.

---

Local (3 commands)

git clone https://github.com/KIM3310/Nexus-Hive.git && cd Nexus-Hive
make install                 # creates venv, installs deps
make seed                    # seeds 10k enterprise sales records into SQLite
make run                     # starts uvicorn on http://localhost:8000


## If your default python3 is older than 3.11:
make BOOTSTRAP_PYTHON=/path/to/python3.11 install

Open http://localhost:8000 for the frontend, or http://localhost:8000/docs for Swagger UI.

Docker

docker compose up app

## With live LLM inference via Ollama:
docker compose --profile with-ollama up
docker exec nexus-hive-ollama ollama pull phi3

Verify Everything Works

make verify   # runs lint + pytest + smoke test against a live server

---

Tech Stack

LayerTechnologyRole
API FrameworkFastAPI 0.115+Async HTTP, OpenAPI docs, middleware
Agent OrchestrationLangGraph + LangChain CoreState graph, conditional edges, typed agent state
LLM RuntimeOllama (phi3 default)Local inference for SQL generation + chart config
Policy EngineCustom PythonDeny/review/allow decisions, sensitive column gating
Warehouse (Demo)SQLite + PandasZero-config local execution with 10k seeded records
Warehouse (Prod)Snowflake, DatabricksLive adapters via snowflake-connector-python / databricks-sdk
VisualizationChart.jsBar, line, pie, doughnut charts from query results
SecurityHMAC-signed cookies, RBACOperator sessions, token auth, role-based column gating
ResilienceCircuit BreakerOllama failure isolation with auto-recovery
InfrastructureDocker, Kubernetes, TerraformContainer, K8s manifests, GCP Cloud Run via Terraform
CI/CDGitHub ActionsLint (ruff), test (pytest + coverage), Docker build

---

Governance Features

FeatureDescriptionEndpoint
Policy EngineDeny write ops, block SELECT *, gate sensitive columns by role, flag non-aggregated queries for reviewPOST /api/policy/check
Audit TrailsEvery query logged with request ID, role, policy verdict, adapter, execution timeGET /api/query-audit/recent
Query TagsStructured tags mapping onto Snowflake QUERY_TAG and Databricks warehouse tag conventionsGET /api/schema/query-tag
Session BoardsOperator surfaces for pending approvals, approval histories, query throughputGET /api/query-session-board
Gold EvalsBuilt-in evaluation suite scoring generated SQL against expected feature patternsGET /api/evals/nl2sql-gold/run
Approval WorkflowsReview-required queries produce actionable approval bundlesGET /api/query-approval-board

---

Core API


## Ask a question (returns stream URL for agent trace)
curl -X POST http://localhost:8000/api/ask \
  -H "Content-Type: application/json" \
  -d '{"question": "Show total net revenue by region"}'


## Stream agent trace (SSE)
curl -N "http://localhost:8000/api/stream?q=Show+total+net+revenue+by+region&rid=REQUEST_ID"


## Policy check -- preview SQL before execution
curl -X POST http://localhost:8000/api/policy/check \
  -H "Content-Type: application/json" \
  -d '{"sql": "SELECT region_name, SUM(net_revenue) FROM sales GROUP BY region_name", "role": "analyst"}'


## Runtime metadata
curl http://localhost:8000/api/meta


## Run gold eval suite
curl http://localhost:8000/api/evals/nl2sql-gold/run

---

Test Results and Benchmarks

From pytest 8.3.5 on Python 3.11 -- make verify (lint + test + smoke)

MetricValue
Test files8
Total test cases80+
Policy engine tests38 (deny, review, allow, sensitive columns, query tags)
Agent orchestration tests12 (translator, executor, visualizer, routing)
API endpoint tests15 (health, meta, ask, policy, audit, schema)
SQL validation tests9 (read-only enforcement, injection blocking)
Circuit breaker tests6 (state transitions, timeout recovery)

Endpoint Response Times (local SQLite)

EndpointAvg Response
GET /health21 ms
GET /api/meta16 ms
GET /api/runtime/brief42 ms
GET /api/evals/nl2sql-gold/run9 ms
GET /api/schema/*< 1 ms

---

Snowflake

pip install -e ".[snowflake]"
export SNOWFLAKE_ACCOUNT=your_account.us-east-1
export SNOWFLAKE_USER=your_username
export SNOWFLAKE_PASSWORD=your_password
export SNOWFLAKE_DATABASE=ANALYTICS

Databricks

pip install -e ".[databricks]"
export DATABRICKS_HOST=https://your-workspace.cloud.databricks.com
export DATABRICKS_AUTH_TYPE=databricks-cli
export DATABRICKS_WAREHOUSE_ID=your_sql_warehouse_id
python scripts/bootstrap_databricks_demo.py

---

Deployment

Kubernetes

kubectl apply -f infra/k8s/namespace.yaml
kubectl apply -f infra/k8s/

GCP Cloud Run -- Terraform configs in infra/terraform/. See infra/terraform/README.md for variables and outputs.

Docker

docker compose up app

---

Enterprise Deployment

Production-grade overlays for regulated and high-scale environments.

Helm chart

A full Helm chart lives at helm/nexus-hive/ with three value overlays:


## Default / dev-staging
helm upgrade --install nexus-hive helm/nexus-hive \
  -n analytics --create-namespace


## Production: HPA, PDB, NetworkPolicy, ServiceMonitor, external secrets, HA spread
helm upgrade --install nexus-hive helm/nexus-hive \
  -n analytics --create-namespace \
  -f helm/nexus-hive/values.yaml \
  -f helm/nexus-hive/values-prod.yaml \
  --set image.tag=0.2.0


## Air-gapped: Ollama sidecar, no external LLM, internal registry only
helm upgrade --install nexus-hive helm/nexus-hive \
  -n analytics --create-namespace \
  -f helm/nexus-hive/values.yaml \
  -f helm/nexus-hive/values-airgap.yaml

See helm/nexus-hive/README.md for the full values reference.

Kubernetes production baseline

infra/k8s/production/ ships a hardened namespace baseline: Pod Security Standards (restricted), ResourceQuota, LimitRange, default-deny NetworkPolicy, and scoped allow policies for ingress and warehouse egress.

infra/k8s/observability/ ships a ServiceMonitor and PrometheusRule set with SLO-grade alerts (error rate, p99 latency, circuit breaker, audit-write stall).

Terraform for GCP Cloud Run

infra/terraform/ provisions Cloud Run v2 with Secret Manager, Workload Identity, VPC connector, uptime checks, and log-based alerting. See infra/terraform/README.md for the variable and output tables.

Runbooks

Five step-by-step runbooks live at docs/runbooks/:

RunbookUse when
`production-deploy.md`First production rollout (60 min)
`airgap-deploy.md`Deploying to a restricted / offline cluster (3 hr)
`incident-response.md`On-call response to alerts, SEV levels, AegisOps handoff
`schema-evolution.md`Evolving the governed schema without breaking queries
`model-swap.md`Swapping phi3 to llama3 to Claude without downtime

---

Composite Discovery Narratives

Narrative discovery handouts for technical review conversations. They are fictional composites, not customer references, production evidence, or outcome claims.

NarrativeUse
Acme FinanceFictional financial-services discovery scenario
Northstar HealthFictional regulated-healthcare discovery scenario

Use these narratives to frame questions and implementation boundaries. Do not present them as live customer deployments, benchmarks, references, or guaranteed business results.

---

Benchmarks

benchmarks/ contains reproducible performance and accuracy tests.

question mix, thresholds gated on p95/p99 latency and checks pass rate.

and renders a per-case accuracy chart.

Sample run (from sample_results.json)

MetricValue
VUs / duration50 / 5 min
Total requests12,847
Failed request rate0.3%
http_req_duration p951,390 ms
http_req_duration p991,842 ms
Policy allow / review / deny82.6% / 13.1% / 4.3%
Gold eval score (mean of 5 runs, Claude Sonnet 4)0.91
Gold eval score stdev0.022
SLO compliancepass

See benchmarks/README.md for the full usage and CI integration recipe.

---

Project Structure

Nexus-Hive/
  main.py                    # FastAPI entrypoint (thin, delegates to modules)
  config.py                  # Centralized config, constants, metric definitions
  graph/
    nodes.py                 # LangGraph agent nodes + graph builder
  policy/
    engine.py                # Policy evaluation, query tags, heuristic inference
    audit.py                 # Audit trail writer
    governance.py            # Governance surfaces (scorecard, warehouse brief)
  routes/
    ask.py                   # /api/ask + /api/stream (SSE agent trace)
    health_meta.py           # /health, /api/meta
    warehouse.py             # Warehouse adapter endpoints
    auth.py                  # Operator auth session endpoints
  services/
    build_helpers.py         # Runtime brief, meta builders
    streaming.py             # SSE streaming for agent trace
    openai_helpers.py        # Optional OpenAI integration
  warehouse_adapter.py       # Adapter base class + SQLite + registry
  snowflake_adapter.py       # Live Snowflake adapter
  databricks_adapter.py      # Live Databricks adapter
  circuit_breaker.py         # Ollama circuit breaker
  security.py                # HMAC sessions, token auth, RBAC
  seed_db.py                 # 10k-row synthetic dataset generator
  tests/                     # 8 test modules, 80+ test cases
  infra/
    k8s/                     # Kubernetes manifests
    terraform/               # GCP Cloud Run Terraform configs
  frontend/                  # Chart.js + agent trace viewer
  docs/
    adr/                     # Architecture Decision Records
    solution-architecture.md
    discovery-guide.md

---

Related Projects

ProjectRelationship
lakehouse-contract-labData pipeline that feeds Nexus-Hive's warehouse
enterprise-llm-adoption-kitEnterprise LLM governance patterns
agent-orchestration-benchmarkComparative benchmarks for multi-agent orchestration frameworks (LangGraph, CrewAI, custom)
llm-onprem-deployment-kitReference deployment kit for airgapped / on-prem LLM serving, reused by Nexus-Hive's airgap overlay

---

Cloud + AI Architecture

Enterprise Productization

System Architecture

Service Architecture