Building the infrastructure behind a real-time AI classroom
A multi-tenant classroom platform where AI agents can conduct live lessons, speak with students, work from educational material, generate assessments, coordinate classroom activities, and produce student-level insights.
- Role
- Sole Full-Stack Engineer
- Current system
- Next.js · Node.js · PostgreSQL · Mastra · WebRTC · LLMs · RAG
- Scope
- Architecture · Frontend · Backend · AI · Realtime · Data · Infrastructure
- Agent architecture
- Mastra · Agents · Tools · Workflows · Memory · Evaluation · Observability

The challenge
A live classroom is fundamentally different from a normal chatbot. Lessons unfold over time. Multiple students interact simultaneously. Application state changes continuously. Some actions require LLM reasoning while others need deterministic guarantees. Voice interaction must remain low latency, and the teaching agent cannot operate independently from the rest of the classroom.
The challenge was to design a system in which AI could function as part of a live, stateful application.
Current architecture
The platform uses Mastra for agent orchestration and separates specialized responsibilities instead of putting the entire classroom into one model prompt. A teacher agent handles instruction and student-facing interaction while a supervisor coordinates lesson progression, pacing, engagement activities, and broader session behavior.
The surrounding application layer manages persistent classroom state, student interactions, assessments, permissions, realtime events, and educational content.
Realtime interaction
Students can participate through live voice, hand raises, reactions, classroom chat, engagement questions, quizzes, and leaderboards. WebRTC handles realtime voice interaction while application-level events synchronize the wider classroom experience.
Retrieval and lesson knowledge
Teachers can provide lesson source material such as PDFs. A RAG pipeline turns those resources into retrievable context so AI interactions can be grounded in the supplied educational content instead of relying exclusively on general model knowledge.
Assessment and student insights
Assessments can be generated from lesson material and processed without interrupting the live classroom. Lesson conversations, assessment results, game performance, and voice sentiment can then contribute to student-level insights.
Why Mastra
As the AI layer grows, orchestration itself becomes a significant engineering concern. I use Mastra as a structured layer around agent behavior, while keeping ordinary application logic in the application.
- Agents
- Handle open-ended reasoning.
- Tools
- Expose controlled application capabilities.
- Workflows
- Handle processes where execution order, branching, retries, or deterministic behavior matter.
- RAG
- Supplies grounded domain context.
- Memory
- Handles appropriate agent context across interactions.
- Tracing and evaluation
- Make agent behavior inspectable.
This separation should make the AI system easier to reason about, test, observe, and evolve as additional agents and capabilities are introduced.
What I own
I work across the product end to end: architecture, frontend, backend, agent integration, realtime communication, data modeling, authorization, and delivery.
AI Super Teacher best represents the kind of engineering work I want to continue doing: technically difficult products where AI is one part of a larger production system.