Skip to content

ujandey/equated

Repository files navigation

πŸŽ“ Equated β€” AI STEM Learning Assistant

License: MIT Python 3.11+ Node.js 18+ Built with FastAPI Built with Next.js

Multi-engine AI platform for STEM education that solves mathematical and scientific problems with step-by-step explanations, solution verification, and intelligent model routing for optimal cost efficiency.

πŸ“‹ Table of Contents


🎯 Overview

Equated is an AI-powered STEM learning platform designed for school and engineering students. Unlike generic AI chatbots, Equated is purpose-built to:

  • βœ… Solve complex STEM problems step-by-step with structured explanations
  • βœ… Verify solutions using a dedicated symbolic math engine (SymPy)
  • βœ… Route problems to the most cost-effective AI model (DeepSeek, Groq, Claude, GPT-4)
  • βœ… Cache solutions using vector similarity search to reduce redundant API calls
  • βœ… Support multiple input formats (text, LaTeX, images via OCR, documents)
  • βœ… Maintain conversation context for follow-up questions
  • βœ… Track user credits and monetize through sustainable pricing

The platform is built to be production-grade from day one, with comprehensive monitoring, error tracking, and analytics.


✨ Features

Core Capabilities

  • Multi-Format Problem Input: Accept typed questions, LaTeX expressions, images (OCR), and uploaded documents
  • Intelligent Model Routing: Automatically select the most cost-effective AI model based on problem complexity
  • Step-by-Step Solutions: Provide structured explanations with problem interpretation, concepts, steps, and summary
  • Solution Verification: Verify all answers using symbolic math before returning to users
  • Vector Caching: 30-60% cost reduction through semantic question caching
  • Conversation Context: Maintain session context for multi-turn interactions
  • Math Engine: SymPy-powered symbolic computation (algebra, calculus, matrices, equation solving)
  • OCR & Parsing: Convert images to text/LaTeX automatically
  • analytics: Track user behavior, model accuracy, cache hit rates, and cost-per-solve

Business Features

  • Credit-Based System: Free tier (5-7 solves/day) + paid packages (β‚Ή10/30 solves)
  • Ad Integration: Non-intrusive banner ads to subsidize free tier
  • Payment Processing: Razorpay integration for secure transactions
  • Usage Monitoring: Real-time analytics and error tracking via PostHog & Sentry

πŸ—οΈ Architecture

High-Level System Design

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Student Browser                         β”‚
β”‚                    (Next.js Frontend)                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Vercel (Deployment)                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   Next.js 14 + App Router + Server Components       β”‚   β”‚
β”‚  β”‚   - Authentication (Supabase Auth)                  β”‚   β”‚
β”‚  β”‚   - API Gateway (Next.js API Routes)                 β”‚   β”‚
β”‚  β”‚   - Model Router (Problem Classification)           β”‚   β”‚
β”‚  β”‚   - UI (Tailwind + shadcn/ui + KaTeX)              β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚
              β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚                     β”‚                      β”‚
              β–Ό                     β–Ό                      β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  Render.com      β”‚  β”‚  Supabase       β”‚  β”‚  Cloud APIs       β”‚
    β”‚                  β”‚  β”‚                 β”‚  β”‚                   β”‚
    β”‚ FastAPI Backend  β”‚  β”‚ - PostgreSQL    β”‚  β”‚ - DeepSeek API    β”‚
    β”‚ - AI Router      β”‚  β”‚ - Auth          β”‚  β”‚ - Groq API        β”‚
    β”‚ - Math Engine    β”‚  β”‚ - Storage       β”‚  β”‚ - OpenAI/Claude   β”‚
    β”‚ - Verification   β”‚  β”‚ - Embeddings    β”‚  β”‚ - Embeddings      β”‚
    β”‚ - OCR/Parser     β”‚  β”‚ - pgvector      β”‚  β”‚                   β”‚
    β”‚ - Celery Workers β”‚  β”‚ - Redis Store   β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚                  β”‚  β”‚                 β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow: Problem-Solving Pipeline

User Input (text/image/LaTeX)
         β”‚
         β–Ό
Problem Parser (OCR, LaTeX β†’ text)
         β”‚
         β–Ό
Vector Similarity Search (pgvector)
    β”œβ”€ HIT  β†’ Return Cached Solution ──┐
    └─ MISS β†’ Continue                 β”‚
             β”‚                         β”‚
             β–Ό                         β”‚
    AI Model Router                    β”‚
    (Classify by complexity)           β”‚
    β”œβ”€ Low  β†’ Groq (free)              β”‚
    β”œβ”€ High β†’ DeepSeek R1 (~$0.001)    β”‚
    └─ Math β†’ SymPy directly           β”‚
             β”‚                         β”‚
             β–Ό                         β”‚
    LLM generates solution              β”‚
             β”‚                         β”‚
             β–Ό                         β”‚
    Math Engine Verification            β”‚
             β”‚                         β”‚
             β–Ό                         β”‚
    Structured Explanation              β”‚
             β”‚                         β”‚
             β–Ό                         β”‚
    Cache Solution                      β”‚
             β”‚                         β”‚
             └─────────────────────────►
                                       β”‚
                                       β–Ό
                            Return to Student

πŸ§ͺ Tech Stack

Layer Technology Purpose
Frontend Next.js 14, React 18, TypeScript Web interface with server-side rendering
Styling Tailwind CSS, PostCSS, shadcn/ui Design system and UI components
Math Rendering KaTeX, react-katex Fast LaTeX math rendering
Backend Python 3.11+, FastAPI, Uvicorn REST API and business logic
AI Models DeepSeek R1/V3, Groq (Llama 3.3 70B), OpenAI Multi-model LLM routing
Math Engine SymPy Symbolic computation & verification
OCR Tesseract, pix2tex, Pillow Image β†’ text/LaTeX conversion
Database PostgreSQL 16 (Supabase), pgvector Relational data + vector embeddings
Cache Redis Session cache, rate limiting, queue
Vector Storage pgvector (Supabase) Semantic similarity search
Auth Supabase Auth, PyJWT Email/OAuth, JWT token validation
Payments Razorpay Credit system transactions
File Storage Supabase Storage Document uploads
Background Jobs Celery + Redis Async task processing
Monitoring PostHog, Sentry Analytics, error tracking
Containerization Docker, Docker Compose Development & production deployment

πŸ“‹ Prerequisites

Before cloning and setting up the project, ensure you have the following installed:

System Requirements

  • OS: Windows, macOS, or Linux
  • RAM: 4 GB minimum (8 GB recommended)
  • Disk Space: 5 GB minimum

Required Software

For Full Stack Development

For Backend Development Only

  • Python (v3.11 or higher): Download Python
    • Verify: python --version
  • pip (package manager, comes with Python)
  • virtualenv or venv (for isolated Python environments)

For Frontend Development Only

  • Node.js (v18 or higher): Download Node.js
    • Verify: node --version
  • npm (v9 or higher, comes with Node.js)
    • Verify: npm --version

Optional (for local database & cache)

API Keys & External Services

You'll need to create accounts and obtain API keys for:

  1. DeepSeek API: https://platform.deepseek.com

    • For multi-engine AI routing
  2. Groq API: https://groq.com

    • For free tier high-speed inference
  3. Supabase: https://supabase.com

    • PostgreSQL database, vector storage, authentication
  4. Razorpay (optional, for payments): https://razorpay.com

  5. PostHog (optional, for analytics): https://posthog.com

  6. Sentry (optional, for error tracking): https://sentry.io


πŸš€ Installation & Setup

Step 1: Clone the Repository

Via HTTPS (Recommended for most users)

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

