An AI-powered math tutoring application built with Next.js, TypeScript, and Tailwind CSS.
AI Math Tutor is a web application that provides interactive math tutoring through Socratic dialogue. Students can input math problems, work through solutions on a canvas, and receive guided feedback from an AI tutor.
- Node.js 18.17 or later
- npm 10.0 or later
- Clone the repository:
git clone <repository-url>
cd ai-math-tutor- Install dependencies:
npm install- Create a
.env.localfile in the root directory:
cp .env.example .env.local- Add your environment variables to
.env.local:
OPENAI_API_KEY=your_openai_api_key_hereStart the development server:
npm run devOpen http://localhost:3000 in your browser to see the application.
Create a .env.local file in the root directory with the following variables:
OPENAI_API_KEY: Your OpenAI API key (required for AI features)
- Copy the example file:
cp .env.example .env.local- Edit
.env.localand replace placeholder values with your actual API keys:
OPENAI_API_KEY=sk-your-actual-api-key-hereImportant Security Notes:
.env.localis gitignored and will never be committed to the repository- Never commit API keys or secrets to the repository
- Use
.env.exampleas a template for required environment variables - The pre-commit hook (Gitleaks) will block commits containing secrets
ai-math-tutor/
├── src/
│ ├── app/ # Next.js App Router pages
│ ├── components/ # React components
│ ├── hooks/ # Custom React hooks
│ ├── services/ # Service layer
│ ├── stores/ # Zustand state stores
│ ├── types/ # TypeScript type definitions
│ ├── lib/ # Infrastructure code
│ └── utils/ # Utility functions
├── public/ # Static assets
├── docs/ # Documentation
└── package.json # Dependencies
- Framework: Next.js 14.2+ (App Router)
- Language: TypeScript 5.3+
- Styling: Tailwind CSS 3.4+
- State Management: Zustand 4.5+
- Canvas Library: Konva.js 9.3+
- Math Rendering: KaTeX 0.16+
- LLM: OpenAI GPT-4
This project uses Gitleaks to prevent accidental commits of API keys and secrets.
- Gitleaks scans staged files before each commit
- If secrets are detected, the commit is blocked
- The pre-commit hook runs automatically via Husky
- Gitleaks configuration:
gitleaks.toml - Pre-commit hook:
.husky/pre-commit - Husky manages git hooks automatically
If you need to bypass the hook for an emergency (not recommended):
git commit --no-verify -m "your message"Warning: Only bypass the hook in genuine emergencies. Never commit secrets, even with --no-verify.
To add custom secret patterns, edit gitleaks.toml:
[[rules]]
id = "custom-pattern"
description = "Custom secret pattern"
regex = '''your-regex-pattern'''Issue: Hook not running
- Solution: Run
npm installto ensure Husky is set up (prepare script runs automatically)
Issue: False positives
- Solution: Add patterns to
gitleaks.tomlallowlist in the[[allowlists]]section
Issue: Gitleaks not found
- Solution: Install Gitleaks via Homebrew:
brew install gitleaks- Or download from: https://github.com/gitleaks/gitleaks/releases
npm run dev- Start development servernpm run build- Build for productionnpm start- Start production servernpm run lint- Run ESLint
This application is optimized for deployment on Vercel, the platform built by the creators of Next.js.
- A Vercel account (sign up at vercel.com)
- Your code pushed to a Git repository (GitHub, GitLab, or Bitbucket)
- An OpenAI API key
-
Connect Your Repository
- Go to vercel.com and log in
- Click "Add New..." → "Project"
- Import your GitHub/GitLab/Bitbucket repository
- Vercel will automatically detect the Next.js configuration
-
Configure Environment Variables
- In the Vercel project configuration screen, add environment variables:
OPENAI_API_KEY- Your OpenAI API key (required)
- These variables should be set for Production, Preview, and Development environments
- In the Vercel project configuration screen, add environment variables:
-
Deploy
- Click "Deploy"
- Vercel will build and deploy your application automatically
- Monitor the build logs for any errors
- Once complete, you'll receive a deployment URL (e.g.,
your-project.vercel.app)
-
Verify Deployment
- Visit your deployment URL
- Test the following features:
- Landing page loads correctly
- Problem input (text and image upload)
- Tutoring workspace with whiteboard
- Chat functionality with AI tutor
- Text-to-speech (TTS) for tutor responses
- Speech-to-text (STT) for student input
- 2D avatar rendering and lip-sync
Once connected, Vercel will automatically:
- Deploy the
mainbranch to production - Create preview deployments for pull requests
- Rebuild on every push to the repository
.env.example- Template for required environment variablesvercel.json- Vercel-specific configuration (function timeouts, build settings)
- API Timeouts: The
vercel.jsonfile configures a 60-second timeout for API routes to accommodate OpenAI API calls - Static Assets: The
public/directory (including VRM avatar models) is automatically deployed as static assets - Serverless Functions: All API routes (
/api/*) are deployed as serverless functions - No Database Required: The application is stateless and doesn't require a database setup
Build Failures
- Check build logs in Vercel dashboard
- Ensure all dependencies are listed in
package.json - Verify TypeScript compilation succeeds locally:
npm run build
Environment Variables
- Ensure
OPENAI_API_KEYis set in Vercel project settings - Variables must be configured for the appropriate environments (Production/Preview/Development)
API Errors
- Check function logs in Vercel dashboard
- Verify OpenAI API key is valid and has sufficient credits
- Check for rate limiting issues with OpenAI API
To use a custom domain:
- Go to your project settings in Vercel
- Navigate to "Domains"
- Add your custom domain
- Follow the DNS configuration instructions
MIT