# 42paris/minilibx-linux architecture

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

- Interactive diagram: https://gitdiagram.com/42paris/minilibx-linux
- Repository: https://github.com/42paris/minilibx-linux

## Overview

##### Main Components
- API Layer: At the top, include the public header (mlx.h) that exposes the library’s API to client applications.
- Core Functionality Modules: Represent the various C source files (e.g., mlx_init.c, mlx_loop.c, mlx_new_window.c, mlx_pixel_put.c, mlx_hook.c, etc.) that make up the core functionalities for:
- Window creation and management (mlx_new_window, mlx_destroy_window, mlx_clear_window, etc.)
- Image management (mlx_new_image, mlx_put_image_to_window, mlx_destroy_image)
- Event handling and hooks (mlx_key_hook, mlx_mouse_hook, mlx_expose_hook, mlx_loop_hook, etc.)
- X11 integration (files like mlx_lib_xpm.c, mlx_ext_randr.c, and other utility modules that interact with X11 and its extensions like XShm)
- Internal Support Modules: Components such as mlx_int_* files and helper functions (mlx_int_get_visual, mlx_int_str_to_wordtab, etc.) that manage internal tasks and abstract X11 specifics.
- Build and Configuration Components: Although not part of the runtime architecture, include the configure script, Makefile, and Makefile.mk to indicate the build process and automated generation of Makefile.gen.
- Test/Demo Program: Represent the test directory and its included demo source files (main.c, new_win.c, etc.), which validate the library’s functions.

##### Component Relationships and Interactions
- Client Applications call the API defined in mlx.h which, in turn, maps to the core functions that manage windows, events, and drawing.
- Internal support modules serve as helpers for the core modules; show those as sub-components that the primary modules depend on.

##### Architectural Patterns and Design Principles
- Modular Design: The code is organized by functionality (e.g., handling events, window management, image operations), making it easy to see separation of concerns.
- Thin Abstraction Layer: The library wraps X11 system calls behind simpler functions for ease of use.
- Test Integration: The presence of a dedicated test suite emphasizes “build and verify” as a part of the development process.
- Configuration-based Build: The use of scripts (configure and Makefile) indicates that building is automated and configurable.

##### Technologies and Dependencies
- X11 (X-Window System): Clearly mark it as an external dependency.
- XShm extension: Required by MinilibX, should be connected to the components handling image data transfer.
- BSD Utility Libraries: Note these utilities where they interact with the system (if applicable).

##### Specific Elements
- Clear Labels: Each module (e.g., “Window Management”, “Image Handling”, “Event Loop”) must be explicitly labeled.
- Library modules (source code files grouped by functionality)
- External Dependencies (X11, XShm, BSD libraries)
- Build/Deployment Tools (configure scripts, Makefiles)
- Test/Demo Application (contents from test/ directory)