Via SSH (If you've set up SSH keys)

git clone git@github.com:your-username/equated.git
cd equated

Via GitHub CLI

gh repo clone your-username/equated
cd equated

Verify Cloning

# Check repository structure
ls -la
# or on Windows PowerShell:
Get-ChildItem -Force

Expected output should show:

docker-compose.yml
README.md
PRD.txt
TechStack.txt
system_architecture.md
ai/
backend/
frontend/
database/
scripts/
infra/

Step 2: Environment Setup

A. Copy Environment Files

Copy the example environment files to create local .env files:

# Backend environment
cd backend
copy .env.example .env
cd ..

# Frontend environment
cd frontend
copy .env.example .env
cd ..

# Root environment (if exists)
copy .env.example .env

On Linux/macOS, replace copy with cp.

B. Configure Environment Variables

Backend (backend/.env):

# FastAPI Configuration
DEBUG=True
WORKERS=1

# Database
DATABASE_URL=postgresql://user:password@localhost:5432/equated
REDIS_URL=redis://localhost:6379/0

# AI Models
DEEPSEEK_API_KEY=your_deepseek_key_here
GROQ_API_KEY=your_groq_key_here
OPENAI_API_KEY=your_openai_key_here

# Supabase
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_PUBLISHABLE_KEY=your_supabase_publishable_key_here
SUPABASE_SECRET_KEY=your_secret_key_here

# JWT verification is automatic via JWKS β€” no secret key needed
JWT_EXPIRATION_HOURS=24

# Razorpay (optional)
RAZORPAY_KEY_ID=your_key_id
RAZORPAY_KEY_SECRET=your_key_secret

# Sentry (optional)
SENTRY_DSN=your_sentry_dsn

# Environment
ENVIRONMENT=development

Frontend (frontend/.env.local):

# Supabase
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=your_supabase_publishable_key_here

# Backend API
NEXT_PUBLIC_API_URL=http://localhost:8000

# PostHog Analytics (optional)
NEXT_PUBLIC_POSTHOG_KEY=your_posthog_key
NEXT_PUBLIC_POSTHOG_HOST=https://app.posthog.com

# Sentry (optional)
NEXT_PUBLIC_SENTRY_DSN=your_sentry_dsn

# Environment
NEXT_PUBLIC_ENVIRONMENT=development

Step 3: Choose Your Setup Method

Choose one of the following based on your preference:

Option A: Docker Compose (Recommended for Full Stack)

Fastest setup β€” runs all services (Frontend, Backend, PostgreSQL, Redis) in isolated containers.

# Start all services
docker-compose up -d

# Check status
docker-compose ps

# View logs
docker-compose logs -f backend
docker-compose logs -f frontend

# Stop all services
docker-compose down

# Stop and remove volumes (clean slate)
docker-compose down -v

Accessing services:


Option B: Manual Setup (Backend Only)

Better for backend-focused development β€” requires manual database/Redis setup.

1. Start PostgreSQL & Redis

If you have them installed locally:

# PostgreSQL (keep running in background)
pg_ctl start

# Redis (keep running in another terminal)
redis-server

Or use Docker for these services only:

docker-compose up -d postgres redis
2. Set Up Backend
cd backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Initialize database migrations
alembic upgrade head

# Start FastAPI server
uvicorn main:app --reload --port 8000

Backend is now running at: http://localhost:8000
API documentation: http://localhost:8000/docs


Option C: Manual Setup (Frontend Only)

Good for UI/UX development β€” requires backend to run separately.

cd frontend

# Install Node dependencies
npm install
# or if you prefer yarn:
yarn install

# Start development server
npm run dev
# or with yarn:
yarn dev

Frontend is now running at: http://localhost:3000


Step 4: Initialize Database

cd backend

# Run migrations
alembic upgrade head

# Seed sample data (optional)
python check_db.py

πŸƒ Running the Project

Using Docker Compose (Full Stack)

# From project root
docker-compose up -d

# View logs in real-time
docker-compose logs -f

# Access services:
# - Frontend: http://localhost:3000
# - Backend API: http://localhost:8000
# - API Docs: http://localhost:8000/docs

Manual Backend + Manual Frontend

Terminal 1 - Backend:

cd backend
source venv/bin/activate  # or venv\Scripts\activate on Windows
uvicorn main:app --reload --port 8000

Terminal 2 - Frontend:

cd frontend
npm run dev

Terminal 3 - Celery Workers (optional, for background jobs):

cd backend
celery -A workers.ai_queue worker --loglevel=info

πŸ”§ Environment Configuration

Backend Configuration Details

The backend uses environment variables for configuration. Key areas:

AI Model Selection

Located in backend/ai/router.py, the router automatically selects models based on:

  • Problem complexity (low/high)
  • Problem type (math, physics, general)
  • Cost considerations

Cache Configuration

  • Vector similarity threshold: 0.85 (highly similar questions)
  • Cache TTL: 604800 seconds (7 days)
  • Enable/disable via ENABLE_CACHE=True/False

Rate Limiting

Defined in backend/services/rate_limiter.py:

  • Free tier: 5-7 solves/day
  • Premium tiers: unlimited

Frontend Configuration Details

The frontend uses Next.js environment variables prefixed with NEXT_PUBLIC_ for client-side access.

Key configurations:

  • Server-side API: Uses process.env.NEXT_PUBLIC_API_URL
  • Supabase: Real-time auth and database sync
  • Analytics: PostHog tracks user behavior

πŸ“ Project Structure

equated/
β”œβ”€β”€ README.md                 # This file
β”œβ”€β”€ docker-compose.yml        # Docker orchestration for full stack
β”œβ”€β”€ PRD.txt                   # Product Requirements Document
β”œβ”€β”€ TechStack.txt             # Technology stack documentation
β”œβ”€β”€ system_architecture.md    # System design & data flow
β”‚
β”œβ”€β”€ backend/                  # Python FastAPI Backend
β”‚   β”œβ”€β”€ main.py              # FastAPI app entry point
β”‚   β”œβ”€β”€ requirements.txt      # Python dependencies
β”‚   β”œβ”€β”€ Dockerfile           # Backend container definition
β”‚   β”œβ”€β”€ .env.example         # Example environment variables
β”‚   β”‚
β”‚   β”œβ”€β”€ ai/                  # AI & ML modules
β”‚   β”‚   β”œβ”€β”€ router.py        # Model selection logic
β”‚   β”‚   β”œβ”€β”€ classifier.py    # Problem classification
β”‚   β”‚   β”œβ”€β”€ prompt_optimizer.py # Prompt engineering
β”‚   β”‚   β”œβ”€β”€ cost_optimizer.py   # Cost tracking
β”‚   β”‚   β”œβ”€β”€ fallback.py      # Fallback strategies
β”‚   β”‚   β”œβ”€β”€ models.py        # AI model definitions
β”‚   β”‚   β”œβ”€β”€ prompts.py       # System prompts
β”‚   β”‚   └── cost_matrix.json # Model pricing data
β”‚   β”‚
β”‚   β”œβ”€β”€ db/                  # Database layer
β”‚   β”‚   β”œβ”€β”€ connection.py    # Database connection pooling
β”‚   β”‚   β”œβ”€β”€ models.py        # SQLAlchemy ORM models
β”‚   β”‚   └── schema.py        # Database schema definitions
β”‚   β”‚
β”‚   β”œβ”€β”€ services/            # Business logic services
β”‚   β”‚   β”œβ”€β”€ math_engine.py       # SymPy math computation
β”‚   β”‚   β”œβ”€β”€ explanation.py       # Solution explanation generation
β”‚   β”‚   β”œβ”€β”€ input_validator.py   # Input validation & normalization
β”‚   β”‚   β”œβ”€β”€ auth.py              # Authentication logic
β”‚   β”‚   β”œβ”€β”€ credits.py           # Credit system management
β”‚   β”‚   β”œβ”€β”€ parser.py            # Problem parsing
β”‚   β”‚   β”œβ”€β”€ query_normalizer.py  # Query normalization
β”‚   β”‚   β”œβ”€β”€ verification.py      # Solution verification
β”‚   β”‚   β”œβ”€β”€ streaming_service.py # Real-time streaming
β”‚   β”‚   └── rate_limiter.py      # Rate limiting
β”‚   β”‚
β”‚   β”œβ”€β”€ routers/             # API endpoint definitions
β”‚   β”‚   β”œβ”€β”€ chat.py          # Chat/solve endpoints
β”‚   β”‚   β”œβ”€β”€ auth.py          # Authentication endpoints
β”‚   β”‚   β”œβ”€β”€ credits.py       # Credit system endpoints
β”‚   β”‚   β”œβ”€β”€ ads.py           # Ad serving endpoints
β”‚   β”‚   β”œβ”€β”€ analytics.py     # Analytics endpoints
β”‚   β”‚   β”œβ”€β”€ health.py        # Health check endpoints
β”‚   β”‚   └── admin.py         # Admin panel endpoints
β”‚   β”‚
β”‚   β”œβ”€β”€ cache/               # Caching mechanisms
β”‚   β”‚   β”œβ”€β”€ query_cache.py       # Question similarity cache
β”‚   β”‚   β”œβ”€β”€ embeddings.py        # Embedding generation
β”‚   β”‚   β”œβ”€β”€ redis_cache.py       # Redis operations
β”‚   β”‚   β”œβ”€β”€ vector_cache.py      # Vector storage interface
β”‚   β”‚   └── cache_metrics.py     # Cache performance metrics
β”‚   β”‚
β”‚   β”œβ”€β”€ workers/             # Celery background jobs
β”‚   β”‚   β”œβ”€β”€ tasks.py         # Task definitions
β”‚   β”‚   β”œβ”€β”€ ai_queue.py      # AI processing queue
β”‚   β”‚   β”œβ”€β”€ queue.py         # General queue management
β”‚   β”‚   └── worker.py        # Worker configuration
β”‚   β”‚
β”‚   β”œβ”€β”€ gateway/             # API gateway middleware
β”‚   β”‚   β”œβ”€β”€ auth_middleware.py   # Authentication checks
β”‚   β”‚   β”œβ”€β”€ rate_limit.py        # Rate limiting middleware
β”‚   β”‚   └── request_logger.py    # Request logging
β”‚   β”‚
β”‚   β”œβ”€β”€ monitoring/          # Observability & monitoring
β”‚   β”‚   β”œβ”€β”€ logging.py       # Structured logging
β”‚   β”‚   β”œβ”€β”€ metrics.py       # Prometheus metrics
β”‚   β”‚   β”œβ”€β”€ tracing.py       # Distributed tracing
β”‚   β”‚   └── json_logger.py   # JSON log formatting
β”‚   β”‚
β”‚   β”œβ”€β”€ core/                # Core utilities
β”‚   β”‚   β”œβ”€β”€ exceptions.py    # Custom exceptions
β”‚   β”‚   └── dependencies.py  # FastAPI dependency injection
β”‚   β”‚
β”‚   β”œβ”€β”€ config/              # Configuration management
β”‚   β”‚   β”œβ”€β”€ settings.py      # Main settings
β”‚   β”‚   └── feature_flags.py # Feature toggles
β”‚   β”‚
β”‚   β”œβ”€β”€ alembic/             # Database migrations
β”‚   β”‚   β”œβ”€β”€ env.py
β”‚   β”‚   β”œβ”€β”€ script.py.mako
β”‚   β”‚   └── versions/        # Migration scripts
β”‚   β”‚
β”‚   └── tests/               # Backend tests
β”‚       β”œβ”€β”€ test_math_engine.py
β”‚       β”œβ”€β”€ test_router.py
β”‚       └── ...
β”‚
β”œβ”€β”€ frontend/                # Next.js Frontend
β”‚   β”œβ”€β”€ package.json         # Node.js dependencies
β”‚   β”œβ”€β”€ next.config.js       # Next.js configuration
β”‚   β”œβ”€β”€ tsconfig.json        # TypeScript configuration
β”‚   β”œβ”€β”€ tailwind.config.js   # Tailwind CSS configuration
β”‚   β”œβ”€β”€ postcss.config.js    # PostCSS configuration
β”‚   β”œβ”€β”€ Dockerfile           # Frontend container definition
β”‚   β”œβ”€β”€ .env.example         # Example environment variables
β”‚   β”‚
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/             # Next.js App Router
β”‚   β”‚   β”‚   β”œβ”€β”€ layout.tsx   # Root layout
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx     # Home page
β”‚   β”‚   β”‚   β”œβ”€β”€ solve/       # Problem solver page
β”‚   β”‚   β”‚   β”œβ”€β”€ dashboard/   # User dashboard
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ components/      # Reusable React components
β”‚   β”‚   β”‚   β”œβ”€β”€ ProblemSolver.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ SolutionDisplay.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ MathRenderer.tsx
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ hooks/           # Custom React hooks
β”‚   β”‚   β”‚   β”œβ”€β”€ useSolver.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ useAuth.ts
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ lib/             # Utility functions
β”‚   β”‚   β”‚   β”œβ”€β”€ api.ts       # API client
β”‚   β”‚   β”‚   β”œβ”€β”€ supabase.ts  # Supabase client
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ store/           # State management (Zustand)
β”‚   β”‚   β”œβ”€β”€ types/           # TypeScript type definitions
β”‚   β”‚   └── styles/          # Global styles
β”‚   β”‚
β”‚   └── public/              # Static assets
β”‚       └── ...
β”‚
β”œβ”€β”€ database/                # Database scripts & migrations
β”‚   β”œβ”€β”€ schema.sql           # Database schema definition
β”‚   β”œβ”€β”€ seed.sql             # Sample data
β”‚   └── migrations/          # SQL migration files
β”‚       └── 001_initial.sql
β”‚
β”œβ”€β”€ ai/                      # AI configuration & docs
β”‚   β”œβ”€β”€ cost_matrix.json     # Model pricing
β”‚   β”œβ”€β”€ model_config.json    # Model configurations
β”‚   └── router_logic.md      # AI routing documentation
β”‚
β”œβ”€β”€ database/                # Database migrations & setup
β”‚   └── schema.sql
β”‚
β”œβ”€β”€ scripts/                 # Utility scripts
β”‚   β”œβ”€β”€ db_migrate.sh        # Database migration script
β”‚   β”œβ”€β”€ start_dev.sh         # Development start script
β”‚   └── start_dev.ps1        # PowerShell dev start
β”‚
β”œβ”€β”€ infra/                   # Infrastructure configuration
β”‚   β”œβ”€β”€ docker/              # Docker configurations
β”‚   β”œβ”€β”€ nginx/               # Nginx reverse proxy
β”‚   β”œβ”€β”€ ci/                  # CI/CD configurations
β”‚   └── env/                 # Environment-specific config
β”‚
└── .gitignore               # Git ignore rules

πŸ‘¨β€πŸ’» Development Workflow

Backend Development

Hot Reload During Development

cd backend
source venv/bin/activate
uvicorn main:app --reload --port 8000

The --reload flag automatically restarts the server when you modify Python files.

Running Tests

cd backend
pytest tests/ -v

# Run specific test file
pytest tests/test_math_engine.py -v

# Run with coverage
pytest --cov=backend tests/

Database Migrations

cd backend

# Create a new migration
alembic revision --autogenerate -m "Add new column"

# Review generated migration in alembic/versions/

# Apply migrations
alembic upgrade head

# Roll back last migration
alembic downgrade -1

Running Background Workers

cd backend

# In one terminal, start Redis (if not already running):
redis-server

# In another terminal, start Celery worker:
celery -A workers.ai_queue worker --loglevel=info

# Monitor tasks:
celery -A workers.ai_queue events

Frontend Development

Hot Module Replacement (HMR)

cd frontend
npm run dev

Next.js automatically reloads changes in the browser.

Building for Production

cd frontend
npm run build
npm start

Linting & Code Quality

cd frontend
npm run lint

Adding New Features

  1. Create a feature branch:

    git checkout -b feature/your-feature-name
  2. Make your changes in the appropriate module

  3. Test your changes:

    # Backend
    cd backend && pytest tests/
    
    # Frontend
    cd frontend && npm run lint
  4. Commit with clear messages:

    git add .
    git commit -m "feat: add new feature description"
  5. Push and create a Pull Request:

    git push origin feature/your-feature-name

πŸ“š API Documentation

Interactive API Docs

Once the backend is running, visit:

http://localhost:8000/docs

This provides an interactive Swagger UI where you can test all endpoints.

Key API Endpoints

Authentication

  • POST /api/auth/register β€” Register new user
  • POST /api/auth/login β€” Login user
  • POST /api/auth/logout β€” Logout user
  • GET /api/auth/me β€” Get current user info

Problem Solving

  • POST /api/solve β€” Submit problem for solving
  • GET /api/solve/{problem_id} β€” Get solution details
  • GET /api/solve/history β€” Get user's solve history

Credits

  • GET /api/credits/balance β€” Get current credit balance
  • POST /api/credits/purchase β€” Purchase credit packages
  • GET /api/credits/history β€” Get credit transaction history

Analytics

  • GET /api/analytics/usage β€” Get usage statistics
  • GET /api/analytics/topics β€” Get topic trends

Example API Call

# Solve a math problem
curl -X POST http://localhost:8000/api/solve \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{
    "problem": "Solve 2x + 5 = 13",
    "subject": "math"
  }'

