A powerful Flask web application that converts natural language queries into SQL statements and executes them across multiple database systems using AI-powered query generation.
- User Registration & Login: Secure user authentication with bcrypt password hashing
- Role-Based Access Control (RBAC): Two user roles with different permissions
- Admin: Full database access (SELECT, INSERT, UPDATE, DELETE)
- User: Read-only access (SELECT queries only)
- Session Management: Secure session handling with automatic logout
- MySQL: Full support with optimized connection handling
- PostgreSQL: Complete PostgreSQL integration
- SQLite: Lightweight database support for local development
- SQL Server: Enterprise-grade SQL Server connectivity
- Natural Language Processing: Convert plain English to SQL using Groq's LLaMA model
- Schema-Aware: Automatically analyzes database structure for accurate query generation
- Syntax Optimization: Database-specific query optimization and formatting
- Error Handling: Intelligent error detection and user-friendly error messages
- SQL Injection Protection: SQLAlchemy parameterized queries
- Input Validation: Comprehensive input sanitization
- Access Control: Role-based query restrictions
- Session Security: Secure session management with encrypted cookies
- Responsive Design: Mobile-friendly interface
- Real-time Feedback: Instant connection status and query results
- Interactive Forms: Dynamic database connection forms
- Result Visualization: Tabular display of query results
- Python 3.8+
- MongoDB (for user management)
- Database system(s) you want to connect to
- Groq API key
-
Clone the repository
git clone <repository-url> cd database-interface-app
-
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables Create a
.envfile in the root directory:# Application Settings SECRET_KEY=your-secret-key-here # MongoDB Configuration MONGODB_URI=mongodb://localhost:27017/ MONGODB_DATABASE=database_app # Groq API Configuration GROQ_API_KEY=your-groq-api-key-here
-
Run the application
python app.py
-
Access the application Open your browser and navigate to
http://localhost:5000
Flask==2.3.3
Flask-Bcrypt==1.0.1
pymongo==4.5.0
pymysql==1.1.0
psycopg2-binary==2.9.7
pyodbc==4.0.39
SQLAlchemy==2.0.21
langchain-groq==0.1.6
langchain==0.2.6
python-dotenv==1.0.0
database-interface-app/
βββ app.py # Main application file
βββ requirements.txt # Python dependencies
βββ .env # Environment variables (create this)
βββ templates/ # HTML templates
β βββ index.html # Main dashboard
β βββ login.html # Login page
β βββ register.html # Registration page
βββ static/ # Static assets
β βββ css/ # Stylesheets
βββ README.md # This file
The application supports multiple database types with specific configuration requirements:
DB_CONFIG = {
'server': 'localhost',
'port': 3306,
'database': 'your_database',
'username': 'your_username',
'password': 'your_password'
}DB_CONFIG = {
'server': 'localhost',
'port': 5432,
'database': 'your_database',
'username': 'your_username',
'password': 'your_password'
}DB_CONFIG = {
'database_path': '/path/to/your/database.db'
}DB_CONFIG = {
'server': 'localhost',
'port': 1433,
'database': 'your_database',
'username': 'your_username',
'password': 'your_password'
}- Sign up at Groq Console
- Create an API key
- Add the key to your
.envfile - The application uses the
llama3-70b-8192model for query generation
- Navigate to
/register - Fill in your details
- Select your role (Admin or User)
- Click "Register"
- Log in to your account
- Select your database type
- Enter connection details
- Click "Connect"
Once connected, you can enter natural language queries such as:
Example Queries:
- "Show me all users"
- "Find customers from New York"
- "Count the number of orders this month"
- "Update user email where id is 5" (Admin only)
- "Delete inactive users" (Admin only)
- Results are displayed in a formatted table
- Generated SQL queries are shown for transparency
- Error messages provide helpful debugging information
- Passwords are hashed using bcrypt
- Session tokens are securely generated
- Automatic session expiration
- Parameterized queries prevent SQL injection
- Connection strings are encrypted
- Database credentials are not logged
- Role-based permissions enforce data access policies
- User role restrictions prevent unauthorized modifications
- Admin oversight for sensitive operations
Connection Errors
- Verify database credentials
- Check network connectivity
- Ensure database server is running
Query Generation Errors
- Verify Groq API key is valid
- Check natural language query clarity
- Ensure database schema is accessible
Permission Errors
- Verify user role permissions
- Check database user privileges
- Confirm table access rights
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Verify the users mail sending otp
- Forgot password
- Report Generation
- Query Optimization





