Study Buddy - Detailed Documentation

This document provides a comprehensive overview of the Study Buddy web application, detailing its features, implementation, and setup instructions.

1. Project Overview

Study Buddy is a comprehensive web application designed to assist students and learners by providing on-demand explanations of topics, generating interactive quizzes, and creating code snippets. It includes user registration, profile management, and admin capabilities, leveraging Google's Gemini API for content generation and PHPMailer for email verification.

2. Features Implemented

2.1. Explanation Generator (pages/explanation.php)

This feature allows users to get detailed explanations on any topic.

  • AI-Powered Explanations: Utilizes the Google Gemini API to generate explanations.
  • Dynamic Content Generation: The explanation is structured into three distinct sections:
    • Main Explanation: Approximately 700-900 words, providing a comprehensive overview of the topic.
    • Frequently Asked Questions (FAQ): Includes 10 small questions and answers related to the topic.
    • Summary/In-short: A concise summary of the topic, within 150 words.
  • Markdown Formatting: The generated explanation is formatted using Markdown (headings, bold, italics, lists) for better readability, which is then converted to HTML for display.

2.2. Quiz Generator (pages/quiz.php)

This feature allows users to test their knowledge with interactive quizzes.

  • AI-Powered Quiz Generation: Utilizes the Google Gemini API to generate multiple-choice quizzes.
  • Configurable Questions: Users can specify the number of questions they want in the quiz (between 5 and 50).
  • Instant Feedback: Provides immediate feedback (correct/incorrect) after each answer selection.
  • Scoreboard:
    • Running Score: Displays the current score (correct answers / total questions) at the top of the quiz.
    • Final Score Modal: Upon completion of all questions, an animated modal appears, showing the final score.
    • Performance Message: Displays a congratulatory message if the user scores more than 90%.
    • Retest Option: The modal includes a "Retest" button to quickly start a new quiz.
  • Pagination: Questions are displayed in pages (10 questions per page) with "Previous" and "Next" navigation buttons.

2.3. Code Generator (pages/code.php)

This feature allows users to generate code snippets for various programming languages.

  • AI-Powered Code Generation: Utilizes the Google Gemini API to generate code based on user queries.
  • Language Selection: Supports a range of popular programming languages (Python, JavaScript, PHP, Java, C#, C++, C).
  • Code Highlighting: Generated code is displayed with syntax highlighting for improved readability.
  • Copy to Clipboard: A convenient button allows users to easily copy the generated code.

2.4. User Registration and Login

  • Secure Registration: Users can register with name, email (Gmail only), password, and age.
  • Email Verification: New users must verify their email using a code sent via PHPMailer.
  • Login System: Secure login with password hashing.

2.5. Profile Management

  • Avatar Upload: Users can upload and update their profile picture.
  • Settings Page: Update name, password, and avatar with secure form handling.
  • Avatar Display: Profile picture is displayed in the navigation bar.

2.6. Admin Panel

  • User Management: Admins can view, delete, and change user roles.
  • Admin Dashboard: Dedicated interface for admin functions.
  • Secure Access: Admin login with role-based access control.

2.7. Navigation Bar (src/layout/navbar.php)

  • Consistent Navigation: A responsive navigation bar is displayed on all main application pages.
  • User Greeting: Displays a personalized greeting "Hello {user}" with profile picture.
  • Menu Items: Links to Home, Documentation, Settings, and Logout.

3. Technical Details

  • Backend: PHP
  • Frontend: HTML, CSS, JavaScript
  • Styling Framework: Bootstrap 5
  • Database: MySQL for user data and settings.
  • Email Handling: PHPMailer for sending verification emails.
  • API Communication: cURL for making HTTP requests to external APIs.
  • AI Integration: Google Gemini API (for explanations and quizzes).
  • Code Highlighting: Highlight.js library.

4. Setup Instructions

To set up and run the Study Buddy application on your local machine, follow these steps:

4.1. Prerequisites

  • Web Server: A web server with PHP support (e.g., Apache, Nginx). XAMPP or MAMP are good options for local development.
  • PHP: PHP 7.4 or higher.
  • cURL Extension: Ensure the cURL extension is enabled in your PHP installation.

4.2. Clone the Repository

git clone https://github.com/pkbehera-dev/study-buddy.git
cd study-buddy

(Note: Replace https://github.com/your-username/study-buddy.git with the actual repository URL if different.)

4.3. Configure API Keys

The application requires an API key for Google Gemini.

  1. Google Gemini API Key:
    • Go to Google AI Studio.
    • Create a new API key.
    • Open config.php in the project's root directory.
    • Replace 'YOUR_GEMINI_API_KEY' with your actual Gemini API key:
      define('GEMINI_API_KEY', 'YOUR_GEMINI_API_KEY');

4.4. Database Setup

  • Create a MySQL database.
  • Import the database.sql file into your database.
  • Update config.php with your database credentials:
    define('DB_SERVER', 'localhost');
    define('DB_USERNAME', 'your_username');
    define('DB_PASSWORD', 'your_password');
    define('DB_NAME', 'your_database_name');

4.5. Email Configuration

  • Update config.php with your SMTP settings for PHPMailer (e.g., Gmail):
    define('SMTP_HOST', 'smtp.gmail.com');
    define('SMTP_USERNAME', 'your_email@gmail.com');
    define('SMTP_PASSWORD', 'your_app_password');
    define('SMTP_SECURE', 'tls');
    define('SMTP_PORT', 587);

4.4. Run the Application

  1. Place the study-buddy project folder in your web server's document root (e.g., htdocs for Apache/XAMPP).
  2. Start your web server.
  3. Open your web browser and navigate to the URL where your project is hosted (e.g., http://localhost/study-buddy).

5. Future Enhancements (Optional)

  • User authentication and persistent profiles.
  • Saving quiz results and explanation history.
  • More advanced markdown rendering (e.g., tables, code blocks).
  • Integration with other AI models or services.
  • Improved UI/UX.