Skip to content

Lokesh-Keswani/Chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– AI Chatbot

A modern, feature-rich AI chatbot application built with vanilla JavaScript, featuring real-time chat, voice interaction, and MongoDB integration.

AI Chatbot JavaScript Node.js MongoDB

โœจ Features

๐ŸŽฏ Core Features

  • 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

๐ŸŽจ User Experience

  • 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

๐Ÿ”ง Technical Features

  • 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

๐Ÿš€ Quick Start

Prerequisites

  • Node.js (v16 or higher)
  • MongoDB account (optional, falls back to local storage)
  • Google Gemini API key

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/ai-chatbot.git
    cd ai-chatbot
  2. Install dependencies

    npm install
  3. Configure API keys

    • Edit config.js and add your Gemini API key:
    GEMINI_API_KEY: 'your-api-key-here'
    • Optionally configure MongoDB URI for cloud storage
  4. Start the server

    node server.cjs
  5. Open in browser Navigate to http://localhost:8000

๐ŸŽฎ Usage

Demo Account

Creating New Account

  1. Click "Don't have an account? Create one"
  2. Fill in your details
  3. Start chatting immediately

Voice Features

  • Click the microphone button to use voice input
  • Toggle auto-speak for AI responses
  • Press Escape to stop recording or speaking

Keyboard Shortcuts

  • Ctrl + Enter - Send message
  • Escape - Stop voice recording/speaking

๐Ÿ“ Project Structure

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

๐Ÿ”ง Configuration

API Keys

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

MongoDB Setup

  1. Create a MongoDB Atlas account
  2. Create a new cluster
  3. Get your connection string
  4. Update MONGODB_URI in config.js

๐ŸŽฏ Key Components

ChatApp

  • Real-time messaging interface
  • Direct DOM manipulation for performance
  • Typing indicators and animations
  • Voice input/output integration

AuthService

  • User registration and login
  • Session management
  • Password validation
  • Secure user data handling

AIService

  • Google Gemini API integration
  • Response generation
  • Error handling and retries
  • Connection testing

VoiceService

  • Speech recognition (Web Speech API)
  • Text-to-speech synthesis
  • Voice command processing
  • Audio controls

๐Ÿ› ๏ธ Development

Running in Development

# Start the server with auto-reload
node server.cjs

# The server will restart automatically when files change

Cache Busting

The application uses version numbers (?v=9) for cache busting. Increment the version in index.html when making updates.

Adding New Features

  1. Create service files in services/ for business logic
  2. Create components in components/ for UI
  3. Update index.html to load new files
  4. Increment cache version

๐Ÿ”’ Security Features

  • Input validation and sanitization
  • Secure password handling
  • API key protection
  • XSS prevention
  • CORS configuration
  • Error message sanitization

๐Ÿ“ฑ Browser Compatibility

  • Chrome - Full support
  • Firefox - Full support
  • Safari - Full support (limited voice features)
  • Edge - Full support
  • Mobile browsers - Responsive design

๐Ÿ› Troubleshooting

Common Issues

  1. Server won't start (port in use)

    # Kill existing process
    Get-Process -Name "node" | Stop-Process -Force
  2. API not working

    • Check your Gemini API key in config.js
    • Verify internet connection
    • Check browser console for errors
  3. Voice features not working

    • Ensure HTTPS (required for speech recognition)
    • Check microphone permissions
    • Try different browser
  4. MongoDB connection issues

    • Verify connection string
    • Check network connectivity
    • Application falls back to local storage

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Google Gemini API - AI response generation
  • Tailwind CSS - UI styling framework
  • MongoDB Atlas - Cloud database service
  • Web Speech API - Voice recognition and synthesis

๐Ÿ“ž Support

If you encounter any issues or have questions:

  1. Check the troubleshooting section
  2. Search existing issues on GitHub
  3. 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages