Document-Grounded AI Question Answering System
Accurate. Secure. Explainable. Free.
- Overview
- Key Features
- Tech Stack
- Architecture
- Project Structure
- Prerequisites
- Getting Started
- Environment Variables
- API Overview
- Role-Based Access Control
- Deployment
- Design Philosophy
- Future Enhancements
- Author
EduQuery is a full-stack, enterprise-grade AI question-answering system that answers strictly from uploaded documents — no internet searches, no hallucinations, no external data leaks.
Unlike generic AI chatbots, EduQuery grounds every response in your uploaded knowledge base (PDFs, DOCX, TXT files), ensuring answers are accurate, traceable, and trustworthy.
| Use Case | Description |
|---|---|
| 🏫 Academic Projects | College and university AI demonstrations |
| 🏢 Enterprise Knowledge Systems | Internal document Q&A for organizations |
| 🔒 Secure AI Deployments | No external data exposure |
| 🤖 AI Research | Document-grounded reasoning experiments |
- Responses generated only from uploaded resources — never from the internet
- Eliminates hallucination and ensures factual accuracy
- Full traceability: every answer maps to a source document
- Admin and User roles with separate login portals
- Admin manages knowledge base; Users interact with the AI
- JWT-based secure authentication
- Powered by Cloudflare AI (LLaMA 3 Instruct) — completely free tier
- No billing from OpenAI, Groq, or HuggingFace
- Unlimited local and cloud-safe inference
- Minimal, distraction-free layout
- Chat-style conversational interface
- Conversation history management per user
- Professional color palette optimized for long sessions
- Rate limiting on chat endpoints to prevent abuse
- Admin accounts created via seed script only (no UI registration)
- Environment-based configuration for all secrets
| Layer | Technology |
|---|---|
| Frontend | React.js, Tailwind CSS |
| Backend | Node.js, Express.js |
| Database | MongoDB (via Mongoose ODM) |
| Authentication | JSON Web Tokens (JWT) |
| AI Inference | Cloudflare AI — LLaMA 3 Instruct |
| Deployment | Render (Static Site + Web Service) |
┌────────────────────────────────────────────────────────────┐
│ Frontend (React.js) │
│ Landing → Login (Admin/User) → Chat UI / Admin Dashboard │
└──────────────────────────┬─────────────────────────────────┘
│ REST API (HTTP)
┌──────────────────────────▼─────────────────────────────────┐
│ Backend (Node.js + Express) │
│ Auth Routes | Chat Routes | Admin Routes | Resource Routes │
│ JWT Middleware | Rate Limiter | Role Guards │
└──────────────────────────┬─────────────────────────────────┘
┌───────────────┼──────────────────┐
▼ ▼ ▼
┌──────────┐ ┌────────────┐ ┌──────────────────┐
│ MongoDB │ │ Cloudflare │ │ Uploaded Docs │
│ (Users, │ │ AI API │ │ (PDF, DOCX, TXT)│
│ Chats, │ │ LLaMA 3 │ │ │
│ Resources│ │ Instruct │ │ │
└──────────┘ └────────────┘ └──────────────────┘
Data Flow:
- User submits a question via the chat UI
- Backend fetches relevant document context from MongoDB
- A strict prompt (document context only) is sent to Cloudflare AI
- AI responds using only the provided context
- Response is saved to conversation history and returned to user
EduQuery/
│
├── backend/
│ ├── config/
│ │ └── db.js # MongoDB connection setup
│ ├── controllers/
│ │ ├── authController.js # Login, register, JWT issuance
│ │ ├── chatController.js # Chat logic, AI call, response save
│ │ ├── adminController.js # Admin dashboard data & user management
│ │ └── resourceController.js # Document upload, list, delete
│ ├── middleware/
│ │ ├── auth.js # JWT verification middleware
│ │ ├── admin.js # Admin role guard
│ │ └── rateLimit.js # Chat endpoint rate limiter
│ ├── models/
│ │ ├── User.js # User schema (name, email, role, password)
│ │ ├── Resource.js # Document/resource schema
│ │ ├── Chat.js # Individual chat message schema
│ │ └── Conversation.js # Conversation thread schema
│ ├── routes/
│ │ ├── authRoutes.js # /api/auth/*
│ │ ├── chatRoutes.js # /api/chat/*
│ │ ├── adminRoutes.js # /api/admin/*
│ │ └── resourceRoutes.js # /api/resources/*
│ ├── services/
│ │ └── cloudflareAI.js # Cloudflare AI API wrapper
│ ├── seedAdmin.js # One-time admin account seeder
│ ├── server.js # Express app entry point
│ └── .env # Backend environment variables
│
├── frontend/
│ ├── public/
│ └── src/
│ ├── components/
│ │ ├── Navbar.jsx # Top navigation bar
│ │ └── admin/ # Admin-specific components
│ ├── pages/
│ │ ├── Landing.jsx # Public landing page
│ │ ├── LoginAdmin.jsx # Admin login page
│ │ ├── LoginUser.jsx # User login page
│ │ ├── Register.jsx # User registration page
│ │ ├── Profile.jsx # User profile page
│ │ ├── UserChat.jsx # Main chat interface
│ │ └── Admin/
│ │ └── AdminDashboard.jsx # Admin control panel
│ ├── services/
│ │ ├── chatApi.js # Axios calls for chat endpoints
│ │ └── resourceApi.js # Axios calls for resource endpoints
│ ├── App.js # Root component with routing
│ └── index.js # React entry point
│ └── .env # Frontend environment variables
│
└── README.md
Make sure the following are installed on your system before proceeding:
- Node.js v18+ and npm
- MongoDB (local instance or MongoDB Atlas)
- A Cloudflare account with AI access enabled
- Git
git clone https://github.com/your-username/eduquery.git
cd EduQuerycd backend
npm installCreate a .env file in the backend/ directory:
PORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
CF_ACCOUNT_ID=your_cloudflare_account_id
CF_AI_TOKEN=your_cloudflare_ai_tokenStart the backend server:
node server.js✅ Backend will be running at: http://localhost:5000
cd frontend
npm installCreate a .env file in the frontend/ directory:
REACT_APP_API_URL=http://localhost:5000Start the frontend:
npm start✅ Frontend will be running at: http://localhost:3000
Admin accounts are not created through the UI for security reasons. Use the seed script to create the initial admin account:
cd backend
node seedAdmin.js
⚠️ Important: Run this only once. UpdateseedAdmin.jswith your desired admin credentials before running.
| Variable | Description | Example |
|---|---|---|
PORT |
Port for the Express server | 5000 |
MONGO_URI |
MongoDB connection string | mongodb+srv://... |
JWT_SECRET |
Secret key for JWT signing | mysupersecretkey |
CF_ACCOUNT_ID |
Cloudflare account ID | abc123def456 |
CF_AI_TOKEN |
Cloudflare AI API token | Bearer xyz... |
| Variable | Description | Example |
|---|---|---|
REACT_APP_API_URL |
Base URL for backend API | http://localhost:5000 |
🔒 Never commit
.envfiles to version control. Add them to.gitignore.
| Method | Endpoint | Description | Access |
|---|---|---|---|
POST |
/register |
Register a new user | Public |
POST |
/login/user |
User login | Public |
POST |
/login/admin |
Admin login | Public |
| Method | Endpoint | Description | Access |
|---|---|---|---|
POST |
/ask |
Ask a question (AI responds from docs) | User |
GET |
/history |
Get conversation history | User |
DELETE |
/history/:id |
Delete a specific conversation | User |
| Method | Endpoint | Description | Access |
|---|---|---|---|
POST |
/upload |
Upload a new document | Admin |
GET |
/ |
List all uploaded documents | Admin |
DELETE |
/:id |
Delete a document | Admin |
| Method | Endpoint | Description | Access |
|---|---|---|---|
GET |
/users |
List all registered users | Admin |
GET |
/stats |
Usage statistics | Admin |
EduQuery uses a two-role system enforced by JWT middleware:
- Register and log in via the User portal
- Ask questions through the conversational chat interface
- View, manage, and delete personal conversation history
- Access profile settings
- Log in via the Admin portal (no self-registration)
- Upload, view, and delete knowledge documents (PDF, DOCX, TXT)
- Monitor user activity and system usage
- Access the full Admin Dashboard
Role is embedded in the JWT payload. The
admin.jsmiddleware checks the role on every protected admin route.
EduQuery is deployed on Render — free tier supported.
- Connect your GitHub repository to Render
- Set Build Command:
npm run build - Set Publish Directory:
build - Add a
_redirectsfile inpublic/for SPA routing:/* /index.html 200 - Set
REACT_APP_API_URLto your deployed backend URL in Render's environment settings
- Connect your GitHub repository to Render
- Set Start Command:
node server.js - Add all backend environment variables in Render's environment settings
- Use MongoDB Atlas for the database (free M0 cluster available)
EduQuery is built around four core principles:
- Accuracy First — No hallucinations. The AI is strictly constrained to answer only from uploaded documents.
- Transparency — Every answer is traceable to a document in the knowledge base.
- Security — JWT authentication, role guards, rate limiting, and seed-only admin creation prevent unauthorized access.
- Simplicity — Clean, minimal UI with clear visual hierarchy makes the system easy to use for long sessions.
- Source Highlighting — Highlight the exact document passage used for each answer
- Confidence Scoring — Show AI confidence level per response
- Multi-Document Citations — Reference multiple source documents in one answer
- Analytics Dashboard — Visualize query trends and document usage
- Document Chunking & Vector Search — Improve retrieval accuracy with embeddings
- Multi-language Support — Support documents and queries in multiple languages
- Export Conversations — Download chat history as PDF or CSV
Balaji
B.Tech — Artificial Intelligence & Machine Learning
This project is intended for academic and demonstration purposes.
EduQuery demonstrates full-stack engineering, secure AI deployment, document-grounded reasoning, and production-ready system design.