LearnEngine
Key Features
AI-Generated Curricula
Type any topic and get a structured lesson plan in seconds with personalized content.
Dynamic Content
Each section receives detailed, AI-written educational content with math support.
Adaptive Quizzes
Questions adjust difficulty based on your performance in real-time.
AI Tutor Chat
Ask questions anytime with full lesson context and persistent history.
Progress Tracking
Track accuracy, time spent, and improvement across all your lessons.
Secure by Design
Multi-layer security with auth, rate limiting, and data isolation.
Overview
This project was a beast. I wanted to build something that actually LEARNS from you, not just throws generic content at your face. Built it on Next.js 16 + React 19, hooked up to multiple AI models through OpenRouter. The cool part? If you're bombing the quizzes, it dials down the difficulty. Crushing it? Questions get harder. It's like having a tutor who pays attention.
The backend was where things got spicy. Supabase for the database and auth, which was honestly great until I spent 3 hours debugging why Row Level Security wasn't working (spoiler: I forgot a semicolon in the policy). The AI stuff goes way beyond just calling an API, I had to build injection protection because apparently people WILL try to break your prompts. Learned that one the hard way.
Security nearly killed me. Had to implement rate limiting after I realized someone could theoretically spam the AI endpoints and rack up my API bill. Added input sanitization, fixed an open redirect bug that was embarrassing, and strengthened the password requirements. Basically paranoia-driven development.
The frontend is probably what I'm most proud of. GSAP animations everywhere, shadcn/ui components that actually look good, and micro-interactions that make it feel alive. The AI chat keeps your conversation history so you can pick up where you left off. Took forever to get the streaming to work right but damn it feels smooth.
How It Started
From notebook to reality
The Idea
High Level Approach
Viability Research
Build Phase 1
Backend & Complexity Testing
Deep Dive & Model Selection
Architecture
System Architecture
- Session handling
- Route protection
- Generate Plan
- Generate Content
- Grade Answer
- Rate limiting
- Input sanitization
- Conversation management
- Message history
- PostgreSQL
- Auth
- RLS Policies
- Mimo Flash
- GPT-120B
- GLM 4.5 Air
User Journey
User Learning Journey
Adaptive Algorithm
Adaptive Learning Algorithm
How It Works
Security
Security Architecture
Database Design
Database Schema
- id
- display_name
- created_at
- is_correct
- user_answer
- time_spent
- topic
- outline
- status
- title
- content
- difficulty
- question_text
- options
- correct_answer
- title
- lesson_id
- model_id
- role
- content
- model_id
Work Items
AI-Generated Curricula
aiType literally any topic and get a structured lesson plan in seconds. The AI breaks it down into 4-6 sections with time estimates. Getting different AI models to format their output consistently was... an adventure.
- •OpenRouter integration, had to debug each model separately because they all have quirks
- •Mimo Flash, GPT-120B, GLM 4.5 Air support (each returns slightly different JSON, fun times)
- •Prompt injection sanitization after someone tried some creative inputs
- •JSON parsing with fallbacks because AI outputs aren't always clean
Dynamic Content Generation
aiEach lesson gets detailed, AI-written content in Markdown with math equation support. Getting the difficulty slider to actually change the language complexity took way more prompt iterations than I want to admit.
- •400-600 words per section (had to tweak prompts to stop AI from writing novels)
- •Difficulty scale 1-10 that actually works (mostly)
- •Markdown rendering with syntax highlighting for code examples
- •KaTeX for math equations, surprisingly smooth to integrate
Adaptive Quiz Engine
featureQuestions get easier if you're struggling (<50% accuracy) or harder if you're crushing it (>80%). The algorithm tracks your last 10 answers. First version was way too aggressive with difficulty swings, had to tune it.
- •Multiple choice, true/false, and short answer question types
- •AI grading for open-ended responses (this took forever to get right)
- •Performance context tracking that actually influences new questions
- •Difficulty adjustment in -2 to +2 range, aggressive enough to feel adaptive, not so much it's jarring
AI Tutor Chat
aiBuilt-in AI tutor that knows what lesson you're on. Ask questions anytime and get contextual help. The first version lost chat history on page refresh, that was a fun bug to explain to testers.
- •Persistent chat history that actually persists (took a few attempts)
- •Model picker so you can choose your AI
- •Lesson context injection so the AI knows what you're learning
- •Message streaming for that ChatGPT-like typing feel
Progress Tracking System
featureTracks accuracy, time spent, and improvement over time. Everything persists across sessions. The database schema for this went through like 3 revisions before it made sense.
- •Per-question answer tracking (yes, I store every answer)
- •Time spent per section and per question
- •Accuracy calculations that update in real-time
- •Visual progress bars that actually feel motivating
Security Architecture
securityMulti-layer security because I'm paranoid. Rate limiting, input sanitization, RLS policies, the works. Found an open redirect vulnerability during my own testing which was embarrassing but better than finding it in prod.
- •Supabase Auth with proper session handling
- •Rate limiting at 10 AI calls/minute (my wallet said so)
- •Prompt injection pattern filtering, people will try to break things
- •Open redirect prevention after I found a vulnerability in my own code
- •RLS policies that actually work (after the semicolon incident)
Database Architecture
architecturePostgreSQL with 7 interconnected tables. Users, lessons, sections, questions, progress, chat history, the whole thing. Took a while to get the relationships right but now it's actually pretty clean.
- •Profiles, lesson_plans, lesson_sections tables (basic but solid)
- •Questions with difficulty levels and type metadata
- •User progress tracking per section and per question
- •Chat conversation and message storage with proper foreign keys
- •RLS policies on everything, nobody sees anyone else's data
Key Highlights
- 01
Built full AI curriculum generation with support for Mimo Flash, GPT-120B, GLM 4.5 Air, DeepSeek R1T2 (had to debug each one individually, they all return slightly different formats)
- 02
Adaptive difficulty that actually works, tracks your last 10 answers and adjusts on the fly
- 03
7-table PostgreSQL schema with RLS policies (after spending a day debugging why users could see each other's data)
- 04
AI grading for short answers, this was HARD, getting consistent grading took like 50 prompt iterations
- 05
Chat history that persists properly (first version was losing messages, that was fun)
- 06
Rate limiting, injection filtering, redirect prevention, basically every security thing I could think of
Technologies