Transform your database queries into insights with natural language.
SQL Agent is a full-stack AI-powered analytics platform that helps you understand your data instantly. Connect any SQL database, ask questions in plain English, and get interactive charts, tables, and summaries.
- Database Wizard: Connect to PostgreSQL, MySQL, SQLite, or Turso in seconds.
- Connection Testing: Validate credentials before saving.
- Secure Storage: Credentials stored locally or via environment variables (self-hosted).
- Natural Language to SQL: Ask "Show me top selling products" and get optimized SQL.
- Multi-step Reasoning: complex questions are broken down into logical steps.
- Auto-Correction: AI automatically fixes SQL syntax errors.
- Smart Charting: Automatically selects Bar, Line, Pie, or Area charts based on data structure.
- Dynamic Switching: Toggle between Chart and Table views instantly.
- Follow-up Questions: AI suggests the next logical questions to ask.
- Chat Interface: Familiar ChatGPT-style experience.
- Dark Mode: Beautiful dark theme by default, with easy toggle.
- Responsive: Works perfectly on desktop and mobile.
- Node.js 18+ and pnpm
- OpenAI API Key
- A database (PostgreSQL, MySQL, SQLite, or Turso)
git clone https://github.com/princepal9120/sql_agent.git
cd sql_agent
pnpm installCreate a .env.local file:
OPENAI_API_KEY=sk-your-key-here
# Optional: Pre-configure a default database (Turso example)
TURSO_DATABASE_URL=libsql://your-db.turso.io
TURSO_AUTH_TOKEN=your-tokenpnpm dev
# Opens at http://localhost:3000Visit http://localhost:3000/setup to use the connection wizard, or go straight to /chat if you configured .env.local.
- Frontend: Next.js 15 (App Router), React 19, Tailwind CSS v4, Lucide Icons
- AI: Vercel AI SDK, OpenAI GPT-4o
- Database Access: Drizzle ORM,
node-sql-parserfor validation - Visualization: Recharts, customized Shadcn/ui components
src/
├── app/
│ ├── api/ # API Routes (Chat, Database Config)
│ ├── chat/ # Chat Interface Page
│ ├── setup/ # Connection Wizard Page
│ └── page.tsx # Landing Page
├── components/ # Reusable UI Components
│ ├── ChartView.tsx # Visualization Engine
│ └── DatabaseWizard.tsx # Connection Flow
├── lib/ # Utilities & AI Logic
│ ├── db-adapter.ts # Dynamic DB Connection Handler
│ └── chartRecommender.ts # Visualization Logic
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
Built with ❤️ using Next.js & AI