Skip to content

Repository files navigation

DocuQuery AI

An AI-powered document Q&A application that allows users to upload PDF or text documents and ask natural language questions about their content. The app uses OpenAI's GPT model to generate accurate answers based solely on the uploaded document.

Node.js Express MongoDB OpenAI

Features

  • Document Upload — Support for PDF and TXT files (up to 10MB)
  • AI-Powered Q&A — Ask natural language questions and receive context-aware answers
  • Question History — All questions and answers are saved per document
  • Multiple Documents — Upload and manage multiple documents
  • Modern UI — Clean, responsive interface

Tech Stack

  • Backend: Node.js, Express.js
  • Database: MongoDB with Mongoose ODM
  • AI Integration: OpenAI GPT-3.5-turbo API
  • View Engine: Handlebars
  • File Processing: Multer (uploads), pdf-parse (PDF text extraction)

How It Works

  1. User uploads a PDF or text document
  2. The application extracts text content from the file
  3. Document content is stored in MongoDB
  4. User asks a question about the document
  5. The question and document content are sent to OpenAI's API
  6. AI generates an answer based solely on the document content
  7. Q&A history is saved for future reference

Installation

Prerequisites

  • Node.js (v16 or higher)
  • MongoDB (local or MongoDB Atlas)
  • OpenAI API Key

Setup

  1. Clone the repository
   git clone https://github.com/yourusername/docuquery-ai.git
   cd docuquery-ai
  1. Install dependencies
   npm install
  1. Create environment file
   cp .env.example .env
  1. Configure environment variables in .env
   OPENAI_API_KEY=your_openai_api_key
   MONGODB_URI=your_mongodb_connection_string
   PORT=3000
  1. Start the application
   npm start
  1. Open http://localhost:3000 in your browser

Project Structure

docuquery-ai/
├── models/
│   └── Document.js          # MongoDB document schema
├── routes/
│   └── documentRoutes.js    # Express routes
├── services/
│   ├── extractionService.js # PDF/text extraction
│   └── openaiService.js     # OpenAI API integration
├── views/
│   ├── layouts/
│   │   └── main.handlebars  # Main layout
│   ├── home.handlebars      # Home page
│   └── document.handlebars  # Document Q&A page
├── public/
│   └── css/
│       └── style.css        # Styles
├── uploads/                 # Temporary file uploads
├── server.js                # Application entry point
├── package.json
└── .env.example

API Endpoints

Method Endpoint Description
GET / Home page with upload form
POST /upload Upload a new document
GET /document/:id View document and Q&A interface
POST /document/:id/ask Submit a question
POST /document/:id/delete Delete a document

Environment Variables

Variable Description
OPENAI_API_KEY OpenAI API key
MONGODB_URI MongoDB connection string
PORT Server port (default: 3000)

Author

Ibrahim Al Shouli
Software Engineering Student — University of Doha for Science and Technology

About

AI-powered document Q&A application using Node.js, Express, MongoDB, and OpenAI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages