# monashdeepneuron/neural-cellular-automata architecture

> Architecture diagram of the GitHub repository monashdeepneuron/neural-cellular-automata, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/monashdeepneuron/neural-cellular-automata
- Repository: https://github.com/monashdeepneuron/neural-cellular-automata

## Overview

##### Main Components
- Training System (TorchModels)
– This includes submodules for Image Segmentation, MedNCA, PersistingGCA, RebuildingGCA, Texture generation, and Toolbox utilities.
– Emphasize that this part is built with PyTorch to experiment with, train, and produce neural network weights and biases.
- Web Simulation & Visualization Platform (web)
– Built as a Next.js/React application which utilizes WebGPU shaders (in web/shaders) to render various Cellular Automata simulations.
– The web directory includes modular simulators (e.g., continuous, conway, larger, lifelike, texture) and shared UI components.
- Cellular Automata Core Library (CAs)
– Contains several variations (e.g., Continuous, ConwaysLife, Larger, LifeLike) that define the simulation logic.
– Includes a Shared subdirectory with common managers (BufferManager, DeviceManager, EventManager, etc.) that are likely used to manage simulation state, WebGPU pipelines, and shaders.

##### And Represent Relationships and Interactions
- A directional flow from the Training System to the Web Simulation Platform:
– Indicate that trained model weights (and possibly biases) generated in TorchModels are converted into a format usable by the website (notably stored or referenced in web/public/weights).
- CAs directory with both the Training and Web components:
– In the simulation engine, the JavaScript implementations of CAs are used to run the interactive demos.
– In some experiments or training setups, similar CA algorithms might be used as baselines.
- If relevant, include external components such as:
– External dependencies (e.g., PyTorch, WebGPU, Next.js).

##### Architectural Patterns and Technologies
- Separation of concerns:
– Training Code: Focused on models and experiments implemented in Python and PyTorch.
– Web Frontend: Focused on real-time simulation and visualization using WebGPU and React-based components.
- Use of modular design:
– Both the simulation code and training experiments are partitioned into modules. In TorchModels, each experiment (Image Segmentation, MedNCA, etc.) is self-contained. In web, each simulator (continuous, conway, etc.) is managed within its own folder with client and page definitions.
- Version control and development process:
– Although not an architectural “component” of the running system, consider adding a small block representing Git branching strategy (Main, Dev, Feature Branches) to capture overall process management if desired.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    Ex1["PyTorch"]:::external
    Ex2["WebGPU"]:::external
    Ex3["Notion Workspace"]:::external

    %% Training System (TorchModels)
    subgraph "Training System (TorchModels)"
        TS1["Image Segmentation"]:::training
        TS2["MedNCA"]:::training
        TS3["PersistingGCA"]:::training
        TS4["RebuildingGCA"]:::training
        TS5["Texture Generation"]:::training
        TS6["Toolbox Utilities"]:::training
    end

    %% Cellular Automata Core Library (CAs)
    subgraph "Cellular Automata Core Library (CAs)"
        subgraph "CA Variations"
            CA1["Continuous"]:::shared
            CA2["ConwaysLife"]:::shared
            CA3["Larger"]:::shared
            CA4["LifeLike"]:::shared
        end
        subgraph "Shared Managers"
            SH1["BufferManager"]:::shared
            SH2["DeviceManager"]:::shared
            SH3["EventManager"]:::shared
            SH4["PipelineManager"]:::shared
            SH5["ShaderManager"]:::shared
        end
    end

    %% Web Simulation & Visualization Platform (Next.js/WebGPU)
    subgraph "Web Simulation Platform (Next.js/WebGPU)"
        WEB1["Next.js/React Application"]:::frontend
        subgraph "Simulator Modules"
            SM1["Continuous"]:::frontend
            SM2["Conway"]:::frontend
            SM3["Larger"]:::frontend
            SM4["LifeLike"]:::frontend
            SM5["Texture"]:::frontend
        end
        subgraph "WebGPU Shaders"
            WG1["Continuous Shaders"]:::frontend
            WG2["Discrete Shaders"]:::frontend
            WG3["NCA Shaders"]:::frontend
        end
        WEB2["Weights Repository"]:::frontend
    end

    %% External Dependencies Connections
    Ex1 -->|"provides"| TS1
    Ex2 -->|"supports"| WG1

    %% Data Flow Connections
    TS6 -->|"trained_weights"| WEB2
    CA1 -->|"baseline"| TS1
    CA2 -->|"simulation"| SM1
    WEB1 -->|"renders_using"| WG1

    %% Class Definitions
    classDef training fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef frontend fill:#C1F0C9,stroke:#333,stroke-width:2px;
    classDef shared fill:#FFFACD,stroke:#333,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px;

    %% Click Events for Training System
    click TS1 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/TorchModels/ImageSegmentation"
    click TS2 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/TorchModels/MedNCA"
    click TS3 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/TorchModels/PersistingGCA"
    click TS4 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/TorchModels/RebuildingGCA"
    click TS5 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/TorchModels/Texture"
    click TS6 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/TorchModels/Toolbox"

    %% Click Events for Web Simulation Platform
    click WEB1 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/web"
    click SM1 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/web/app/simulator/continuous"
    click SM2 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/web/app/simulator/conway"
    click SM3 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/web/app/simulator/larger"
    click SM4 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/web/app/simulator/lifelike"
    click SM5 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/web/app/simulator/texture"
    click WG1 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/web/shaders/continuous"
    click WG2 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/web/shaders/discrete"
    click WG3 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/web/shaders/nca"
    click WEB2 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/web/public/weights"

    %% Click Events for Cellular Automata Core Library
    click CA1 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/CAs/Continuous"
    click CA2 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/CAs/ConwaysLife"
    click CA3 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/CAs/Larger"
    click CA4 "https://github.com/monashdeepneuron/neural-cellular-automata/tree/main/CAs/LifeLike"
    click SH1 "https://github.com/monashdeepneuron/neural-cellular-automata/blob/main/CAs/Shared/managers/BufferManager.js"
    click SH2 "https://github.com/monashdeepneuron/neural-cellular-automata/blob/main/CAs/Shared/managers/DeviceManager.js"
    click SH3 "https://github.com/monashdeepneuron/neural-cellular-automata/blob/main/CAs/Shared/managers/EventManager.js"
    click SH4 "https://github.com/monashdeepneuron/neural-cellular-automata/blob/main/CAs/Shared/managers/PipelineManager.js"
    click SH5 "https://github.com/monashdeepneuron/neural-cellular-automata/blob/main/CAs/Shared/managers/ShaderManager.js"
```
