This document provides a technical overview of Evo's architecture and codebase structure.
- Frontend Framework: React 19 with TypeScript
- Build Tools: Vite (web), electron-vite (desktop)
- Desktop Runtime: Electron
- UI Components: Bootstrap 5
- Styling: CSS with custom theming
Evo/
├── src/
│ ├── main/ # Electron main process
│ │ └── index.ts # Main entry point for Electron
│ ├── preload/ # Electron preload scripts
│ └── renderer/ # React application (runs in browser/Electron renderer)
│ ├── App.tsx # Root React component
│ ├── main.tsx # React entry point
│ ├── components/ # React UI components
│ ├── core/ # Core simulation logic
│ │ ├── Agent.ts # Agent class (AI creatures)
│ │ ├── NeuralNetwork.ts # Neural network implementation
│ │ ├── EvolutionManager.ts # Handles evolution/genetics
│ │ └── utilities/ # Helper utilities and configs
│ ├── hooks/ # Custom React hooks
│ ├── types/ # TypeScript type definitions
│ └── assets/ # Static assets (CSS, images)
├── build/ # Build resources (icons, entitlements)
├── resources/ # Application resources
├── docs/ # Documentation
└── .github/ # GitHub configurations
└── workflows/ # CI/CD workflows
The simulation runs in a continuous loop, updating all agents and food entities each frame:
┌─────────────────────────────────────────────────┐
│ Game Loop │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Update │→ │ Physics │→ │ Render │ │
│ │ Agents │ │ Check │ │ Frame │ │
│ └─────────┘ └─────────┘ └─────────┘ │
└─────────────────────────────────────────────────┘
Each agent contains:
- Neural Network: Multi-layer perceptron for decision making
- Sensors: Raycasting system for environment perception
- Genetic Information: DNA that encodes traits and behaviors
- State: Position, velocity, energy, age, fitness
interface Agent {
id: string
species: string
position: { x: number; y: number }
velocity: { x: number; y: number }
energy: number
age: number
fitness: number
neuralNetwork: NeuralNetwork
genome: number[]
}Agents use a configurable multi-layer perceptron:
Input Layer Hidden Layers Output Layer
(Sensor Data) (Configurable) (Actions)
○ ○ ○ (Move Forward)
○ ───────────→ ○ ───────────→ ○ (Turn Left)
○ ○ ○ (Turn Right)
○ ○ ○ (Eat)
Supported Activation Functions:
- Swish
- ELU
- Leaky ReLU
- Tanh
The evolution process follows a generational model:
- Evaluation: Each agent accumulates fitness based on survival and food consumption
- Selection: Top performers are selected based on
selectionRate - Reproduction: Selected agents create offspring through:
- Crossover: Combining genes from two parents
- Mutation: Random modifications to neural network weights
- Population Reset: New generation begins
Evo uses HTML Canvas for efficient 2D rendering:
┌──────────────────────────────────────────────────┐
│ Canvas Rendering │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Clear │→ │ Draw │→ │ Draw │→ ... │
│ │ Canvas │ │ Grid │ │ Agents │ │
│ └─────────┘ └─────────┘ └─────────┘ │
└──────────────────────────────────────────────────┘
Features:
- Camera transformation for infinite world navigation
- Efficient redraw with dirty region tracking
- Selection highlighting and agent trails
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Config │ ──→ │ Simulation │ ──→ │ Render │
│ Panel │ │ Engine │ │ Canvas │
└─────────────┘ └──────────────┘ └─────────────┘
↑ │ │
│ ↓ │
│ ┌──────────────┐ │
└───────────│ Stats │←────────────┘
│ Updates │
└──────────────┘
Evo uses React's built-in state management with useState and useCallback:
- Simulation Config: User-adjustable parameters
- Simulation Stats: Real-time metrics (FPS, generation, fitness)
- Agent State: Current population and selection
- Evolution History: Generational tracking data
Controls agent behavior, neural network structure, and simulation parameters.
Runtime-adjustable evolution parameters:
- Generation time
- Selection rate
- Mutation rate
- Population size
vite.config.ts- Web build configurationelectron.vite.config.ts- Electron build configurationelectron-builder.yml- Desktop app packaging
- Canvas Optimization: Minimal redraws, efficient transforms
- React Optimization: Memoized callbacks, minimal re-renders
- Agent Limit: Configurable max population to maintain 60 FPS
- Spatial Partitioning: Efficient collision detection (future enhancement)
Edit src/renderer/core/NeuralNetwork.ts:
export function yourActivation(x: number): number {
// Your implementation
return x
}Extend the sensor system in src/renderer/core/Agent.ts to detect new entity types or implement different sensing patterns.
Modify the neural network output interpretation in the agent update loop to add new actions or behaviors.