Skip to content

An intelligent AI-powered chatbot system designed to help resolve student queries efficiently using Retrieval-Augmented Generation (RAG) technology. The system features both user and admin interfaces, allowing for dynamic query handling, AI-powered responses, and comprehensive query management.

Notifications You must be signed in to change notification settings

kartik-grg/chatbot-for-students-queries

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

79 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Student Query Resolution Chatbot

An intelligent AI-powered chatbot system designed to help resolve student queries efficiently using Retrieval-Augmented Generation (RAG) technology. The system features both user and admin interfaces, allowing for dynamic query handling, AI-powered responses, and comprehensive query management with cloud storage integration.

πŸš€ Key Features

πŸ€– AI-Powered Query Resolution

  • RAG (Retrieval-Augmented Generation) for intelligent responses
  • Google AI (Gemini) integration for natural language processing
  • LangChain framework for advanced language processing
  • Pinecone vector database for semantic search and embedding storage
  • PDF document processing for knowledge base creation with Cloudinary integration

πŸ” User Authentication System

  • Secure user signup and login
  • JWT-based authentication with session management
  • Password encryption using Bcrypt
  • Admin authentication with role-based access

πŸ’¬ Advanced Query Management

  • Real-time AI-powered query responses
  • Automatic query storage and categorization
  • Historical query search and analytics
  • Unanswered query tracking for admin review

πŸŽ›οΈ Comprehensive Admin Dashboard

  • Dedicated admin login system
  • Query analytics and statistics
  • Manage unanswered queries with bulk operations
  • Add and update responses manually
  • PDF management with Cloudinary integration
  • One-click embedding rebuilding for knowledge base updates
  • Email notification system for critical queries
  • Chat history management

πŸ“§ Email Integration

  • Automated email notifications
  • Admin alerts for unanswered queries
  • Test email functionality for system verification

☁️ Cloud Storage Integration

  • Cloudinary PDF storage for document management
  • PDF preview with Google Docs viewer
  • Original filename preservation
  • Public/private access management

πŸ› οΈ Technology Stack

Backend (Flask)

  • Flask 2.3.3 - Modern Python web framework
  • Flask-CORS - Cross-Origin Resource Sharing support
  • Gunicorn - WSGI HTTP Server for production deployment
  • MongoDB with PyMongo - NoSQL database for scalable data storage
  • Google AI (Gemini) - Advanced language model integration
  • LangChain - AI application framework
  • Pinecone - Vector database for production-ready RAG systems
  • Cloudinary - Cloud-based PDF storage and management
  • Flask-Mail - Email service integration
  • JWT - Secure token-based authentication
  • Flask-CORS - Cross-origin resource sharing

Frontend (React + Vite)

  • React 18.3.1 - Modern UI library
  • Vite - Fast build tool and dev server
  • Tailwind CSS - Utility-first CSS framework
  • ShadCN/UI - Modern component library
  • React Router - Client-side routing
  • Axios - HTTP client for API communication
  • Lucide React - Beautiful icons

AI & ML Stack

  • Google AI API - Generative AI responses
  • LangChain Community - Extended AI capabilities
  • Pinecone - Managed vector database for production RAG deployments
  • TextBlob - Text processing and analysis
  • PyPDF2 - PDF document processing
  • ReportLab - PDF generation for Q&A documents
  • Cloudinary SDK - Cloud storage API integration

πŸ“‘ API Endpoints

πŸ” Authentication

POST /api/signup              # Register new user
POST /api/login               # User login  
POST /api/admin/login         # Admin authentication

πŸ’¬ Chat & Query Management

POST /api/query               # Submit query (AI-powered response)
GET  /api/chat-history        # Retrieve user chat history
POST /api/add-response        # Add manual response to query

πŸŽ›οΈ Admin Management

GET  /api/admin/stats         # Get system statistics
GET  /api/admin/chat-history  # Get all chat history (admin)
GET  /api/admin/query-analytics # Get query analytics
GET  /api/unanswered-queries  # Get pending queries
DELETE /api/delete-query/<id> # Delete specific query

πŸ“„ PDF Management

GET  /api/pdfs/               # List all PDFs
POST /api/pdfs/upload         # Upload a PDF file
DELETE /api/pdfs/<public_id>  # Delete a PDF
POST /api/pdfs/rebuild-embeddings # Rebuild embeddings from PDFs

πŸ” System Endpoints

GET  /health                  # Health check
GET  /debug/routes            # List all available routes
GET  /debug/email             # Test email service
POST /debug/send-test-email   # Send test email

πŸš€ Getting Started

Prerequisites

  • Python 3.8+ (recommended 3.10+)
  • Node.js 16+ and npm
  • MongoDB Atlas account or local MongoDB
  • Google AI API key
  • Gmail account for email services (with app password)
  • LangSmith account (optional, for AI tracing)

πŸ”§ Backend Setup

  1. Clone the repository:
git clone https://github.com/Arnavkesari/chatbot-for-students-queries.git
cd chatbot-for-students-queries
  1. Navigate to backend directory:
cd backend
  1. Create and activate virtual environment:
# Windows
python -m venv venv
venv\Scripts\activate

# macOS/Linux  
python3 -m venv venv
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables: Create .env file in the backend directory:
# Database Configuration
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/chatbot?retryWrites=true&w=majority

# Google AI Configuration  
GOOGLE_API_KEY=your_google_ai_api_key

# LangChain Configuration (Optional - for AI tracing)
LANGSMITH_API_KEY=your_langsmith_api_key
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=Faculty Chatbot
LANGCHAIN_ENDPOINT=https://api.smith.langchain.com

# Email Configuration (Gmail SMTP)
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_gmail_app_password

# Security
SECRET_KEY=your_secure_random_secret_key

# Flask Configuration
FLASK_ENV=development
PORT=5000

# Admin Credentials
ADMIN_EMAIL=
ADMIN_PASSWORD=
  1. Add PDF documents to resources folder:
# Place your PDF documents in:
backend/resources/
  1. Start the backend server:
python app.py

🎨 Frontend Setup

  1. Navigate to frontend directory:
cd frontend
  1. Install dependencies:
npm install
  1. Configure environment variables:
# Create .env.local file
cp .env.local.example .env.local

# Edit .env.local to set the API base URL
# For development:
VITE_API_BASE_URL=http://localhost:5000

# For production (when deploying):
# VITE_API_BASE_URL=https://your-backend-url.onrender.com
  1. Start the development server:
npm run dev

The frontend will run on http://localhost:5173

πŸ—οΈ Project Structure

chatbot-for-students-queries/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app.py                    # Main Flask application
β”‚   β”œβ”€β”€ requirements.txt          # Python dependencies
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ config.py            # Configuration settings
β”‚   β”‚   └── database.py          # Database connection
β”‚   β”œβ”€β”€ controllers/             # Business logic controllers
β”‚   β”œβ”€β”€ middleware/              # Custom middleware
β”‚   β”œβ”€β”€ models/                  # Database models
β”‚   β”œβ”€β”€ routes/                  # API route definitions
β”‚   β”œβ”€β”€ services/                # Business services
β”‚   β”œβ”€β”€ utils/                   # Utility functions
β”‚   └── resources/               # PDF documents for RAG
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/          # React components
β”‚   β”‚   β”œβ”€β”€ assets/              # Static assets
β”‚   β”‚   └── lib/                 # Utility libraries
β”‚   β”œβ”€β”€ package.json             # Frontend dependencies
β”‚   └── vite.config.js           # Vite configuration
└── RAG/                         # RAG implementation notes

πŸ—ƒοΈ Database Schema

Users Collection

{
  "_id": "ObjectId",
  "username": "string",
  "email": "string", 
  "password": "bcrypt_hashed_string",
  "created_at": "datetime",
  "last_login": "datetime"
}

Queries Collection

{
  "_id": "ObjectId",
  "question": "string",
  "answer": "string", 
  "answered": "boolean",
  "user_id": "ObjectId",
  "timestamp": "datetime",
  "ai_generated": "boolean",
  "similarity_score": "float",
  "category": "string"
}

πŸ”§ Configuration Details

πŸ€– AI Configuration

  • Google AI (Gemini): Powers intelligent response generation
  • LangChain: Handles RAG pipeline and document processing
  • FAISS: Vector database for semantic similarity search
  • LangSmith: Optional AI tracing and monitoring

πŸ“§ Email Service

  • Gmail SMTP integration for notifications
  • Flask-Mail for email management
  • Automated alerts for unanswered queries

πŸ›‘οΈ Security Features

  • Bcrypt password hashing with salt rounds
  • JWT token authentication with expiration
  • Admin role-based access control
  • Environment variable protection
  • CORS middleware for secure API access
  • Session timeout management

πŸŽ›οΈ Admin

Admin Capabilities:

  • View system statistics and analytics
  • Manage unanswered queries
  • Add manual responses to queries
  • Delete inappropriate queries
  • Monitor chat history across all users
  • Receive email notifications for critical queries

πŸ” Development

Environment Modes

  • Development: FLASK_ENV=development (Hot reloading enabled)
  • Production: FLASK_ENV=production (Optimized for performance)
  • Testing: FLASK_ENV=testing (Test configuration)

Testing the System

  1. Health Check: GET http://localhost:5000/health
  2. Email Service: GET http://localhost:5000/debug/email
  3. Send Test Email: POST http://localhost:5000/debug/send-test-email
  4. List Routes: GET http://localhost:5000/debug/routes

API Testing with cURL

# Test user signup
curl -X POST http://localhost:5000/api/signup \
  -H "Content-Type: application/json" \
  -d '{"username":"testuser","email":"test@example.com","password":"password123"}'

# Test query submission  
curl -X POST http://localhost:5000/api/query \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{"question":"What are the admission requirements?"}'

πŸ“š RAG Implementation

The system uses Retrieval-Augmented Generation to provide accurate, context-aware responses:

  1. Document Processing: PDF files in resources/ are processed and chunked
  2. Vector Embeddings: Text chunks are converted to vectors using Google AI
  3. Vector Storage: FAISS stores embeddings for fast similarity search
  4. Query Processing: User questions are embedded and matched against knowledge base
  5. Response Generation: Relevant context + user query sent to Google AI for response generation

Adding New Documents

  1. Upload PDF files through the admin dashboard
  2. Rebuild embeddings using the dedicated button
  3. System automatically processes and indexes new content

πŸš€ Deployment

Backend Deployment (Render)

The backend is configured for deployment on Render.com:

  1. Render.yaml Configuration: The project includes a render.yaml file with all the necessary configuration for deployment on Render.

  2. Environment Variables: Make sure to set up all required environment variables in the Render Dashboard:

    • MONGODB_URI
    • JWT_SECRET_KEY
    • GOOGLE_API_KEY
    • All email configuration variables
    • Cloudinary credentials
    • Pinecone API key and environment
  3. CORS Configuration: The backend is configured to accept requests from the frontend domain. Make sure to update the CORS_ALLOW_ORIGIN environment variable with your frontend URL.

Frontend Deployment (Vercel/Netlify)

  1. Build the frontend:
cd frontend
npm run build
  1. Environment Variables: Set the VITE_API_BASE_URL to your deployed backend URL:
VITE_API_BASE_URL=https://your-backend-url.onrender.com
  1. Deploy: Use Vercel, Netlify, or any static hosting service to deploy the dist folder.

🀝 Contributing

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

Development Guidelines

  • Follow PEP 8 for Python code
  • Use ESLint configuration for JavaScript
  • Add docstrings to all functions
  • Write tests for new features
  • Update README for significant changes

πŸ“„ License

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

πŸ†˜ Support & Contact


Built with ❀️ for educational institutions and student success

About

An intelligent AI-powered chatbot system designed to help resolve student queries efficiently using Retrieval-Augmented Generation (RAG) technology. The system features both user and admin interfaces, allowing for dynamic query handling, AI-powered responses, and comprehensive query management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 55.7%
  • JavaScript 41.9%
  • CSS 1.3%
  • Other 1.1%