A complete RAG (Retrieval Augmented Generation) system featuring Authentication, User Roles (Admin/Student), and File Upload capabilities. Built with Next.js (Frontend) and FastAPI (Backend).
- Authentication: Secure Login and Registration system using JWT.
- User Roles:
- Admin: Can upload PDF/Text files to the knowledge base.
- Student: Can chat with the AI about the uploaded knowledge.
- Persistent RAG: Uses ChromaDB (saved to disk) to remember uploaded files across restarts.
- Modern UI: Dark-themed, responsive chat interface.
graph LR
User[Clients] --> Frontend[Next.js App]
Frontend --> Auth[Auth System]
Frontend --> Backend[FastAPI Server]
Backend --> DB[(SQLite Users DB)]
Backend --> VectorDB[(Chroma Vector DB)]
Backend --> LLM[OpenRouter/LLM]
- Python 3.8+
- Node.js 18+
Navigate to the Backend directory:
cd BackendCreate and activate virtual environment:
python -m venv env
# Windows
.\env\Scripts\activate
# Mac/Linux
source env/bin/activateInstall dependencies:
pip install -r requirements.txt
# Verify bcrypt compatibility
pip install "bcrypt<4.0.0"Create a .env file in the Backend directory:
OPENROUTER_API_KEY=your_api_key_here
SECRET_KEY=your_super_secret_jwt_keyRun the server:
uvicorn app:app --reload --port 8000Server runs at http://localhost:8000
Navigate to the Frontend directory:
cd frontendInstall dependencies:
npm installCreate a .env.local file:
NEXT_PUBLIC_BACKEND_URL=http://localhost:8000Run the development server:
npm run devApp runs at http://localhost:3000
- Register: Go to
http://localhost:3000/register.- Create an Admin account (select role: Admin).
- Create a Student account.
- Upload Knowledge (Admin):
- Login as Admin.
- Use the "Upload Knowledge" panel to upload PDF or Text files.
- Chat (Student/Admin):
- Login.
- Ask questions! The AI will answer based on the files you uploaded.
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/register |
Create a new user | No |
POST |
/token |
Login (Returns JWT) | No |
POST |
/upload |
Upload & Index File | Yes (Admin) |
POST |
/ask |
Chat with RAG | Yes |
GET |
/users/me |
Get current user info | Yes |
Error: AttributeError: module 'bcrypt' has no attribute '__about__'
- Fix: Run
pip install "bcrypt<4.0.0"in your backend environment. This is a known compatibility issue withpasslib.