A modern, feature-rich AI chatbot application built with vanilla JavaScript, featuring real-time chat, voice interaction, and MongoDB integration.
- Real-time Chat Interface - Instant messaging like WhatsApp/ChatGPT
- AI-Powered Responses - Powered by Google Gemini 2.0 Flash API
- Voice Input/Output - Speech recognition and text-to-speech
- User Authentication - Secure login and registration system
- Message History - Persistent chat storage with MongoDB
- Export Functionality - Export chats as PDF, TXT, or JSON
- Responsive Design - Works seamlessly on desktop and mobile
- Real-time Typing Indicators - Shows when AI is responding
- Message Animations - Smooth fade-in effects for new messages
- Auto-scroll - Automatically scrolls to latest messages
- Copy to Clipboard - Easy message copying functionality
- Theme-aware UI - Modern, clean interface with Tailwind CSS
- Modular Architecture - Clean separation of services and components
- Error Handling - Comprehensive error recovery and user feedback
- Cache Busting - Automatic file versioning for updates
- Local Storage Fallback - Works offline with local data storage
- MongoDB Integration - Cloud database with automatic migration
- API Key Protection - Secure configuration management
- Node.js (v16 or higher)
- MongoDB account (optional, falls back to local storage)
- Google Gemini API key
-
Clone the repository
git clone https://github.com/yourusername/ai-chatbot.git cd ai-chatbot -
Install dependencies
npm install
-
Configure API keys
- Edit
config.jsand add your Gemini API key:
GEMINI_API_KEY: 'your-api-key-here'- Optionally configure MongoDB URI for cloud storage
- Edit
-
Start the server
node server.cjs
-
Open in browser Navigate to
http://localhost:8000
- Email: demo@example.com
- Password: demo123
- Click "Don't have an account? Create one"
- Fill in your details
- Start chatting immediately
- Click the microphone button to use voice input
- Toggle auto-speak for AI responses
- Press Escape to stop recording or speaking
- Ctrl + Enter - Send message
- Escape - Stop voice recording/speaking
ai-chatbot/
โโโ components/ # UI components
โ โโโ App.js # Main application component
โ โโโ ChatApp.js # Chat interface component
โ โโโ LoginForm.js # Authentication component
โ โโโ Component.js # Base component class
โโโ services/ # Business logic services
โ โโโ aiService.js # Gemini API integration
โ โโโ authService.js # Authentication logic
โ โโโ databaseService.js # Data management
โ โโโ mongoService.js # MongoDB operations
โ โโโ voiceService.js # Speech recognition/synthesis
โโโ utils/ # Utility functions
โ โโโ helpers.js # Common helper functions
โโโ config.js # Configuration settings
โโโ server.cjs # Express server
โโโ index.html # Main HTML file
โโโ package.json # Dependencies and scripts
Edit config.js to configure:
- Gemini API Key - For AI responses
- MongoDB URI - For cloud storage (optional)
- Voice Settings - Speech rate, pitch, volume
- Auto-save Interval - Message backup frequency
- Create a MongoDB Atlas account
- Create a new cluster
- Get your connection string
- Update
MONGODB_URIinconfig.js
- Real-time messaging interface
- Direct DOM manipulation for performance
- Typing indicators and animations
- Voice input/output integration
- User registration and login
- Session management
- Password validation
- Secure user data handling
- Google Gemini API integration
- Response generation
- Error handling and retries
- Connection testing
- Speech recognition (Web Speech API)
- Text-to-speech synthesis
- Voice command processing
- Audio controls
# Start the server with auto-reload
node server.cjs
# The server will restart automatically when files changeThe application uses version numbers (?v=9) for cache busting. Increment the version in index.html when making updates.
- Create service files in
services/for business logic - Create components in
components/for UI - Update
index.htmlto load new files - Increment cache version
- Input validation and sanitization
- Secure password handling
- API key protection
- XSS prevention
- CORS configuration
- Error message sanitization
- Chrome - Full support
- Firefox - Full support
- Safari - Full support (limited voice features)
- Edge - Full support
- Mobile browsers - Responsive design
-
Server won't start (port in use)
# Kill existing process Get-Process -Name "node" | Stop-Process -Force
-
API not working
- Check your Gemini API key in
config.js - Verify internet connection
- Check browser console for errors
- Check your Gemini API key in
-
Voice features not working
- Ensure HTTPS (required for speech recognition)
- Check microphone permissions
- Try different browser
-
MongoDB connection issues
- Verify connection string
- Check network connectivity
- Application falls back to local storage
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
- Google Gemini API - AI response generation
- Tailwind CSS - UI styling framework
- MongoDB Atlas - Cloud database service
- Web Speech API - Voice recognition and synthesis
If you encounter any issues or have questions:
- Check the troubleshooting section
- Search existing issues on GitHub
- Create a new issue with detailed information
Made with โค๏ธ by [Your Name]
A modern AI chatbot that brings conversational AI to your browser with a beautiful, responsive interface. commit test through cursor