A sophisticated full-stack application that leverages artificial intelligence to facilitate natural language interactions with relational and NoSQL databases. This system translates conversational queries into optimized SQL statements while maintaining session context, comprehensive audit logs, and enterprise-grade security.
DataMind Chat provides a seamless interface for non-technical users to query databases through natural conversation. The platform comprises a modern React frontend and a robust FastAPI backend, enabling secure, authenticated access to multiple database systems through AI-powered SQL generation.
graph TB
subgraph Frontend["Frontend Layer"]
React["React TypeScript Application"]
UI["UI Components & State Management"]
end
subgraph Backend["API Layer"]
FastAPI["FastAPI Server"]
Auth["JWT Authentication"]
Chat["Chat Processing"]
end
subgraph Processing["Processing Layer"]
OpenAI["OpenAI GPT-4 Integration"]
SQLGen["SQL Generation"]
Validation["Query Validation"]
end
subgraph Data["Data Layer"]
PostgreSQL["PostgreSQL"]
MySQL["MySQL"]
MongoDB["MongoDB"]
SQLite["SQLite Logs"]
end
React -->|API Requests| FastAPI
FastAPI --> Auth
FastAPI --> Chat
Chat --> OpenAI
OpenAI --> SQLGen
SQLGen --> Validation
Validation --> PostgreSQL
Validation --> MySQL
Validation --> MongoDB
FastAPI -->|Query Logs| SQLite
- JWT-based token authentication for all API endpoints
- Secure credential management through environment variables
- Role-based access control with read-only database operations
- Session isolation and user context tracking
- PostgreSQL with full schema introspection
- MySQL with comprehensive table metadata
- MongoDB with collection structure analysis
- Extensible architecture for additional database systems
- OpenAI GPT-4 powered natural language to SQL conversion
- Context-aware query generation based on database schema
- Intelligent error handling and query optimization
- Session memory for maintaining conversation context
- Query execution logging with SQLite backend
- Complete audit trail of user interactions
- Schema viewer API for database structure exploration
- Secure SELECT-only query execution
- Docker containerization for seamless deployment
- Environment-based configuration management
- Production-grade security recommendations
- Health check endpoints for monitoring
| Component | Technology |
|---|---|
| Frontend | React, TypeScript, Vite, Tailwind CSS |
| Backend | FastAPI, Python 3.11+ |
| Authentication | JWT (JSON Web Tokens) |
| AI Integration | OpenAI API |
| Databases | PostgreSQL, MySQL, MongoDB, SQLite |
| Containerization | Docker |
| Package Manager | Bun (Frontend), pip (Backend) |
- Python 3.11 or higher
- Node.js 18+ (for frontend development)
- Docker (optional, for containerized deployment)
- Git for version control
- OpenAI API key with GPT-4 access
- Database connection strings for target systems
- Secure secret key for JWT operations
-
Navigate to backend directory:
cd backend -
Create virtual environment:
python3 -m venv venv source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables:
cp .env.example .env
Update
.envwith your credentials:OPENAI_API_KEY=your_openai_key_here POSTGRES_URL=postgresql://user:password@host:5432/database MYSQL_URL=mysql://user:password@host:3306/database MONGO_URL=mongodb://user:password@host:27017/database JWT_SECRET=your_secure_secret_key JWT_ALGORITHM=HS256
-
Run the server:
uvicorn app.main:app --reload
API available at
http://localhost:8000
-
Install dependencies:
bun install
-
Start development server:
bun run dev
-
Build for production:
bun run build
docker build -t datamind-chat-backend .docker run \
--env-file .env \
-p 8000:8000 \
--name datamind-backend \
datamind-chat-backendFor multi-container orchestration with databases:
docker-compose up -dPOST /auth/login
POST /auth/logout
POST /auth/refresh
POST /chat
Request body: { "message": "string", "database": "string" }
Response: { "response": "string", "query": "string", "timestamp": "ISO8601" }
GET /logs?skip=0&limit=10
Response: [{ "id": int, "user_id": int, "query": "string", "timestamp": "ISO8601" }]
GET /schema/{database_type}
Response: { "tables": [...], "schemas": [...] }
GET /health
Response: { "status": "healthy" }
| Variable | Description | Example |
|---|---|---|
OPENAI_API_KEY |
OpenAI API authentication key | sk-... |
POSTGRES_URL |
PostgreSQL connection string | postgresql://user:pass@localhost:5432/db |
MYSQL_URL |
MySQL connection string | mysql://user:pass@localhost:3306/db |
MONGO_URL |
MongoDB connection string | mongodb://user:pass@localhost:27017/db |
JWT_SECRET |
Secret key for JWT signing | your-secret-key-min-32-chars |
JWT_ALGORITHM |
JWT algorithm | HS256 |
LOG_LEVEL |
Application logging level | INFO, DEBUG, ERROR |
graph LR
A["Frontend<br/>src/"] -->|API Calls| B["Backend<br/>app/"]
B --> C["API<br/>api.py"]
B --> D["Auth<br/>auth.py"]
B --> E["Database<br/>db.py"]
B --> F["Models<br/>models.py"]
B --> G["AI Client<br/>openai_client.py"]
Enable debug logging:
export LOG_LEVEL=DEBUG
uvicorn app.main:app --reload --log-level debug- Set
JWT_SECRETto a cryptographically secure random string (minimum 32 characters) - Implement HTTPS with valid SSL/TLS certificates
- Use environment variable management systems (AWS Secrets Manager, HashiCorp Vault)
- Configure database users with read-only permissions
- Enable query result pagination to prevent data exfiltration
- Implement rate limiting on API endpoints
- Set up monitoring and alerting for unusual access patterns
- Deploy with production ASGI server (Gunicorn, Uvicorn)
- Implement Redis for session persistence instead of in-memory storage
- Configure database connection pooling
- Enable query caching for frequent requests
- Use CDN for static frontend assets
- Implement centralized logging (ELK Stack, Datadog)
- Monitor API response times and error rates
- Track database query performance
- Set up alerts for authentication failures
- Log all SQL execution for compliance
Database Connection Failed
- Verify connection string format in
.env - Ensure database service is running
- Check firewall rules and network connectivity
OpenAI API Errors
- Validate API key has appropriate permissions
- Check rate limits and usage quotas
- Ensure model version (GPT-4) is available
Authentication Issues
- Verify JWT_SECRET is consistent across sessions
- Check token expiration time settings
- Ensure Authorization header format:
Bearer <token>
Guidelines for contributing to the DataMind Chat project:
- Create feature branches from
main - Ensure code follows project style guidelines
- Write comprehensive tests for new functionality
- Submit pull requests with detailed descriptions
- Code review required before merge
data-mind-chat/
├── backend/ # FastAPI backend application
│ ├── app/ # Application code
│ │ ├── main.py # FastAPI application entry point
│ │ ├── api.py # API route definitions
│ │ ├── auth.py # Authentication logic
│ │ ├── db.py # Database connections
│ │ ├── models.py # Data models
│ │ └── openai_client.py # AI integration
│ ├── requirements.txt # Python dependencies
│ └── Dockerfile # Container configuration
├── src/ # React frontend application
│ ├── components/ # React components
│ ├── pages/ # Page components
│ ├── hooks/ # Custom React hooks
│ ├── lib/ # Utility libraries
│ └── store/ # State management
└── package.json # Frontend dependencies
For detailed documentation and additional resources:
- API Documentation: Available at
http://localhost:8000/docs(Swagger UI) - Backend README: See backend/README.md
- Issue Tracking: GitHub Issues for bug reports and feature requests
MIT License - See LICENSE file for complete terms
- OpenAI for GPT-4 language model
- FastAPI community for the excellent web framework
- React community for frontend tooling and libraries
- Contributors and maintainers
Last Updated: January 2026