🚒 Deployment

Frontend Deployment (Vercel)

  1. Push code to GitHub:

    git add .
    git commit -m "Deploy to production"
    git push origin main
  2. Connect GitHub to Vercel:

    • Go to vercel.com
    • Click "New Project"
    • Import your GitHub repository
    • Set environment variables in Vercel dashboard
  3. Automatic deployments:

    • Every push to main triggers production deployment
    • Every PR creates a preview deployment

Backend Deployment (Render)

  1. Create Render account at render.com

  2. Connect GitHub repository:

    • Create new "Web Service"
    • Connect GitHub repo
    • Set root directory to backend/
    • Set build command: pip install -r requirements.txt
    • Set start command: uvicorn main:app --host 0.0.0.0
    • Add environment variables
  3. Add database:

    • Create PostgreSQL database on Render
    • Update DATABASE_URL in service environment

Database Deployment (Supabase)

  1. Create Supabase project at supabase.com

  2. Get connection strings:

    • Project Settings β†’ Database β†’ Connection Strings
    • Use PostgreSQL connection string in backend
  3. Run migrations:

    alembic upgrade head

🀝 Contributing

We welcome contributions! Here's how to get started:

Code of Conduct

  • Be respectful and inclusive
  • Report issues constructively
  • Collaborate openly

Contribution Guidelines

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request with:
    • Clear description of changes
    • Reference to related issues
    • Screenshots for UI changes
    • Test results

Development Standards

  • Code Style: Follow PEP 8 (Python) and Prettier (JavaScript)
  • Type Hints: Use TypeScript on frontend, type hints on backend
  • Tests: Write tests for new features (target 80%+ coverage)
  • Docstrings: Document functions and classes
  • Commits: Use conventional commits (feat:, fix:, docs:, etc.)

πŸ†˜ Troubleshooting

Common Issues

Issue: docker-compose: command not found

Solution: Install Docker Desktop (includes Docker Compose)

Issue: ModuleNotFoundError: No module named 'fastapi'

Solution:

cd backend
source venv/bin/activate
pip install -r requirements.txt

Issue: Cannot connect to localhost:5432 (PostgreSQL)

Solution:

# Using Docker:
docker-compose up -d postgres

# Check if running:
docker-compose ps postgres

Issue: npm ERR! code EACCES (permission denied)

Solution (Linux/macOS):

sudo npm install -g npm
cd frontend
npm install

Issue: CORS errors when calling backend

Solution: Check NEXT_PUBLIC_API_URL matches backend URL in frontend .env.local

Issue: Redis connection refused

Solution:

# Start Redis via Docker:
docker-compose up -d redis

