A full-stack application that transforms natural language into SQL queries using AI. Built with Flask backend and React frontend.
- Natural Language to SQL: Convert plain English to SQL queries
- OpenAI Integration: Powered by GPT-3.5-turbo for accurate query generation
- Query Explanation: AI-generated explanations in plain English
- Query Improvements: AI suggestions for query optimization
- JWT Authentication: Secure token-based authentication
- Password Hashing: bcrypt password security
- Protected Routes: Route guards for authenticated users
- Rate Limiting: Protection against API abuse
- Multiple Projects: Create and manage multiple SQL projects
- Schema Management: Store and manage database table schemas
- Query History: Track and search through generated queries
- Project Statistics: Analytics and insights
- Dark Theme: Beautiful dark mode with glass morphism
- Responsive Design: Mobile-first approach
- Smooth Animations: Framer Motion powered transitions
- Real-time Feedback: Toast notifications and loading states
- Framework: Flask with Python 3.8+
- Database: MongoDB with PyMongo
- Authentication: JWT with Flask-JWT-Extended
- AI Integration: OpenAI GPT-3.5-turbo
- Validation: Marshmallow schemas
- Security: bcrypt, rate limiting, CORS
- Framework: React 18+ with TypeScript
- Styling: Tailwind CSS with shadcn/ui
- State Management: Zustand with persistence
- API Integration: TanStack Query (React Query)
- Routing: React Router v6
- Forms: React Hook Form with Zod validation
- Python 3.8+
- Node.js 18+
- MongoDB (local or cloud)
- OpenAI API key
git clone <repository-url>
cd QueryCraft./start-app.shThis script will:
- Check and start MongoDB
- Set up environment files
- Install dependencies
- Start both backend and frontend
cd server
cp env.example .env
# Edit .env with your configuration
pip install -r requirements.txt
python app.pycd web
echo "VITE_API_URL=http://localhost:5000/api" > .env
npm install
npm run dev- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- API Documentation: http://localhost:5000/api
MONGODB_URI=mongodb://localhost:27017/sql_query_generator
SECRET_KEY=your-super-secret-key
JWT_SECRET_KEY=your-jwt-secret-key
OPENAI_API_KEY=your-openai-api-key
CORS_ORIGINS=http://localhost:3000VITE_API_URL=http://localhost:5000/apiPOST /api/auth/register - User registration
POST /api/auth/login - User login
GET /api/auth/me - Get current user
POST /api/auth/refresh - Refresh JWT token
POST /api/projects - Create project
GET /api/projects - List user projects
GET /api/projects/{id} - Get project details
PUT /api/projects/{id} - Update project
DELETE /api/projects/{id} - Delete project
POST /api/projects/{id}/schema - Create/update schemas
GET /api/projects/{id}/schema - Get project schemas
PUT /api/projects/{id}/schema - Replace all schemas
POST /api/projects/{id}/query - Generate SQL query
GET /api/projects/{id}/queries - List project queries
GET /api/queries/{id}/explain - Get detailed explanation
GET /api/queries/{id}/improve - Get improvement suggestions
- Sign up/login to the application
- Click "New Project" on the dashboard
- Enter project name and description
- Save the project
- Navigate to your project
- Go to the Schema section
- Add table schemas in JSON format:
{
"schemas": [
{
"table_name": "users",
"table_schema": {
"columns": [
{ "name": "id", "type": "INTEGER", "primary_key": true },
{ "name": "username", "type": "VARCHAR(50)", "unique": true },
{ "name": "email", "type": "VARCHAR(100)", "unique": true }
]
}
}
]
}- Go to the Query section
- Enter natural language request:
- "Show me all users who registered in the last 30 days"
- "Find products with low stock (less than 10 items)"
- "Get total sales by category"
- Click "Generate Query"
- Review the generated SQL and explanation
QueryCraft/
βββ server/ # Flask Backend
β βββ app/
β β βββ models/ # MongoDB models
β β βββ routes/ # API endpoints
β β βββ services/ # Business logic
β β βββ utils/ # Utilities
β β βββ config/ # Configuration
β βββ requirements.txt # Python dependencies
β βββ app.py # Main application
β βββ README.md # Backend documentation
βββ web/ # React Frontend
β βββ src/
β β βββ components/ # React components
β β βββ pages/ # Page components
β β βββ store/ # Zustand stores
β β βββ lib/ # Utilities and services
β β βββ types/ # TypeScript interfaces
β βββ package.json # Node.js dependencies
β βββ README.md # Frontend documentation
βββ start-app.sh # Full stack startup script
βββ README.md # This file
- Set production environment variables
- Use Gunicorn or uWSGI
- Set up MongoDB with authentication
- Configure reverse proxy (Nginx/Apache)
- Set up SSL/TLS certificates
- Build the application:
npm run build - Deploy to Vercel, Netlify, or similar
- Set environment variables
- Configure API URL for production
cd server
python test_api.pycd web
npm run test- Password Hashing: bcrypt with salt
- JWT Authentication: Secure token-based auth
- Input Validation: Comprehensive validation
- SQL Injection Prevention: Query validation
- Rate Limiting: Protection against abuse
- CORS Configuration: Controlled cross-origin requests
- 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.
For issues and questions:
- Check the documentation
- Review the console logs
- Ensure all services are running
- Create an issue in the repository
- OpenAI for GPT-3.5-turbo API
- Flask and React communities
- shadcn/ui for beautiful components
- All contributors and users