A production-ready MERN stack application that enables users to upload documents (PDF/TXT), extract text content, and ask AI-powered questions with answers strictly grounded in their uploaded documents.
- Secure Signup & Login with email and password
- JWT-based authentication with token expiration
- Password hashing using bcrypt
- Protected routes - users can only access their own data
- Upload PDF and TXT files (max 10MB)
- Automatic text extraction from documents
- Real-time processing status (processing, completed, failed)
- Document metadata tracking (name, size, upload date)
- Delete documents with file cleanup
- Drag-and-drop upload interface
- Ask questions about uploaded documents
- AI answers strictly from document content - no hallucinations
- Source references for every answer
- Chat-style interface with conversation history
- Automatic context building from all user documents
- Fallback responses when information is not found
- View past questions and answers
- Pagination support for large histories
- Delete individual queries or clear all history
- Timestamp tracking for all interactions
- Responsive design - works on all devices
- Clean, intuitive interface with smooth animations
- Real-time updates for document processing
- Loading states and error handling
- Premium gradient designs and glassmorphism effects
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database
- Mongoose - ODM
- JWT - Authentication
- bcryptjs - Password hashing
- Multer - File uploads
- pdf-parse - PDF text extraction
- Google Gemini AI - Answer generation
- React 18 - UI library
- Vite - Build tool
- React Router - Navigation
- Axios - HTTP client
- Context API - State management
- CSS3 - Styling with custom design system
DocAssign/
βββ backend/
β βββ controllers/
β β βββ authController.js
β β βββ documentController.js
β β βββ queryController.js
β βββ middleware/
β β βββ auth.js
β βββ models/
β β βββ User.js
β β βββ Document.js
β β βββ QueryHistory.js
β βββ routes/
β β βββ auth.js
β β βββ document.js
β β βββ query.js
β βββ utils/
β β βββ upload.js
β β βββ textExtractor.js
β β βββ aiService.js
β βββ uploads/
β βββ server.js
β βββ .env
β βββ .env.example
β βββ .gitignore
β βββ package.json
β
βββ frontend/
βββ src/
β βββ components/
β β βββ ChatInput.jsx
β β βββ ChatMessage.jsx
β β βββ DocumentList.jsx
β β βββ DocumentUpload.jsx
β β βββ Navigation.jsx
β β βββ PrivateRoute.jsx
β βββ context/
β β βββ AuthContext.jsx
β βββ pages/
β β βββ Home.jsx
β β βββ Login.jsx
β β βββ Register.jsx
β β βββ Dashboard.jsx
β β βββ Chat.jsx
β βββ services/
β β βββ api.js
β βββ styles/
β β βββ App.css
β β βββ Auth.css
β β βββ Dashboard.css
β β βββ Chat.css
β β βββ Home.css
β βββ App.jsx
β βββ main.jsx
βββ .env
βββ index.html
βββ package.json
βββ vite.config.js
- Node.js (v18 or higher)
- MongoDB (local or Atlas)
- Google Gemini API Key (or OpenAI API Key)
git clone <repository-url>
cd DocAssigncd backend
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Edit .env file with your configuration
# Required variables:
# - MONGO_URI: Your MongoDB connection string
# - JWT_SECRET: A strong random string
# - GEMINI_API_KEY: Your Google Gemini API keyCreate a .env file in the backend directory:
# Server Configuration
PORT=5000
# Database
MONGO_URI=mongodb://localhost:27017/docassign
# For MongoDB Atlas: mongodb+srv://username:password@cluster.mongodb.net/docassign
# JWT Secret (Use a strong random string in production)
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production
# AI Configuration
GEMINI_API_KEY=your_gemini_api_key_here
# Alternative: OPENAI_API_KEY=your_openai_api_key_here
# File Upload Configuration
MAX_FILE_SIZE=10485760# Development mode with auto-reload
npm run dev
# Production mode
npm startThe backend server will run on http://localhost:5000
cd frontend
# Install dependencies
npm install
# Create .env file
echo "VITE_API_URL=http://localhost:5000" > .env
# Start development server
npm run devThe frontend will run on http://localhost:5173
- Visit Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy the key and add it to your
.envfile
- Visit OpenAI Platform
- Sign in or create an account
- Create a new API key
- Copy the key and add it to your
.envfile - Uncomment the OpenAI code in
backend/utils/aiService.js
- Upload: User uploads a PDF or TXT file
- Storage: File is saved to the
uploads/directory - Database Entry: Document metadata is stored in MongoDB with status "processing"
- Text Extraction:
- PDF files: Extracted using
pdf-parselibrary - TXT files: Read directly from filesystem
- PDF files: Extracted using
- Update: Document status updated to "completed" or "failed"
- Ready: Document text is now available for AI queries
- User Question: User asks a question in the chat interface
- Context Building: System retrieves all completed documents for the user
- Prompt Construction: Creates a prompt with:
- System instructions (answer only from documents)
- All document texts with metadata
- User's question
- AI Generation: Sends to Google Gemini (or OpenAI)
- Reference Extraction: Identifies relevant document excerpts
- Response: Returns answer with source references
- History: Saves question, answer, and references to database
- Answers questions strictly based on uploaded document content
- Provides source references for every answer
- Indicates when information is not found in documents
- Generate answers from general knowledge
- Make assumptions beyond document content
- Process scanned PDFs (OCR not implemented)
- Understand images or charts in PDFs
- No OCR: Scanned PDFs without text layer won't be processed
- Basic Matching: Uses simple keyword matching for references (no vector DB)
- Context Limit: Very large documents may exceed AI context window
- English-focused: Best results with English text
- No Multi-modal: Cannot process images, tables, or charts
- Navigate to the home page
- Click "Get Started" or "Sign Up"
- Enter your email and password (min 6 characters)
- Click "Create Account"
- Go to the Dashboard
- Drag and drop a PDF or TXT file, or click "Choose File"
- Click "Upload Document"
- Wait for processing to complete (status will update automatically)
- Navigate to the Chat page
- Type your question in the input field
- Press Enter or click the send button
- View the AI's answer with source references
- View all documents in the Dashboard
- Check processing status
- Delete documents you no longer need
- All questions and answers are saved automatically
- Scroll through chat history
- Clear history if needed
- Password Hashing: All passwords hashed with bcrypt (10 salt rounds)
- JWT Authentication: Secure token-based auth with 7-day expiration
- Protected Routes: Backend validates JWT on all protected endpoints
- User Isolation: Users can only access their own documents and queries
- File Validation: Only PDF and TXT files allowed, max 10MB
- Error Handling: Comprehensive error handling without exposing sensitive data
- Create a simple TXT file with some content
- Upload it via the Dashboard
- Wait for "Completed" status
- Upload a document with known content
- Ask a specific question about that content
- Verify the answer matches the document
- Check that references are provided
- Ask a question about content NOT in your documents
- Verify you get: "The uploaded documents do not contain enough information to answer this."
- Check MongoDB is running
- Verify
.envfile exists and has correct values - Ensure port 5000 is not in use
- Verify backend is running on port 5000
- Check
VITE_API_URLin frontend.env - Check browser console for CORS errors
- Check file is valid PDF or TXT
- Verify file size is under 10MB
- Check backend logs for errors
- Verify your API key is correct
- Check document was processed successfully
- Review backend logs for AI service errors
Register a new user
{
"email": "user@example.com",
"password": "password123"
}Login user
{
"email": "user@example.com",
"password": "password123"
}Get current user profile (requires auth)
Upload a document (requires auth, multipart/form-data)
Get all user documents (requires auth)
Get single document (requires auth)
Delete document (requires auth)
Ask a question (requires auth)
{
"question": "What is the main topic?"
}Get query history (requires auth)
Delete single query (requires auth)
Clear all history (requires auth)
- Push code to GitHub
- Connect repository to hosting platform
- Set environment variables
- Deploy
- Push code to GitHub
- Connect repository to hosting platform
- Set build command:
npm run build - Set output directory:
dist - Add environment variable:
VITE_API_URL=<your-backend-url> - Deploy
- Create account at MongoDB Atlas
- Create a cluster
- Create database user
- Whitelist IP addresses (or allow all for development)
- Get connection string
- Update
MONGO_URIin backend.env
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
This project is licensed under the MIT License.
Built with β€οΈ using the MERN stack
- Google Gemini AI for intelligent answer generation
- pdf-parse library for PDF text extraction
- MongoDB for flexible document storage
- React and Vite for modern frontend development
Note: This is a demonstration project. For production use, consider adding:
- Rate limiting
- File virus scanning
- Vector database for better semantic search
- OCR for scanned PDFs
- Multi-language support
- User email verification
- Password reset functionality
- Document sharing features
- Advanced analytics