# benmmari/genetic-algorithm-example architecture

> Architecture diagram of the GitHub repository benmmari/genetic-algorithm-example, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/benmmari/genetic-algorithm-example
- Repository: https://github.com/benmmari/genetic-algorithm-example

## Overview

##### Project type and purpose
- This is a Ruby‐based console application whose sole purpose is to demonstrate how a genetic algorithm evolves a population of candidate “solutions” (organisms) toward a target string. It is not a web or UI‐driven system but rather a self-contained simulation tool.

##### File structure
- Top‐level files:
- Gemfile/Gemfile.lock – Ruby dependencies
- README.md – project overview and instructions
- .github/workflows/ruby.yml – CI pipeline to run tests
- Directories:
- console/ – entry points and orchestration (main.rb, simulation.rb)
- models/ – core domain objects: Gene, Chromosome, Organism, Environment
- spec/ – RSpec tests mirroring model structure

##### README for additional insights
- Describes the genetic algorithm steps: initialization, fitness sorting, culling, mating (chromosome exchange), mutation, and termination when an organism matches the target.
- Specifies inputs: population capacity, initial size, solution string, generations to print.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% I/O Layer
    subgraph "I/O Layer"
        CLI["CLI Interface"]:::io
        Simulation["Simulation Manager"]:::core
        Output["Output Renderer"]:::io
    end

    %% Core Simulation Engine
    subgraph "Core Engine"
        ENV["Environment"]:::core
    end

    %% Domain Models
    subgraph "Domain Model Layer"
        Organism["Organism"]:::model
        Chromosome["Chromosome"]:::model
        Gene["Gene"]:::model
    end

    %% Infrastructure
    subgraph "Infrastructure"
        Tests["Test Suite"]:::infra
        CI["CI Pipeline"]:::infra
        Dependencies["Gemfile & Gemfile.lock"]:::infra
        README["Project Overview"]:::infra
    end

    %% Relationships
    CLI -->|"args"| Simulation
    Simulation -->|"initialize Environment"| ENV
    ENV -->|"creates"| Organism
    Organism -->|"composes"| Chromosome
    Chromosome -->|"composes"| Gene
    ENV -->|"next generation"| ENV
    ENV -->|"final lineage"| Simulation
    Simulation -->|"print results"| Output

    %% Click Events
    click CLI "https://github.com/benmmari/genetic-algorithm-example/blob/master/console/main.rb"
    click Simulation "https://github.com/benmmari/genetic-algorithm-example/blob/master/console/simulation.rb"
    click ENV "https://github.com/benmmari/genetic-algorithm-example/blob/master/models/environment.rb"
    click Organism "https://github.com/benmmari/genetic-algorithm-example/blob/master/models/organism.rb"
    click Chromosome "https://github.com/benmmari/genetic-algorithm-example/blob/master/models/chromosome.rb"
    click Gene "https://github.com/benmmari/genetic-algorithm-example/blob/master/models/gene.rb"
    click Tests "https://github.com/benmmari/genetic-algorithm-example/tree/master/spec/"
    click CI "https://github.com/benmmari/genetic-algorithm-example/blob/master/.github/workflows/ruby.yml"
    click Dependencies "https://github.com/benmmari/genetic-algorithm-example/tree/master/Gemfile"
    click Dependencies "https://github.com/benmmari/genetic-algorithm-example/blob/master/Gemfile.lock"
    click README "https://github.com/benmmari/genetic-algorithm-example/blob/master/README.md"

    %% Styles
    classDef io fill:#FFD580,stroke:#FFB347,stroke-width:2px
    classDef core fill:#A0D3E8,stroke:#73B1C6,stroke-width:2px
    classDef model fill:#B8EBA4,stroke:#8CCB76,stroke-width:2px
    classDef infra fill:#E4E4E4,stroke:#CCCCCC,stroke-width:1px,stroke-dasharray: 2 2
```
