gudb: The Database Seatbelt 🛡️ - A professional database guardian SDK with AI-backed query interception and safety guardrails.
Project description
gudb: The Database Seatbelt 🛡️
"You never notice a seatbelt until it saves your life. We do the same for your production database."
gudb is a high-performance safety layer that prevents "Career-Ending" database disasters. It intercepts unconstrained DELETE, DROP, and TRUNCATE operations in real-time with zero latency, while using Gemini AI as an asynchronous "Senior DRE Advisor" to suggest performance optimizations.
🎬 Killer Demo (Hackathon Special)
Check out our high-impact terminal demo that showcases the seatbelt in action:
python3 examples/hackathon_demo.py
Features
- ⚡ Zero-Latency Seatbelt: Hardcoded safety rules block disasters in <1ms.
- 🤖 AI Advisor: Asynchronous query analysis suggests indexes and refactors.
- 🔔 Command Center: A beautiful dashboard for real-time observability.
- 🔧 One-Line Integration:
conn = monitor(raw_psycopg2_conn)
Architecture
User Request → Middleware (Detects Slow Query) → Creates Alert → Triggers AI Analysis
↓
Notification Badge
↓
User Clicks → Shows Details
↓
AI Recommendations + Fix
Installation
- Clone the repository:
git clone <your-repo-url>
cd gudb
- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Configure environment variables:
cp .env.example .env
# Edit .env with your database URL and Gemini API key
Configuration
Edit .env file:
# Database Connection
DB_URL=postgresql://user:password@localhost:5432/your_database
# Gemini API
GEMINI_API_KEY=your_gemini_api_key_here
# Thresholds (milliseconds)
SLOW_QUERY_THRESHOLD_MS=500
CRITICAL_THRESHOLD_MS=2000
Usage
Start the Server
uvicorn main:app --reload
Access the Dashboard
Open your browser and navigate to:
- Production Dashboard: https://gudb.ai/dashboard
- Local Dashboard: http://localhost:8000/dashboard
- Local API Docs: http://localhost:8000/docs
Test Slow Query Detection
Trigger a test slow query:
curl http://localhost:8000/test/slow
Watch the notification badge update and click to see AI analysis!
API Endpoints
Notifications
GET /api/notifications/- Get all alertsGET /api/notifications/?severity=critical- Filter by severityGET /api/notifications/count- Get notification countGET /api/notifications/{alert_id}- Get specific alert
Analysis
GET /api/analysis/{alert_id}- Get detailed AI analysis for an alert
Health
GET /health- Health checkGET /- Service info
How It Works
- Detection: Middleware measures query execution time
- Alert Creation: If time exceeds threshold, creates an alert with severity level
- Background Analysis: Triggers AI analysis using LangGraph workflow:
- Detective Node: Runs EXPLAIN ANALYZE and gathers schema info
- Architect Node: Uses Gemini to identify bottlenecks and suggest fixes
- Validator Node: Stores analysis results
- User Interaction: User sees notification badge, clicks to view detailed analysis
- Action: User can copy the suggested SQL fix and apply it
LangGraph Workflow
Detective → Architect → Validator
↓ ↓ ↓
EXPLAIN Gemini AI Store
ANALYZE Analysis Results
Project Structure
gudb/
├── main.py # FastAPI app with middleware
├── services/
├── src/
│ └── gudb/ # The SDK Package
│ ├── core/
│ ├── providers/
│ └── middlewares/
├── static/ # Dashboard UI
└── requirements.txt
Use as SDK/Middleware
To integrate into your own FastAPI app:
from fastapi import FastAPI
from gudb.middlewares.fastapi import SafeDBMiddleware
app = FastAPI()
app.add_middleware(SafeDBMiddleware)
# Your routes here...
Customization
Adjust Thresholds
Edit .env:
SLOW_QUERY_THRESHOLD_MS=300 # More sensitive
CRITICAL_THRESHOLD_MS=1000 # Lower critical threshold
Disable Auto-Analysis
ENABLE_AUTO_ANALYSIS=false
🌐 Vercel Deployment
To deploy the gudb Command Center on Vercel as a static site:
- Project Root: Ensure you are in the repository root.
- Configuration: The included
vercel.jsonautomatically handles routing to thestatic/directory. - Deployment:
vercel --prod
[!TIP] This deployment mode is for the frontend only. To protect your production database, ensure the gudb SDK is deployed within your application cluster.
License
MIT
Contributing
Contributions welcome! Please open an issue or PR.
Built with ❤️ using FastAPI, LangGraph, and Google Gemini
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gudb-0.1.0.tar.gz.
File metadata
- Download URL: gudb-0.1.0.tar.gz
- Upload date:
- Size: 54.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e68afd37589022e85d77d8e5a1bdc882e6b28bc32711939a6e961cfa609fcca1
|
|
| MD5 |
d08998dfe48ed750f80c911cfd30fb13
|
|
| BLAKE2b-256 |
b6e7407334e4fdc9e62f05815e41b3a4878038176d1fe1b7d222dcbe746b50dd
|
File details
Details for the file gudb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gudb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2dad839a55861a01347f9c1d3df052f84b736ff0876f42a833d108b357476a54
|
|
| MD5 |
d6f8a9ce95c499a2346c7429b2b2594f
|
|
| BLAKE2b-256 |
7fa576626f7757f20bccf30c30d586b87a1549635f20e7ef0513418019fb19e9
|