System Architecture
Sprout follows a modern full-stack architecture with clear separation between frontend visualization, backend orchestration, and AI agent processing.- Frontend
- Backend
- AI Agents
- Framework: Next.js 16 with React 19
- 3D Visualization: Three.js + react-force-graph-3d
- 2D Graph: React Flow (@xyflow/react)
- Real-time: Server-Sent Events (SSE) for agent streaming
- Hand Tracking: WebSocket connection to Python CV service
Data Flow
Key Design Principles
1. Agent-Based Architecture
All AI agents run through a shared agent loop (src/agents/agent-loop.ts) that handles:
- Multi-turn tool calling with Claude
- Retry logic with exponential backoff for rate limits
- Reasoning visibility via SSE callbacks
- Configurable iteration limits (5-15 rounds)
Agents persist data through tool calls, not return values. This ensures all graph mutations are immediately visible to other agents and streamed to the frontend.
2. DAG-Based Learning Graphs
Learning pathways form Directed Acyclic Graphs (DAGs), not linear sequences:- Root nodes: Topic entry points
- Concept nodes: Major learning concepts (6-10 per topic)
- Subconcept nodes: Granular learning units (8-12 per concept)
- Edges: Prerequisites and dependencies
3. Real-Time Streaming
All agent operations stream progress via Server-Sent Events:4. Observe-Reason-Act-Verify Loop
The Concept Refinement Agent follows a structured reasoning loop:- OBSERVE: Load diagnostic results + student history
- REASON: Analyze gaps, misconceptions, mastery patterns
- ACT: Add/remove subconcepts, insert prerequisite/follow-up concepts
- VERIFY: Validate graph integrity (no orphans, cycles, or broken edges)
- VERIFY AGAIN: Confirm all issues are resolved
This is Sprout’s star feature — the graph adapts based on each student’s actual performance, not just predefined templates.
Technology Stack
Core Dependencies
Deployment Architecture
Sprout is designed as a hackathon project with a simple deployment model:- Single User: Hardcoded
DEFAULT_USER_ID(no authentication) - Local SQLite: Database stored in
sprout-backend/sprout.db - S3 Storage: Document uploads (optional)
- Python CV Service: Hand tracking via WebSocket (ws://localhost:8765)
For production use, consider adding:
- Multi-user authentication
- PostgreSQL for concurrent access
- Redis for SSE event buffering
- Docker containers for CV service
Performance Considerations
Agent Concurrency
Subconcept bootstrap agents run in parallel with concurrency limit:Small Mode
For testing and cost reduction, enable small mode:- Topic Agent: 1-2 concepts instead of 6-10
- Subconcept Bootstrap: 2-3 subconcepts instead of 8-12
- Diagnostic Questions: 2-3 instead of 5-10
Next Steps
Backend Architecture
Explore Express routes, agent orchestration, and SSE streaming
Frontend Architecture
Learn about 3D graphs, React Flow, and hand tracking integration
Database Schema
Understand the SQLite data model and Drizzle ORM usage