Skip to content

Joseph24x7/PDFChatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Document Q&A System πŸ€–

An AI-powered document analysis platform with real-time chat and intelligent search capabilities.

✨ Features

  • πŸ“„ PDF Upload & Analysis - Upload PDFs and chat with your documents
  • πŸ” Smart Search - WebSocket & Elasticsearch-powered fuzzy search with autocomplete
  • πŸ” Privacy First - 100% local processing with Ollama (no external APIs)
  • 🎯 Session Management - Multiple concurrent document conversations

πŸ› οΈ Technology Stack

Backend

  • Spring Boot 3.5.7 + Java 21
  • Spring AI (LLM integration)
  • Elasticsearch 8.11 (search)
  • MongoDB 7.0 (storage)
  • WebSocket/STOMP (real-time)
  • Apache PDFBox (PDF parsing)

Frontend

  • React 18 + Vite
  • STOMP.js + SockJS (WebSocket client)
  • Custom design system

Infrastructure

  • Docker Compose
  • Ollama (Llama 3.1 8B model)
  • Single-port deployment

πŸ“ Architecture & Data Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           USER BROWSER                              β”‚
β”‚                     React 18 + Vite Frontend                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ Session List β”‚  β”‚ Document     β”‚  β”‚ Chat Interface           β”‚   β”‚
β”‚  β”‚ (Search)     β”‚  β”‚ Upload       β”‚  β”‚ (WebSocket Streaming)    β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
└─────────────┬────────────┬────────────────────┬────────────────── β”€β”€β”˜
              β”‚            β”‚                    β”‚
              β”‚  WebSocket β”‚ REST API           β”‚ REST API
              β”‚ (Search)   β”‚ (Upload)           β”‚ (Real-time Chat)
              β”‚            β”‚                    β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    SPRING BOOT APPLICATION                         β”‚
β”‚                      (Single Port: 8080)                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚                     Controllers Layer                        β”‚  β”‚
β”‚  β”‚  β€’ WebSocketController  β€’ DocumentController β€’ ChatControllerβ”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚               β”‚                     β”‚                  β”‚           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚                      Service Layer                            β”‚ β”‚
β”‚  β”‚  β€’ ChatService                                                β”‚ β”‚
β”‚  β”‚  β€’ DocumentService                                            β”‚ β”‚    
β”‚  β”‚  β€’ ElasticsearchSearchService                                 β”‚ β”‚
β”‚  β”‚                                                               β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚           β”‚              β”‚              β”‚             β”‚            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  AI         β”‚  β”‚   PDFBox    β”‚ β”‚ MongoDB  β”‚ β”‚ Elasticsearch β”‚   β”‚
β”‚  β”‚ Integration β”‚  β”‚  Text       β”‚ β”‚ Repo     β”‚ β”‚    Client     β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β”‚  Extraction β”‚ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚           β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚            β”‚              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚                            β”‚            β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  OLLAMA LLM    β”‚         β”‚    MONGODB     β”‚ β”‚ ELASTICSEARCH  β”‚
    β”‚  (Llama 3.1)   β”‚         β”‚                β”‚ β”‚                β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„ Data Flow Scenarios

1. Document Upload Flow:

User β†’ Upload PDF β†’ DocumentController β†’ PDFBox (Extract) 
     β†’ Save to MongoDB β†’ Create Session β†’ Sync to Elasticsearch 
     β†’ Return Session ID

2. Chat Message Flow (WebSocket):

User β†’ Send Message β†’ WebSocketController β†’ ChatService 
     β†’ Retrieve Context from MongoDB β†’ Spring AI β†’ Ollama LLM
     β†’ Stream Tokens β†’ WebSocket β†’ User (Real-time Display)
     β†’ Save to MongoDB β†’ Sync to Elasticsearch

3. Search Flow (Real-time):

User β†’ Type Query β†’ WebSocketController β†’ ElasticsearchSearchService
     β†’ Fuzzy Search in Elasticsearch β†’ Return Results β†’ WebSocket
     β†’ Display Matches (Live Update)

4. Session Retrieval Flow:

User β†’ Select Session β†’ REST API β†’ ChatService 
     β†’ Fetch from MongoDB β†’ Return History β†’ Display Chat

πŸš€ Quick Start

Prerequisites

  • 8GB RAM minimum (for Ollama LLM)
  • Docker Desktop or Podman
  • Maven 4.x+
  • Java 21+
  • IntelliJ IDEA or VSCode (optional)

One-Command Setup

docker-compose up -d

Wait 1-2 minutes for services to start and Ollama model to download.

mvn clean install

4. Build & Run Application

spring-boot:run 
(or)
java -jar target/PDFChatBot.jar

Then open: http://localhost:8080

πŸ“– How It Works

  1. Upload PDF β†’ System extracts text and creates a chat session
  2. Ask Questions β†’ LLM analyzes document context and responds
  3. Real-Time Streaming β†’ Responses stream token-by-token like ChatGPT
  4. Search Sessions β†’ Find past conversations with fuzzy search
  5. Continue Conversations β†’ Resume any chat session

πŸ“¦ Project Structure

document-summary/
β”œβ”€β”€ src/main/java/com/docqa/
β”‚   β”œβ”€β”€ config/         # Spring & Elasticsearch config
β”‚   β”œβ”€β”€ controller/     # REST & WebSocket endpoints
β”‚   β”œβ”€β”€ service/        # Business logic & LLM integration
β”‚   β”œβ”€β”€ repository/     # MongoDB repositories
β”‚   └── model/          # Domain entities
β”œβ”€β”€ frontend/src/
β”‚   β”œβ”€β”€ components/     # React components
β”‚   β”œβ”€β”€ api/           # API client
β”‚   └── design-system.css  # UI styles
└── docker-compose.yml  # Infrastructure setup

πŸ” Architecture Highlights

  • Single-Port Deployment - Frontend served from Spring Boot
  • Async Streaming - Non-blocking WebSocket responses
  • Search Indexing - Auto-sync MongoDB β†’ Elasticsearch
  • Session Isolation - Each document gets separate context

πŸ“„ License

MIT License - Feel free to use for personal or commercial projects!

🀝 Contributing

Contributions welcome! Please open an issue or PR.


Built with ❀️ using Spring Boot β€’ React β€’ Ollama β€’ Elasticsearch β€’ MongoDB

About

A full-stack application combining React + Vite frontend with Spring Boot backend for intelligent document Q&A powered by Ollama LLM. Upload PDFs and chat about their content with an AI chatbot that remembers previous questions and context.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors