A powerful natural language processing application that enables users to query database information using plain English. This comprehensive tool integrates cutting-edge AI technology with robust database connectivity to provide intuitive data exploration and analysis capabilities.
- Overview
- Key Features
- System Architecture
- Technology Stack
- Installation
- Usage Guide
- Database Support
- Security Features
- Configuration Options
- Troubleshooting
- Development
- Contributing
- License
The NLP Engine for Employee Data is an intelligent interface that bridges the gap between non-technical users and complex database systems. Built on a modern tech stack featuring React, TypeScript, and Google's Gemini AI, it enables users to:
- Query complex databases using natural language
- Visualize database schema and relationships
- Generate instant, professional data visualizations
- Receive AI-powered suggestions for analysis
- Upload and process file-based data alongside databases
- Securely manage multiple database connections
This application is ideal for HR professionals, data analysts, managers, and anyone who needs to work with employee data without writing SQL queries manually.
- Natural Language Queries: Ask questions about your data in plain English without writing SQL
- Multi-Database Support: Connect to MySQL, PostgreSQL, SQLite, and SQL Server databases
- Schema Discovery and Visualization: Automatically analyze and visualize database structures
- AI-Powered Analysis: Use Google's Gemini AI to convert natural language to SQL and provide insights
- Smart Query Caching: Performance optimizations for frequently asked questions
- File-Based Data Processing: Upload and analyze CSV, JSON, and other structured data files
- Real-time Data Visualization: Generate charts, graphs and tables from query results
- Secure Architecture: Dedicated Node.js server handles all database connections safely
- Enterprise-Grade Security: Rate limiting, CORS protection, and SQL injection prevention
- Multi-Project Management: Create and manage multiple projects with different data sources
- Chat Interface: Conversational UI for intuitive data exploration
- Dark/Light Mode: Customizable UI theme for comfortable viewing
- Cross-Platform Compatibility: Works on Linux, macOS, and Windows environments
The application is structured using a modern client-server architecture:
- UI Components: React-based interface with TypeScript for type safety
- State Management: React hooks with local storage persistence
- API Communication: Fetch API for communication with backend server
- Data Visualization: Dynamic rendering of query results in various formats
- Theming System: Customizable light/dark mode with Tailwind CSS
- API Server: Express.js server handling HTTP requests
- Connection Management: Secure pooling and management of database connections
- Query Processing: Translation of natural language to SQL with AI assistance
- Schema Analysis: Automatic detection of tables, columns, and relationships
- Security Middleware: Rate limiting, CORS, and input validation
- Error Handling: Comprehensive error capture and client-friendly responses
- Gemini API: Integration with Google's Gemini AI model
- Context Building: Conversation history management for contextual understanding
- Query Generation: Conversion of natural language to SQL queries
- Error Recovery: Intelligent handling of query errors and suggestion generation
- Framework: React 19 with TypeScript
- Build Tool: Vite for fast development and optimized builds
- Styling: Tailwind CSS for responsive design
- UI Components: Custom component library with responsive design
- Runtime: Node.js with Express
- Database Drivers: MySQL2, PostgreSQL, SQLite3, and SQL Server
- Security: Helmet, Express Rate Limit, CORS
- Utilities: UUID for ID generation, nodemon for development
- NLP Engine: Google Gemini API
- Text Processing: Custom context management and prompt engineering
- Query Analysis: Pattern recognition for SQL generation
- Node.js: Version 18 or higher
- NPM: Version 8 or higher
- Databases: Any of MySQL, PostgreSQL, SQLite, or SQL Server (optional)
- API Key: Google Gemini API key for AI functionality
# Clone the repository
git clone https://github.com/rinu143/NLP-Engine-for-employee-data.git
cd NLP-Engine-for-employee-data
# Start the application
./start.sh# Clone the repository
git clone https://github.com/rinu143/NLP-Engine-for-employee-data.git
cd NLP-Engine-for-employee-data
# Start the application
start.bat
# Or for simpler display without colors:
start-plain.batIf you prefer to set up manually:
- Install Dependencies
# Install frontend dependencies
npm install
# Install server dependencies
cd server
npm install
cd ..- Environment Setup
Create a
.envfile in the root directory:
VITE_GEMINI_API_KEY=your_gemini_api_key_here- Start Services
# Terminal 1: Start database server
cd server
npm run dev
# Terminal 2: Start frontend
npm run dev- Access the Application
Open your browser and navigate to
http://localhost:3001
-
Launch the Application: After starting the application, you'll be presented with a login screen. Click "Sign in with Google" (mock login for demonstration purposes).
-
Create a New Project: Click the "New Project" button in the sidebar.
-
Name Your Project: Click on the project name to edit it and give it a meaningful name related to your data.
-
Project Organization: The application allows you to manage multiple projects, each with its own database connections, files, and chat history.
-
Database Panel: Navigate to the database panel in your project.
-
Connection String: Enter a connection string for your database. The system supports:
- MySQL:
mysql://username:password@hostname:port/database - PostgreSQL:
postgresql://username:password@hostname:port/database - SQLite:
sqlite:///path/to/database.db - SQL Server:
mssql://username:password@hostname:port/database
- MySQL:
-
Connection Test: The system automatically tests the connection and displays the status.
-
Schema Discovery: Upon successful connection, the application automatically discovers and displays your database schema.
-
File Upload: If you don't have a database, you can upload structured data files (CSV, JSON, etc.).
-
Schema Inference: The system automatically analyzes uploaded files to infer their structure.
-
File Management: Uploaded files appear in the Files panel where they can be viewed, analyzed, or removed.
-
Chat Interface: Use the chat panel to interact with your data using natural language.
-
Query Examples:
- "Show me all employees in the Sales department"
- "What's the average salary by department?"
- "Who has been working here for more than 5 years?"
- "Show me a breakdown of employees by job title"
-
Context Awareness: The system maintains conversation context, so you can ask follow-up questions.
-
Automatic Visualization: Query results are automatically rendered in the most appropriate format (tables, charts).
-
Customization: Some visualizations can be customized by clicking on elements or using the visualization controls.
-
Export Options: Data can be exported for use in other applications.
mysql://username:password@hostname:port/database
mysql://root:password@localhost:3306/employees_db
postgresql://username:password@hostname:port/database
postgres://username:password@hostname:port/database
sqlite:///absolute/path/to/database.db
sqlite://./relative/path/to/database.db
mssql://username:password@hostname:port/database
sqlserver://username:password@hostname:port/database
The NLP Engine incorporates multiple layers of security:
-
Database Connection Security:
- Connection strings are never stored in plain text in the browser
- All database operations go through a secure server layer
- Read-only operations by default, with no data modification capabilities
-
API Security:
- Rate limiting to prevent abuse
- CORS protection
- Helmet.js for HTTP header security
-
Input Validation:
- SQL injection prevention
- Input sanitization for all user inputs
- Prepared statements for database queries
-
Error Handling:
- Secure error messages that don't leak implementation details
- Comprehensive server-side logging
- Graceful failure recovery
-
Authentication & Session Management:
- Secure logout functionality with complete cache and storage clearing
- Session data management through localStorage
- Mock authentication system (can be extended to real authentication)
The application uses environment variables for configuration:
VITE_GEMINI_API_KEY: Your Google Gemini API keyPORT: Server port (defaults to 3002 if not specified)
The backend server's behavior can be customized through:
- Rate limiting parameters in
server.js - CORS settings for controlling allowed origins
- Database connection timeouts and pool settings
User preferences that persist across sessions:
- Selected theme (light/dark mode)
- Active project selection
- Chat history and context
-
Connection Errors:
- Verify your database is running and accessible
- Check connection string format for proper escaping of special characters
- Ensure database user has appropriate permissions
-
API Key Issues:
- Verify your Gemini API key is correctly set in the
.envfile - Check for API usage limits or restrictions
- Verify your Gemini API key is correctly set in the
-
Performance Problems:
- Large databases may require more time for schema discovery
- Complex queries might take longer to process
- Consider clearing the cache if responses seem stale
The application maintains logs at multiple levels:
- Frontend console logs for UI interactions
- Server logs for database operations and errors
- Performance metrics tracked per project
NLP-Engine-for-employee-data/
├── components/ # React UI components
│ ├── ChatPanel.tsx # Chat interface component
│ ├── Dashboard.tsx # Main application dashboard
│ ├── DatabasePanel.tsx # Database connection management
│ ├── DataVisualizer.tsx # Data visualization component
│ ├── FilePanel.tsx # File upload and management
│ ├── FormattedContent.tsx # Content formatting utilities
│ ├── LibraryView.tsx # Library/resource browser
│ ├── LoginPage.tsx # Authentication component
│ ├── SchemaViewer.tsx # Database schema visualization
│ └── Sidebar.tsx # Application navigation sidebar
├── server/ # Backend server components
│ ├── server.js # Express server main file
│ ├── services/ # Server-side services
│ │ ├── ConnectionManager.js # Database connection pooling
│ │ └── DatabaseService.js # Database operations
│ └── local_database.db # Default SQLite database
├── services/ # Frontend services
│ ├── databaseService.ts # Frontend DB communication service
│ └── geminiService.ts # AI service integration
├── App.tsx # Main React application
├── constants.ts # Application constants
├── index.html # HTML entry point
├── index.tsx # Application entry point
├── package.json # Frontend dependencies
├── start.sh # Linux/macOS startup script
├── start.bat # Windows startup script
├── start-plain.bat # Plain text Windows startup script
├── types.ts # TypeScript type definitions
└── vite.config.ts # Vite build configuration
To build the application from source:
# Build the frontend
npm run build
# The output will be in the dist/ directory
# Serve the built application with a static server
npm run preview# Run frontend tests
npm test
# Run server tests
cd server
npm testContributions are welcome! Here's how you can contribute to the project:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Google Gemini API for natural language processing capabilities
- The React and TypeScript teams for their excellent frameworks
- The open-source database driver communities for SQLite, MySQL, PostgreSQL, and SQL Server
### SQLite
```bash
sqlite:////absolute/path/to/database.db
sqlite:////tmp/skillsync_enterprise.db
sqlite://./relative/path/database.db
mssql://username:password@hostname:port/database
sqlserver://sa:password@localhost:1433/CompanyDB- "Show me all employees in the IT department"
- "List employees with salary greater than 75000"
- "Find all managers and their contact information"
- "What's the average salary by department?"
- "Count employees hired each year"
- "Show department with highest turnover rate"
- "Find the top 5 highest paid employees with their managers"
- "Show salary distribution across all departments"
- "List employees hired in the last 6 months with their positions"
The database server provides these endpoints:
POST /api/test-connection- Test database connectionPOST /api/close-connection- Close database connectionGET /api/connections- List active connections
POST /api/discover-schema- Discover database schemaPOST /api/execute-query- Execute SELECT queries
GET /health- Server health check
- Rate Limiting: 100 requests per 15 minutes per IP
- CORS Protection: Configured for development environments
- SQL Injection Prevention: Only SELECT queries allowed
- Connection Limits: Maximum 50 concurrent connections
- Auto Cleanup: Connections expire after 30 minutes
- Input Validation: All parameters validated and sanitized
The server provides comprehensive logging:
Successfully connected to mysql database: employees_db
Schema extracted: 8 tables, 45 columns, 6 tables with relationships
Query executed successfully: 25 rows returned- Connection failures with detailed error messages
- Query execution errors and timeouts
- Schema discovery issues
- Rate limiting and security events
Frontend:
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production build
Server:
npm run dev- Start server with auto-reloadnpm start- Start server in production mode
├── components/ # React components
│ ├── ChatPanel.tsx # Natural language interface
│ ├── Dashboard.tsx # Main application
│ ├── DatabasePanel.tsx # Connection management
│ └── ... # Other UI components
├── services/ # Frontend services
│ ├── databaseService.ts # Server communication
│ └── geminiService.ts # AI integration
├── server/ # Backend server
│ ├── server.js # Express application
│ ├── services/ # Database services
│ │ ├── DatabaseService.js # Database operations
│ │ └── ConnectionManager.js # Connection pooling
│ └── package.json # Server dependencies
├── types.ts # TypeScript definitions
├── start.sh # Startup script
└── README.md # This file
Database Server Not Running:
Error: Cannot connect to database server at http://localhost:3002
Solution: Make sure the server is running with `cd server && npm run dev`Database Connection Failed:
Error: Failed to connect to mysql database: Access denied
Solution: Verify credentials and database permissionsSQLite File Access:
Error: SQLite database file not accessible
Solution: Check file path and permissions, use absolute pathsSlow Schema Discovery:
- Large databases may take 10-15 seconds
- Check database performance and indexes
- Consider connection timeout settings
Query Timeouts:
- Complex queries have 30-second timeout
- Optimize queries or increase timeout
- Check database server performance
Port Conflicts:
- Frontend: Change port in
vite.config.ts - Server: Set
PORTenvironment variable
CORS Errors:
- Check server CORS configuration
- Verify frontend is calling correct server URL
VITE_GEMINI_API_KEY=your_api_keyPORT=3002
NODE_ENV=production
MAX_CONNECTIONS=50
CONNECTION_TIMEOUT=1800000- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Database Support: MongoDB, Oracle, Redis integration
- Advanced Analytics: Data visualization dashboard
- Query Management: History, saved queries, templates
- Multi-tenancy: User authentication and data isolation
- Export Features: CSV, Excel, PDF report generation
- Real-time Data: WebSocket streaming for live updates
- Performance: Query optimization suggestions
- Deployment: Docker containers and cloud deployment guides
- 🐛 Issues: Create GitHub issues for bugs
- 💡 Features: Request features via GitHub discussions
- 📖 Documentation: Check server README in
/server/README.md - 🔧 Development: Review troubleshooting section above
Made with ❤️ for better data accessibility