<<<<<<< HEAD
AI-Powered Data Model Dependency Extraction Hierarchical Multi-Tenant Platform for SQL, Power BI, Databricks, and Diagram Analysis
DataGraph AI automatically extracts dependencies from SQL databases (including Snowflake), Databricks Unity Catalog, BI tools, and diagram images using off-the-shelf foundation models (Meta Llama 3.1/3.3, Anthropic Claude Sonnet 4) and Vision AI (Claude 3.5 Sonnet Vision, GPT-4V) with sophisticated prompt engineering. It achieves 90-95% accuracy without the need for expensive fine-tuning.
Version 2 (Current) features hierarchical multi-tenant organization (Customer β Business Unit β Use Case), Databricks Unity Catalog live connectivity, ERD diagram visualization with Primary/Foreign Keys, and dual-server deployment architecture.
"Off-the-shelf foundation models with good engineering can match custom fine-tuned modelsβat a fraction of the cost and complexity."
"Vision AI makes legacy diagrams machine-readableβextract data models from screenshots, ERDs, and whiteboard photos with 90%+ accuracy."
- β Hierarchical Multi-Tenant: Customer β Business Unit β Use Case structure
- β
Lakebase Integration: PostgreSQL metadata storage for fast queries and history tracking
- Extractions are linked to Use Cases via foreign key (
usecase_id) - Each extraction record stores metadata (node/edge counts, confidence, model, timestamps)
- Actual extraction data files stored in Unity Catalog Volumes (hierarchical path)
- Database indexes enable fast queries by customer, BU, use case, source type, status
- Extractions are linked to Use Cases via foreign key (
- β Context-Aware Navigation: Sidebar tree navigation with breadcrumbs
- β
Extraction Management:
- Multiple extractions per use case (SQL, Power BI, Images, Databricks, Merged)
- History view filtered by customer/BU/use case
- Status tracking:
uploading,processing,completed,failed
- β
SQL Databases: Oracle, PostgreSQL, MySQL, SQL Server, Snowflake (
.sql,.ddlfiles) - β Databricks Unity Catalog: Live connection to extract tables, views, functions, procedures, volumes, models, PK/FK constraints, and table lineage
- β
BI Tools: Power BI (
.pbix,.jsonfiles) with automatic JSON extraction from .pbix archives - β
Diagrams & Images: ERD diagrams, database schemas, Power BI screenshots (
.png,.jpg,.jpeg,.pdfusing Vision AI) - β SQL Dialect Patterns: CTEs, recursive CTEs, subqueries, triggers, foreign keys, materialized views, cross-schema dependencies, streams, tasks
- β Foundation Model Integration: Llama 3.1 8B, Llama 3.3 70B, Claude Sonnet 4
- β Vision AI: Claude 3.5 Sonnet Vision, GPT-4 Vision for diagram extraction
- β Ensemble Strategy: Combine multiple models for improved accuracy
- β Automatic Product Detection: Identifies source database/BI tool from files
- β Modern Web Interface: Next.js 16 with TypeScript, shadcn/ui, and ReactFlow
- β ERD Diagram View: Entity-Relationship Diagrams with Primary Keys, Foreign Keys, and relationship arrows
- β Interactive Graph View: Network visualization with multiple layouts (hierarchical, force-directed, radial)
- β Export Capabilities: JSON, Cypher (Neo4j), CSV, PNG export
- β
Merge Extractions Within Use Case:
- Scope: Merge operates within a single use case only
- Constraints: Cannot merge two extractions of the same source type
- Supported combinations: SQL + Images, SQL + Power BI, Power BI + Images, Databricks + any other type
- Process: Select 2 completed extractions β Merge β Creates new extraction with
source_type='merged' - Storage: Merged result saved to use case's Volume path, metadata recorded in Lakebase
- Deduplication: Automatically handles duplicate nodes/edges across sources
- β REST API Backend: FastAPI with Server-Sent Events (SSE) streaming and 4 workers
- β Background Tasks: Asynchronous processing with polling for long extractions
- β Metadata Storage: Databricks Lakebase (PostgreSQL) for structured metadata and project management
- β File Storage: Unity Catalog Volumes for hierarchical file organization
- β
Production Ready: Databricks Apps deployment with dual-server architecture:
- Next.js server (port 8000, exposed)
- FastAPI server (port 8001, internal)
- Next.js proxies
/api/*requests to FastAPI
- β Comprehensive Testing: 700+ synthetic schemas with ground truth
- β Rich Analytics: Performance by database, domain, complexity, and object type
- β Real-time Progress: Streaming test results with live metrics
data-model-nel-archiecture/
β
βββ π README.md # This file
βββ π ARCHITECTURE_DIAGRAM.html # Interactive system architecture diagram
βββ π DATABRICKS_DEPLOYMENT.md # Databricks Apps deployment guide
βββ app.yaml # Databricks Apps configuration (dual-server)
βββ deploy_new.sh # Deployment script for Databricks Apps
β
βββ api/ # FastAPI Backend
β βββ main.py # Thin ASGI entrypoint: `uvicorn api.main:app`
β βββ app_factory.py # `create_app()` + router registration
β βββ core/ # Cross-cutting concerns (config, wiring, identity, tracking)
β βββ routers/ # Modular FastAPI routers (HTTP layer)
β βββ services/ # Business logic helpers (non-HTTP)
β βββ hierarchy_api.py # Customer/BU/Usecase API endpoints (legacy router module)
β βββ sql_extractor.py # SQL dependency extraction
β βββ sql_extractor_hierarchical.py # Hierarchical SQL extraction (>96K chars)
β βββ json_extractor.py # Power BI JSON extraction
β βββ pbix_extractor.py # Power BI .pbix extraction
β βββ pbix_extractor_hierarchical.py # Hierarchical Power BI extraction
β βββ vision_extractor.py # Vision AI diagram extraction
β βββ databricks_catalog_extractor.py # Unity Catalog live extraction
β βββ model_adapter.py # Unified AI model interface
β βββ file_operations.py # Volume/local file operations
β βββ metadata_extractor.py # Metadata detection
β βββ jobs_api.py # Databricks Jobs API integration
β βββ scripts/
β β βββ lakebase.py # Lakebase (PostgreSQL) integration
β β βββ schema.sql # PostgreSQL schema for metadata
β β βββ [setup scripts]
β βββ requirements.txt # Python dependencies
β βββ π README.md # API documentation
β
βββ frontend/ # Next.js Web Interface
β βββ app/ # App router pages
β β βββ page.tsx # Dashboard (homepage)
β β βββ layout.tsx # Root layout with sidebar
β β βββ customers/ # Customer management
β β β βββ new/ # Create customer
β β β βββ detail/ # Customer details
β β βββ business-units/ # Business Unit management
β β β βββ new/ # Create BU
β β β βββ detail/ # BU details
β β βββ usecases/ # Use Case management
β β β βββ new/ # Create use case
β β β βββ detail/ # Use case details
β β βββ upload/ # File upload & Databricks connect
β β βββ extract/ # Extraction progress & status
β β βββ visualize-erd/ # ERD diagram view (PK/FK)
β β βββ graph-view/ # Interactive graph visualization
β β βββ merge-extractions/ # Merge multiple extractions
β β βββ history/ # Extraction history
β β βββ export/ # Export (JSON, Cypher, CSV, PNG)
β β βββ run-tests/ # Batch testing interface
β β βββ test-results/ # Results visualization
β β βββ model-comparison/ # Model performance comparison
β β βββ admin/analytics/ # Admin analytics
β β βββ settings/ # Application settings
β β βββ feedback/ # User feedback
β β βββ product-backlog/ # Feature requests
β βββ components/ # Reusable React components
β β βββ app-sidebar.tsx # Hierarchical navigation sidebar
β β βββ erd-diagram.tsx # ERD visualization components
β β βββ graph-visualizer.tsx # Graph visualization
β β βββ backend-status-indicator.tsx # Health check indicator
β β βββ ui/ # shadcn/ui components
β βββ contexts/ # React Context providers
β β βββ organization-context.tsx # Customer/BU/Usecase state
β βββ hooks/ # Custom React hooks
β βββ lib/ # Utility functions
β β βββ api-config.ts # API fetch wrapper
β βββ next.config.ts # Next.js configuration (proxies)
β βββ package.json # Node dependencies
β βββ π README.md # Frontend documentation
β
βββ data/ # Local development data storage
β βββ customers/ # Hierarchical: {customer_id}/{bu_id}/{usecase_id}/
β βββ sessions/ # Extraction session files
β βββ training/ # Training data
β βββ sql_sources/ # SQL files by split (train/val/test)
β βββ non_sql_sources/ # Power BI JSON files
β βββ image_sources/ # Diagram images
β
βββ phase1_training_data/ # ποΈ Synthetic Data Generation
β βββ configs/ # Configuration files
β βββ data/ # Generated schemas (700+)
β βββ 00_load_training_data_BASIC_PHASE1_ONLY.py # Data generator
β βββ validate_training_data.py # Validation script
β βββ π README.md # Training data documentation
β
βββ phase1_hierarchical_approach/ # ποΈ Archived Fine-Tuning Experiments
β βββ training/ # 3-stage training scripts
β βββ inference/ # Hierarchical inference
β βββ π README.md # Architecture documentation
β
βββ docs/ # ποΈ Legacy Documentation
βββ QUICKSTART.md
βββ BLOG_POST_TWO_MONTH_JOURNEY.md
βββ [50+ detailed guides]
- Python 3.9+ with
pipandvenv - Node.js 18+ with
npm - PostgreSQL 13+ (for Lakebase metadata storage)
- Databricks Workspace with model serving endpoints (or API keys for Anthropic/OpenAI)
git clone <repository-url>
cd data-model-nel-archiectureLakebase stores organizational metadata (customers, business units, use cases, extractions).
Option A: Local PostgreSQL
# Install PostgreSQL (if not already installed)
# macOS: brew install postgresql@14
# Ubuntu: sudo apt-get install postgresql-14
# Windows: Download from postgresql.org
# Start PostgreSQL service
# macOS: brew services start postgresql@14
# Ubuntu: sudo systemctl start postgresql
# Windows: Start via Services
# Create database and user
psql postgres
CREATE DATABASE data_lineage_metadata;
CREATE USER lakebase_user WITH PASSWORD 'lakebase_password';
GRANT ALL PRIVILEGES ON DATABASE data_lineage_metadata TO lakebase_user;
\q
# Run schema setup script
cd api/scripts
psql -U lakebase_user -d data_lineage_metadata -f schema.sqlOption B: Docker PostgreSQL (Easier)
# Start PostgreSQL in Docker
docker run --name lakebase-postgres \
-e POSTGRES_DB=data_lineage_metadata \
-e POSTGRES_USER=lakebase_user \
-e POSTGRES_PASSWORD=lakebase_password \
-p 5432:5432 \
-d postgres:14
# Wait 10 seconds for PostgreSQL to start
sleep 10
# Run schema setup script
cd api/scripts
psql -h localhost -U lakebase_user -d data_lineage_metadata -f schema.sql
# Password: lakebase_passwordcd api
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure environment (create .env file)
cat > .env << EOF
# Databricks Configuration
DATABRICKS_HOST=https://your-workspace.cloud.databricks.com
DATABRICKS_TOKEN=your_token_here
# Model Endpoints
LLAMA_8B_ENDPOINT=https://.../serving-endpoints/llama-8b/invocations
LLAMA_70B_ENDPOINT=https://.../serving-endpoints/llama-70b/invocations
CLAUDE_SONNET_4_ENDPOINT=https://.../serving-endpoints/claude-sonnet-4/invocations
# Lakebase (PostgreSQL) Configuration
LAKEBASE_HOST=localhost
LAKEBASE_PORT=5432
LAKEBASE_DATABASE=data_lineage_metadata
LAKEBASE_USER=lakebase_user
LAKEBASE_PASSWORD=lakebase_password
# Data Paths (optional - defaults to <project_root>/data/)
LOCAL_TRAINING_DATA_PATH_SQL=../phase1_training_data/data/sql_sources
LOCAL_TRAINING_RESULTS_PATH_SQL=../phase1_training_data/data/test_results
EOF
# Start API server (entrypoint is stable)
cd ..
uvicorn api.main:app --reload --port 8000API will be available at: http://localhost:8000
cd frontend
# Install dependencies
npm install
# Configure environment
echo "NEXT_PUBLIC_API_URL=http://localhost:8000" > .env.local
# Start development server
npm run devFrontend will be available at: http://localhost:3000
Open your browser and navigate to:
- Frontend:
http://localhost:3000 - API Docs:
http://localhost:8000/docs
Hierarchical Workflow (Customer β Business Unit β Use Case):
- Dashboard β Click "Start Here" button
- Create Customer β Enter customer name (e.g., "Acme Corp")
- Add Business Unit β Enter BU name (e.g., "Finance Department")
- Create Use Case β Enter use case name (e.g., "CRM Data Model") and select source type:
sql_sources- SQL filespower_bi- Power BI .pbix or JSONimage_sources- Diagram imagesdatabricks_sources- Unity Catalog connection
- Upload or Connect:
- File Upload: Drag & drop SQL, Power BI (.pbix), or diagram images
- Databricks Connect: Enter host, catalog, schema, SQL warehouse path
- Extract Dependencies β Select AI model, monitor real-time progress
- View Results:
- ERD Diagram β Entity-Relationship view with Primary/Foreign Keys
- Graph View β Interactive network visualization
- Export β JSON, Cypher, CSV, PNG
# From project root
./start.shThis starts both services locally:
- API:
http://localhost:8000(FastAPI,uvicorn api.main:app) - Frontend:
http://localhost:3000(Next.js dev server)
To stop everything cleanly:
./stop.shIf you want to run the same ports as Databricks Apps locally (Frontend :8000, API :8001):
./start_prod.sh
./stop.sh
start_prod.shis intended for local validation; Databricks Apps deployment behavior is controlled byapp.yaml.
Why Hierarchical? Organize extractions by customer, business unit, and use case for better project management, collaboration, and tracking across your organization.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STEP 1: SETUP β
β Create Customer β Business Unit β Use Case β
β β
β Customer: Your organization or client β
β ββ Business Unit: Department or team (e.g., Finance, Sales) β
β ββ Use Case: Specific project (e.g., "CRM Data Model") β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STEP 2: UPLOAD β
β Upload your source files (one type per use case) β
β β
β Source Types: β
β β’ SQL Files (DDL, stored procedures, views) β
β β’ Power BI Files (.pbix or .json files) β
β β’ Diagrams & Images (ERD diagrams, screenshots) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STEP 3: EXTRACT β
β AI extracts dependencies automatically β
β β
β β’ Select AI model (Llama 8B/70B, Claude Sonnet 4, Vision AI) β
β β’ Monitor real-time progress β
β β’ Background processing for large files β
β β’ Automatic save to Lakebase (metadata storage) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STEP 4: VIEW GRAPH β
β Explore your dependency graph β
β β
β β’ Interactive visualization with multiple layouts β
β β’ Table view with filtering β
β β’ Export to JSON, CSV, PNG, SVG, Neo4j Cypher β
β β’ Merge multiple extractions within a use case β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
a) Create Customer
- Click "Start Here" or "New Customer" from Dashboard
- Enter customer name (e.g., "Acme Corp")
- Optional: Add industry, region, description
b) Create Business Unit
- After creating customer, add business unit
- Enter BU name (e.g., "Finance Analytics", "Sales Operations")
- Optional: Add description
c) Create Use Case
- After creating business unit, define your use case
- Enter use case name (e.g., "CRM Data Model", "Sales Pipeline")
- Select ONE source type: SQL, Power BI, or Diagrams
- Optional: Add description
After creating a use case, you'll be automatically directed to upload:
SQL Files (.sql, .ddl):
- Supported databases: Oracle, MySQL, PostgreSQL, SQL Server, Snowflake
- Examples: DDL scripts, stored procedures, views, functions, triggers
- Hierarchical extraction for large SQL files (>96K characters)
Power BI Files (.pbix, .json):
- Upload
.pbixfiles directly OR pre-extractedReportLayout.jsonfiles - System automatically extracts JSON from
.pbixfiles (using zipfile) - Detects tables, measures, relationships, DAX formulas, calculated columns
- Hierarchical extraction for complex Power BI models
Diagrams & Images (.png, .jpg, .jpeg, .pdf):
- Examples: ERD diagrams, database schemas, Power BI screenshots, whiteboard photos
- Uses Vision AI (Claude 3.5 Sonnet Vision or GPT-4 Vision)
- Confidence scoring from model (no hardcoded values)
Model Selection:
- For SQL/Power BI: Llama 8B, Llama 70B, or Claude Sonnet 4
- For Diagrams: Claude 3.5 Sonnet Vision or GPT-4 Vision
Extraction Process:
- Real-time progress updates (file processing, AI extraction, saving)
- Background processing for large files (>96K characters)
- Hierarchical extraction for very large files (chunks + merge)
- Automatic save to Lakebase metadata storage
- Results stored in Unity Catalog Volumes
Dependency Graph:
- Table View: Browse all nodes and edges with filtering
- Graph View: Interactive visualization
- Force-directed layout (shows relationships)
- Hierarchical layout (top-down structure)
- Circular layout (radial design)
- Zoom, pan, and click nodes for details
Export Options:
- JSON (complete graph data)
- CSV (tabular format)
- PNG/SVG (visual export)
- Neo4j Cypher (import to graph database)
Merge Extractions (Optional):
- Navigate:
/merge-extractions?usecase={usecase_id} - Select: Choose 2 completed extractions from the same use case
- Constraint: Must be different source types (e.g., SQL + Images, not SQL + SQL)
- Supported combinations: SQL + Power BI, SQL + Images, Power BI + Images, Databricks + any
- Result: Creates new extraction record with
source_type='merged' - Storage: Saved to use case's hierarchical Volume path:
/Volumes/.../customers/{c}/{b}/{u}/results/merged_*.json - Metadata: Lakebase stores references to source extractions in metadata field
- Deduplication: Automatically merges nodes (by name) and edges (by sourceβtargetβtype)
Sidebar Navigation:
- Browse all customers β business units β use cases
- Quick access to any extraction
- View extraction history per use case
- Track progress across your organization
Extraction History:
- View all extractions across all use cases
- Filter by customer, business unit, source type
- Compare extractions over time
- Access previous results anytime
-
Run Batch Tests
- Select models to test (1-4 models)
- Choose data split: train, val, or test
- Set sample size (default: 20 schemas)
- Monitor streaming results
-
Analyze Results
- Overview: Aggregate F1 scores, test counts, timing
- By Database: Performance per SQL dialect
- By Domain: Accuracy across business domains
- By Complexity: Simple vs. complex schema handling
- Object Types: Detection rates for tables, views, functions, etc.
- Dependencies: Accuracy per relationship type
- Errors: Debug failed tests
-
Compare Models
- Side-by-side performance comparison
- Cost analysis
- Response time benchmarks
| Model | Overall F1 | Node F1 | Edge F1 | Avg Time | Cost (1K schemas) |
|---|---|---|---|---|---|
| Meta Llama 3.1 8B | 90% | 93% | 87% | 5s | $26 |
| Meta Llama 3.3 70B | 93% | 95% | 91% | 8s | $260 |
| Claude Sonnet 4 | 95% | 97% | 93% | 10s | $780 |
| Model | Node Detection | Edge Detection | Overall Accuracy | Avg Time | Cost (1K diagrams) |
|---|---|---|---|---|---|
| Claude 3.5 Sonnet Vision | 95% | 85-90% | 90-92% | 8-10s | $10-20 |
| GPT-4 Vision (Turbo) | 95% | 85-90% | 90-92% | 5-8s | $15-30 |
| Metric | Target | Current (Llama 70B) | Status |
|---|---|---|---|
| Overall F1 | β₯ 93% | 93% | β Ready |
| Node F1 | β₯ 95% | 95% | β Ready |
| Edge F1 | β₯ 90% | 91% | β Ready |
| Response Time | < 15s | 8s | β Ready |
| Database | Supported Features |
|---|---|
| Oracle | DDL, PL/SQL, procedures, functions, triggers, packages |
| PostgreSQL | DDL, PL/pgSQL, functions, triggers, materialized views |
| MySQL | DDL, procedures, views, functions, triggers |
| SQL Server | T-SQL, procedures, views, functions, triggers |
| Snowflake | DDL, SQL, procedures, functions, streams, tasks, transient tables, external tables, clustering |
- CTEs (Common Table Expressions): WITH clause queries
- Recursive CTEs: Self-referencing CTEs with UNION ALL
- Subqueries: Nested SELECT statements (correlated and non-correlated)
- Triggers: BEFORE/AFTER/INSTEAD OF triggers with actions
- Foreign Keys: Table relationships and constraints
- Materialized Views: Cached views with refresh logic
- Function/Procedure Calls: Cross-object invocations
- Cross-schema Dependencies: References across database schemas
- Index Definitions: Performance indexes on tables
- Sequences: Auto-increment generators
- Streams (Snowflake): Change data capture on tables
- Tasks (Snowflake): Scheduled SQL execution with dependencies
- Transient/External Tables (Snowflake): Temporary and external data sources
- Clustering Keys (Snowflake): Table clustering for performance
| Tool | Supported Features |
|---|---|
| Power BI | Datasets, tables, columns, measures (DAX), relationships, visuals, reports, pages |
| Source Type | Supported Features |
|---|---|
| ERD Diagrams | Tables, columns, primary keys, foreign keys, relationships, cardinality (1-to-many, etc.) |
| Database Schemas | Entity boxes, attribute lists, relationship lines, key indicators (PK/FK) |
| Power BI Screenshots | Visual layouts, dataset connections, measure definitions |
| Whiteboard Photos | Hand-drawn diagrams, annotations, relationship arrows |
Supported Formats: .png, .jpg, .jpeg, .pdf
Expected Accuracy:
- Table/Entity Detection: 95%
- Column/Attribute Extraction: 90%
- Relationship Detection: 85-90%
- Cardinality Recognition: 85%
Fine-Tuning Approach (Archived):
- Training: $2,000-3,000 initial
- Training time: 15-18 hours
- Ongoing costs: $2,000-3,000/month for iterations
- Inference: ~$0.01 per schema
- Total (1K schemas): ~$2,010-3,010
Foundation Model Approach (Current):
- Training: $0
- Setup time: <1 hour
- Ongoing costs: $0 (no training)
- Inference: ~$0.26-0.78 per schema
- Total (1K schemas): ~$260-780
Savings: 60-90% cost reduction + 100x faster iteration
Create api/.env (optional - see api/env.template for all options):
# Databricks Configuration
DATABRICKS_HOST=https://your-workspace.cloud.databricks.com
DATABRICKS_TOKEN=your_token_here
# Model Endpoints
LLAMA_8B_ENDPOINT=https://.../serving-endpoints/llama-8b/invocations
LLAMA_70B_ENDPOINT=https://.../serving-endpoints/llama-70b/invocations
CLAUDE_SONNET_4_ENDPOINT=https://.../serving-endpoints/claude-sonnet-4/invocations
# Vision AI (Optional - for diagram extraction)
# Use Databricks endpoint or Anthropic API key
# ANTHROPIC_API_KEY=your_anthropic_key_here
# OPENAI_API_KEY=your_openai_key_here # For GPT-4V
# Metadata Storage (Optional - for Lakebase integration)
# LAKEBASE_INSTANCE_NAME=data-lineage-metadata # Auto-configured in Databricks Apps
# Data Paths (optional - defaults to <project_root>/data/...)
# TRAINING_DATA_PATH_SQL=/custom/path/sql_sources
# TRAINING_DATA_PATH_IMAGE=/custom/path/image_sources
# TRAINING_RESULTS_PATH_SQL=/custom/path/results
# EXTRACTION_PATH_SQL=/custom/path/extractsπ Note: Data paths now default to
<project_root>/data/for local development. Seedocs/PATH_CONFIGURATION.mdfor complete details.
Create frontend/.env.local:
NEXT_PUBLIC_API_URL=http://localhost:8000This repo deploys as a single Databricks App (dual server):
- Frontend: Next.js on port 8000 (exposed)
- Backend: FastAPI on port 8001 (internal)
- Frontend proxies
/api/*to the backend based onapp.yaml
./deploy_new.shWhat deploy_new.sh does:
- (Optional) initializes/validates Lakebase schema if configured in
app.yaml - bundles the code (includes
api/core/,api/routers/,api/services/) - uploads to your workspace under
/Workspace/Users/<you>/<APP_NAME> - runs
databricks apps deploy <APP_NAME> --source-code-path <workspace-path>
- Databricks CLI authenticated (if auth expires:
databricks auth login --host <workspace-url>) npmavailable (for frontend deps during deployment)python3available (for local prep steps)
For environment variables (UC/Lakebase/etc.), edit
app.yaml.
- Frontend: Databricks Apps OAuth (automatic user login)
- Backend: OAuth token validation + Service Principal for models
See: AUTHENTICATION_SETUP.md for complete guide
- Set Up Unity Catalog - Create catalog, schema, and volumes
- Configure Model Endpoints - Deploy foundation model serving endpoints
- Upload Training Data - Upload 700 schemas to Unity Catalog volume
- Deploy Application - Execute
./deploy_new.sh - Verify Deployment - Test API and frontend
- Configure CORS - Update allowed origins if needed
- Configure Monitoring - Set up alerts and tracking
See: DATABRICKS_DEPLOYMENT.md for detailed instructions
The system includes 700+ synthetic SQL schemas:
- 5 Databases: Oracle, PostgreSQL, MySQL, SQL Server, Snowflake
- 10 Domains: Ecommerce, Healthcare, Finance, Logistics, Manufacturing, Retail, Insurance, Education, Telecommunications, Real Estate
- 3 Splits: Train (70%), Val (15%), Test (15%)
Each schema includes:
- Tables: 5-8 base tables with foreign keys
- Views: 2-3 views with complex queries
- Functions: 1-2 reusable functions
- Procedures: 1-2 stored procedures
- Triggers: 1 audit/logging trigger
Complexity Distribution:
- Simple: β€12 objects
- Medium: 13-16 objects
- Complex: 17-20 objects
- Very Complex: >20 objects
Backend:
- Python 3.9+
- FastAPI (REST API with SSE streaming)
- OpenAI SDK (Databricks vision endpoint compatibility)
- Anthropic SDK (Claude Vision API)
- asyncpg (PostgreSQL async driver for Lakebase)
- Requests (HTTP client)
- Pydantic (data validation)
- Pillow (image processing)
Frontend:
- TypeScript 5
- Next.js 16 (App Router)
- React 19
- Tailwind CSS
- shadcn/ui (Radix UI)
- Recharts (visualizations)
- ReactFlow (graph visualization)
Infrastructure:
- Databricks (model serving)
- Unity Catalog Volumes (persistent storage)
- Databricks Lakebase (PostgreSQL for metadata)
- Databricks Apps (hosting with OAuth)
Backend (API):
- Add endpoint in the appropriate router under
api/routers/(orapi/hierarchy_api.pyfor hierarchy endpoints) - If you add a new router module, include it in
api/app_factory.py - Keep
api/main.pyminimal (it should only exposeapp = create_app()) - Test with FastAPI docs:
http://localhost:8000/docs - Update API documentation in
api/README.md
Frontend:
- Create page in
frontend/app/your-feature/page.tsx - Add to sidebar in
frontend/components/app-sidebar.tsx - Use existing UI components from
frontend/components/ui/ - Test in browser at
http://localhost:3000
API won't start:
- Check Python version:
python --version(requires 3.9+) - Activate virtual environment:
source venv/bin/activate - Install dependencies:
pip install -r requirements.txt - Verify
.envfile exists with valid tokens
Frontend won't start:
- Check Node.js version:
node --version(requires 18+) - Clear cache:
rm -rf node_modules .next && npm install - Verify
.env.localhas correct API URL
CORS errors:
- Ensure API CORS is configured for
http://localhost:3000 - Check API is running on port 8000
- Verify
NEXT_PUBLIC_API_URLin.env.local
Model endpoint errors:
- Verify Databricks token is valid
- Check endpoint URLs are correct in
.env - Test endpoint directly:
curl -X POST <endpoint-url> -H "Authorization: Bearer <token>"
File size errors:
- Llama models: Max 96K characters
- Claude Sonnet 4: Max 150K characters
- Split large files into smaller chunks
- Remove unnecessary comments/whitespace
Vision AI errors:
- Ensure ANTHROPIC_API_KEY or OPENAI_API_KEY is set in
.envfor direct API access - For Databricks endpoints, verify vision model is deployed
- Check image format: .png, .jpg, .jpeg, .pdf only
- Image size limit: 5MB per image (API limitation)
- For poor results, try higher quality images or clearer diagrams
For detailed troubleshooting, see:
- ARCHITECTURE_DIAGRAM.md - π Complete system architecture, workflows, and diagrams
- METADATA_EXTRACTION_ARCHITECTURE.md - AI-first metadata extraction approach
- QUICKSTART.md - 5-minute quick start guide
- SETUP_GUIDE.md - Complete local setup instructions
- RUN_LOCALLY.md - Local development setup
- DATABRICKS_DEPLOYMENT.md - Deploy to Databricks Apps
- LAKEBASE_DEPLOYMENT_GUIDE.md - Lakebase (PostgreSQL) metadata storage setup
- AUTHENTICATION_SETUP.md - Configure authentication
- SECURITY_SETUP.md - Security best practices
- api/README.md - FastAPI backend documentation
- frontend/README.md - Next.js frontend documentation
- phase1_training_data/README.md - Data generation documentation
- PROJECTS_AND_CONTEXT_MANAGEMENT.md - Project organization and metadata management
- VISION_EXTRACTION_QUICKSTART.md - Quick start for diagram extraction
- VISION_MODEL_COMPARISON.md - Model selection guide
- MERGE_EXTRACTIONS_GUIDE.md - Combining SQL + Image + JSON results
- BLOG_POST_TWO_MONTH_JOURNEY.md - Complete project journey, learnings, and insights
- β Hierarchical Multi-Tenant Workflow - π Customer β Business Unit β Use Case organization
- β Lakebase Integration - PostgreSQL-based metadata storage for hierarchical project management
- β Streamlined Navigation - π Context-aware UI with sidebar tree, workflow-aligned menus
- β Power BI Support - Direct .pbix and .json file upload with hierarchical extraction
- β Vision AI Extraction - Extract from ERD diagrams and screenshots (Claude 3.5 Sonnet Vision, GPT-4V)
- β Merge Extractions - Combine SQL + Power BI + Images into unified graphs
- β Background Tasks - Asynchronous processing with polling for long extractions
- β Snowflake Support - Full support for Snowflake SQL including streams, tasks, transient tables, clustering
- β Unity Catalog Volumes - Production-ready persistent storage with hierarchical paths
-
Chain-of-Thought (COT) Prompting
- Guide models through step-by-step extraction
- Potential 2-5% accuracy improvement
- Trade-off: Higher latency and token costs
-
Hybrid Symbolic + LLM Approach
- Use deterministic parsers for simple patterns
- Reserve LLMs for complex ambiguous cases
- Potential 50-70% cost reduction
-
Advanced Caching
- Cache results for common schemas
- Reduce redundant API calls
- Improve response times
-
Additional Data Sources
- Tableau metadata
- Looker models
- dbt models
- Teradata
- SAP HANA
-
Enhanced Visualizations
- Animated dependency flows
- Impact analysis (what-if scenarios)
- Export to diagram formats (Mermaid, PlantUML)
- Visual differentiation by source (SQL vs Image vs JSON)
-
Vision AI Enhancements
- OCR preprocessing for low-quality images
- Multi-page diagram support
- Automatic diagram type detection
- Confidence-based diagram quality warnings
See BLOG_POST_TWO_MONTH_JOURNEY.md for detailed future directions.
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Make changes and test thoroughly
- Submit a pull request with detailed description
Copyright 2024 - All Rights Reserved
For questions or issues:
- Check documentation files (listed above)
- Review API documentation at
http://localhost:8000/docs - Check logs in console output
- Contact project maintainers
Version: 3.0.0
Last Updated: November 30, 2024
Status: Production Ready β
Architecture: Hierarchical Multi-Tenant + Foundation Models + Vision AI
New in 3.0: Customer/BU/Use Case hierarchy, Lakebase metadata storage, Streamlined workflow, Power BI support (.pbix and .json)
Supported Databases: Oracle, PostgreSQL, MySQL, SQL Server, Snowflake
Supported BI Tools: Power BI (.pbix, .json)
Supported Diagram Formats: PNG, JPG, PDF (via Vision AI)
Previous Approaches Explored: Hierarchical Fine-Tuning (archived)
<<<<<<< HEAD
407f04c (Datagraph release 1) =======
5d8df17 (first commit)