# deontologician/evofighters architecture

> Architecture diagram of the GitHub repository deontologician/evofighters, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/deontologician/evofighters
- Repository: https://github.com/deontologician/evofighters

## Overview

##### Main Components

a) Simulation Core:
- Arena System (manages encounters between creatures)
- Creature Management System
- DNA Processing Pipeline
- Evolution Engine

b) DNA Processing Pipeline (Key Subsystem):
- Parser
- Compiler
- AST Evaluator
- Mutation Engine

##### Component Relationships

**Top Level:**
**[Simulation Controller] → [Arena] → [Encounter Manager]**
- ↓
**[Population Manager] ← → [DNA Processing Pipeline]**
- ↓
**[Save/Load System] ← → [Statistics/Evaluation]**

DNA Processing Pipeline (Detail View):
**[Raw DNA] → [Parser] → [AST Builder] → [Compiler] → [Evaluator] → [Action Decision]**
- ↑                                         ↓
- [Grammar Rules] ← - - - - - - - - - - [Mutation Engine]

##### Specific Implementation Details

- Rectangles: Core processing components
- Hexagons: Decision points
- Diamonds: Evaluation steps

- Blue: Core simulation components
- Green: DNA processing components
- Yellow: Data storage/persistence
- Red: Critical decision points

##### Key Processes to Highlight

a) Creature Lifecycle:
**[Creation] → [DNA Parsing] → [Compilation] → [Evaluation] → [Action Execution]**

b) Evolution Cycle:
**[Population] → [Selection] → [Mating] → [Mutation] → [New Generation]**

##### Important Elements

- Both Python and Rust implementations as parallel systems
- Grammar.bnf file's role in DNA parsing
- Save/load functionality
- Encounter system's flow
- Demonstrate the mutation and breeding mechanics

##### Technical Details to Note

- Error handling paths
- Where parallelization is possible
- System boundaries

##### Implementation-Specific Notes

For the Rust implementation, highlight:
- AST optimization paths
- Pre-compilation optimizations
- Memory management boundaries

For the Python implementation, show:
- PyPy optimization points
- Interpretation paths

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Simulation Core"]
        SimController["Simulation Controller"]:::controller
        Arena["Arena System"]:::arena
        EncounterMgr["Encounter Manager"]:::arena
        PopMgr["Population Manager"]:::core
        SaveLoad["Save/Load System"]:::storage
        Stats["Statistics/Evaluation"]:::stats
    end

    subgraph DNA["DNA Processing Pipeline"]
        Parser["Parser"]:::dna
        ASTBuilder["AST Builder"]:::dna
        Compiler["Compiler"]:::dna
        Evaluator["AST Evaluator"]:::dna
        MutationEngine["Mutation Engine"]:::dna
        Grammar["Grammar Rules"]:::dna
    end

    subgraph Evolution["Evolution Cycle"]
        Population["Population"]:::evo
        Selection["Selection"]:::evo
        Mating["Mating"]:::evo
        Mutation["Mutation"]:::evo
        NewGen["New Generation"]:::evo
    end

    subgraph Implementation["Implementation"]
        Python["Python Implementation"]:::lang
        Rust["Rust Implementation"]:::lang
        PyPyOpt["PyPy Optimization"]:::opt
        RustOpt["AST Optimization"]:::opt
    end

    %% Core Relationships
    SimController --> Arena
    Arena --> EncounterMgr
    SimController --> PopMgr
    PopMgr <--> SaveLoad
    SaveLoad <--> Stats

    %% DNA Pipeline Flow
    Parser --> ASTBuilder
    ASTBuilder --> Compiler
    Compiler --> Evaluator
    Grammar --> Parser
    Evaluator --> MutationEngine
    MutationEngine -.-> Grammar

    %% Evolution Cycle
    Population --> Selection
    Selection --> Mating
    Mating --> Mutation
    Mutation --> NewGen
    NewGen --> Population

    %% Implementation Details
    Python --> PyPyOpt
    Rust --> RustOpt
    
    %% Component Mappings
    click SimController "https://github.com/deontologician/EvoFighters/blob/master/evofighters_rust/src/sim.rs"
    click Arena "https://github.com/deontologician/EvoFighters/blob/master/EvoFighters/Arena.py"
    click SaveLoad "https://github.com/deontologician/EvoFighters/blob/master/EvoFighters/SaveData.py"
    click Stats "https://github.com/deontologician/EvoFighters/blob/master/evofighters_rust/src/stats.rs"
    click Parser "https://github.com/deontologician/EvoFighters/blob/master/EvoFighters/Parsing.py"
    click Evaluator "https://github.com/deontologician/EvoFighters/blob/master/EvoFighters/Eval.py"
    click Grammar "https://github.com/deontologician/EvoFighters/blob/master/EvoFighters/grammar.bnf"
    click RustOpt "https://github.com/deontologician/EvoFighters/blob/master/evofighters_rust/src/simplify.rs"

    %% Styling
    classDef controller fill:#9cf,stroke:#333
    classDef arena fill:#f9f,stroke:#333
    classDef core fill:#fcf,stroke:#333
    classDef storage fill:#ff9,stroke:#333
    classDef stats fill:#f96,stroke:#333
    classDef dna fill:#9f9,stroke:#333
    classDef evo fill:#69f,stroke:#333
    classDef lang fill:#999,stroke:#333
    classDef opt fill:#f66,stroke:#333

    %% Legend
    subgraph Legend
        L1["Controller"]:::controller
        L2["Arena Components"]:::arena
        L3["Core Components"]:::core
        L4["Storage"]:::storage
        L5["Statistics"]:::stats
        L6["DNA Processing"]:::dna
        L7["Evolution"]:::evo
        L8["Implementation"]:::lang
        L9["Optimization"]:::opt
    end
```
