Skip to content

saptarshidey3000/ChatPDF-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README.md

ChatPDF Backend

AI-powered PDF chat backend built with Node.js, Express.js, Gemini AI, Qdrant Vector DB, Prisma, PostgreSQL, and Cloudinary.

This backend allows users to:

- Upload PDFs
- Parse and chunk PDF content
- Generate embeddings using Gemini
- Store vectors in Qdrant
- Perform semantic search (RAG)
- Chat with PDFs using AI
- Persist chat history
- Authenticate users using Clerk

---

Tech Stack

- Node.js
- Express.js
- PostgreSQL
- Prisma ORM
- Google Gemini AI
- Qdrant Vector Database
- Cloudinary
- Clerk Authentication
- Multer
- pdf-parse-new
- Rate Limiting + Security Middleware

---

Features

 Authentication
- Clerk JWT authentication
- Protected API routes
- User-specific PDFs and chats

PDF Upload Pipeline
- Upload PDF files
- Store files in Cloudinary
- Extract PDF text
- Chunk text intelligently
- Generate embeddings
- Store vectors in Qdrant

AI Chat System
- Retrieval-Augmented Generation (RAG)
- Semantic search over PDF chunks
- Gemini-powered responses
- Citation support
- Persistent chat history

Security
- Helmet
- Rate limiting
- CORS protection
- Secure cookies
- Request validation

---

Project Structure

```bash
src
├── config
├── controllers
├── middlewares
├── routes
├── services
├── scripts
├── utils
├── app.js
└── server.js

Environment Variables

Create a .env file:

PORT=8000
DATABASE_URL=
FRONTEND_URL=
CLERK_SECRET_KEY=
CLERK_PUBLISHABLE_KEY=
GEMINI_API_KEY=
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
QDRANT_URL=
QDRANT_API_KEY=

Installation

git clone <repo-url>

cd chatpdf-backend

npm install

Prisma Setup

npx prisma generate

npx prisma migrate dev

Run Development Server

npm run dev

Production Start

npm start

API Routes

Health Check

GET /

Test Database

GET /test-db

Upload PDF

POST /api/v1/upload/pdf

FormData

pdf: File

Ask Questions About PDF

POST /api/v1/chat/ask

Request Body

{
  "pdfId": "pdf_id",
  "question": "Explain this PDF"
}

RAG Flow

PDF Upload
   ↓
PDF Parsing
   ↓
Chunking
   ↓
Embedding Generation
   ↓
Store Vectors in Qdrant
   ↓
Semantic Retrieval
   ↓
Gemini AI Response

Future Improvements

  • Streaming AI responses
  • Multi-PDF chat
  • PDF page preview
  • OCR support
  • LangChain integration
  • Background processing queues
  • Redis caching
  • Conversation memory

🖼 Frontend Preview

Screenshot 2026-05-24 211156

Screenshot 2026-05-24 211323

chatpdf ui


Author

Saptarshi Dey

About

AI-powered ChatPDF SaaS to upload PDFs and chat with documents in real time using advanced AI.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors