RAG-edu is a document-learning platform focused on Vietnamese history study materials. The current backend direction is Spring Boot plus a FastAPI RAG service: users upload documents, the Spring API stores metadata and files, then the RAG service extracts content, chunks it, embeds it, stores vectors in Qdrant, and answers questions with citations.
| Layer | Technology | Purpose |
|---|---|---|
| Web app | Next.js, React, Tailwind CSS | Student/admin/moderator user interface |
| Main backend | Spring Boot, Java 21, Spring Security, JPA | Auth, users, folders, documents, settings, RAG gateway |
| RAG service | FastAPI, Python 3.12 | Extraction, chunking, embeddings, retrieval, LLM answers |
| Database | MySQL | Users, refresh tokens, folders, documents, settings |
| Vector store | Qdrant | Embedded document chunks for retrieval |
| AI provider | Google GenAI | Embeddings and answer generation |
| Local runtime | Docker Compose | MySQL, Spring backend, RAG service |
- A user registers or logs in through the Spring Boot API.
- The user creates folders and uploads PDF/DOCX/TXT documents.
- Spring Boot stores the file locally and creates a document record.
- After the DB transaction commits, Spring Boot calls the RAG service to ingest the file.
- FastAPI extracts text, chunks it, creates embeddings, and upserts vectors to Qdrant.
- Users ask questions against a folder or the RAG gateway.
- The RAG service retrieves relevant chunks and returns an answer with citations.
RAG-edu/
├─ backend/ # Spring Boot API
│ ├─ src/main/java/ # Auth, documents, folders, settings, RAG gateway
│ ├─ src/main/resources/ # application.yml and Flyway migrations
│ └─ src/test/java/ # Spring unit/controller tests
├─ rag-service/ # FastAPI RAG service
│ ├─ app/api/ # /rag chat, ingest, retrieve endpoints
│ ├─ app/services/ # extraction, chunking, embedding, retrieval, LLM
│ ├─ app/vectorstore/ # Qdrant client/repository
│ └─ tests/ # Python unit/API tests
├─ apps/web/ # Next.js frontend
├─ apps/test-files/ # Small sample files for upload/manual testing
├─ packages/ # Shared frontend tokens/config packages
├─ docker-compose.yaml # Local MySQL + backend + RAG service
├─ e2e-test.sh # Spring/RAG smoke test script
└─ .env.example # Environment variable template
Copy the root template and fill in secrets:
cp .env.example .envImportant variables:
| Variable | Description |
|---|---|
MYSQL_URL |
Spring datasource URL |
MYSQL_USER / MYSQL_PASSWORD |
MySQL credentials |
JWT_SECRET_KEY |
HS384 JWT signing key |
RAG_SERVICE_URL |
Spring -> FastAPI base URL |
QDRANT_URL / QDRANT_API_KEY |
Qdrant endpoint and key |
QDRANT_COLLECTION |
Vector collection name |
GOOGLE_API_KEY |
Google GenAI key |
UPLOAD_BASE_PATH |
Local upload directory shared by Spring/RAG |
CORS_ALLOWED_ORIGINS |
Allowed frontend origins |
docker compose up --buildDefault local services:
| Service | URL |
|---|---|
| Spring Boot API | http://localhost:8080 |
| API base path | http://localhost:8080/api/v1 |
| RAG service | http://localhost:8001 |
| MySQL | localhost:3307 |
Health checks:
curl http://localhost:8080/actuator/health
curl http://localhost:8080/api/v1/rag/health
curl http://localhost:8001/rag/healthcd backend
mvn spring-boot:runThis requires Maven on the host. If Maven is not installed, use Docker Compose instead.
cd backend
mvn spring-boot:runcd rag-service
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8001On Windows PowerShell:
cd rag-service
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8001pnpm install
pnpm --filter web devThe web app is still being aligned to the Spring Boot API contract. When working
on frontend integration, set NEXT_PUBLIC_API_URL=http://localhost:8080.
| Command | Description |
|---|---|
docker compose up --build |
Start MySQL, Spring Boot backend, and RAG service |
cd backend && mvn test |
Run Spring tests when Maven is installed locally |
cd rag-service && pytest |
Run RAG service tests |
pnpm --filter web dev |
Start the Next.js web app |
pnpm --filter web test |
Run web tests |
./e2e-test.sh |
Run Spring/RAG smoke flow after services are up |
Spring Boot exposes versioned APIs under /api/v1.
Key groups:
POST /api/v1/auth/registerPOST /api/v1/auth/loginPOST /api/v1/auth/refreshGET /api/v1/auth/meGET/POST /api/v1/foldersPOST /api/v1/folders/{id}/chatGET/POST /api/v1/documentsPATCH /api/v1/documents/{id}DELETE /api/v1/documents/{id}POST /api/v1/documents/{id}/restorePOST /api/v1/documents/{id}/reindexGET/PATCH /api/v1/admin/configGET /api/v1/dashboardPOST /api/v1/rag/chatPOST /api/v1/rag/chat/streamPOST /api/v1/rag/retrievePOST /api/v1/rag/ingest
FastAPI RAG endpoints are mounted under /rag.
- Treat
backend/andrag-service/as the source of truth for backend work. - The removed NestJS/MongoDB backend artifacts are no longer part of the active backend direction.
- Keep generated folders out of git:
.next/,target/,__pycache__/,.pytest_cache/,.venv/, and uploaded local files. - Before changing API contracts, update the web integration code and the E2E script together.