Skip to content

Farfesadee/mathgenius

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ MathGenius

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.


✨ Features

🧠 AI-Powered Learning

  • 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

πŸ“ Exam Practice

  • 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

πŸ† Gamification & Social

  • 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

πŸ“Š Progress & Analytics

  • 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

πŸ› οΈ Utilities & Accessibility

  • 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

πŸ—οΈ Tech Stack

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)

πŸ“ Project Structure

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

βš™οΈ Requirements

System

Tool Version
Python 3.11+
Node.js 20+
npm 10+

Python Packages

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

Frontend Packages

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

πŸ” Environment Variables

Backend β€” backend/.env

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_key

Frontend β€” frontend/.env

VITE_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 .env files. Keep SUPABASE_SERVICE_KEY backend-only β€” it bypasses row-level security.


πŸš€ Local Setup

1. Clone the Repository

git clone https://github.com/your-username/Math_Genius.git
cd Math_Genius

2. Backend Setup

cd backend
python -m venv venv

# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate

pip install --upgrade pip
pip install -r ../requirements.txt

Create backend/.env with your credentials (see above).

Start the API server:

uvicorn app.main:app --reload --host 127.0.0.1 --port 8000

Verify it's running:

GET http://127.0.0.1:8000/

3. Frontend Setup

cd frontend
npm install

Create frontend/.env with your credentials (see above).

Start the dev server:

npm run dev

App opens at: http://localhost:5173


🌐 API Reference

/solve β€” Math Solver

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

/teach β€” AI Tutor

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

/cbt β€” Computer-Based Testing

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

/exams β€” Exam Papers

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

/tracking β€” Progress & Analytics

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

/past-questions β€” Past Questions

Method Endpoint Description
GET /past-questions/ List questions with filters (exam, year, topic)
GET /past-questions/{id} Get a specific question

/study-plan β€” Study Planner

Method Endpoint Description
POST /study-plan/generate Generate a personalized study plan

/api/solution β€” Standalone Solution

Method Endpoint Description
POST /api/solution Alternative solution generator endpoint

πŸ“š RAG Pipeline (Textbook-Grounded Answers)

To enable textbook-based context in AI answers:

  1. Add PDF textbooks to backend/books/
  2. Run the ingest script:
    cd backend
    python -m app.rag.ingest
  3. The vector store is built under backend/qdrant_db/ and used automatically on subsequent API calls.

πŸ› οΈ Data Pipeline Scripts

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

πŸ—„οΈ Database (Supabase)

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.


πŸ”§ Development Notes

  • CORS is configured to allow http://localhost:5173 and http://localhost:3000
  • Static question images are served from backend/images/ at /images/{filename}
  • Frontend falls back to http://localhost:8000 if VITE_API_URL is 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

πŸ› Troubleshooting

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

πŸ“œ License

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).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors