What This Guide Does
This guide uses an incremental build approach to create your student AI chat interface. You'll build the application in five distinct stages, with each stage producing a fully functional system. Test and verify each stage before moving to the next.
Why Build Incrementally
Clear progress markers - Each stage has specific, testable deliverables. You'll know when you're done.
Easier debugging - When something breaks, you know it's related to the current stage. The previous stage worked.
Flexible stopping points - Each stage produces something functional. Stop at Stage 2 if you just need basic chat with persistence. Continue to Stage 5 for the full production system.
Manageable complexity - AI coding agents (and humans) work better with bounded, clear requirements than large, complex instructions.
Working code at every step - No long periods where nothing works. Build, test, move forward.
How to Use This Guide
1. Complete the preparation steps below
The preparation section walks you through workspace setup, configuration questions to answer before building, and how to prepare your AI coding agent with the right context.
2. Then read the Architecture Reference
Understanding the system design before building helps you make informed decisions when adapting the guide to your specific needs.
3. Then tackle the stages in order
Each stage builds on the previous one. Don't skip ahead.
4. Use each stage file as a complete prompt to your AI agent
The stage files contain everything your AI coding agent needs to build that stage. Feed the complete file to your AI agent and let it implement.
5. Verify thoroughly before moving on
Test each stage according to its verification steps. Don't move to the next stage until the current one works completely.
6. Expect iteration
Often, something won't work perfectly the first time. That's normal. Read error messages, consult logs, ask your AI agent to help debug. This is part of the learning process.
The Five Stages
Stage 1: Basic API Connection
What you'll build: Simple web page that sends messages to an AI provider and displays responses.
What you'll prove: Your hosting environment works, your API key works, the basic request/response cycle functions correctly.
Components: HTML page, basic JavaScript, PHP API proxy, hardcoded system instruction.
Verification: Type a message, get a response from the AI.
Stage 2: Conversation Storage
What you'll add: Browser-based storage so conversations persist across sessions.
What you'll prove: Students can save conversations, close their browser, come back later, and continue where they left off.
New components: IndexedDB storage via LocalForage, conversation save/load functionality, basic conversation list.
Verification: Create a conversation, close the browser, reopen, and see your conversation still there.
Stage 3: Configuration Files
What you'll add: Move hardcoded values into JSON configuration files. Add server-side instruction assembly.
What you'll prove: Configuration changes take effect without editing code. The foundation for modular instruction building works.
New components: Configuration file, PHP configuration reader, server-side instruction assembly logic.
Verification: Change the system instruction in the config file, create a new conversation, observe the change in AI behavior.
Stage 4: Modular Configuration
What you'll add: Conversation frameworks library, learning supports library, ID-based referencing, conversation instruction snapshots, path-based storage namespacing.
What you'll prove: You can switch between different conversation frameworks and combine different learning supports. Existing conversations maintain their original instructions even when you change the global config.
What are learning supports? Modular instructional strategies that adapt how the AI assists students — like English Language Learner support (simplified vocabulary), chunking (breaking tasks into steps), or Socratic questioning (guiding through questions). These can be mixed and matched with any conversation framework.
New components: Conversation frameworks library file, learning supports library file, enhanced assembly logic, snapshot storage in conversations.
Verification: Create a conversation with one framework, switch to a different framework in config, create another conversation. Confirm both conversations use their respective frozen instructions.
Stage 5: Production Ready
What you'll add: Rate limiting, enhanced error handling, security headers, UI improvements, configuration editor.
What you'll prove: The system is secure, handles errors gracefully, and provides a polished user experience.
New components: Rate limiter, comprehensive error handling, security headers, markdown rendering, keyboard shortcuts, config editor UI.
Verification: Full system test across all features. Intentionally trigger errors and confirm graceful handling.
What You'll Learn
Application Development Skills
- How various web-based components work (API interactions, storage, user interfaces, JSON)
- How to design configuration systems that are both powerful and maintainable
- How to build modular, composable systems
Working with AI Coding Agents
- How to provide clear, bounded requirements
- How to structure incremental development tasks
- How to verify AI-generated code works correctly
- How to debug when things don't work as expected
- How to iterate with an AI agent to refine implementation
- How to maintain architectural vision while delegating implementation
Architectural Thinking
- Why certain design patterns exist and when to use them
- Trade-offs between simplicity and features
- Security considerations for web applications
- How to design for specific deployment constraints (shared hosting)
Preparation
Before you begin building, set up your workspace, gather necessary resources, and make key technical decisions.
Prerequisites Checklist
Ensure you have:
- Hosting access - Shared hosting with PHP 7.4+ and Apache
- File management - FTP/SFTP client or cPanel file manager access
- Environment variables - Ability to set environment variables for API key storage
- Text editor - For editing code locally (VS Code, Sublime Text, etc.)
- Web browser - Chrome or Firefox with DevTools for testing
- AI coding assistant - Command-line AI coding assistant
-
Git installed - For version control (check with
git --versionin terminal)
Technical Decisions
Make these choices before building:
AI Provider
Choose your AI API provider:
- Google Gemini - Flash models are fast and inexpensive
- OpenAI - GPT-3.5/4 models widely used
- Anthropic - Claude models strong for educational use
- Others: Deepseek, Mistral, etc.
Real-world experience: The original Babbleborg uses Google Gemini, which has proven reliable and cost-effective for educational use across multiple classes and subject areas. Gemini Flash models are significantly less expensive than OpenAI or Anthropic while offering robust built-in safety features. That said, all major providers work well — choose based on your budget, feature requirements, and organizational preferences.
Get your API key from your chosen provider and have it ready.
Cost estimation: Use LLM Pricing Calculator to compare current pricing across providers.
Hosting Environment
Document your hosting specifics:
- What control panel do you use? (cPanel, Plesk, custom)
- What PHP version is available?
- Are there known ModSecurity or firewall restrictions?
- How do you set environment variables in your hosting environment?
You'll provide these details to your AI coding assistant so it can account for your specific constraints.
Note on alternative platforms: This guide's build stages use PHP/Apache as the implementation example. If your environment uses a different backend stack (Node.js, Python, etc.), the architectural patterns described in the Architecture Reference still apply - you'll work with your AI coding assistant to implement those patterns in your preferred technology. The core requirements remain the same: a secure backend that keeps API keys server-side and proxies requests to your AI provider.
Workspace Setup
1. Create Local Project Directory
mkdir student-ai-chat
cd student-ai-chat
2. Initialize Git Repository
git init
This creates a local version control repository. You'll commit your work at logical points throughout the build process. No GitHub account needed - this is purely local.
3. Create Initial Project Structure
mkdir docs
Complete AI Context Template
The ai-context-template.md file provides your AI coding
assistant with essential information about your specific environment
and requirements.
Get the template:
- Download the template from the AI Context Template page
-
Save it to your
docs/folder asai-context-template.md
Fill out all sections with your specific information:
- Hosting environment details
- AI API provider and model choice
- Development tools you're using
- Educational context
- Project file structure
- Any additional constraints or requirements
This template captures critical parameters that vary between installations. Your AI assistant will reference this when making implementation decisions.
Editing the template: Use any text editor (VS Code, Sublime Text, Notepad++, etc.). For better readability, markdown editors render the formatting as you edit. Recommended free options:
- Obsidian - Feature-rich desktop app with live preview
- MarkText - Simple, focused markdown editor
- Dillinger - Web-based, no installation needed
When to provide it: Include the completed template file when starting each build stage, along with the stage instructions, testing information, and architecture reference.
Preparing Your AI Agent's Reference Library
Your docs/ folder should contain reference materials for
your AI coding assistant:
Required:
- ai-context-template.md (completed with your specifics) - Download template
- architecture.md (from this build guide) - Download
- Stage files (as you progress through stages) - Download from each stage page
- testing.md (from this build guide) - Download
Optional but helpful:
- API provider documentation pages (saved as markdown)
- Hosting-specific documentation (if your environment has unusual constraints)
API Documentation Resources
Your AI agent can reference these online. Optionally save key pages as markdown for offline reference:
Google Gemini:
OpenAI:
Anthropic Claude:
Tools for Saving Webpages as Markdown
If you choose to save documentation pages:
- MarkDownload (GitHub) - Free browser extension that converts webpages to markdown files
- LLMFeeder (GitHub) - Browser extension specifically designed for feeding web content to AI agents
- Obsidian Web Clipper - If you use Obsidian for note-taking, built-in web clipping to markdown
Prepare Testing Content
Simplified System Instruction
During the build process (Stages 1-4), you'll use a simplified system instruction for testing. This proves functionality without overwhelming complexity.
If you'd like something more substantial, save this as a reference (you'll provide it to your AI agent during Stage 1):
You are an educational AI assistant helping students learn and understand concepts. Your role is to support student learning while maintaining their ownership of the work.
Core principles:
- Guide students to understand concepts rather than simply providing answers
- Ask what students already know before explaining new material
- Break complex ideas into manageable pieces
- Use clear, accessible language
- Provide concrete examples relevant to students' experiences
- Never complete assignments for students - help them complete their own work
- Check for understanding and adjust explanations as needed
Maintain a warm, supportive tone that is direct and honest, balancing support with promoting independence.
This basic instruction creates meaningful educational interactions while you build and test each stage. Feel free to edit this example, but keep in mind that you'll refine and expand your pedagogical approach later in the Making It Yours phase.
Working with Your AI Coding Assistant
Provide Context at Each Stage
When you begin each build stage, you'll provide your AI assistant with:
- The stage file itself - Complete instructions for that stage (download from stage page)
- Architecture Reference - System design reference (download)
- AI Context Template (completed) - Your specific environment and requirements (download)
- Testing Guide - For reference during verification steps (download)
- Previous stage's code (for stages 2-5)
- Optional: Any API or hosting documentation you've saved
The AI Context Template is particularly important - it provides the AI agent with critical information about your deployment environment that affects implementation choices.
AI Agent Roles
Your AI coding assistant will:
- Create and modify files as needed for the stage (with your permission)
- Make git commits when it determines a logical checkpoint has been reached (with your permission)
- Ask clarifying questions about your specific environment or preferences
- Include diagnostic logging and error output in generated code
You remain responsible for:
- Testing and verifying each component works
- Reviewing code before moving to the next stage
- Making final decisions about implementation choices
- Understanding what the code does (ask questions if unclear)
Iteration and Debugging
Expect things not to work perfectly on the first try. When errors occur:
- Read the error message - Copy the complete error text
- Check browser DevTools Console - Look for JavaScript errors
- Check server error logs - Most hosting provides error log access
- Provide error details to your AI assistant - Include full error messages, relevant log entries, and what you were doing when it failed
- Iterate - Your AI assistant will help debug and refine
This is normal and part of the learning process.
Configuration Planning
You don't need to finalize your pedagogical approach before building, but consider:
What's your primary use case?
- General homework help across subjects?
- Subject-specific support (science, writing, math)?
- Project-based learning support?
- Something else?
Who are your students?
- What grade level(s)?
- What's their general comfort level with technology?
- Are there specific learning needs to consider?
What's your educational philosophy about AI?
- How do you want students to interact with AI tools?
- What boundaries are important to you?
- What does authentic learning look like in your context?
These questions inform the system instructions, conversation frameworks, and learning supports you'll develop. You don't need final answers now — just start thinking about them.
During Stage 1-3, you'll use the simplified system instruction referenced above. In Stage 4, you'll create basic conversation frameworks and learning supports. After Stage 5, the Making It Yours page will guide you in refining these based on your specific pedagogical approach.
Ready to Build?
Once you've completed this preparation:
- ✅ Made technical decisions (API provider, hosting details)
- ✅ Set up local workspace with Git
- ✅ Created
docs/folder - ✅ Completed
ai-context-template.md -
✅ Assembled your AI agent's reference library in
docs/folder
You're ready!
Next step: Read the Architecture Reference to understand the system design, then proceed to Stage 1.