Query GPT

April 4, 2025 ยท View on GitHub

Query GPT

Convert natural language to SQL queries instantly with AI

Overview

Query GPT is a modern web application that transforms natural language questions into SQL and NoSQL database queries using advanced language models. The application provides an intuitive interface for generating queries across multiple database systems and offers features like syntax highlighting, schema analysis, and easy query sharing.

Live Demo

๐Ÿ”— Try Query GPT Online

Experience the tool directly in your browser without any installation.

Table of Contents

Project Architecture

graph TD
    A[User Interface] --> B[Query Generator]
    B --> C[AI Model API]
    B --> D[Database Type Selection]
    E[Schema Input] --> B
    F[Query Input] --> B
    B --> G[Generated Query with Syntax Highlighting]
    A --> H[Features Display]
    C --> I[Language Model Selection]
    C --> J[Context Handling]
    
    style A fill:#f9f,stroke:#333,stroke-width:2px
    style B fill:#bbf,stroke:#333,stroke-width:2px
    style C fill:#fbf,stroke:#333,stroke-width:2px
    style G fill:#bfb,stroke:#333,stroke-width:2px
    style I fill:#fbf,stroke:#333,stroke-width:2px
    style J fill:#fbf,stroke:#333,stroke-width:2px

Technology Stack

CategoryTechnologies
Frontend FrameworkReact, TypeScript
Build ToolVite
StylingTailwindCSS, Shadcn UI
State ManagementReact Hooks, Context API
Data FetchingTanStack Query (React Query)
RoutingReact Router
UI ComponentsRadix UI, Lucide React icons
Form HandlingReact Hook Form, Zod validation
AI IntegrationOpenRouter API, LLM prompting
Developer ToolsESLint, TypeScript

Core Features

  • ๐Ÿค– AI-Powered Query Generation: Transforms natural language to SQL using advanced LLMs
  • ๐Ÿ—„๏ธ Multi-Database Support: Generates queries for SQL, MySQL, PostgreSQL, SQL Server, SQLite, and MongoDB
  • ๐Ÿ” Schema Analysis: Interprets database schemas to create accurate queries
  • โœจ Syntax Highlighting: Displays generated queries with code highlighting
  • ๐Ÿ“ฑ Responsive Design: Works seamlessly across desktop and mobile devices
  • ๐Ÿ”„ Preferences Saving: Remembers your model and language preferences
  • ๐Ÿ“‹ One-Click Copy: Easy sharing of generated queries

AI Capabilities

  • Multiple LLM Support: Integrate with various language models through OpenRouter
  • Context-Aware Queries: Generate database queries that understand table relationships and schema context
  • Intelligent Schema Analysis: AI analyzes provided schemas to generate accurate and optimized queries
  • Natural Language Understanding: Process complex questions and convert them to precise database queries
  • Query Optimization: Suggestions for query performance improvements based on schema analysis
  • Model Selection: Choose from different AI models based on your specific needs and performance requirements
  • Prompt Engineering: Optimized prompts for generating accurate SQL and NoSQL queries
  • Real-time Generation: Fast response times for an interactive query development experience

Getting Started

If you want to work locally using your own IDE, you can clone this repo and push changes.

The only requirement is having Node.js & npm installed - install with nvm

Follow these steps:

# Step 1: Clone the repository using the project's Git URL.
git clone <YOUR_GIT_URL>

# Step 2: Navigate to the project directory.
cd <YOUR_PROJECT_NAME>

# Step 3: Install the necessary dependencies.
npm i

# Step 4: Create a .env file based on .env.example and add your OpenRouter API key.
cp .env.example .env
# Edit .env and add your OpenRouter API key (get one from https://openrouter.ai/keys)

# Step 5: Start the development server with auto-reloading and an instant preview.
npm run dev

Key Components

ComponentPurposeFile Location
QueryGeneratorCore query generation functionalitysrc/components/QueryGenerator.tsx
SchemaInputDatabase schema input interfacesrc/components/SchemaInput.tsx
QueryInputNatural language question inputsrc/components/QueryInput.tsx
CodeDisplaySyntax highlighted query displaysrc/components/CodeDisplay.tsx
ModelSelectorAI model and DB type selectionsrc/components/ModelSelector.tsx
AIProviderManages AI model connections and contextsrc/providers/AIProvider.tsx
HeroMain landing sectionsrc/components/Hero.tsx
FeaturesFeature showcase sectionsrc/components/Features.tsx

Project Structure

query-gpt/
โ”œโ”€โ”€ src/                     # Source code
โ”‚   โ”œโ”€โ”€ components/          # React components
โ”‚   โ”‚   โ”œโ”€โ”€ ui/              # UI component library (Shadcn)
โ”‚   โ”‚   โ”œโ”€โ”€ QueryGenerator.tsx  # Main query generation component
โ”‚   โ”‚   โ””โ”€โ”€ ...              # Other components
โ”‚   โ”œโ”€โ”€ hooks/               # Custom React hooks
โ”‚   โ”‚   โ”œโ”€โ”€ useAIModel.ts    # Hook for AI model management
โ”‚   โ”‚   โ””โ”€โ”€ ...              # Other hooks
โ”‚   โ”œโ”€โ”€ lib/                 # Utility functions and helpers
โ”‚   โ”‚   โ”œโ”€โ”€ ai/              # AI-related utilities and API clients
โ”‚   โ”‚   โ””โ”€โ”€ ...              # Other utilities
โ”‚   โ”œโ”€โ”€ pages/               # Page components
โ”‚   โ””โ”€โ”€ App.tsx              # Main application component
โ”œโ”€โ”€ public/                  # Static assets
โ”œโ”€โ”€ index.html               # HTML entry point
โ”œโ”€โ”€ vite.config.ts           # Vite configuration
โ”œโ”€โ”€ tailwind.config.ts       # Tailwind CSS configuration
โ””โ”€โ”€ package.json             # Project dependencies and scripts

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request