Overview
The presentation engine coordinates:- Audio playback: TTS narration with word-level timing
- Trigger execution: Commands fire at word positions
- Scene state management: What’s visible on stage
- Animation scheduling: Enter/exit effects for blocks
- User controls: Play, pause, seek, skip, playback rate
src/presentation/
Architecture
Presentation Store
File:src/presentation/store.ts
A Zustand store holds all presentation state:
Key State Fields
lesson: The parsed lesson (from parser)currentStepIndex: Current step (chapter) being playedstatus: Playback state (idle, playing, paused)playbackRate: Speed multiplier (0.5x, 1x, 1.5x, 2x)currentWordIndex: Current word in narration (synced to audio)sceneIndex: Current scene (frame) in the step’s scene sequencecompletedStepIds: Set of completed step IDs for progress tracking
Actions
loadLesson: Initializes the store with a parsed lessonplay/pause: Control playbacksetWordIndex: Called by audio player to sync word positionadvanceScene: Transition to next scene (triggered by word index)
Playback Orchestration
File:src/presentation/use-playback.ts
The usePlayback hook manages audio playback and trigger execution.
Playback Flow
Prefetch TTS audio
React Query prefetches TTS audio for all narration blocks:This ensures smooth playback without waiting for synthesis.
Event Scheduling
File:src/presentation/event-scheduler.ts
Maps triggers to word positions and schedules execution.
Data Structure
wordIndex.
Scheduling Algorithm
- For each trigger in narration:
- Compute word position (sum of word counts before trigger)
- Store
{ wordIndex, trigger }
- Sort events by word index
- As playback progresses, check if current word index has passed any events
- If yes, execute trigger
Example
Narration:- Word 0: Execute
show: code-a - Word 4: Execute
focus: line-1
Scene State Management
File:src/presentation/resolve-scene-at.ts
Computes the scene state at a given word index.
Scene State Structure
Resolving Scene State
Given a word index, replay all triggers up to that point:Animation System
File:src/presentation/animation-variants.ts
Defines Motion animation variants for enter/exit effects.
Animation Variants
Each effect has enter/exit variants:Custom Animations
Triggers can override default animations:Stage Rendering
File:src/presentation/Stage.tsx
The stage is the main rendering surface for visualizations.
Stage Layout
- Default mode: Single block centered
- Split mode: Multiple blocks side-by-side
Rendering Logic
AnimatePresence: Handles enter/exit animations for blocks.
VisualizationBlock: Renders the appropriate component (Code, Data, Diagram, etc.) based on block type.
User Controls
File:src/presentation/Controls.tsx
Provides playback controls:
- Play/Pause: Toggle playback
- Skip forward/backward: Jump to next/previous step
- Seek bar: Scrub through narration
- Playback rate: 0.5x, 1x, 1.5x, 2x
- Step navigation: Jump to specific step
Seek Behavior
When user seeks:- Pause audio
- Compute word index for new position
- Update
currentWordIndex - Resolve scene state at new word index
- Render new scene
- Resume playback at new position
Narration Text Display
File:src/presentation/NarrationText.tsx
Displays narration text with word-level highlighting.
Highlighting Current Word
TTS Integration
Location:src/tts/
Synthesis
File:src/tts/synthesize.ts
Invokes backend TTS command:
Audio Playback
File:src/tts/audio-player.ts
Wraps Howler.js:
Prefetching
File:src/tts/use-prefetch-tts.ts
Prefetches TTS audio for all narration blocks using React Query:
Performance Optimizations
- React Query caching: TTS audio cached per narration text
- Lazy rendering: Visualization blocks only render when visible
- RequestAnimationFrame: Word position updates throttled to 60fps
- Debounced seeks: Avoid rapid scene recomputation during scrubbing
Future Enhancements
- Subtitle track: Display narration text with word highlighting (already implemented)
- Keyboard shortcuts: Space to play/pause, arrow keys to skip
- Chapter markers: Visual markers for each step on seek bar
- Auto-advance: Option to auto-advance to next lesson
- Accessibility: Keyboard navigation, screen reader support
Next Steps
Parser
Understand how markdown becomes IR
Frontend
Explore the React frontend
Backend
Dive into the Rust backend
Architecture
High-level system overview