##### Final Assembly
- Branch out to show connections to core modules (splitting them further into window, image, and event categories).
- Conclude with a separate block for the test suite that uses the library, to ensure clarity on how the API is consumed and validated.
- A note on the build process with connections from build scripts to generated artifacts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Public API
    subgraph "Public API"
        API["mlx.h"]
    end

    %% Core Loop / Initialization
    subgraph "Core Loop / Initialization"
        CL1["mlx_init.c"]
        CL2["mlx_loop.c"]
    end

    %% Window Management
    subgraph "Window Management"
        WM1["mlx_new_window.c"]
        WM2["mlx_destroy_window.c"]
        WM3["mlx_clear_window.c"]
    end

    %% Image Management
    subgraph "Image Management"
        IM1["mlx_new_image.c"]
        IM2["mlx_put_image_to_window.c"]
        IM3["mlx_destroy_image.c"]
    end

    %% Event Handling & Hooks
    subgraph "Event Handling & Hooks"
        EH1["mlx_hook.c"]
        EH2["mlx_key_hook.c"]
        EH3["mlx_mouse_hook.c"]
        EH4["mlx_loop_hook.c"]
        EH5["mlx_expose_hook.c"]
        EH6["mlx_mouse.c"]
    end

    %% X11 Integration & Utilities
    subgraph "X11 Integration & Utilities"
        XI1["mlx_lib_xpm.c"]
        XI2["mlx_ext_randr.c"]
        XI3["mlx_xpm.c"]
        XI4["mlx_get_data_addr.c"]
        XI5["mlx_get_color_value.c"]
        XI6["mlx_rgb.c"]
        XI7["mlx_screen_size.c"]
        XI8["mlx_set_font.c"]
        XI9["mlx_string_put.c"]
        XI10["mlx_flush_event.c"]
    end

    %% Internal Support Modules
    subgraph "Internal Support Modules"
        IS1["mlx_int.h"]
        IS2["mlx_int_anti_resize_win.c"]
        IS3["mlx_int_do_nothing.c"]
        IS4["mlx_int_get_visual.c"]
        IS5["mlx_int_param_event.c"]
        IS6["mlx_int_set_win_event_mask.c"]
        IS7["mlx_int_str_to_wordtab.c"]
        IS8["mlx_int_wait_first_expose.c"]
    end

    %% Build & Configuration
    subgraph "Build & Configuration"
        BT1["configure"]
        BT2["Makefile"]
        BT3["Makefile.mk"]
        BT4["test/Makefile.mk"]
    end

    %% Test / Demo Program
    subgraph "Test/Demo Program"
        TP1["test/main.c"]
        TP2["test/new_win.c"]
        TP3["test/open.xpm"]
        TP4["test/open24.xpm"]
        TP5["test/open30.xpm"]
        TP6["test/run_tests.sh"]
    end

    %% Library Artifact and External Dependency
    LA["Library Artifact (libmlx.a)"]
    EX["External Dependency (X11, XShm, BSD Libraries)"]

    %% Connections from API to Core Modules
    API --> CL1
    API --> WM1
    API --> IM1
    API --> EH1
    API --> XI1
    API --> IS1

    %% Connections from Core Modules to Library Artifact
    CL1 --> LA
    WM1 --> LA
    IM1 --> LA
    EH1 --> LA
    XI1 --> LA
    IS1 --> LA

    %% Build Tools feed into Library Artifact
    BT1 --> LA

    %% Test Program uses the API
    TP1 --> API

    %% X11 Integration uses External Dependency
    XI1 -->|"uses"| EX

    %% Styles
    classDef api fill:#DDEEFF,stroke:#0000FF,stroke-width:2px;
    classDef core fill:#E0FFE0,stroke:#008000,stroke-width:2px;
    classDef build fill:#FFF5CC,stroke:#FF9900,stroke-width:2px;
    classDef test fill:#F3E5F5,stroke:#9C27B0,stroke-width:2px;
    classDef external fill:#FFE0E0,stroke:#FF0000,stroke-width:2px;

    class API api;
    class CL1,CL2,WM1,WM2,WM3,IM1,IM2,IM3,EH1,EH2,EH3,EH4,EH5,EH6,XI1,XI2,XI3,XI4,XI5,XI6,XI7,XI8,XI9,XI10,IS1,IS2,IS3,IS4,IS5,IS6,IS7,IS8 core;
    class BT1,BT2,BT3,BT4,LA build;
    class TP1,TP2,TP3,TP4,TP5,TP6 test;
    class EX external;

    %% Click Events
    click API "https://github.com/42paris/minilibx-linux/blob/master/mlx.h"
    click CL1 "https://github.com/42paris/minilibx-linux/blob/master/mlx_init.c"
    click CL2 "https://github.com/42paris/minilibx-linux/blob/master/mlx_loop.c"
    click WM1 "https://github.com/42paris/minilibx-linux/blob/master/mlx_new_window.c"
    click WM2 "https://github.com/42paris/minilibx-linux/blob/master/mlx_destroy_window.c"
    click WM3 "https://github.com/42paris/minilibx-linux/blob/master/mlx_clear_window.c"
    click IM1 "https://github.com/42paris/minilibx-linux/blob/master/mlx_new_image.c"
    click IM2 "https://github.com/42paris/minilibx-linux/blob/master/mlx_put_image_to_window.c"
    click IM3 "https://github.com/42paris/minilibx-linux/blob/master/mlx_destroy_image.c"
    click EH1 "https://github.com/42paris/minilibx-linux/blob/master/mlx_hook.c"
    click EH2 "https://github.com/42paris/minilibx-linux/blob/master/mlx_key_hook.c"
    click EH3 "https://github.com/42paris/minilibx-linux/blob/master/mlx_mouse_hook.c"
    click EH4 "https://github.com/42paris/minilibx-linux/blob/master/mlx_loop_hook.c"
    click EH5 "https://github.com/42paris/minilibx-linux/blob/master/mlx_expose_hook.c"
    click EH6 "https://github.com/42paris/minilibx-linux/blob/master/mlx_mouse.c"
    click XI1 "https://github.com/42paris/minilibx-linux/blob/master/mlx_lib_xpm.c"
    click XI2 "https://github.com/42paris/minilibx-linux/blob/master/mlx_ext_randr.c"
    click XI3 "https://github.com/42paris/minilibx-linux/blob/master/mlx_xpm.c"
    click XI4 "https://github.com/42paris/minilibx-linux/blob/master/mlx_get_data_addr.c"
    click XI5 "https://github.com/42paris/minilibx-linux/blob/master/mlx_get_color_value.c"
    click XI6 "https://github.com/42paris/minilibx-linux/blob/master/mlx_rgb.c"
    click XI7 "https://github.com/42paris/minilibx-linux/blob/master/mlx_screen_size.c"
    click XI8 "https://github.com/42paris/minilibx-linux/blob/master/mlx_set_font.c"
    click XI9 "https://github.com/42paris/minilibx-linux/blob/master/mlx_string_put.c"
    click XI10 "https://github.com/42paris/minilibx-linux/blob/master/mlx_flush_event.c"
    click IS1 "https://github.com/42paris/minilibx-linux/blob/master/mlx_int.h"
    click IS2 "https://github.com/42paris/minilibx-linux/blob/master/mlx_int_anti_resize_win.c"
    click IS3 "https://github.com/42paris/minilibx-linux/blob/master/mlx_int_do_nothing.c"
    click IS4 "https://github.com/42paris/minilibx-linux/blob/master/mlx_int_get_visual.c"
    click IS5 "https://github.com/42paris/minilibx-linux/blob/master/mlx_int_param_event.c"
    click IS6 "https://github.com/42paris/minilibx-linux/blob/master/mlx_int_set_win_event_mask.c"
    click IS7 "https://github.com/42paris/minilibx-linux/blob/master/mlx_int_str_to_wordtab.c"
    click IS8 "https://github.com/42paris/minilibx-linux/blob/master/mlx_int_wait_first_expose.c"
    click BT1 "https://github.com/42paris/minilibx-linux/tree/master/configure"
    click BT2 "https://github.com/42paris/minilibx-linux/tree/master/Makefile"
    click BT3 "https://github.com/42paris/minilibx-linux/blob/master/Makefile.mk"
    click BT4 "https://github.com/42paris/minilibx-linux/blob/master/test/Makefile.mk"
    click TP1 "https://github.com/42paris/minilibx-linux/blob/master/test/main.c"
    click TP2 "https://github.com/42paris/minilibx-linux/blob/master/test/new_win.c"
    click TP3 "https://github.com/42paris/minilibx-linux/blob/master/test/open.xpm"
    click TP4 "https://github.com/42paris/minilibx-linux/blob/master/test/open24.xpm"
    click TP5 "https://github.com/42paris/minilibx-linux/blob/master/test/open30.xpm"
    click TP6 "https://github.com/42paris/minilibx-linux/blob/master/test/run_tests.sh"
```
