# greentec/mazes-for-programmers-js architecture

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

- Interactive diagram: https://gitdiagram.com/greentec/mazes-for-programmers-js
- Repository: https://github.com/greentec/mazes-for-programmers-js

## Overview

##### Core Components Layer
- `Cell` (Base class) at the center
- `Grid` (Base class) connected to Cell
- `Distances` class for pathfinding calculations
These form the foundation of all maze operations.

##### Grid Variations Layer
Specialized grid types branching from the base Grid:
- `ColoredGrid`
- `WeightedGrid`
- `MaskedGrid`
- `PolarGrid`
- `HexGrid`
- `TriangleGrid`
- `WeaveGrid`
- `Grid3D`

##### Cell Variations Layer
Specialized cell types branching from the base Cell:
- `WeightedCell`
- `PolarCell`
- `HexCell`
- `TriangleCell`
- `WeaveCells`
- `Cell3D`

##### Algorithm Layer
Maze generation algorithms into categories:
a. Basic Algorithms:
- `BinaryTree`
- `SideWinder`
b. Random Walk Algorithms:
- `AldousBroder`
- `Wilsons`
- `HuntAndKill`
c. Advanced Algorithms:
- `RecursiveBacktracker`
- `Kruskals`
- `Prims`
- `Ellers`
- `RecursiveDivision`
- `GrowingTree`

##### Utility Components
- `Mask` class for cell filtering
- Demo implementations (HTML files)

- Blue: Core components
- Green: Grid variations
- Yellow: Cell variations
- Red: Algorithms
- Gray: Utilities

Key Design Principles to Highlight:
##### Inheritance Hierarchy: Show how specialized grids and cells inherit from base classes
2. Algorithm Independence: Illustrate how maze generation algorithms are separate from grid/cell implementations
##### Visualization Layer: Show how the HTML demos connect to the core components

Important Notes:
- Related algorithms together (e.g., random walk-based algorithms)
- How the visualization layer (HTML files) connects to the core components

Level of Detail:
- Keep implementation details (methods, properties) hidden
- Component relationships and data flow
- Pluggable nature of the algorithms
- Clear separation between core infrastructure and specific implementations

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Core Components
    subgraph Core
        Cell["Cell (Base)"]:::core
        Grid["Grid (Base)"]:::core
        Distances["Distances"]:::core
        
        Cell <--> Grid
        Grid --- Distances
    end

    %% Grid Variations
    subgraph GridVariations
        ColoredGrid["ColoredGrid"]:::grid
        WeightedGrid["WeightedGrid"]:::grid
        MaskedGrid["MaskedGrid"]:::grid
        PolarGrid["PolarGrid"]:::grid
        HexGrid["HexGrid"]:::grid
        TriangleGrid["TriangleGrid"]:::grid
        WeaveGrid["WeaveGrid"]:::grid
        Grid3D["Grid3D"]:::grid

        Grid --> ColoredGrid
        Grid --> WeightedGrid
        Grid --> MaskedGrid
        Grid --> PolarGrid
        Grid --> HexGrid
        Grid --> TriangleGrid
        Grid --> WeaveGrid
        Grid --> Grid3D
    end

    %% Cell Variations
    subgraph CellVariations
        WeightedCell["WeightedCell"]:::cell
        PolarCell["PolarCell"]:::cell
        HexCell["HexCell"]:::cell
        TriangleCell["TriangleCell"]:::cell
        WeaveCells["WeaveCells"]:::cell
        Cell3D["Cell3D"]:::cell

        Cell --> WeightedCell
        Cell --> PolarCell
        Cell --> HexCell
        Cell --> TriangleCell
        Cell --> WeaveCells
        Cell --> Cell3D
    end

    %% Algorithms
    subgraph BasicAlgorithms
        BinaryTree["BinaryTree"]:::algo
        SideWinder["SideWinder"]:::algo
    end

    subgraph RandomWalkAlgorithms
        AldousBroder["AldousBroder"]:::algo
        Wilsons["Wilsons"]:::algo
        HuntAndKill["HuntAndKill"]:::algo
    end

    subgraph AdvancedAlgorithms
        RecursiveBacktracker["RecursiveBacktracker"]:::algo
        Kruskals["Kruskals"]:::algo
        Prims["Prims"]:::algo
        Ellers["Ellers"]:::algo
        RecursiveDivision["RecursiveDivision"]:::algo
        GrowingTree["GrowingTree"]:::algo
    end

    %% Utilities
    Mask["Mask"]:::util
    MaskedGrid -.-> Mask

    %% Click Events
    click Cell "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch5/Cell.js"
    click Grid "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch5/Grid.js"
    click Distances "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch5/Distances.js"
    click ColoredGrid "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch9/ColoredGrid.js"
    click WeightedGrid "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch9/WeightedGrid.js"
    click MaskedGrid "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch6/MaskedGrid.js"
    click PolarGrid "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch7/PolarGrid.js"
    click HexGrid "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch8/HexGrid.js"
    click TriangleGrid "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch8/TriangleGrid.js"
    click WeaveGrid "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch10/WeaveGrid.js"
    click Grid3D "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch13/Grid3D.js"
    click WeightedCell "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch9/WeightedCell.js"
    click PolarCell "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch7/PolarCell.js"
    click HexCell "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch8/HexCell.js"
    click TriangleCell "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch8/TriangleCell.js"
    click WeaveCells "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch10/WeaveCells.js"
    click Cell3D "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch13/Cell3D.js"
    click BinaryTree "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch5/BinaryTree.js"
    click SideWinder "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch5/SideWinder.js"
    click AldousBroder "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch5/AldousBroder.js"
    click Wilsons "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch5/Wilsons.js"
    click HuntAndKill "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch5/HuntAndKill.js"
    click RecursiveBacktracker "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch13/RecursiveBacktracker.js"
    click Kruskals "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch10/Kruskals.js"
    click Prims "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch11/Prims.js"
    click Ellers "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch12/Ellers.js"
    click RecursiveDivision "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch12/RecursiveDivision.js"
    click GrowingTree "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch11/GrowingTree.js"
    click Mask "https://github.com/greentec/mazes-for-programmers-js/blob/master/Ch6/Mask.js"

    %% Styles
    classDef core fill:#a8d1f0,stroke:#333,stroke-width:2px
    classDef grid fill:#90EE90,stroke:#333
    classDef cell fill:#FFE5B4,stroke:#333
    classDef algo fill:#FFB6C1,stroke:#333
    classDef util fill:#D3D3D3,stroke:#333

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Grid Variations]:::grid
        L3[Cell Variations]:::cell
        L4[Algorithms]:::algo
        L5[Utilities]:::util
    end
```
