An AI-powered math tutoring application that guides students through problem-solving using Socratic questioning methodology. Students can input problems via text or image upload, and the tutor helps them discover solutions through guided dialogue without providing direct answers.
This application combines:
- Conversational AI using OpenAI GPT-4 with Vision
- Math Rendering with KaTeX for beautiful LaTeX equations
- Markdown Formatting for rich text responses (bold, italic, code)
- Real-time Persistence via Firebase Firestore
- Image Upload via Firebase Storage for problem parsing
- Frontend: React 19+ with Vite
- Backend: Express.js (deployed to Vercel as serverless functions)
- Database: Firebase Firestore
- Storage: Firebase Storage (for images)
- AI: OpenAI GPT-4 Vision via Vercel AI SDK v5 (all calls through Express backend)
Security: OpenAI API key is stored server-side only. Frontend never directly communicates with OpenAI - all requests go through our Express API.
For detailed architecture information, see ARCHITECTURE.md.
- Node.js 18+ installed (Download)
- npm or yarn package manager
- Firebase account (free tier works)
- OpenAI API key with GPT-4 access
For detailed setup instructions, see SETUP.md.
git clone <repository-url>
cd Math-Tutoring-AppFrontend:
cd frontend
npm installBackend:
cd ../api
npm installCreate .env files in both frontend/ and api/ directories with the following variables:
Frontend (frontend/.env):
# Firebase Configuration
# Get these from Firebase Console -> Project Settings -> General -> Your apps -> Web app
VITE_FIREBASE_API_KEY=your_firebase_api_key
VITE_FIREBASE_AUTH_DOMAIN=your_project_id.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your_project_id
VITE_FIREBASE_STORAGE_BUCKET=your_project_id.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=your_messaging_sender_id
VITE_FIREBASE_APP_ID=your_app_id
# Backend API URL
VITE_API_URL=http://localhost:3000Backend (api/.env):
# OpenAI API Key
# Get from: https://platform.openai.com/api-keys
OPENAI_API_KEY=your_openai_api_key
# Firebase Admin SDK
# Get from Firebase Console -> Project Settings -> Service Accounts -> Generate new private key
FIREBASE_PROJECT_ID=your_project_id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYour private key with \n newlines preserved\n-----END PRIVATE KEY-----\n"
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxxxx@your_project_id.iam.gserviceaccount.com
# Server Configuration
PORT=3000
FRONTEND_URL=http://localhost:5173Terminal 1 - Backend:
cd api
npm run devBackend runs on http://localhost:3000
Terminal 2 - Frontend:
cd frontend
npm run devFrontend runs on http://localhost:5173
Visit http://localhost:5173 in your browser. You'll need to:
- Sign up for a new account (or log in)
- Start chatting with the AI tutor!
Math-Tutoring-App/
βββ frontend/ # React frontend application
β βββ src/
β β βββ components/ # React components (Chat, MessageList, etc.)
β β βββ contexts/ # React contexts (AuthContext)
β β βββ hooks/ # Custom React hooks (useAuth)
β β βββ services/ # API and service utilities
β β βββ utils/ # Utility functions (firebase, markdownParser)
β β βββ App.jsx # Main app component
β β βββ main.jsx # Entry point
β βββ package.json
β βββ vite.config.js
βββ api/ # Express backend
β βββ routes/ # API routes (chat.js)
β βββ services/ # Business logic (promptService, contextManager)
β βββ middleware/ # Express middleware (auth.js)
β βββ utils/ # Backend utilities (firebaseAdmin)
β βββ server.js # Express server
β βββ index.js # Vercel serverless wrapper
β βββ package.json
βββ memory-bank/ # Project context and progress docs
βββ SETUP.md # Detailed setup instructions
βββ ARCHITECTURE.md # Architecture documentation
βββ architecture.mermaid # Architecture diagram (Mermaid)
βββ vercel.json # Vercel deployment configuration
βββ firestore.rules # Firestore security rules
βββ README.md
- Text Input: Type math problems directly
- Image Upload: Upload images of problems (printed text, max 10MB)
- Socratic Dialogue: AI guides through questions, never gives direct answers
- Math Rendering: Beautiful LaTeX equation rendering with KaTeX
- Markdown Formatting: Support for bold, italic, and code formatting
- Real-time Persistence: Conversations saved to Firestore
- Optimistic UI: Instant message display with background persistence
- Streaming Responses: Real-time AI response streaming
- Context Awareness: AI adapts to student understanding level
- Interactive Whiteboard: Step-by-step visualizations (planned)
- Voice Interface: TTS/STT for hands-free learning (planned)
curl http://localhost:3000/api/healthExpected response:
{"status":"ok","message":"Backend is running"}- Open browser console at
http://localhost:5173 - Check for connection status messages
- Try sending a message to verify streaming works
- Click the camera icon in the message input
- Select an image (PNG, JPG, max 10MB)
- Verify image preview appears
- Send message and verify image displays in chat
- Vercel account (free tier works)
- Vercel CLI installed:
npm i -g vercel
-
Login to Vercel:
vercel login
-
Set Environment Variables in Vercel Dashboard:
- Go to your project settings β Environment Variables
- Add all environment variables from
.env.examplefiles - For frontend variables, prefix with
VITE_ - For backend, add without prefix
-
Deploy:
vercel
Or push to your connected Git repository for automatic deployments.
The vercel.json file configures:
- Frontend static build from
frontend/dist - Backend Express routes via
/api/*paths - Express app auto-wrapped as serverless functions
For detailed deployment instructions, see docs/SETUP.md.
- Create route file in
api/routes/ - Import and use in
api/server.js:const newRoute = require('./routes/newRoute'); app.use('/api/new', newRoute);
- Route automatically available at
/api/new
Frontend uses the VITE_API_URL environment variable to connect to the backend. Set this to:
http://localhost:3000for local development- Your production backend URL after deployment
All API calls use the full URL from this environment variable.
- Frontend: React functional components with hooks
- Backend: Express routes with CommonJS modules
- State Management: React Context API for auth, local state for messages
- Styling: Inline styles (to be migrated to SASS in PR #16)
Backend not connecting:
- Check backend is running on port 3000
- Verify
FRONTEND_URLin api.envmatches frontend URL - Check CORS settings in
api/server.js
Firebase connection fails:
- Verify all Firebase env variables are set correctly
- Check Firebase project has Firestore and Storage enabled
- Ensure service account key is properly formatted (with quotes and
\nnewlines)
OpenAI API errors:
- Verify
OPENAI_API_KEYis set correctly - Check API key has sufficient credits and GPT-4 access
- Review OpenAI API rate limits
Image upload fails:
- Verify Firebase Storage is enabled
- Check image size (max 10MB)
- Verify CORS is configured for Firebase Storage
Math rendering not working:
- Check browser console for KaTeX errors
- Verify LaTeX syntax is correct (use
$...$format)
For more detailed troubleshooting, see SETUP.md.
- SETUP.md - Detailed setup and configuration instructions
- ARCHITECTURE.md - System architecture and design
- PRD.md - Product Requirements Document
- tasks.md - Development roadmap and PR breakdown
-
Frontend:
- React 19.2.0
- Vite 7.1.12
- Firebase 11.1.0 (Auth, Firestore, Storage)
- KaTeX 0.16.11 + react-katex 3.0.1 (math rendering)
- react-router-dom 7.9.5
-
Backend:
- Express 4.21.2
- AI SDK 5.0.76 (Vercel AI SDK)
- @ai-sdk/openai 2.0.53
- firebase-admin 13.5.0
- OpenAI API 4.67.3
ISC
Built as part of The Gauntlet challenge.
Note: This is an MVP. See PRD.md for full requirements and tasks.md for development roadmap.