# Or install locally and start:
redis-server

Issue: JWTClaimsError or authentication issues

Solution:

  1. JWT verification is now automatic via JWKS public keys
  2. Ensure SUPABASE_URL is correct in backend/.env
  3. Clear browser cookies
  4. Re-login

Issue: Database migration fails

Solution:

cd backend
# Check migration status:
alembic current

# View migration history:
alembic history

# Downgrade if needed:
alembic downgrade -1

Debug Logging

Backend:

# In your Python code
import logging
logger = logging.getLogger(__name__)
logger.debug(f"Debug info: {variable}")
logger.error(f"Error occurred: {error}")

Frontend:

// In your TypeScript/JavaScript
console.log("Debug info:", variable);
console.error("Error occurred:", error);

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.

You are free to:

  • Use this software for commercial and private purposes
  • Modify and distribute the code
  • Use it in proprietary applications

You must:

  • Include the original license and copyright notice
  • Document all significant changes

πŸ’¬ Support

Getting Help

  1. Check this README β€” Most common questions are answered here
  2. Read documentation β€” See PRD.txt, system_architecture.md, TechStack.txt
  3. Search existing issues β€” https://github.com/your-username/equated/issues
  4. Create an issue β€” Report a bug or request feature

Contact & Community


πŸ“Š Project Status

  • βœ… MVP: Core problem-solving and verification
  • πŸ”„ In Development: Hint system, visualization engine, study tools
  • πŸ“… Planned: Mobile app, API for partners, premium analytics

