System overview
Architecture Diagram
┌─────────────────────────────────────────────────────────────┐
│ Solana Blockchain │
└────────────────┬────────────────────────────────────────────┘
│ Real-time transactions
↓
┌─────────────────────────────────────────────────────────────┐
│ Helius gRPC Stream │
│ (laserstream-mainnet-fra.helius-rpc.com) │
└────────────────┬────────────────────────────────────────────┘
│ Millisecond latency
↓
┌─────────────────────────────────────────────────────────────┐
│ CAIVEMEN Backend (Rust) │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Transaction Parser │ │
│ │ - Classify type (buy/sell/transfer) │ │
│ │ - Classify size (small/medium/large) │ │
│ │ - Extract wallet & amount │ │
│ └────────────┬────────────────────────────────────────────┘ │
│ ↓ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ Event Generator │ │
│ │ - Map transaction → world effect │ │
│ │ - Spawn food/disasters │ │
│ │ - Update tension │ │
│ └────────────┬─────────────────────────────────────────────┘ │
│ ↓ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ Game State Manager │ │
│ │ - Central state (cavemen, food, disasters) │ │
│ │ - Position updates │ │
│ │ - Combat resolution │ │
│ │ - Death/respawn logic │ │
│ └────────────┬─────────────────────────────────────────────┘ │
│ ↓ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ AI Decision Engine (every 3s) │ │
│ │ - Build prompts for each caveman │ │
│ │ - Call OpenRouter LLM APIs in parallel │ │
│ │ - Parse JSON responses │ │
│ │ - Execute actions (move/attack/flee/eat) │ │
│ └────────────┬─────────────────────────────────────────────┘ │
│ ↓ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ Game Loop (every 100ms) │ │
│ │ - Apply hunger/health changes │ │
│ │ - Process disaster damage │ │
│ │ - Update respawn timers │ │
│ │ - Clamp positions │ │
│ └────────────┬─────────────────────────────────────────────┘ │
└──────────────┼────────────────────────────────────────────┘
│
├────────────┐
↓ ↓
┌──────────────────┐ ┌──────────────────────────────┐
│ WebSocket │ │ Firestore │
│ Broadcast │ │ (Persistent Storage) │
│ (every 200ms) │ │ - Events │
└────┬─────────────┘ │ - Transactions │
│ │ - Kills │
│ │ - Stats │
│ │ - Disasters │
│ └──────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ Next.js Frontend (React + Canvas) │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ WebSocket Client │ │
│ │ - Receive state updates │ │
│ │ - Handle reconnection │ │
│ └────────────┬────────────────────────────────────────────┘ │
│ ↓ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ State Management │ │
│ │ - Store current game state │ │
│ │ - Smooth position interpolation (lerp) │ │
│ │ - Click detection for caveman selection │ │
│ └────────────┬────────────────────────────────────────────┘ │
│ ↓ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ Canvas Renderer (60 FPS) │ │
│ │ - Draw terrain (rivers, forests) │ │
│ │ - Draw cavemen with smooth movement │ │
│ │ - Draw food & disasters │ │
│ │ - Health bars & name labels │ │
│ └─────────────────────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ UI Components │ │
│ │ - Event log (real-time feed) │ │
│ │ - Stats panel (kills, health) │ │
│ │ - Selected caveman details │ │
│ └─────────────────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────────────┘
│
↓
Browser (User)Core Components
Backend Stack
Frontend Stack
Data Flow Paths
Last updated