# link-wolf/lem_in architecture

> Architecture diagram of the GitHub repository link-wolf/lem_in, 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/link-wolf/lem_in
- Repository: https://github.com/link-wolf/lem_in

## Overview

##### Main Components
- Input & File Reading: Represent the command-line interface and the modules that read the map input file or generator output. This component is responsible for fetching the map data.
- Parsing & Graph Creation: Illustrate the parser (in srcs/parsing) that processes the file, ignores comments, handles instructions (like “##start” and “##end”), and builds the internal graph data (rooms, links).
- Data Structures & Utilities: Show the underlying data representations (rooms, tubes/links, ants, etc.) based on headers in “includes” and functions from “libs/libft” for utility routines.
- Algorithm Processing Engine: This component (in srcs/processing and parts of srcs/map_manipulation) contains the core algorithm that computes the quickest path(s) for ants, including sorting paths and managing ant movement (throw_ants, resolve).
- Output Formatter: The areas in srcs/utils and the main files (lem_in.c) assemble the simulation steps and print formatted results (per turn) to the console.
- Bonus Visualizer: Separately, the srcs/visualiser module, which depends on MLX42 (from libs/MLX42), handles graphical output. It takes the same data from the simulation engine and visualizes the ant movements, complete with input hooks and debug options.

##### Relationships and Data Flow
- The Data Structures then feed into the Algorithm Processing Engine which computes optimal paths.
- The Processing Engine outputs simulation state changes per turn.
- Finally, mention the supplementary map generator (generator_linux) as an optional component that feeds into the Input Module.

##### Architectural Patterns and Design Principles
- Modular separation – each functionality (parsing, processing, visualization) is isolated in its own folder/module.
- Separation between core simulation logic (algorithm in processing) and various output layers (console vs. graphical).
- The use of libraries (libft for common C routines; MLX42 for graphics) shows a layered dependency structure.

##### Relevant Technologies & Frameworks
- Language: C.
- Graphical Library: MLX42 (responsible for rendering via OpenGL and interfacing with X11).
- Utility Library: libft (providing foundational functions used across the project).
- Build System: Makefile (and CMake for MLX42).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        A1["Map Input Handler"]:::module
        A2["Map Generator (optional)"]:::optional
    end

    %% Parsing and Graph Creation
    subgraph "Parsing and Graph Creation"
        B1["Parser & Graph Builder"]:::module
    end

    %% Data Structures & Utilities
    subgraph "Data Structures & Utilities"
        C1["Data Structures & Utils"]:::module
        C2["libft Utilities"]:::external
    end

    %% Algorithm Processing Engine
    subgraph "Algorithm Processing Engine"
        D1["Ant Routing Engine"]:::module
    end

    %% Output Layer
    subgraph "Output Layer"
        E1["Text Output Formatter"]:::module
        E2["Graphical Visualizer"]:::module
        E3["MLX42 Library"]:::external
    end

    %% Connections
    A2 -->|"feeds"| A1
    A1 -->|"parses"| B1
    B1 -->|"builds"| C1
    C1 -->|"supplies data"| D1
    D1 -->|"outputs text"| E1
    D1 -->|"outputs visual"| E2
    E2 -->|"renders with"| E3
    C2 ---|"provides utilities"| C1

    %% Click Events for Input & File Reading
    click A1 "https://github.com/link-wolf/lem_in/blob/main/srcs/lem_in.c"
    click A1 "https://github.com/link-wolf/lem_in/blob/main/srcs/parsing/read_input.c"
    click A2 "https://github.com/link-wolf/lem_in/tree/main/generator_linux"

    %% Click Events for Map Parsing & Graph Creation
    click B1 "https://github.com/link-wolf/lem_in/tree/main/srcs/parsing"
    click B1 "https://github.com/link-wolf/lem_in/tree/main/srcs/map_manipulation"
    click B1 "https://github.com/link-wolf/lem_in/blob/main/includes/parsing.h"
    click B1 "https://github.com/link-wolf/lem_in/blob/main/includes/map_manipulation.h"

    %% Click Events for Data Structures & Utilities
    click C1 "https://github.com/link-wolf/lem_in/blob/main/includes/structures.h"
    click C1 "https://github.com/link-wolf/lem_in/blob/main/includes/utils.h"
    click C1 "https://github.com/link-wolf/lem_in/tree/main/srcs/utils"
    click C2 "https://github.com/link-wolf/lem_in/tree/main/libs/libft"

    %% Click Events for Algorithm Processing Engine
    click D1 "https://github.com/link-wolf/lem_in/tree/main/srcs/processing"
    click D1 "https://github.com/link-wolf/lem_in/blob/main/srcs/processing/check_for_trivials.c"
    click D1 "https://github.com/link-wolf/lem_in/blob/main/srcs/processing/resolve.c"
    click D1 "https://github.com/link-wolf/lem_in/blob/main/srcs/processing/sort_pathes.c"
    click D1 "https://github.com/link-wolf/lem_in/blob/main/srcs/processing/throw_ants.c"

    %% Click Events for Output Formatter
    click E1 "https://github.com/link-wolf/lem_in/blob/main/srcs/utils/print_parsing.c"
    click E1 "https://github.com/link-wolf/lem_in/blob/main/srcs/lem_in.c"

    %% Click Events for Bonus Visualizer
    click E2 "https://github.com/link-wolf/lem_in/tree/main/srcs/visualiser"
    click E2 "https://github.com/link-wolf/lem_in/blob/main/srcs/visualiser/visualiser.c"
    click E2 "https://github.com/link-wolf/lem_in/blob/main/srcs/visualiser/draw.c"
    click E2 "https://github.com/link-wolf/lem_in/blob/main/srcs/visualiser/visualize.c"
    click E2 "https://github.com/link-wolf/lem_in/blob/main/srcs/visualiser/hook.c"
    click E2 "https://github.com/link-wolf/lem_in/blob/main/srcs/visualiser/evaluate_coords.c"
    click E3 "https://github.com/link-wolf/lem_in/tree/main/libs/MLX42"

    %% Styles
    classDef module fill:#AEDFF7,stroke:#1E90FF,stroke-width:2px;
    classDef optional fill:#F6E3CE,stroke:#ED8B00,stroke-width:2px;
    classDef external fill:#FDD,stroke:#F00,stroke-width:2px;
```
