An open-source chatbot application that allows users to interact with their Supabase database using natural language queries. Built with Next.js (frontend) and Python/FastAPI (backend).
- Natural Language Interface: Query your database using plain English
- Supabase Integration: Direct connection to your Supabase database
- AI-Powered: Uses OpenAI GPT models for query interpretation
- Modern UI: Clean, responsive interface built with Next.js and shadcn/ui
- Easy Configuration: Simple setup with API keys
- Secure: Credentials stored locally, no external data collection
- Rich Responses: Get both natural language explanations and raw data
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ │ │ │ │ │
│ Next.js │ │ Python │ │ Supabase │
│ Frontend │───▶│ FastAPI │───▶│ Database │
│ │ │ Backend │ │ │
│ │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ │
│ OpenAI API │
│ │
└─────────────────┘
- Node.js 18+ and npm
- Python 3.13+ and uv package manager
- Supabase account and project
- OpenAI API key
git clone https://github.com/your-username/supabase-chatbot.git
cd supabase-chatbotcd backend
uv sync
cp config.ini.example config.ini
uv run python main.pyThe backend will start on http://localhost:8000
cd frontend
npm install
npm run devThe frontend will start on http://localhost:3000
- Open the application in your browser
- Click on the Configuration tab
- Enter your credentials:
- Supabase URL: Your project URL (e.g.,
https://your-project.supabase.co) - Supabase Anon Key: Your anonymous public key
- OpenAI API Key: Your OpenAI API key (starts with
sk-)
- Supabase URL: Your project URL (e.g.,
Try some example queries:
- "What tables do I have?"
- "Show me all users"
- "Count products with price > 100"
- "Show user names and emails"
Copy the example configuration file and fill in your actual API keys:
cd backend
cp config.ini.example config.iniEdit config.ini with your credentials:
[DEFAULT]
supabase_url = https://your-project.supabase.co
supabase_key = your-supabase-anon-key-here
openai_key = sk-your-openai-api-key-here
api_host = 0.0.0.0
api_port = 8000
debug = false
log_level = INFO
⚠️ Security Note: Theconfig.inifile contains sensitive API keys and is ignored by git. Never commit this file to version control.
Create a .env.local file in the frontend directory:
BACKEND_URL=http://localhost:8000GET /- Health checkGET /health- Health statusPOST /api/chat- Process chat queries (non-streaming)POST /api/chat/stream- Process chat queries with streaming responseGET /api/config- Get configuration statusPOST /api/config- Save configuration
POST /api/chat- Proxy to backend chat endpointPOST /api/chat/stream- Proxy to backend streaming chat endpointGET /api/config- Proxy to backend config endpoint
User: "What tables do I have?"
Bot: "Your database has 3 tables: users, products, orders. You can ask me questions about any of these tables..."
User: "Show me all users"
Bot: "I found 25 users in your database. Here are the first 10 results..."
User: "Count products with price > 100"
Bot: "There are 15 products with a price greater than 100."
User: "Show users created in the last week"
Bot: "I found 8 users created in the last week..."
User: "What's the average order value?"
Bot: "The average order value is $127.50 based on 234 orders."
cd backend
uv sync
uv run uvicorn main:app --reload --port 8000
uv run pytestcd frontend
npm run dev
npm run build
npm start- Local Configuration: API keys are stored in local
config.inifiles (ignored by git) - Browser Storage: Frontend credentials are stored in browser session storage only
- No External Data Collection: No credentials are sent to external services except the configured APIs (Supabase & OpenAI)
- Production Setup: Use environment variables for production deployments
- Rate Limiting: Consider implementing rate limiting for production deployments
- Database Security: Ensure your Supabase RLS (Row Level Security) policies are properly configured
- API Key Rotation: Regularly rotate your API keys, especially if exposed
- Repository Security: The
config.inifile is automatically ignored by git to prevent accidental commits
-
"Connection failed"
- Check your Supabase URL and API key
- Ensure your Supabase project is active
- Verify network connectivity
-
"Query interpretation failed"
- Check your OpenAI API key
- Ensure you have sufficient OpenAI credits
- Try rephrasing your query
-
"Permission denied"
- Check your Supabase RLS policies
- Ensure the anon key has necessary permissions
- Consider using a service role key for development (not recommended for production)
-
"Config file not found"
- Make sure you've copied
config.ini.exampletoconfig.ini - Verify the file is in the
backend/directory - Check file permissions
- Make sure you've copied
-
"API keys exposed in git"
- The
config.inifile should be ignored by git automatically - If accidentally committed, remove with:
git rm --cached backend/config.ini - Rotate your API keys immediately if they were exposed
- The
- Backend logs are available in the console where you run the Python server
- Frontend logs are available in the browser console
- Adjust log levels in
config.ini
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.