Skip to content

maneeshsandra/seeQL

Repository files navigation

SeeQL

SeeQL πŸ“Š

SeeQL is an AI-powered conversational interface for querying databases using natural language. Built with Next.js and the Model Context Protocol (MCP), it lets users ask complex questions in plain English and receive rich, visual dashboards (Charts, Graphs, Tables, Metrics) instead of raw SQL results.


πŸš€ Key Features

  • Natural Language to SQL: Converts conversational questions into SQL queries automatically
  • Dynamic Visualizations: Renders appropriate UI based on query results (stats, bar/pie charts, data tables)
  • MCP Integration: Uses Model Context Protocol for secure database schema introspection and query execution
  • Two-Stage Query Processing: Smart routing determines if a database query is needed before executing
  • Large Dataset Handling: Efficiently handles large results with pagination, search, and print functionality
  • Persistent Conversations: Thread-based chat history stored in SQLite
  • Conversation Starters: Pre-built prompts for common queries

πŸ“‚ Project Structure

seeQL/
β”œβ”€β”€ database/                    # Database files and schema
β”‚   β”œβ”€β”€ university.db            # Pre-seeded SQLite database with university ERP data
β”‚   └── init.sql                 # Database schema (30+ tables)
β”œβ”€β”€ src/                         # Next.js application source
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   β”œβ”€β”€ chat/            # Main chat endpoint (NL to SQL pipeline)
β”‚   β”‚   β”‚   β”œβ”€β”€ mcp/             # MCP SSE transport endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ messages/        # Message persistence
β”‚   β”‚   β”‚   β”œβ”€β”€ query-results/     # Large dataset retrieval
β”‚   β”‚   β”‚   └── threads/         # Thread CRUD operations
β”‚   β”‚   β”œβ”€β”€ page.tsx             # Main application page
β”‚   β”‚   └── layout.tsx           # Root layout
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ CustomAssistantMessage.tsx  # Renders openui-lang components
β”‚   β”‚   └── FullResultsModal.tsx        # Modal for large datasets
β”‚   └── lib/
β”‚       β”œβ”€β”€ db.ts                # SQLite database operations
β”‚       β”œβ”€β”€ mcp.ts               # MCP server and tools
β”‚       └── query-cache.ts       # Query result caching (legacy)
β”œβ”€β”€ public/                      # Static assets
β”‚   └── logo.png                 # Application logo
β”œβ”€β”€ package.json                 # Next.js app configuration
└── .env.local                   # Environment variables

βš™οΈ How It Works

Query Pipeline

  1. User Input: User submits a natural language question
  2. Schema Fetch: Backend retrieves database schema and relationships via MCP
  3. Query Decision: LLM determines if a SQL query is needed
  4. SQL Generation: If needed, LLM generates a SELECT query
  5. Query Execution: MCP executes the query in a secure sandbox
  6. UI Generation: LLM generates openui-lang code for visualization
  7. Rendering: React components render charts, tables, or metrics

Large Dataset Handling

When query results exceed 50 rows:

  1. Full results are saved to the database
  2. A 20-row preview is sent to the LLM
  3. LLM generates a "View All" button
  4. Clicking the button opens FullResultsModal with:
    • Infinite scroll pagination (100 rows/page)
    • Server-side search across all columns
    • Print functionality for all data

πŸ› οΈ MCP Tools

The application uses 6 MCP tools for database interaction:

Tool Description
get_schema Returns complete database schema (tables, columns, foreign keys)
list_tables Lists all tables with column/row counts
get_table_details Detailed info for a specific table with sample data
get_database_relationships All foreign key relationships
get_sample_data Sample rows from a table
run_query Executes SELECT/WITH queries with security validation

Security: Only SELECT and WITH queries are allowed. Dangerous patterns (DROP, DELETE, UPDATE, etc.) are blocked.


πŸ—„οΈ Database Schema

The pre-seeded university.db contains a comprehensive University Management System:

Category Tables
Campus & Organization campuses, departments, degree_programs, academic_terms, classrooms
Staff Management staff, staff_positions_history, staff_salary_payouts, staff_attendance
Student Management students, admissions, student_program_enrollments, student_transfers
Academics sections, course_catalog, program_curriculum, staff_subject_allocations
Scheduling timetable_slots, timetable_entries, student_attendance
Assessments assessments, student_results
Fees & Finance student_fee_invoices, student_fee_payments
Library library_books, library_book_copies, library_memberships, library_loans
Transport transport_routes, transport_stops, student_transport_enrollments
Other study_materials, support_tickets

Views: vw_student_cgpa, vw_fee_outstanding


πŸ§‘β€πŸ’» Tech Stack

Layer Technology
Frontend React 19, Next.js 16, Tailwind CSS
UI Framework @openuidev/react-ui, @openuidev/react-lang
AI/LLM Google Gemini (via OpenAI-compatible API)
Database SQLite (better-sqlite3)
Protocol Model Context Protocol (MCP)
Streaming Server-Sent Events (SSE)

βš™οΈ Setup & Installation

Prerequisites

  • Node.js 18+
  • Google Gemini API key

Environment Variables

Create .env inside the root directory with:

# LLM API Key
LLM_API_KEY=your_llm_api_key

# LLM API Base URL (OpenAI-compatible)
LLM_BASE_URL=base URL of your LLM

# Path to SQLite database 
DB_PATH=database/university.db

Installation

# Install dependencies
npm install

# Start development server
npm run dev

The application will be available at http://localhost:3000

Production Build

npm run build
npm start

πŸ’¬ Sample Queries

Try these conversation starters:

  • "How many students are currently enrolled? Break it down by department."
  • "Show me the top 5 departments ranked by the number of students enrolled."
  • "What is the current fee collection status? How much is pending vs paid?"
  • "Give me an overview of all active courses grouped by department."

πŸ“Š Storage

The application uses two SQLite databases:

Database Location Purpose
university.db database/ Source data (read-only)
chats.db Root directory Chat threads, messages, and cached query results

Tables in chats.db:

  • threads: Chat conversation threads
  • messages: Individual messages within threads
  • query_results: Cached results for large dataset queries

πŸ”’ Security

  • Query Validation: Only SELECT and WITH queries allowed
  • SQL Injection Protection: Blocks dangerous patterns (DROP, DELETE, UPDATE, etc.)
  • Read-Only Database: Source database is opened in read-only mode
  • No Comment Injection: Blocks SQL comments (--, /* */)

πŸ—ΊοΈ Roadmap

  • Add support for multiple database drivers (PostgreSQL, MySQL, etc.)
  • Implement IAM / Auth based access control for Retrieval
  • Build a custom UI component library for better UI and more use case coverage
  • Enhance text2SQL module while reducing the LLM dependency, so that we can even use smaller LLMs in future
  • Introduce full-coverage unit testing setup

πŸ“ License

See LICENSE for details.

About

SeeQL is an AI-powered conversational interface for querying databases using natural language. It lets users ask complex questions in plain English and receive rich, visual dashboards (Charts, Graphs, Tables, Metrics) instead of raw SQL results.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages