How hoangnam2464/ai-teacher-copilot works
Purpose and topology
AI Teacher Copilot is a K–12 teacher tool for producing cited lesson plans and quizzes from uploaded teaching documents. It is a three-service system: React browser client → Spring Boot public API/gateway → internal FastAPI AI service. Core bootstraps are frontend/src/main.jsx, backend/src/main/java/com/aiteachercopilot/AiTeacherCopilotApplication.java, and ai-service/app/main.py.
Client application
The React/Vite frontend owns teacher-facing navigation, authenticated route gating, workspace context, document management, and lesson/quiz screens. It calls the Spring Boot API through a centralized client rather than FastAPI. Key boundaries: frontend/src/app/routes/AppRoutes.jsx, frontend/src/core/services/client.js, frontend/src/core/store/authStore.js, frontend/src/features/lesson-planner/pages/LessonPlannerPage.jsx, and frontend/src/features/quiz-generator/pages/QuizGeneratorPage.jsx.
Identity, tenancy, and gateway
Spring Boot is the externally reachable REST boundary. It authenticates users with JWT, applies Spring Security, and owns application-level user/workspace/document metadata and authorization. Workspace ownership scopes downstream document and generation actions. Key paths: backend/src/main/java/com/aiteachercopilot/auth/AuthController.java, backend/src/main/java/com/aiteachercopilot/auth/JwtAuthenticationFilter.java, backend/src/main/java/com/aiteachercopilot/workspace/WorkspaceService.java, and backend/src/main/java/com/aiteachercopilot/config/SecurityConfig.java.
Document storage and ingestion
Document uploads are represented and managed in the backend, with binary PDFs/DOCX intended for MinIO object storage. The AI service performs the content pipeline: parse document structure, chunk text, create embeddings, and persist searchable chunk/vector records. This isolates untrusted document content from the public gateway and browser. Key paths: backend/src/main/java/com/aiteachercopilot/document/DocumentService.java, backend/src/main/java/com/aiteachercopilot/config/MinioConfig.java, ai-service/app/ingestion/parser.py, ai-service/app/ingestion/chunker.py, and ai-service/app/ingestion/service.py.
Retrieval and generation
FastAPI exposes internal document, ingestion, retrieval, and generation routes. Retrieval embeds a teacher query and performs metadata-filtered semantic search against pgvector, expected to scope results by workspace/subject/grade. Generation consumes retrieved chunks, wraps them as <sources>...</sources> untrusted context, calls an LLM provider, validates structured outputs, and returns citation-capable results to the backend. Key paths: ai-service/app/api/routes/retrieval.py, ai-service/app/retrieval/service.py, ai-service/app/api/routes/generation.py, ai-service/app/generation/service.py, and ai-service/app/generation/schemas.py.
Provider and trust boundary
LLM and embedding access is behind a provider abstraction so Gemini and OpenAI can be selected without coupling ingestion/generation orchestration to a vendor. Prompt construction must retain the explicit sources boundary: uploaded/retrieved text must never become trusted system instructions. Key paths: ai-service/app/providers/base.py, ai-service/app/providers/gemini_provider.py, ai-service/app/providers/openai_provider.py, and ai-service/app/core/security.py.
Persistence and infrastructure
PostgreSQL 16 with pgvector is the shared relational/vector store; Flyway owns schema evolution, including vector dimensions. MinIO stores original files. Docker Compose provides development/production deployment definitions and container images for all three services. Material paths: backend/src/main/resources/db/migration/V1__init_schema.sql, backend/src/main/resources/db/migration/V2__update_vector_dimension.sql, infrastructure/docker-compose/docker-compose.dev.yml, infrastructure/docker-compose/docker-compose.prod.yml, and infrastructure/docker/ai-service.Dockerfile.
Primary control flow
A teacher logs in, selects/creates a workspace, uploads a source document, and waits for ingestion to make its knowledge base searchable. For a lesson or quiz request, the frontend sends JWT-authenticated REST to Spring Boot; the gateway authorizes and calls FastAPI internally. FastAPI retrieves scoped chunks, generates validated grounded output with source references, and returns it through the gateway for UI review, history/export-oriented generation handling, and citation display. Backend generation integration is centered at backend/src/main/java/com/aiteachercopilot/generation/GenerationController.java and backend/src/main/java/com/aiteachercopilot/generation/GenerationService.java.
Main entry points: main.py FastAPI AI service · DocumentService.java Document management · main.jsx React/Vite app · AiTeacherCopilotApplication.java Spring Boot API
Components 19
Teacher client
- React/Vite app · Teacher workspace, document, lesson, and quiz UI.
frontend/src/main.jsx - Protected routes
frontend/src/app/routes/AppRoutes.jsx - Auth state
frontend/src/core/store/authStore.js - Central API client · Calls Spring Boot rather than the AI service.
frontend/src/core/services/client.js - Lesson planner
frontend/src/features/lesson-planner/pages/LessonPlannerPage.jsx - Quiz generator
frontend/src/features/quiz-generator/pages/QuizGeneratorPage.jsx
Public gateway
- Spring Boot API · External boundary for authenticated teacher actions.
backend/src/main/java/com/aiteachercopilot/AiTeacherCopilotApplication.java - JWT security
backend/src/main/java/com/aiteachercopilot/auth/JwtAuthenticationFilter.java - Workspace authorization · Scopes documents and generation actions to ownership.
backend/src/main/java/com/aiteachercopilot/workspace/WorkspaceService.java - Document management
backend/src/main/java/com/aiteachercopilot/document/DocumentService.java - Generation integration · Authorizes requests and calls the internal AI service.
backend/src/main/java/com/aiteachercopilot/generation/GenerationService.java
Internal AI service
- FastAPI AI service · Internal ingestion, retrieval, and generation boundary.
ai-service/app/main.py - Ingestion pipeline · Converts untrusted uploads into searchable chunk records.
ai-service/app/ingestion/service.py - Scoped retrieval · Filters pgvector results by workspace, subject, and grade.
ai-service/app/retrieval/service.py - Grounded generation · Wraps retrieved text in an untrusted sources boundary and validates output.
ai-service/app/generation/service.py - LLM providers · Selects Gemini or OpenAI without coupling orchestration.
ai-service/app/providers/base.py
Data & deployment
- PostgreSQL + pgvector · Stores application metadata and searchable embeddings.
backend/src/main/resources/db/migration/V2__update_vector_dimension.sql - MinIO · Stores original PDF and DOCX files.
backend/src/main/java/com/aiteachercopilot/config/MinioConfig.java - Docker Compose · Runs the three services and supporting stores.
infrastructure/docker-compose/docker-compose.dev.yml
Connections 26
- React/Vite app → Protected routes: renders
- Protected routes → Auth state: gates with
- React/Vite app → Lesson planner: provides
- React/Vite app → Quiz generator: provides
- Lesson planner → Central API client: requests generation
- Quiz generator → Central API client: requests generation
- Central API client → Spring Boot API: JWT REST
- Spring Boot API → JWT security: enforces
- JWT security → Workspace authorization: authorizes tenant actions
- Workspace authorization → Document management: scopes
- Document management → MinIO: stores originals
- Document management → PostgreSQL + pgvector: stores metadata
- Document management → FastAPI AI service: submits ingestion
- Spring Boot API → Generation integration: routes requests
- Generation integration → FastAPI AI service: internal call
- FastAPI AI service → Ingestion pipeline: runs
- Ingestion pipeline → MinIO: reads uploads
- Ingestion pipeline → PostgreSQL + pgvector: persists chunks/vectors
- FastAPI AI service → Scoped retrieval: runs
- Scoped retrieval → PostgreSQL + pgvector: semantic search
- FastAPI AI service → Grounded generation: runs
- Grounded generation → Scoped retrieval: gets scoped sources
- Grounded generation → LLM providers: uses
- Docker Compose → React/Vite app: deploys
- Docker Compose → Spring Boot API: deploys
- Docker Compose → FastAPI AI service: deploys