# ๐ ๏ธ Technical Architecture
LearnAI TV is built on a **serverless, API-first architecture** designed for scalability and rapid development.
๐๏ธ System Overview
โโโโโโโโโโโโโโโ
โ Browser โ (HTML/CSS/JS - GitHub Pages)
โ (Student) โ
โโโโโโโโฌโโโโโโโ
โ HTTPS POST
โผ
โโโโโโโโโโโโโโโ
โ n8n Flow โ (Easypanel hosted)
โ Webhook โ
โโโโโโโโฌโโโโโโโ
โ
โโโโบ OpenAI GPT-4.1-mini (LLM)
โโโโบ Gemini-2.5-flash (Fallback Model)
โโโโบ Wolfram|Alpha (Math)
โโโโบ 6x MCP Servers (Subject DBs)
โโโโบ Memory Buffer (Chat history)
โ
โผ
โโโโโโโโโโโโโโโ
โ Response โ
โ (JSON) โ
โโโโโโโโโโโโโโโ๐ฆ Tech Stack
Frontend
HTML5 - Semantic structure
CSS3 - Gradients, animations, flexbox/grid
Vanilla JavaScript - No frameworks (lightweight!)
KaTeX 0.16.9 - Math formula rendering
Why Vanilla JS?
โก Faster load times (no React bundle)
๐ฏ Educational transparency (readable code)
๐ฆ Single-file deploy (GitHub Pages friendly)
Backend / AI Orchestration
n8n (self-hosted on Easypanel) - Visual workflow automation
OpenAI GPT-4.1-mini - Cost-effective LLM ($0.10/1M tokens)
Gemini Flash 2.5 API - For free
Wolfram|Alpha API - Mathematical computation engine
Knowledge Layer (MCP Servers)
6 MCP Servers connected to Google Docs:
matematica_mcpโ Math curriculumportugues_mcpโ Portuguese lessonsciencias_mcpโ Science topicshistoria_mcpโ History contentgeografia_mcpโ Geography dataidiomas_mcpโ Language lessons
Wolfram MCP โ Advanced math via SSE transport
Data Source: Google Docs (easily editable by teachers/parents)
Deployment
Frontend: GitHub Pages (free, CDN, HTTPS)
Backend: Easypanel (Docker containers)
Domain: Custom subdomain (iavendas-n8n.tkxtrv.easypanel.host)
๐ n8n Workflow Design
Main Flow (Learn AI agent):
MCP Server Pattern:
Key Design Decisions:
Stateless API - No database needed (MCP servers handle persistence)
Session memory via origin header - Tracks conversations per user
Fallback logic - JavaScript handles AI failures gracefully
Timeout protection - 10-15s max per request
๐ฎ Wolfram|Alpha Integration
Implementation
n8n Node: Wolfram Alpha Tool
Credentials: WolframAlphaApi account (app ID)
Use Cases:
Solve equations:
solve 2x + 5 = 15Graphing:
plot x^2 from -5 to 5Unit conversion:
convert 50 miles to kmStep-by-step solutions
Code Example (JavaScript parser)
Student Experience
When student asks: "What's the integral of xยฒ?"
AI detects math complexity
Calls Wolfram via MCP
Returns:
โซxยฒ dx = (xยณ/3) + Cwith step-by-step linkStudent clicks link โ Full Wolfram explanation opens
Impact: Students learn how to solve, not just what the answer is.
๐ค MCP (Model Context Protocol) Servers
What are MCP Servers?
MCP is an open protocol by Anthropic that lets AI models access external data sources (like databases, APIs, or documents) in a standardized way.
Our Implementation:
Each subject has a dedicated MCP server:
Data Flow:
Why MCP?
โ Curriculum control - Teachers update Google Docs, AI uses latest info
โ Subject isolation - Math queries don't search History docs
โ Audit trail - All tool calls logged in n8n
โ Scalability - Add new subjects without changing code
๐งฎ Quiz Generation Pipeline
Challenge: Generate consistent, parseable quizzes from LLM responses.
Solution: Multi-layer parsing with fallbacks.
Prompt Engineering
Parsing Logic
Fallback System
If AI generation fails:
Use
generateFallbackQuiz()with pre-written questions per subjectDisplay fallback gracefully (student never knows it failed)
Log error for debugging
Result: 95%+ quiz success rate, even with varying AI outputs.
๐จ Frontend Architecture
Design Philosophy: Progressive enhancement + accessibility first.
File Structure
State Management
Why Globals?
Single-page app (no routing)
All state resets on page reload
Simpler debugging (inspect in console)
API Communication
Error Handling:
Network failures โ Show fallback content
Timeouts โ Use cached/default data
Malformed responses โ Parse defensively
๐ Security & Privacy
โ No user accounts - Zero PII collected
โ Session-only memory - Chat history cleared on reload
โ Public API - Webhook is rate-limited, not secret
โ HTTPS only - GitHub Pages enforces SSL
โ CORS enabled - Safe cross-origin requests
Data Flow:
Compliance:
COPPA-friendly (no data collection)
GDPR-compliant (no personal data)
Safe for schools (no ads, no trackers)
๐ Performance Metrics
First Contentful Paint
<1.5s
0.8s
Time to Interactive
<3s
2.1s
API Response Time
<8s
3-6s
Quiz Parse Success
>90%
~95%
Mobile Usability
100/100
โ
Optimizations:
Lazy-load KaTeX (only when chat opens)
Debounce API calls (prevent spam)
Cache subject lists (reduce re-renders)
Minify CSS/JS (GitHub Pages auto-minifies)
๐ Deployment Pipeline
Local Development:
Production Deploy:
n8n Workflow Updates:
Edit workflow in n8n UI
Save (auto-activates)
No restart needed (hot reload)
๐ฎ Future Architecture Plans
Phase 2 (Post-Hackathon):
Phase 3 (Scale):
Last updated