Project Overview
Timeline: 1-2 hours swarm runStack: React, Three.js, React Three Fiber, TypeScript, Vite
Runtime: Fully client-side, offline-capable after initial load
Source:
examples/minecraft-browser/
Key Features
- Procedural terrain generation with Simplex noise
- Voxel rendering with chunk-based optimization
- First-person controls - WASD movement + mouse look
- Physics-based interactions using React Three Cannon
- Block breaking and placing with real-time world updates
- Day/night cycle with ambient lighting changes
- Persistent world state stored in browser storage
Product Requirements
Product Statement
FromSPEC.md:
A browser-based Minecraft clone built with React, React Three Fiber, and TypeScript. The player loads a single HTML page and is dropped into a procedurally generated 3D voxel world. They can walk around, break blocks, place blocks, manage inventory, and experience a day/night cycle. The project leverages the React ecosystem (Drei, Cannon) to provide a modern, declarative, and modular codebase.
Success Criteria (Ranked)
- Playable 3D voxel world renders at 30+ FPS with procedural terrain, leveraging React Three Fiber’s component architecture
- Player interactions - move (WASD + mouse), break blocks (left click), place blocks (right click) using physics
- Inventory and crafting system with React UI components for resource management
- Day/night cycle with ambient lighting making the world feel alive
- Zero-config build - compiles with zero TypeScript errors and runs from
npm start
Hard Limits
- Time budget: 1-2 hours wall clock (single swarm run)
- Resource budget: Modern browser with WebGL 2.0 (no special GPU requirements)
- External services: No paid APIs, no backend server, no database
- Runtime mode: Fully client-side, works offline after initial load
Project Structure
Acceptance Tests
FromSPEC.md, objective completion criteria:
- Opening localhost in Chrome shows 3D voxel world
- WASD keys move player through world
- Mouse controls camera look direction
- Left-clicking block removes it (updates state/mesh)
- Right-clicking places selected block from inventory
- Pressing E opens/closes inventory panel
- Sky color transitions blue (day) → dark (night) over 5-minute cycle
- Terrain is different each page reload (seeded random generation)
- FPS counter shows 30+ FPS on standard laptop
Specification Documents
SPEC.md - Game Design Specification
Scope Model: Must Have (7):- Procedural terrain generation with Simplex noise
- Chunk-based or optimized instance-mesh rendering
- First-person camera with mouse look (PointerLockControls) + WASD movement
- Physical interactions (jumping, collision) using Cannon
- Block breaking/placing updating global store
- Basic inventory UI (React DOM overlay) showing selected block
- Day/night cycle (Sky component or custom)
- Texture selector (1-9 keys)
- Sound effects (use-sound or native Audio)
- Advanced biomes
- Ambient occlusion
- Save/Load to LocalStorage persistence
- Multiplayer / networking
- Mobs / AI entities
- Redstone logic
- Infinite world generation (limited chunks)
AGENTS.md - Development Policies
Key Conventions:Architecture Decisions
FromDECISIONS.md:
Render Stack: Three.js + Custom Voxel Mesher
- Date: 2026-02-14
- Decision: Use Three.js for low-level rendering while owning chunk meshing and world simulation
- Why: Three.js accelerates browser rendering setup while preserving control over voxel-specific performance and data structures
- Alternatives: BabylonJS, PlayCanvas, raw WebGL2
- Status: active
Persistence: Local-First Browser Storage
- Date: 2026-02-14
- Decision: Persist world edits in browser storage with explicit schema versioning
- Why: Matches offline-first requirement and minimizes infrastructure dependencies
- Alternatives: Backend-only persistence, IndexedDB wrapper service worker
- Status: active
Testing Strategy: Unit + E2E Baseline
- Date: 2026-02-14
- Decision: Gate progress with deterministic unit tests for world logic and one browser E2E flow for place/reload persistence
- Why: Protects core gameplay loop with fast feedback while validating real browser behavior
- Alternatives: E2E only, unit only
- Status: active
Setup and Execution
Prerequisites
Quick Start
Start Development Server
Verification
Demo Flow
Test Controls
- Move with
WASDkeys - Look around with mouse
- Break block with left click
- Place block with right click
Implementation Highlights
Procedural Terrain Generation
The world uses Simplex noise for natural-looking terrain:Physics-Based Player Controller
Using React Three Cannon for realistic movement:Block Interaction System
Raycast-based block breaking and placing:State Management with Zustand
Global game state for blocks and inventory:Operational Runbook
Operating Modes
Monitoring
Key Logs:- Browser console for runtime errors
- Terminal output from Vite for build issues
playwright-report/for E2E test failures
- Average frame time (target < 33ms for 30 FPS)
- Chunk generation time
- Chunk mesh rebuild counts
- Save latency to browser storage
- Persistent frame time above 33ms → reduce render distance
- Chunk loads stalling near player → check mesh generation
- Block edits not persisted after reload → check storage API
- Repeated uncaught exceptions → check error boundaries
Recovery Procedures
Restart Orchestrator:
Partial Failure Handling:
- Identify failed component from logs: render loop, world generation, input, or persistence
- Isolate by disabling failing subsystem behind feature flag while keeping read-only world view
- Verify healthy state:
Manual smoke test for movement and block editing
- CPU cap: Reduce render distance and chunk meshing budget per frame
- Memory cap: Evict far chunks from memory and compact block edit history
- Disk cap: Rotate save snapshots - keep latest plus one rollback
Performance Optimization
Chunk-Based Rendering
Instead of rendering individual cubes, merge blocks into chunk meshes:Frustum Culling
Only render chunks visible to camera:Level of Detail (LOD)
Simplify distant chunks:Key Learnings
What Worked Well
- React Three Fiber: Declarative 3D scene composition simplified complex rendering logic
- Zustand for state: Lightweight state management perfect for game state without Redux overhead
- Vite build tool: Lightning-fast hot reload during development
- Browser storage: Simple persistence without backend complexity
Challenges Addressed
- Performance at scale: Solved with chunk merging and frustum culling to maintain 30+ FPS
- Pointer lock issues: Handled with proper event listeners and escape key handling
- Physics stability: Tuned Cannon physics settings to prevent falling through world
- Memory leaks: Added proper cleanup in React useEffect for Three.js objects
Next Steps
Decagon Assistant
See full-stack AI application example
Basic Template
Start your own project from scratch
Project Structure
Learn the specification framework
Swarm Execution
Understand multi-agent coordination