# jadhaidar/ts-hashlife architecture

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

- Interactive diagram: https://gitdiagram.com/jadhaidar/ts-hashlife
- Repository: https://github.com/jadhaidar/ts-hashlife

## Overview

##### Project Type and Purpose
- This is a TypeScript library implementing the HashLife algorithm – an optimized algorithm for simulating Conway’s Game of Life.
- Its purpose is to provide a highly optimized simulation engine that leverages memoization and quadtree-based compression. It includes both core algorithm functions and utilities (such as drawing and pattern formatting) and supports both Node.js and browser environments.

##### Main Components (to be visually separated as modules)
a. Core Simulation Engine:
- Modules: hash-life.ts, life-universe.ts, macrocell.ts
- Function: Implements the HashLife algorithm. These files are likely responsible for the internal simulation logic, data structure (such as macros for cell groups), state representation, and memoization.
b. Utility and Support Components:
c. Main API / Entry Point:
- Module: index.ts (which aggregates and exports the functionalities from the other modules).
- Function: Acts as the primary interface for external consumers of the library.
d. Example Usage:
- Path: example/ folder (example/app.js, example/index.html)
- Function: Demonstrates how to integrate and use the library in practice (both in the browser and in Node.js environments).

##### Architectural Relationships and Interactions
- The main API (index.ts) should be at the center of your design, exposing the simulation capabilities.

##### Patterns and Design Principles
- Use of memoization and quadtree-based compression as key optimization methods within the HashLife algorithm.
- Architectural patterns such as:
- Modular layering (Core vs. Utilities)
- Event-driven interactions (as suggested by the event-bus module)

##### Detail and Clarity
- Don’t hesitate to separate the library into as many smaller components as possible. Every file in “src” represents a distinct role in the architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main API
    subgraph "Main API"
        API["Main API (index.ts)"]:::api
    end

    %% Core Simulation Engine
    subgraph "Core Simulation Engine"
        H["hash-life.ts"]:::core
        LU["life-universe.ts"]:::core
        MC["macrocell.ts"]:::core
    end

    %% Utility Components
    subgraph "Utility Components"
        DR["draw.ts"]:::util
        FR["formats.ts"]:::util
        EB["event-bus.ts"]:::util
    end

    %% Example Usage
    subgraph "Example Usage"
        EX["Example (example/)"]:::example
    end

    %% Relationships
    API -->|"calls"| H
    API -->|"calls"| LU
    API -->|"calls"| MC
    API -->|"uses"| DR
    API -->|"uses"| FR
    API -->|"uses"| EB
    EX -->|"consumes"| API

    %% Click Events
    click H "https://github.com/jadhaidar/ts-hashlife/blob/main/src/hash-life.ts"
    click LU "https://github.com/jadhaidar/ts-hashlife/blob/main/src/life-universe.ts"
    click MC "https://github.com/jadhaidar/ts-hashlife/blob/main/src/macrocell.ts"
    click DR "https://github.com/jadhaidar/ts-hashlife/blob/main/src/draw.ts"
    click FR "https://github.com/jadhaidar/ts-hashlife/blob/main/src/formats.ts"
    click EB "https://github.com/jadhaidar/ts-hashlife/blob/main/src/event-bus.ts"
    click API "https://github.com/jadhaidar/ts-hashlife/blob/main/src/index.ts"
    click EX "https://github.com/jadhaidar/ts-hashlife/tree/main/example/"

    %% Classes
    classDef core fill:#f9e79f,stroke:#000,stroke-width:2px;
    classDef util fill:#aed6f1,stroke:#000,stroke-width:2px;
    classDef api fill:#d5f5e3,stroke:#000,stroke-width:2px;
    classDef example fill:#fadbd8,stroke:#000,stroke-width:2px;
```
