-
Activate virtual environment:
cd backend source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies (if not already done):
pip install -r requirements.txt
-
Create
.envfile inbackend/directory:OPENAI_API_KEY=your_openai_api_key_here # OR ANTHROPIC_API_KEY=your_anthropic_api_key_here # Optional: For PostgreSQL in production # DATABASE_URL=postgresql://user:password@localhost/dbname
-
Initialize Database:
# Database auto-initializes on first run, but you can manually run: python -c "from app.db.database import init_db; init_db(); print('Database initialized')"
-
Run Migration (if upgrading from old version):
# If you see "no such column: visualizations.blueprint_id" errors: PYTHONPATH=$(pwd) python scripts/migrate_add_blueprint_id.py
-
Start the server:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
OR use the startup script (recommended):
# From project root - starts both backend and frontend ./start.shThe database will be automatically initialized on startup (SQLite by default).
-
Install dependencies (if not already done):
cd frontend npm install -
Create
.env.local(optional, defaults to localhost:8000):NEXT_PUBLIC_API_URL=http://localhost:8000
-
Start the development server:
npm run dev
OR use the startup script (recommended):
# From project root - starts both backend and frontend ./start.sh -
Open browser: http://localhost:3000
./start.sh- Starts both backend and frontend
- Shows combined logs
- Handles all setup automatically
./start-dev.sh- Opens backend in one terminal
- Opens frontend in another terminal
- Better for development with separate log views
./stop.sh- Kills all running servers
- Cleans up ports
- 18 Fixed Templates: Each question is automatically routed to the best template
- Template Routing: LLM analyzes question and selects appropriate template
- Blueprint Generation: Creates structured JSON instead of generic HTML
- Template Components: Each template has dedicated React component
- Template Routing (Layer 2.5) - Selects game template
- Template-Aware Story Generation - Uses template-specific supplements
- Blueprint Generation - Creates template-specific JSON
- Asset Planning - Identifies required images/assets
- Asset Generation - Generates asset URLs
- GameBlueprint Model: Stores template-specific blueprints
- Visualization.blueprint_id: Links visualizations to blueprints
- Migration Required: Run migration script if upgrading
- GameEngine Component: Routes to correct template component
- 18 Template Components: Each implements specific interactions
- TypeScript Types: Full type safety for all blueprints
- Manual Navigation: "Go to Game" button instead of auto-redirect
Each of the 18 templates has:
- Metadata JSON:
backend/app/templates/{TEMPLATE}.json- Description, domains, required fields, HTML contract
- Story Supplement:
backend/prompts/story_templates/{TEMPLATE}.txt- Template-specific guidance for story generation
- TypeScript Interface:
backend/prompts/blueprint_templates/{TEMPLATE}.ts.txt- Exact schema for blueprint generation
- React Component:
frontend/src/components/templates/{Template}Game.tsx- Interactive game implementation
The system automatically:
- Analyzes question (type, subject, difficulty, concepts, intent)
- Routes to best template using LLM
- Generates template-specific story
- Creates blueprint matching template schema
- Renders with appropriate React component
POST /api/upload- Upload documentGET /api/questions/{id}- Get question detailsPOST /api/process/{id}- Start processing pipelineGET /api/progress/{id}- Get processing progressGET /api/visualization/{id}- Get visualization (blueprint or HTML)
GET /api/visualizations/{id}- Get visualization with blueprint supportGET /api/pipeline/steps/{process_id}- Get all steps for a processPOST /api/pipeline/retry/{step_id}- Retry a failed stepGET /api/pipeline/history/{question_id}- Get processing history
- "no such column: visualizations.blueprint_id": Run migration script
cd backend source venv/bin/activate PYTHONPATH=$(pwd) python scripts/migrate_add_blueprint_id.py
- Database not found: Delete
backend/ai_learning_platform.dband restart (will auto-create) - SQLite foreign keys: Automatically enabled via event listener
- "Template not found": Ensure all 18 JSON files exist in
backend/app/templates/ - "Failed to load prompt": Check file paths (should be 4 levels up from pipeline services)
- Template registry empty: Check logs for template loading errors
- "No such file or directory: prompts/...":
- Ensure paths use
.parent.parent.parent.parent(4 levels) - Check that prompt files exist in
backend/prompts/
- Ensure paths use
- TypeScript errors: Run
npm run buildto see all errors - ESLint errors: Fix unescaped entities (
'→') - Missing types: Ensure
gameBlueprint.tshas all template interfaces
- Make sure virtual environment is activated
- Run
pip install -r requirements.txtto ensure all dependencies are installed - Check Python path for migration scripts:
PYTHONPATH=$(pwd)
- Ensure
.envfile exists inbackend/directory - Check that API key is valid
- Server will log which API keys are found on startup
- System tries OpenAI first, falls back to Anthropic
- Check browser console for errors
- Verify
visualizationIdexists in localStorage - Ensure blueprint data is valid JSON
- Check that GameEngine receives correct
templateType
- Upload document via frontend
- Review question on preview page
- Click "Start Interactive Game"
- Watch progress through pipeline steps
- Click "Go to Game" when complete
- Interact with template-specific game
- Check backend logs for each step
- Use
/api/pipeline/steps/{process_id}to see step details - Retry failed steps via
/api/pipeline/retry/{step_id} - Check database for stored blueprints
See SETUP.md for detailed instructions on adding new templates.
| Old System | New System |
|---|---|
| Generic HTML generation | Template-specific blueprints |
| Single visualization type | 18 template types |
| HTML stored in database | JSON blueprints stored |
| Static HTML rendering | Interactive React components |
| Manual template selection | Automatic LLM routing |
| No asset system | Asset planning & generation |
- Complete Template Components: Many templates are placeholders - implement full interactions
- Asset Generation: Integrate actual image generation API (currently placeholder URLs)
- Task System: Implement task display and evaluation across all templates
- Feedback System: Add comprehensive feedback for all interactions
- Path Tracking: Implement for MICRO_SCENARIO_BRANCHING and similar path-based templates