# m-u-c-k-a/fractol architecture

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

- Interactive diagram: https://gitdiagram.com/m-u-c-k-a/fractol
- Repository: https://github.com/m-u-c-k-a/fractol

## Overview

##### Main Components
- User Events Handler – Modules that process user interactions such as on_destroy, on_mouse_hook, on_key_hook, and on_mousemove. This component captures inputs from the windowing system.
- Fractal Algorithms – The collection of fractal implementations (mandelbrot, julia, burning ship, tricorn, mandelbar/ “celtic_mandelbar”, mandelbox). These functions compute the fractal values based on the complex coordinate inputs.
- Engine (Core Logic) – The Fractol Engine that coordinates the overall logic including selecting and switching fractal types, resetting parameters, and initializing the system. Functions like change_fractal, set_fractal_type, reset_engine, and init_engine reside here.
- Utilities – A set of helper functions for error messages, string manipulations (e.g., ft_strlower), printing, and help displays.
- External Dependencies – External libraries such as libft (a custom C utilities library) and the MLX (MiniLibX) library used for window management and rendering.

##### Understand the Relationships and Data Flow
- Input Flow: User Events capture input from the graphical window (managed through MLX). These inputs are sent to the Engine.
- Engine Logic: The Engine interprets the event, decides when to change parameters, reset the state, or even swap fractals.
- Rendering Process: The Render module takes these computed values and uses MLX functions to plot them as pixels on the window.
- Utility Support: Throughout, utility functions provide logging, error handling, and other supportive tasks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Input Layer"
        A["User Events Handler"]:::frontend
    end

    subgraph "Core Logic"
        B["Engine (Core Logic)"]:::core
    end

    subgraph "Algorithm Layer"
        C["Fractal Algorithms"]:::algorithm
    end

    subgraph "Rendering Layer"
        D["Render Module"]:::render
    end

    subgraph "Support Layer"
        E["Utilities"]:::util
    end

    subgraph "External Dependencies"
        F["libft"]:::external
        G["MLX (MiniLibX)"]:::external
    end

    %% Connections
    A -->|"triggers"| B
    B -->|"selects_fractal"| C
    B -->|"controls_rendering"| D
    D -->|"feedback"| B
    E -->|"supports_engine"| B
    E -->|"supports_render"| D
    G -->|"provides_window_features"| A
    G -->|"provides_rendering"| D
    F -->|"provides_utilities"| E

    %% Click Events
    click A "https://github.com/m-u-c-k-a/fractol/blob/main/srcs/events.c"
    click C "https://github.com/m-u-c-k-a/fractol/tree/main/srcs/fractals"
    click B "https://github.com/m-u-c-k-a/fractol/blob/main/srcs/make_engine.c"
    click B "https://github.com/m-u-c-k-a/fractol/blob/main/fractol.h"
    click D "https://github.com/m-u-c-k-a/fractol/blob/main/srcs/render.c"
    click E "https://github.com/m-u-c-k-a/fractol/blob/main/srcs/utils.c"
    click F "https://github.com/m-u-c-k-a/fractol/tree/main/libft/"
    click G "https://github.com/m-u-c-k-a/fractol/tree/main/mlx_linux/"

    %% Styles
    classDef frontend fill:#E8F4FA,stroke:#1A8CD8,stroke-width:2px,color:#000;
    classDef core fill:#FFF4E5,stroke:#F28B20,stroke-width:2px,color:#000;
    classDef algorithm fill:#E9F9E7,stroke:#2F8F2C,stroke-width:2px,color:#000;
    classDef render fill:#FCE7F1,stroke:#D6336C,stroke-width:2px,color:#000;
    classDef util fill:#F0ECE2,stroke:#B8860B,stroke-width:2px,color:#000;
    classDef external fill:#EBEDEF,stroke:#707070,stroke-width:2px,color:#000;
```
