Spaces:
Configuration error
Configuration error
File size: 6,038 Bytes
e46d575 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | # ๐งฎ MathMind AI โ MVP
AI-powered adaptive math tutor for **Grades 6โ12**.
Built with **Streamlit ยท FastAPI ยท Anthropic Claude ยท Supabase**.
---
## Architecture
```
Streamlit (localhost:8501)
โโโ httpx calls โ FastAPI (localhost:8000)
โโโ Anthropic Claude API (AI explanations + tests)
โโโ Supabase (Auth + PostgreSQL)
```
---
## Quick Start
### 1. Clone & Install
```bash
git clone <repo-url>
cd mathmind
pip install -r requirements.txt
```
### 2. Configure Environment
```bash
cp .env.example .env
# Fill in the values in .env (see Environment Variables section below)
```
### 3. Set Up Supabase
1. Create a free project at [supabase.com](https://supabase.com)
2. Go to **SQL Editor** and run the scripts **in order**:
- `database/01_schema.sql`
- `database/02_rls.sql`
- `database/03_seed.sql`
3. Copy your project URL and keys from **Settings โ API**
### 4. Run the Backend
```bash
# From the mathmind/ root directory
uvicorn backend.main:app --reload --port 8000
```
Verify: open [http://localhost:8000/api/health](http://localhost:8000/api/health)
You should see: `{"status": "ok"}`
### 5. Run the Frontend
```bash
# In a second terminal, from the mathmind/ root directory
streamlit run streamlit_app/app.py
```
Open [http://localhost:8501](http://localhost:8501) in your browser.
---
## Environment Variables
Create a `.env` file in the `mathmind/` root:
```bash
# Anthropic โ get your key at console.anthropic.com
ANTHROPIC_API_KEY=sk-ant-...
# Supabase โ from your project: Settings โ API
SUPABASE_URL=https://xxxx.supabase.co
SUPABASE_ANON_KEY=eyJ... # "anon" key (public)
SUPABASE_SERVICE_ROLE_KEY=eyJ... # "service_role" key (secret โ never expose to browser)
# FastAPI
ALLOWED_ORIGINS=http://localhost:8501
API_BASE_URL=http://localhost:8000
```
---
## Project Structure
```
mathmind/
โโโ .env.example
โโโ README.md
โโโ requirements.txt
โ
โโโ streamlit_app/ # Frontend (Streamlit)
โ โโโ app.py # Landing page + router
โ โโโ pages/
โ โ โโโ 1_Login.py # Auth (login + signup)
โ โ โโโ 2_Tutor.py # Core learning flow
โ โ โโโ 3_Dashboard.py # Badges + streak + history
โ โโโ utils/
โ โโโ auth.py # Supabase auth helpers
โ โโโ api_client.py # FastAPI HTTP client
โ โโโ state.py # session_state helpers
โ
โโโ backend/ # API (FastAPI)
โ โโโ main.py # App entry + CORS
โ โโโ core/
โ โ โโโ config.py # Env var loading
โ โ โโโ auth.py # JWT verification
โ โโโ routers/
โ โ โโโ explain.py # POST /api/explain
โ โ โโโ practice.py # POST /api/practice
โ โ โโโ test.py # POST /api/test/*
โ โ โโโ badges.py # GET/POST /api/badges
โ โโโ services/
โ โ โโโ claude_service.py # Anthropic SDK wrapper
โ โ โโโ supabase_service.py # Supabase client wrapper
โ โ โโโ prompt_templates.py # Grade-level prompts
โ โโโ models/ # Pydantic request/response models
โ
โโโ database/
โโโ 01_schema.sql # Table definitions
โโโ 02_rls.sql # Row Level Security
โโโ 03_seed.sql # Badge definitions
โโโ README.md
```
---
## API Endpoints
| Method | Endpoint | Description | Auth |
|--------|----------|-------------|------|
| GET | `/api/health` | Health check | None |
| POST | `/api/explain` | Stream grade-appropriate explanation | JWT |
| POST | `/api/practice` | Generate 3 practice problems | JWT |
| POST | `/api/test/generate` | Generate 5-question mini-test | JWT |
| POST | `/api/test/evaluate` | Evaluate answers + save result | JWT |
| GET | `/api/badges` | Get student's earned badges | JWT |
| POST | `/api/badges/check` | Check + award new badges | JWT |
Interactive docs: [http://localhost:8000/docs](http://localhost:8000/docs)
---
## Student Flow
```
Sign Up โ Select Grade โ Ask Question
โ Streamed Explanation
โ Practice Problems (3x)
โ Mini-Test (5 questions)
โโโ PASS (โฅ80%) โ Badge Awarded โ Dashboard
โโโ FAIL (<80%) โ See Feedback โ Retry Test
```
---
## Badge System
| Badge | Emoji | Condition |
|-------|-------|-----------|
| First Try Champion | ๐ | Pass your first test |
| Getting Started | ๐ | Complete 5 sessions |
| Math Explorer | ๐ | Complete 10 sessions |
| On Fire | ๐ฅ | 5-day streak |
| Perfect Score | ๐ฏ | Score 100% on a test |
---
## Tech Stack
| Layer | Technology |
|-------|-----------|
| Frontend | Streamlit 1.35+ |
| Backend | FastAPI + Uvicorn |
| AI | Anthropic Claude `claude-sonnet-4-6` |
| Database | Supabase (PostgreSQL + Auth + RLS) |
| HTTP Client | httpx (async-capable) |
| Validation | Pydantic v2 |
---
## Development Notes
- **Backend auto-reloads** on file changes with `--reload`
- **Streamlit auto-reloads** on file saves
- **JWT flow:** Supabase issues JWT on login โ stored in `st.session_state` โ sent as `Authorization: Bearer <token>` to FastAPI โ FastAPI verifies via Supabase auth API
- **Streaming:** `/api/explain` uses FastAPI `StreamingResponse` + Anthropic streaming SDK โ Streamlit renders chunks live
- **Service role key** is used by FastAPI only โ bypasses RLS for server-side writes. Never expose to the browser.
---
## Phase 2 Roadmap (not in MVP)
- [ ] Re-engagement email nudges (SendGrid)
- [ ] LMS integration (Google Classroom, Canvas)
- [ ] Parent weekly report emails
- [ ] Adaptive ML difficulty engine
- [ ] Subscription/payment (Stripe)
- [ ] Mobile app
|