How mostafaai10/mofid works
Mofid is an offline-first curriculum Q&A MVP: a student asks through the web app, the API retrieves course-scoped curriculum passages, and a local Karnak model generates a grounded answer with citations—or the API refuses when retrieval finds no relevant content. The repository also includes curriculum preparation and indexing, plus the documented teacher-upload capability. The tree has no teacher-dashboard UI or FAQ implementation, so those are not represented as implemented components; deployment scripts are omitted. Some frontend and ingestion links are based on explicit documentation because their full source was not sampled.
Main entry points: rag.py RAG retrieval/indexing · app.py FastAPI endpoints · physics_grade12.json Curriculum chunks · app.js Chat interface
Components 18
Student experience
- Chat interface
webapp/app.js - API client
webapp/api.js
Answer backend
- FastAPI endpoints
backend/app.py - RAG retrieval/indexing
backend/rag.py - Query normalization
backend/textnorm.py - Backend settings
backend/config.py - Embedding model
- Chroma vector store
- Karnak inference server
Curriculum preparation
- Curriculum chunks
content/physics_grade12.json - PDF extraction
tools/extract_pdf.py - Chunk generation
tools/make_chunks.py - Chunk review
tools/review_report.py - Chunk validation
tools/validate_chunks.py - Initial index loader
backend/index_content.py
Offline delivery
- App cache
webapp/sw.js
Other components
- Student
- Teacher content uploader
Connections 19
- Student → Chat interface: asks question
README.md - Chat interface → API client: uses API
webapp/app.js - API client → FastAPI endpoints: calls ask/health
webapp/api.js - Chat interface → App cache: registers worker
webapp/app.js - FastAPI endpoints → RAG retrieval/indexing: retrieves context
backend/app.py - FastAPI endpoints → RAG retrieval/indexing: indexes uploads
backend/app.py - FastAPI endpoints → Karnak inference server: requests generation
backend/app.py - RAG retrieval/indexing → Embedding model: embeds text
backend/rag.py - RAG retrieval/indexing → Chroma vector store: queries and upserts
backend/rag.py - RAG retrieval/indexing → Query normalization: checks coverage
backend/rag.py - RAG retrieval/indexing → Backend settings: reads settings
backend/rag.py - FastAPI endpoints → Backend settings: reads settings
backend/app.py - Curriculum chunks → Initial index loader: loaded from
backend/index_content.py - Initial index loader → RAG retrieval/indexing: indexes chunks
backend/index_content.py - PDF extraction → Chunk generation: provides page text
tools/make_chunks.py - Chunk generation → Curriculum chunks: produces draft
- Curriculum chunks → Chunk review: reviewed as input
tools/review_report.py - Curriculum chunks → Chunk validation: validated as input
tools/validate_chunks.py - Teacher content uploader → FastAPI endpoints: uploads chunks
README.md