AI-powered Mathematics Learning Platform for Nigerian Exam Prep
MathGenius is a full-stack web application that combines symbolic math solving, AI tutoring, Computer-Based Testing (CBT), past-question practice, and progress tracking β all tailored for students preparing for WAEC, JAMB, NECO, BECE, and NABTEB examinations.
- AI Solver β Step-by-step solutions for typed or image-based math problems using Groq LLMs + SymPy
- AI Tutor (Teach) β Ask math questions by topic and get structured, curriculum-aligned explanations
- Topic Wiki β Auto-generated study notes and overviews for any math topic
- Floating Chat β Persistent AI assistant available across the app
- Practice Grading β Submit open-ended answers and get AI feedback
- CBT Mode β Timed multiple-choice sessions with automatic marking, difficulty classification, and report summaries
- Past Questions β WAEC, JAMB, NECO, BECE, and NABTEB past questions with filtering by year, topic, and exam type
- Theory Practice β Long-answer theory questions with model-answer comparison
- Mock Exam β Full simulated exam experience with timed sessions
- Daily Challenge β One fresh question set every day
- AI Quiz β Dynamically generated MCQs on any topic
- Question Bank β Browse and filter all stored questions
- XP & Streak System β Earn experience points and build daily streaks
- Leaderboard β Compete with other users globally or by school
- Challenges β Challenge a friend to a head-to-head question set
- Battle Mode β Real-time or async math battles
- Study Groups β Collaborative group study sessions
- Certificates β Downloadable achievement certificates
- Share Profile / Results β Share progress cards to social media
- Dashboard β Overview of XP, streaks, weak topics, and performance prediction
- Topic Mastery β Per-topic mastery percentages with drill-down
- Weekly Report β Printable/downloadable weekly performance report cards
- CBT History β Full history of past CBT sessions with per-question breakdowns
- Bookmarks β Save and revisit specific questions
- Spaced Repetition Reviews β Optimal review scheduling for weak questions
- Study Planner β AI-generated personalized study schedules
- Formula Sheet β Quick-reference sheet of key formulas by topic
- Notes β Personal in-app notes with Markdown support
- Teacher / Parent Dashboard β Read-only monitoring view for guardians
- PWA Support β Installable as a mobile/desktop app with offline caching
- Push Notifications β Browser push notifications for reminders and alerts
| Layer | Technology |
|---|---|
| Frontend | React 19, Vite 7, Tailwind CSS 4, React Router 7 |
| Math Rendering | KaTeX, react-katex |
| Backend | FastAPI, Uvicorn, Pydantic v2 |
| AI / LLM | Groq SDK (Llama / Mixtral models) |
| Symbolic Math | SymPy |
| RAG Pipeline | Qdrant (local vector store), SentenceTransformers, LangChain Text Splitters |
| PDF Processing | PyPDF, pdfplumber |
| Auth & Database | Supabase (Auth, PostgREST, Storage) |
| Scraping | Selenium, BeautifulSoup4, Requests |
| Image Processing | Pillow |
| PWA | vite-plugin-pwa |
| HTTP Client | Axios (frontend), Httpx (backend) |
Math_Genius/
βββ backend/
β βββ app/
β β βββ main.py # FastAPI app entry point, CORS, router registration
β β βββ dependencies.py # Shared dependency injection (Supabase client, etc.)
β β βββ routers/
β β β βββ solve.py # Math solving, step explanations, image OCR, practice
β β β βββ teach.py # AI tutoring, topic overviews, wiki generation
β β β βββ cbt.py # CBT sessions, MCQ generation, daily challenge
β β β βββ exams.py # Exam paper ingestion and retrieval
β β β βββ past_questions.py # Past question fetching and filtering
β β β βββ tracking.py # User sessions, XP, streaks, stats, weak topics
β β β βββ study_plan.py # AI-generated study plan creation
β β βββ services/
β β β βββ groq_service.py # LLM interaction wrapper (Groq)
β β β βββ math_service.py # SymPy symbolic computation helpers
β β β βββ latex_cleaner.py # LaTeX / math expression sanitization
β β β βββ alert_service.py # In-app alert/notification logic
β β β βββ push_service.py # Web push notification dispatch
β β βββ rag/
β β βββ ingest.py # PDF ingestion β embedding β Qdrant upload
β βββ books/ # PDF textbooks for RAG ingestion
β βββ images/ # Served static images (question diagrams)
β βββ qdrant_db/ # Local Qdrant vector store (auto-created)
β βββ waec/ # Scraped WAEC JSON question data
β βββ neco/ # Scraped NECO JSON question data
β βββ jamb/ # Scraped JAMB JSON question data
β βββ bece_objective.json # BECE objective questions (scraped)
β βββ bece_theory.json # BECE theory questions (scraped)
β βββ nabteb_*.json # NABTEB theory questions by year
β βββ solution_generator.py # Standalone solution generation endpoint
β βββ *.py # Utility scripts (scraping, upload, cleanup)
β
βββ frontend/
β βββ public/ # Static assets, PWA manifest, icons
β βββ src/
β β βββ App.jsx # Root component, routing definitions
β β βββ main.jsx # React entry point
β β βββ pages/ # Full page components (35 pages)
β β β βββ Landing.jsx # Public landing/marketing page
β β β βββ Login.jsx / Onboarding.jsx
β β β βββ Dashboard.jsx # Main student dashboard
β β β βββ Solve.jsx # AI math solver interface
β β β βββ Teach.jsx / TopicWiki.jsx / Classroom.jsx
β β β βββ CBT.jsx / CBTHistory.jsx / MockExam.jsx
β β β βββ PastQuestions.jsx / QuestionBank.jsx
β β β βββ Practice.jsx / TheoryPractice.jsx / Review.jsx
β β β βββ AIQuiz.jsx / DailyChallenge.jsx
β β β βββ Battle.jsx / Challenge.jsx / Groups.jsx
β β β βββ Leaderboard.jsx / TopicMastery.jsx
β β β βββ Profile.jsx / ShareProfile.jsx / Certificate.jsx
β β β βββ WeeklyReport.jsx / StudyPlanner.jsx
β β β βββ Notes.jsx / Bookmarks.jsx / FormulaSheet.jsx
β β β βββ TeacherParentDashboard.jsx
β β βββ components/ # Reusable UI components
β β β βββ layout/ # Navbar, Sidebar
β β β βββ solve/ # Solver sub-components (input, display)
β β β βββ teach/ # Topic sidebar, chat components
β β β βββ FloatChat.jsx # Global floating AI assistant
β β β βββ SolutionDisplay.jsx # Formatted math solution renderer
β β β βββ ShareResultCard.jsx # Shareable result card generator
β β β βββ NotificationBell.jsx # In-app notification UI
β β β βββ InstallBanner.jsx # PWA install prompt
β β β βββ OfflineBanner.jsx # Offline status indicator
β β β βββ XPToast.jsx # XP gain animation toast
β β βββ lib/ # Supabase client, XP/stats utilities
β β βββ context/ # React context providers
β β βββ hooks/ # Custom React hooks
β β βββ sw.js # Service worker for PWA caching
β βββ package.json
β βββ vite.config.js
β
βββ requirements.txt # Python dependencies
βββ README.md
| Tool | Version |
|---|---|
| Python | 3.11+ |
| Node.js | 20+ |
| npm | 10+ |
Managed via requirements.txt in the project root. Key packages:
| Package | Purpose |
|---|---|
fastapi, uvicorn |
API server |
pydantic |
Request/response validation |
sympy |
Symbolic math engine |
groq |
LLM API client |
qdrant-client |
Local vector database |
sentence-transformers |
Text embedding for RAG |
pypdf, pdfplumber |
PDF text extraction |
supabase |
Database & auth client |
selenium, beautifulsoup4 |
Web scraping |
Pillow |
Image processing |
wordninja |
Word-boundary fixing in scraped text |
Managed via frontend/package.json. Key packages:
| Package | Purpose |
|---|---|
react, react-dom |
UI framework |
react-router-dom |
Client-side routing |
@supabase/supabase-js |
Supabase auth & DB |
axios |
HTTP requests |
katex, react-katex |
Math formula rendering |
lucide-react |
Icon library |
vite-plugin-pwa |
PWA generation |
tailwindcss |
Utility CSS framework |
GROQ_API_KEY=your_groq_api_key
APP_NAME=MathGenius
ENVIRONMENT=development
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=your_supabase_service_role_keyVITE_API_URL=http://127.0.0.1:8000
VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
β οΈ Never commit real.envfiles. KeepSUPABASE_SERVICE_KEYbackend-only β it bypasses row-level security.
git clone https://github.com/your-username/Math_Genius.git
cd Math_Geniuscd backend
python -m venv venv
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate
pip install --upgrade pip
pip install -r ../requirements.txtCreate backend/.env with your credentials (see above).
Start the API server:
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000Verify it's running:
GET http://127.0.0.1:8000/
cd frontend
npm installCreate frontend/.env with your credentials (see above).
Start the dev server:
npm run devApp opens at: http://localhost:5173
| Method | Endpoint | Description |
|---|---|---|
POST |
/solve/ |
Solve a math expression symbolically |
POST |
/solve/explain |
Get a step-by-step explanation |
POST |
/solve/image |
Extract and solve from an image (OCR) |
POST |
/solve/practice/question |
Generate a practice question |
POST |
/solve/practice/grade |
Grade a submitted answer |
| Method | Endpoint | Description |
|---|---|---|
POST |
/teach/ask |
Ask the AI tutor a topic question |
POST |
/teach/overview |
Get a topic overview/study note |
GET |
/teach/topics |
List all available curriculum topics |
GET |
/teach/wiki/{topic} |
Retrieve pre-generated wiki for a topic |
| Method | Endpoint | Description |
|---|---|---|
POST |
/cbt/parse |
Parse a question set for CBT session |
POST |
/cbt/explain |
Explain a CBT question answer |
POST |
/cbt/report-summary |
Generate an AI summary of a CBT result |
POST |
/cbt/classify-difficulty |
Tag questions by difficulty level |
POST |
/cbt/verify-answers |
Batch verify answer correctness |
GET |
/cbt/daily-challenge |
Fetch today's daily challenge questions |
POST |
/cbt/generate-mcq |
Generate new MCQs on any topic |
| Method | Endpoint | Description |
|---|---|---|
POST |
/exams/ask |
Query an exam paper via RAG |
POST |
/exams/ingest |
Ingest a new exam PDF into the vector store |
GET |
/exams/papers |
List all available exam papers |
| Method | Endpoint | Description |
|---|---|---|
POST |
/tracking/session/start |
Start a study session |
POST |
/tracking/session/end |
End a study session |
POST |
/tracking/attempt |
Log a question attempt |
GET |
/tracking/profile/{user_id} |
Get user profile |
PUT |
/tracking/profile/{user_id} |
Update user profile |
GET |
/tracking/stats/{user_id} |
Get overall statistics |
GET |
/tracking/topics/{user_id} |
Get per-topic performance |
GET |
/tracking/history/{user_id} |
Get session history |
POST |
/tracking/teach-log |
Log a tutoring interaction |
POST |
/tracking/streak/update |
Update daily streak |
GET |
/tracking/weak-topics/{user_id} |
Identify weak topics |
| Method | Endpoint | Description |
|---|---|---|
GET |
/past-questions/ |
List questions with filters (exam, year, topic) |
GET |
/past-questions/{id} |
Get a specific question |
| Method | Endpoint | Description |
|---|---|---|
POST |
/study-plan/generate |
Generate a personalized study plan |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/solution |
Alternative solution generator endpoint |
To enable textbook-based context in AI answers:
- Add PDF textbooks to
backend/books/ - Run the ingest script:
cd backend python -m app.rag.ingest - The vector store is built under
backend/qdrant_db/and used automatically on subsequent API calls.
The backend/ directory contains utility scripts for question data management:
| Script | Purpose |
|---|---|
scraper.py |
Scrape WAEC objective questions |
scraper_theory.py |
Scrape WAEC theory questions |
scraper_bece.py |
Scrape BECE questions (1990β2012) |
scraper_nabteb.py |
Scrape NABTEB theory questions |
scrape_all.py |
Orchestrate full scrape across all exams |
upload_questions.py |
Upload objective questions to Supabase |
upload_theory.py |
Upload theory questions to Supabase |
upload_bece.py |
Upload BECE questions to Supabase |
upload_nabteb.py |
Upload NABTEB questions to Supabase |
fast_upload_bece.py |
Faster parallel BECE upload |
verify_answers.py |
Verify answer correctness in DB |
verify_bece.py |
Verify BECE upload integrity |
fix_missing_options.py |
Patch questions missing answer options |
fix_word_spacing.py |
Fix word-boundary errors in scraped text |
fix_image_paths.py |
Normalise image paths after upload |
classify_questions.py |
Classify questions by topic using AI |
clean_images.py |
Remove orphaned/unused images |
check_quality.py |
Run quality checks on question data |
The app uses Supabase (PostgreSQL + auth) with approximately the following table structure:
| Table | Purpose |
|---|---|
profiles |
Extended user profile (XP, streak, onboarding data) |
exam_questions |
Objective MCQ questions (WAEC, JAMB, NECO, BECE, NABTEB) |
theory_questions |
Long-answer theory questions |
user_attempts |
Individual question attempt records |
study_sessions |
Session start/end logs |
bookmarks |
Saved/bookmarked questions |
teach_logs |
AI tutoring interaction history |
Row-Level Security (RLS) is enforced β users can only access their own data. The Supabase service key is never exposed to the frontend.
- CORS is configured to allow
http://localhost:5173andhttp://localhost:3000 - Static question images are served from
backend/images/at/images/{filename} - Frontend falls back to
http://localhost:8000ifVITE_API_URLis not set - The PWA service worker (
src/sw.js) caches core assets for offline use - KaTeX is used for all math rendering; LaTeX strings are sanitized on the backend before being sent to the frontend
| Problem | Solution |
|---|---|
ModuleNotFoundError |
Confirm backend venv is activated and pip install -r ../requirements.txt ran successfully |
| Frontend can't reach API | Check VITE_API_URL in frontend/.env and confirm backend is running on port 8000 |
| Groq API errors | Check GROQ_API_KEY is valid in backend/.env |
| Supabase 401 / 403 | Verify URL/key pair; ensure the service key is only in the backend |
| No RAG context returned | Run python -m app.rag.ingest and confirm backend/qdrant_db/ contains data |
| Selenium scraper fails | Ensure ChromeDriver is compatible with your installed Chrome version (webdriver-manager handles this automatically) |
| Images not loading | Check backend/images/ path and that the FastAPI static mount is active |
No license file is currently present in this repository. If you plan to distribute this project publicly, add an appropriate license (e.g., MIT, Apache 2.0).