Skip to content

ayushh8/AI-doubt-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Doubt Solver

A full-stack application for document-based Q&A, built with Node.js (Express, MongoDB) for the backend and Vite + React for the frontend.


Features

User Management

  • User registration and login (student, faculty, admin roles)
  • JWT-based authentication and protected routes
  • Role-based access control (backend-ready, UI coming soon)

Document Management

  • Upload PDF documents with metadata (faculty and students)
  • View list of documents and document details
  • Public/private document visibility (faculty uploads are public by default)
  • Secure file storage and access

AI Chat

  • Chat with AI about uploaded documents
  • View chat history (previous Q&A)

API Integration

  • All frontend features communicate with the backend via RESTful API endpoints

Backend Features & Security

  • Authentication:
    • Secure JWT-based authentication for all protected routes
    • Passwords are hashed using bcrypt before storage
  • Role-Based Access:
    • User roles: student, faculty, admin
    • Backend checks user roles for sensitive actions (e.g., uploading documents)
  • Error Handling:
    • Consistent error responses for failed operations
    • User-friendly error messages for common issues (e.g., invalid PDF, unauthorized access)
  • File Security:
    • Only authenticated users can upload or access documents
    • Uploaded files are validated (PDF only, size limits)
  • Environment Variables:
    • Sensitive configuration (JWT secret, DB URI) is stored in environment variables

API Endpoints

Authentication

Method Endpoint Description Required Fields
POST /api/auth/register Register a new user username, email, password, full_name, role
POST /api/auth/login Login user username, password
GET /api/auth/me Get current user (JWT token in Authorization header)

Documents

Method Endpoint Description Required Fields / Notes
POST /api/files/upload Upload a PDF document file (PDF), title, description, subject, course_code, is_public (form-data, JWT required)
GET /api/files/ List documents JWT required
GET /api/files/:id Get document details JWT required, :id = document ID

Chat

Method Endpoint Description Required Fields / Notes
POST /api/chat/ask Ask a question to the AI question (string), document_ids (optional, array), JWT required
GET /api/chat/history Get chat history JWT required

Planned Features (Future Updates)

  • Role-based UI and permissions (e.g., only faculty can upload, students can only view)
  • Enhanced document visibility controls (public/private toggle)
  • Improved UI/UX and error handling (UI enhancements, loading states, notifications)
  • Admin dashboard and management tools
  • Code refactoring and performance improvements
  • More granular permissions and audit logging

Getting Started

Prerequisites

  • Node.js (v20.19.0 or higher recommended)
  • MongoDB (local or cloud instance)

Backend Setup

  1. cd backend
  2. Install dependencies:
    npm install
  3. Configure your environment variables (see env_example.txt).
  4. Start the backend server:
    node server.js
    # or, for auto-reload:
    npx nodemon server.js
  5. Backend runs by default on http://localhost:5000

Frontend Setup

  1. cd frontend
  2. Install dependencies:
    npm install
  3. Ensure vite.config.js proxies /api to your backend (default: http://localhost:5000).
  4. Start the frontend dev server:
    npm run dev
  5. Frontend runs by default on http://localhost:5173

Usage

  • Register as a student or faculty (faculty can upload documents, students can view public documents).
  • Upload and view documents.
  • Chat with the AI about your documents.
  • View your chat history.

Notes

  • Make sure both backend and frontend servers are running for full functionality.
  • For future role-based features and UI/UX improvements, see the "Planned Features" section above.
  • For any issues, check backend and frontend logs for error messages.

πŸš€ Tech Stack

Backend

  • Node.js - Runtime environment
  • Express.js - Web framework
  • MongoDB - NoSQL database
  • JWT - Authentication
  • Multer - File upload handling
  • pdf-parse - PDF text extraction

AI Integration

  • Groq API - High-performance AI inference
  • RAG Pipeline - Retrieval-Augmented Generation
  • Text Chunking - Intelligent document processing
  • Similarity Search - Keyword-based content retrieval

πŸ“‹ Prerequisites

  • Node.js (v16 or higher)
  • MongoDB (v4.4 or higher)
  • Groq API key

πŸ› οΈ Installation

  1. Clone the repository

    git clone https://github.com/ayushh8/AI-doubt-solver.git
    cd AI-doubt-solver
  2. Install dependencies

    cd backend
    npm install
  3. Set up environment variables Create a .env file in the backend directory:

    PORT=5000
    MONGODB_URI=mongodb://localhost:27017/doubt_solver
    JWT_SECRET=your_jwt_secret_here
    GROQ_API_KEY=your_groq_api_key_here
  4. Start MongoDB

    # On Windows
    mongod --dbpath C:\data\db
    
    # On macOS/Linux
    sudo systemctl start mongod
  5. Start the server

    npm start

🎯 Usage

API Endpoints

Authentication

  • POST /api/auth/register - Register a new user
  • POST /api/auth/login - Login user
  • GET /api/auth/profile - Get user profile

Documents

  • POST /api/files/upload - Upload PDF document
  • GET /api/files/ - List user's documents
  • GET /api/files/:id - Get specific document
  • DELETE /api/files/:id - Delete document
  • POST /api/files/:id/reprocess - Reprocess document

Chat

  • POST /api/chat/ask - Ask a question
  • GET /api/chat/history - Get chat history
  • GET /api/chat/health - Check AI service health
  • GET /api/chat/debug - Debug AI memory

Testing

Visit http://localhost:5000/test.html for an interactive testing interface.

πŸ“ Project Structure

backend/
β”œβ”€β”€ models/           # Database models
β”œβ”€β”€ routes/           # API routes
β”œβ”€β”€ services/         # Business logic
β”œβ”€β”€ middleware/       # Custom middleware
β”œβ”€β”€ uploads/          # File storage
β”œβ”€β”€ server.js         # Main server file
└── package.json      # Dependencies

πŸ”§ Configuration

Environment Variables

Variable Description Default
PORT Server port 5000
MONGODB_URI MongoDB connection string mongodb://localhost:27017/doubt_solver
JWT_SECRET JWT signing secret Required
GROQ_API_KEY Groq API key Required

File Upload Limits

  • Maximum file size: 50MB
  • Supported formats: PDF only
  • Processing limit: 10MB for text extraction

πŸš€ Deployment

Local Development

npm run dev

Production

npm start

Environment Setup

  1. Set up MongoDB Atlas or local MongoDB
  2. Get Groq API key from Groq Console
  3. Configure environment variables
  4. Deploy to your preferred platform

🀝 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

πŸ“ž Support

If you have any questions or need help, please open an issue on GitHub.


Made with ❀️ for students everywhere!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published