# razimantv/mazegenerator architecture

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

- Interactive diagram: https://gitdiagram.com/razimantv/mazegenerator
- Repository: https://github.com/razimantv/mazegenerator

## Overview

This project is a maze generator utility written in C++ that supports several maze types (rectangular, hexagonal, honeycomb, circular, and user-defined) and multiple maze generation algorithms (Kruskal, depth-first search, breadth-first search, loop-erased random walk, and Prim’s algorithm). It also supports outputting the mazes in SVG or PNG (via gnuplot with pngcairo). The file structure and README make it clear that while the entire functionality is encapsulated in the "src" directory, the overall design is modular — separating maze definitions, maze algorithms, and rendering concerns.

##### Main Components & Their Roles
- Maze Generation Engine: This is the core module that orchestrates the maze generation. It reads command-line parameters (in main.cpp) and selects the maze type and algorithm.
- Algorithms Module: Located in src/algorithms, this contains different maze-generation algorithms (e.g., breadth-first search, depth-first search, kruskal, prim, and loop-erased random walk). Each algorithm implements the logic to compute a spanning tree or path through the maze.
- Maze Core & Rendering: The src/maze directory encapsulates maze core functions and possibly the handling of cell borders (cellborder.cpp/h) that are crucial for visual representation. Rendering is then handled by either outputting directly as SVG or by generating a gnuplot intermediary file (PNG via a .plt file). The dependency on gnuplot is noted in the README.
- Build & Configuration: The src/makefile and configuration files drive the compilation process, ensuring that all components of the maze generator are built properly.

##### Relationships & Interactions
- The main executable (src/main.cpp) is the entry point where user inputs (maze type, algorithm type, size, output type, and file prefix) are parsed.
- Based on inputs, the main module interacts with the Maze Types module to create an instance of the appropriate maze structure.
- The main module then invokes the Algorithms module where one of the algorithm functions runs to generate a maze layout (i.e., a spanning tree) on the maze instance.
- Once the maze is generated, the program passes the layout to a renderer module that either exports it directly as an SVG file or launches gnuplot to render a PNG (using an intermediate .plt file).

##### Key Architectural Patterns & Design Principles
- Modular Design: Separate directories for algorithms, maze types, and core maze functions encapsulate distinct responsibilities.
- Separation of Concerns: Input parsing, maze generation logic, maze representation, and output rendering are separated into different modules.
- Extensibility: The modular project structure allows for new algorithms or maze types to be added without significant modification to existing code.

##### Technologies & Frameworks
- C++11 for the application logic.
- gnuplot (with pngcairo support) for output rendering when PNG format is selected.
- Standard build tools (using make) are employed for compiling the project.

##### Elements
- Clear labels for each component (e.g., "Main (CLI Parser)", "Maze Types Module", "Algorithms Module", "Rendering Engine", "External: gnuplot").
- Core logic components (such as main, algorithms, and maze types)
- Data representation modules (maze, cell borders)
- External systems/dependencies (gnuplot)
- Build/configuration artifacts (makefile) if desired, though the focus should remain on runtime interactions.

- It starts at the CLI input (main executable).
- It then splits into the Maze Types and Algorithms modules.
- These modules intersect when the maze layout is produced.
- The layout is subsequently passed to the Rendering Engine, which either directly outputs an SVG or uses an intermediary (.plt) to generate a PNG via gnuplot.
- A note regarding dependency on system environment (gnuplot 5.0+).

## Diagram (Mermaid)

```mermaid
graph TD
    B["Build & Configuration"]:::build
    M["Main (CLI Parser)"]:::cli
    MT["Maze Types Module"]:::module
    AL["Algorithms Module"]:::module
    LG["Maze Layout Generation"]:::module
    MC["Maze Core & Rendering"]:::maze
    SVG["SVG Renderer"]:::maze
    PNG["PNG Renderer (.plt)"]:::maze
    GP["External: gnuplot"]:::external

    B --> M
    M --> MT
    MT --> AL
    AL --> LG
    LG --> MC
    MC --> SVG
    MC --> PNG
    PNG --> GP

    click B "https://github.com/razimantv/mazegenerator/tree/master/src/makefile"
    click M "https://github.com/razimantv/mazegenerator/blob/master/src/main.cpp"
    click MT "https://github.com/razimantv/mazegenerator/tree/master/src/mazetypes/"
    click AL "https://github.com/razimantv/mazegenerator/tree/master/src/algorithms/"
    click MC "https://github.com/razimantv/mazegenerator/tree/master/src/maze/"

    classDef cli fill:#8ED1FC,stroke:#1B75BC,stroke-width:2px;
    classDef module fill:#F8CECC,stroke:#B85450,stroke-width:2px;
    classDef maze fill:#FFF2CC,stroke:#D6B656,stroke-width:2px;
    classDef external fill:#D9EAD3,stroke:#6AA84F,stroke-width:2px;
    classDef build fill:#E1D5E7,stroke:#9673A6,stroke-width:2px;
```
