How scratchfoundation/scratch-vm works
Main Components
a. Core Runtime Layer:
• Virtual Machine (src/virtual-machine.js)
• Runtime Engine (src/engine/runtime.js)
• Thread Execution System (src/engine/thread.js, src/engine/sequencer.js)
• Blocks Execution Engine (src/engine/blocks.js)
b. Extension System:
• Extension Manager (src/extension-support/extension-manager.js)
• Extension Worker Infrastructure (src/extension-support/extension-worker.js)
• Built-in Extensions (src/extensions/*)
c. I/O System:
• Device I/O (BLE, Bluetooth, Video, etc.)
• User Input (Keyboard, Mouse, etc.)
• Cloud Data Handling
d. Block Implementation Layer:
• Core Blocks (Motion, Looks, Sound, etc.)
• Custom Block Support
• Block Utilities
Architectural Relationships
┌─────────────────────────────────────────────────────┐
• Scratch Blocks UI │
• ┬───────────────────────────────────┘
┌─────────────────▼───────────────────────────────────┐
• Virtual Machine │
• ┤
• ┌─────────────┐ ┌──────────────┐ ┌──────────┐ │
• Runtime │◄─►│Thread Manager │◄─►│ Blocks │ │
• ┘ └──────────────┘ └──────────┘ │
• ▲ ▲ ▲ │
• ┼──────────────────┼──────────────┼─────────┤
• ┌───────▼──────┐ ┌──────▼─────┐ ┌────▼─────┐ │
• Extensions │ │ I/O System │ │Serializer │ │
• ┘ └────────────┘ └──────────┘ │
• ┘
Important Architectural Patterns to Highlight
a. Event-Driven Architecture:
• How block events flow from the UI through the VM
• Event dispatch system
b. Worker Architecture:
• Demonstrate the separation between main thread and extension workers
• Communication channels between components
c. Plugin System:
• How extensions are loaded and integrated
• Extension API interface
Additional Elements
• Notes for key architectural decisions
• Version compatibility interfaces (SB2/SB3)
• External dependencies and interfaces
Implementation Details to Consider
• Block execution pipeline
• Thread scheduling system
• Demonstrate asset loading and management
• How the VM interfaces with the Scratch Blocks UI