πŸ™ Acknowledgments

  • Built with ❀️ for STEM students everywhere
  • Special thanks to the open-source community (SymPy, FastAPI, Next.js, etc.)
  • Powered by DeepSeek, Groq, and community AI models

Last Updated: March 2026
Current Version: 1.0.0-beta β”œβ”€β”€ backend/ # FastAPI microservice β”‚ β”œβ”€β”€ ai/ # Model router, classifier, cost optimizer β”‚ β”œβ”€β”€ cache/ # Redis + vector cache layers β”‚ β”œβ”€β”€ config/ # Settings, feature flags β”‚ β”œβ”€β”€ db/ # Database connection & models β”‚ β”œβ”€β”€ gateway/ # Rate limiting, auth, request logging β”‚ β”œβ”€β”€ monitoring/ # Logging, metrics, tracing β”‚ β”œβ”€β”€ routers/ # API endpoints β”‚ β”œβ”€β”€ services/ # Business logic (math, parsing, streaming) β”‚ β”œβ”€β”€ workers/ # Celery background tasks β”‚ └── tests/ # Unit & integration tests β”œβ”€β”€ frontend/ # Next.js 14 app β”‚ └── src/ β”‚ β”œβ”€β”€ app/ # App Router pages β”‚ β”œβ”€β”€ components/ β”‚ β”œβ”€β”€ hooks/ β”‚ β”œβ”€β”€ lib/ β”‚ β”œβ”€β”€ store/ β”‚ β”œβ”€β”€ types/ β”‚ └── utils/ β”œβ”€β”€ database/ # SQL schema, migrations, seed data β”œβ”€β”€ infra/ # Docker, CI/CD, nginx, env configs β”œβ”€β”€ ai/ # Shared AI config (model registry, costs) └── scripts/ # Dev helper scripts


## Docs

- [PRD v2.0](./PRD.txt)
- [Tech Stack Guide](./TechStack.txt)
- [System Architecture](./system_architecture.md)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors