Skip to content

yasharyas/Tutor-Chatbot

Repository files navigation

AI Study Tutor – Subject Tutor Chatbot

🚀 Live Demo: https://tutor-chatbot-eight.vercel.app/

An AI-powered Subject Tutor Chatbot built with Next.js 16 and Google Gemini 2.5 Flash API, featuring multimodal input support (text, voice, images), adaptive teaching modes, and intelligent conversation management.

Built with production-ready features including rate limiting, lazy loading, strict TypeScript, and comprehensive error handling.

✨ Features

🧠 Core Tutor Functionality

Multiple Tutor Modes

  • Explain Mode – Clear step-by-step teaching with examples
  • Socratic Mode – Guided learning through thought-provoking questions
  • Revision Mode – Summaries, patterns, and practice problems
  • Exam-Focused Mode – Concise, exam-ready answers

Subject-Agnostic Learning

  • Physics, Mathematics, Biology, History, Computer Science, or any subject
  • Context-aware responses based on selected subject and level
  • Intelligent conversation continuity with session memory

🎙️ Advanced Input Methods

Voice Input

  • Real-time 48-bar audio visualizer
  • Web Audio API integration
  • Auto-recording with visual feedback

File Upload

  • Drag-and-drop image upload
  • Image preview with hover animations
  • Multimodal analysis (images + text combined)

Text Chat

  • Standard text input with file attachment support
  • Markdown rendering with LaTeX math support
  • Code syntax highlighting

💬 Chat Experience

  • Real-time Streaming – Token-by-token response generation
  • Character Animation – Smooth typewriter effect using Framer Motion
  • Session Management – Maintains conversation context
  • Notes Panel – Take and export study notes during chat
  • Error Recovery – Preserves partial responses on errors

🎨 UI/UX

  • Modern Design – Clean, distraction-free chat interface
  • Dark Mode – System preference detection with manual toggle
  • Responsive – Mobile, tablet, and desktop optimized
  • Rate Limited Demo – 10 requests per user per 24 hours
  • Demo Banner – Shows remaining requests for transparency

🚀 Tech Stack

Frontend

  • Next.js 16.1.1 with Turbopack
  • React 19 with Server & Client Components
  • TypeScript (strict mode, zero any types)
  • Tailwind CSS for styling
  • shadcn/ui component library
  • Framer Motion 12 for animations
  • next-themes for dark mode

Backend

  • Next.js API Routes (streaming endpoints)
  • Google Gemini 2.5 Flash AI model
  • Zustand for state management
  • Web Audio API for voice visualizer

Infrastructure

  • Vercel deployment
  • IP-based rate limiting (10 requests/24h)
  • Lazy loading with dynamic imports
  • Environment-based configuration

🏗️ Project Structure tutor-chatbot/ ├── app/ │ ├── api/chat/route.ts # Gemini streaming API │ ├── layout.tsx # Root layout │ ├── page.tsx # Main chat UI │ └── globals.css # Global styles ├── components/ │ ├── ChatWindow.tsx │ ├── ChatInput.tsx

🏗️ Project Structure

tutor-chatbot/
├── app/
│   ├── api/chat/stream/        # Streaming API endpoint
│   ├── demo/                   # Component showcase
│   ├── layout.tsx              # Root layout with providers
│   └── page.tsx                # Main app (lazy loaded)
├── components/
│   ├── chat/                   # Chat UI components
│   │   ├── chat-input.tsx
│   │   ├── message.tsx
│   │   ├── file-upload.tsx
│   │   ├── audio-input.tsx
│   │   └── tutor-mode-selector.tsx
│   ├── ui/                     # shadcn/ui components
│   │   ├── ai-voice-input.tsx  # 48-bar visualizer
│   │   ├── animated-text.tsx   # Typewriter effect
│   │   └── ...
│   ├── notes/                  # Notes panel
│   ├── tutor-interface-v2.tsx  # Main chat interface
│   ├── demo-banner.tsx         # Rate limit banner
│   └── theme-toggle.tsx        # Dark mode toggle
├── lib/
│   ├── utils.ts                # Utility functions
│   └── rate-limiter.ts         # IP-based rate limiting
├── store/
│   └── session-store.ts        # Zustand state management
├── hooks/
│   ├── useMemory.ts            # Session memory hook
│   └── useSession.ts           # Session management
├── types/
│   └── index.ts                # TypeScript interfaces
└── __tests__/                  # Jest test suite

🔧 Installation & Setup

Prerequisites

  • Node.js 18+
  • npm/pnpm/yarn
  • Google Gemini API Key (Get it free)

Local Development

  1. Clone the repository
git clone https://github.com/yasharyas/Tutor-Chatbot.git
cd Tutor-Chatbot
  1. Install dependencies
npm install
  1. Set up environment variables

Create .env.local in the root directory:

GEMINI_API_KEY=your_gemini_api_key_here
  1. Run the development server
npm run dev
  1. Open in browser
http://localhost:3000

Production Build

npm run build
npm start

🌐 Deployment

Deploy to Vercel

Live Demo: https://tutor-chatbot-eight.vercel.app/

Quick Deploy:

Deploy with Vercel

Manual Steps:

  1. Push your code to GitHub
  2. Go to vercel.com/new
  3. Import your repository
  4. Add environment variable:
    • GEMINI_API_KEY = your API key
  5. Deploy!

Note: The live demo has rate limiting (10 requests per user per 24 hours). Deploy your own version for unlimited access.

See DEPLOYMENT.md for detailed deployment instructions.

Open: 👉 http://localhost:3000

🧠 Tutor Modes Explained

1️⃣ Explain Mode

  • Clear, patient teaching style
  • Step-by-step breakdowns with examples
  • Starts simple, adds complexity gradually
  • Best for: Learning new concepts

2️⃣ Socratic Mode

  • Guides through thought-provoking questions
  • Never gives direct answers
  • Encourages critical thinking
  • Best for: Deep understanding

3️⃣ Revision Mode

  • Creates summaries and finds patterns
  • Tests understanding with practice problems
  • Consolidates knowledge
  • Best for: Exam preparation

4️⃣ Exam-Focused Mode

  • Concise, exam-ready answers
  • Highlights key concepts and common mistakes
  • Direct and efficient
  • Best for: Quick revision

📱 Usage Guide

Getting Started

  1. Select Your Subject: Enter your subject (e.g., "Physics", "Computer Science")
  2. Choose Your Level: Specify your level (e.g., "High School", "University")
  3. Pick a Mode: Choose the teaching style that fits your needs
  4. Start Chatting: Ask questions naturally!

Using Voice Input

  1. Click the microphone icon
  2. Speak your question
  3. The 48-bar visualizer shows your audio input
  4. Click stop when done

Uploading Files

  1. Click the attachment icon or drag files
  2. Supports images (diagrams, screenshots, problems)
  3. AI analyzes images along with your text question
  4. Hover over files to see animated details

Taking Notes

  1. Click the "Notes" tab
  2. Jot down important points during chat
  3. Export notes as text file
  4. Notes persist during session

🎯 Key Features Implemented

Performance Optimizations

  • ✅ Lazy loading with dynamic imports
  • ✅ Streaming responses (SSE)
  • ✅ Optimized bundle size
  • ✅ Server and Client Components separation

Type Safety

  • ✅ Strict TypeScript mode
  • ✅ Zero any types
  • ✅ Proper interface definitions
  • ✅ Type-safe API routes

Error Handling

  • ✅ Preserves partial responses on error
  • ✅ Specific error messages (rate limit, overload, etc.)
  • ✅ Graceful degradation
  • ✅ Network status detection

Production Ready

  • ✅ Rate limiting for demo deployment
  • ✅ Environment-based configuration
  • ✅ Comprehensive test coverage
  • ✅ Clean code with no verbose comments

🧪 Testing

Run the test suite:

npm test

Run with coverage:

npm run test:coverage

🔒 Security & Privacy

  • API key stored securely in environment variables
  • Rate limiting prevents abuse
  • No user data collection
  • Session-based memory (no database)

🐛 Known Limitations

  • Session-based history (no persistence)
  • In-memory rate limiting (resets on server restart)
  • Free tier API rate limits may apply
  • Voice transcription not yet implemented

🚀 Future Enhancements

  • Persistent chat history with database
  • Voice-to-text transcription
  • Text-to-speech responses
  • Multi-language support
  • User authentication
  • Conversation export (PDF/Markdown)

👥 Contributors

Yash Arya

Kuljot (Team Member)

  • Collaboration on architecture and feature planning

📄 License

MIT License - feel free to use this project for learning and personal projects.

🙏 Acknowledgments

  • Next.js Team for the amazing framework
  • Vercel for free hosting
  • Google for Gemini API
  • shadcn for the beautiful UI components
  • Framer for Motion animations

⭐ If you find this project helpful, please give it a star!

🔗 Live Demo: https://tutor-chatbot-eight.vercel.app/

📚 Happy Learning!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors