# mzafarm/darwin architecture

> Architecture diagram of the GitHub repository mzafarm/darwin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mzafarm/darwin
- Repository: https://github.com/mzafarm/darwin

## Overview

##### Main components
- Core Simulation Engine – This includes files like agents.py, enums.py, config.py, and helper.py. These components define the critters, their sensor inputs, and available actions.
- Handlers – Under the “handlers” directory you have genetics.py, organisms.py, and ui.py. These handle various aspects of the simulation:
- genetics.py likely manages reproduction and traits evolution.
- organisms.py deals with interactions between critters.
- ui.py manages user interface events or real-time simulation updates.
- UI/Presentation Components – Found under “components” (home.py, laboratory.py) and augmented by assets (images and fonts). “home” might represent the primary dashboard, while “laboratory” could be a more detailed analytical or experimental component.
- Asset Management – The assets directory (broken down into fonts and images) supports the UI with graphical resources.
- Main Application Flow – main.py acts as the entry point and likely orchestrates the initialization and interconnection between the simulation engine, the handlers, and the UI components.

##### Relationships and interactions
- The Main Application (main.py) initiates the simulation, loads configuration from config.py, and instantiates critter agent objects (agents.py).
- The Simulation Engine uses helper routines and enums (from helper.py and enums.py) to manage internal state and properties.
- Handlers are triggered to process specific simulation “events:”
- The “genetics” handler processes reproduction and possibly mutation logic.
- The “organisms” handler governs interactions among critters (e.g., eating, defending, or changing direction).
- The “ui” handler communicates between the simulation logic and the presentation layer.
- The Component modules (home.py and laboratory.py) provide UI representations based upon data supplied by the simulation engine via the ui handler.
- Assets (fonts and images) are consumed by the UI to render critter profiles, simulation graphs, and other visual elements.

##### Architectural patterns and design choices
- The project follows a modular separation of concerns, splitting simulation logic (agents, handlers) from presentation/UI controls (components, assets).
- The presence of handlers suggests an event-driven approach to simulate critter interactions.
- The configuration file and helpers point to centralized settings/utilities shared across components.
- The file structure reinforces a separation between the simulation core and the UI elements (with clear directories and naming conventions).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Application
    MainApp("Main Application"):::mainapp

    %% Simulation Core Subgraph
    subgraph "Simulation Core"
        Agents("agents.py"):::core
        Enums("enums.py"):::core
        Config("config.py"):::core
        Helper("helper.py"):::core
    end

    %% Handlers Subgraph
    subgraph "Handlers"
        Genetics("Genetics Handler"):::handler
        Organisms("Organisms Handler"):::handler
        UIHandler("UI Handler"):::handler
    end

    %% UI Components Subgraph
    subgraph "UI Components"
        Home("Home Screen"):::ui
        Laboratory("Laboratory"):::ui
    end

    %% Asset Management Subgraph
    subgraph "Asset Management"
        Fonts("Fonts"):::assets
        Images("Images"):::assets
    end

    %% Connections
    MainApp -->|"init_simulation"| Agents
    Agents -->|"triggers_events"| Genetics
    Agents -->|"triggers_events"| Organisms
    Agents -->|"triggers_events"| UIHandler
    UIHandler -->|"updates_UI"| Home
    UIHandler -->|"updates_UI"| Laboratory
    UIHandler -->|"loads_fonts"| Fonts
    UIHandler -->|"loads_images"| Images

    %% Click Events
    click MainApp "https://github.com/mzafarm/darwin/blob/main/main.py"
    click Agents "https://github.com/mzafarm/darwin/blob/main/agents.py"
    click Enums "https://github.com/mzafarm/darwin/blob/main/enums.py"
    click Config "https://github.com/mzafarm/darwin/blob/main/config.py"
    click Helper "https://github.com/mzafarm/darwin/blob/main/helper.py"
    click Genetics "https://github.com/mzafarm/darwin/blob/main/handlers/genetics.py"
    click Organisms "https://github.com/mzafarm/darwin/blob/main/handlers/organisms.py"
    click UIHandler "https://github.com/mzafarm/darwin/blob/main/handlers/ui.py"
    click Home "https://github.com/mzafarm/darwin/blob/main/components/home.py"
    click Laboratory "https://github.com/mzafarm/darwin/blob/main/components/laboratory.py"
    click Fonts "https://github.com/mzafarm/darwin/tree/main/assets/fonts"
    click Images "https://github.com/mzafarm/darwin/tree/main/assets/images"

    %% Styles
    classDef mainapp fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef handler fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef ui fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef assets fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
