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.