# sabona-69/so_long architecture

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

- Interactive diagram: https://gitdiagram.com/sabona-69/so_long
- Repository: https://github.com/sabona-69/so_long

## Overview

##### Project type and purpose
- This is a native 2D maze game written in C, built with MiniLibX.
- It parses a map file (`*.ber`), loads textures, runs an event‐driven game loop, and renders frames to the screen.
- There are two build targets: `so_long` (mandatory) and `so_long_bonus` (bonus with animations, enemies, multiple levels).

##### File structure
- Top‐level:
- Makefile, README.md
- `include/` – shared headers (`so_long.h`, `so_long_b.h`)
- `mandatory/` & `bonus/` – each contains subfolders:
– `parse/` – map‐loading modules
– `game/` – core gameplay logic
– `utils/` – helper functions (I/O, string ops, GNL)
– `handle_errors.*` – error reporting
– root files (`so_long.c`, `so_long_b.c`)
- Asset folders:
- `textures/` – XPM files grouped by theme (player, enemy, attack…)
- `maps/` – `.ber` maze definitions
- Build artifacts: `.o` files in each directory.

##### README for additional insights
- Mandatory features: player movement, item collection, exit check
- Bonus features: animations, enemies, multi‐level, improved graphics
- Build commands: `make` → `./so_long map.ber`, `make bonus` → `./so_long_bonus map.ber`

1. Build System (Makefile)
2. Parser Module
3. Game State Manager
4. Input Handler
5. Renderer (MiniLibX + Texture Loader)
6. Animation & Enemy Controller (bonus)
7. Asset Manager (maps + textures)
8. Error Handler
9. Utility Library (get_next_line, string utils)

- Build System → compiles → all modules → Game binary (`so_long`, `so_long_bonus`)
- Game binary startup:
1. Parser Module loads `map.ber` via Asset Manager → builds initial Game State
2. Game Loop:
– Input Handler (keyboard events) → Game State Manager
– Game State Manager uses Animation & Enemy Controller (bonus)
– Renderer fetches Textures from Asset Manager → draws frame via MiniLibX
3. Game State Manager checks win/lose → calls Error Handler or cleanup
- Utility Library & Error Handler are used by all modules

c. Architectural patterns & principles:
- Modular separation: parsing, game logic, rendering, assets, error handling
- Event‐driven loop pattern (input → update → render)
- Single codebase with feature flags (mandatory vs bonus)

d. Key technologies & libraries:
- C99 (Makefile)
- MiniLibX for window management & rendering
- XPM textures
- Custom GNL for file I/O

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build Layer
    subgraph "Build System"
        BuildSystem["Makefile"]:::crosscut
    end

    %% Game Binaries
    subgraph "Game Binaries"
        SoLong["so_long (mandatory)"]:::binary
        SoLongBonus["so_long_bonus (bonus)"]:::binary
    end

    BuildSystem -->|"compile"| SoLong
    BuildSystem -->|"compile with bonus flag"| SoLongBonus

    %% Asset Manager
    subgraph "Asset Manager" 
        direction TB
        AssetMaps["Maps (.ber)"]:::assets
        AssetTextures["Textures (.xpm)"]:::assets
    end

    %% Mandatory Modules
    subgraph "Mandatory Modules"
        direction TB
        ParserMand["Parser Module"]:::module
        InputMand["Input Handler"]:::module
        GameStateMand["Game State Manager"]:::module
        RendererMand["Renderer"]:::module
        ErrorMand["Error Handler"]:::crosscut
        UtilsMand["Utility Library"]:::crosscut
    end

    %% Bonus Modules
    subgraph "Bonus Modules"
        direction TB
        ParserBon["Parser Module (bonus)"]:::module
        InputBon["Input Handler (bonus)"]:::module
        GameStateBon["Game State Manager (bonus)"]:::module
        RendererBon["Renderer (bonus)"]:::module
        AnimEnemy["Animation & Enemy Controller"]:::module
        ErrorBon["Error Handler (bonus)"]:::crosscut
        UtilsBon["Utility Library (bonus)"]:::crosscut
    end

    %% Mandatory Flow
    SoLong --> ParserMand
    ParserMand -->|"loads map"| AssetMaps
    SoLong -->|"start loop"| InputMand
    InputMand --> GameStateMand
    GameStateMand --> AnimSkip1
    GameStateMand --> RendererMand
    RendererMand -->|"fetch textures"| AssetTextures
    GameStateMand -->|"check win/lose"| ErrorMand
    ParserMand --> UtilsMand
    InputMand --> UtilsMand
    GameStateMand --> UtilsMand
    RendererMand --> UtilsMand
    ErrorMand --> UtilsMand

    %% Bonus Flow
    SoLongBonus --> ParserBon
    ParserBon -->|"loads map"| AssetMaps
    SoLongBonus -->|"start loop"| InputBon
    InputBon --> GameStateBon
    GameStateBon --> AnimEnemy
    GameStateBon --> RendererBon
    RendererBon -->|"fetch textures"| AssetTextures
    GameStateBon -->|"check win/lose"| ErrorBon
    ParserBon --> UtilsBon
    InputBon --> UtilsBon
    GameStateBon --> UtilsBon
    RendererBon --> UtilsBon
    ErrorBon --> UtilsBon

    %% Legend
    subgraph "Legend"
        direction TB
        L1["Module"]:::module
        L2["Asset"]:::assets
        L3["Cross-cutting"]:::crosscut
        L4["Binary"]:::binary
    end

    %% Click Events
    click BuildSystem "https://github.com/sabona-69/so_long/tree/master/Makefile"
    click ParserMand "https://github.com/sabona-69/so_long/blob/master/mandatory/parse/map.c"
    click ParserMand "https://github.com/sabona-69/so_long/blob/master/mandatory/parse/map2.c"
    click ParserBon "https://github.com/sabona-69/so_long/blob/master/bonus/parse/map_b.c"
    click ParserBon "https://github.com/sabona-69/so_long/blob/master/bonus/parse/map2_b.c"
    click GameStateMand "https://github.com/sabona-69/so_long/blob/master/mandatory/game/game.c"
    click GameStateMand "https://github.com/sabona-69/so_long/blob/master/mandatory/game/game_utils.c"
    click GameStateBon "https://github.com/sabona-69/so_long/blob/master/bonus/game/game_b.c"
    click GameStateBon "https://github.com/sabona-69/so_long/blob/master/bonus/game/game_utils_b.c"
    click InputMand "https://github.com/sabona-69/so_long/blob/master/mandatory/game/game_utils.c"
    click InputBon "https://github.com/sabona-69/so_long/blob/master/bonus/game/game_utils_b2.c"
    click RendererMand "https://github.com/sabona-69/so_long/blob/master/mandatory/game/game.c"
    click RendererBon "https://github.com/sabona-69/so_long/blob/master/bonus/game/game_output.c"
    click AnimEnemy "https://github.com/sabona-69/so_long/blob/master/bonus/game/animation.c"
    click AnimEnemy "https://github.com/sabona-69/so_long/blob/master/bonus/game/enemy_patrol.c"
    click AssetMaps "https://github.com/sabona-69/so_long/tree/master/maps/"
    click AssetTextures "https://github.com/sabona-69/so_long/tree/master/textures/"
    click ErrorMand "https://github.com/sabona-69/so_long/blob/master/mandatory/handle_errors.c"
    click ErrorBon "https://github.com/sabona-69/so_long/blob/master/bonus/handle_errors_b.c"
    click UtilsMand "https://github.com/sabona-69/so_long/blob/master/mandatory/utils/get_next_line.c"
    click UtilsMand "https://github.com/sabona-69/so_long/blob/master/mandatory/utils/utils.c"
    click UtilsMand "https://github.com/sabona-69/so_long/blob/master/mandatory/utils/utils2.c"
    click UtilsMand "https://github.com/sabona-69/so_long/blob/master/mandatory/utils/utils3.c"
    click UtilsBon "https://github.com/sabona-69/so_long/blob/master/bonus/utils/get_next_line_b.c"
    click UtilsBon "https://github.com/sabona-69/so_long/blob/master/bonus/utils/utils_b.c"
    click UtilsBon "https://github.com/sabona-69/so_long/blob/master/bonus/utils/utils2_b.c"
    click UtilsBon "https://github.com/sabona-69/so_long/blob/master/bonus/utils/utils3_b.c"

    %% Styles
    classDef module fill:#cce5ff,stroke:#004085,color:#004085;
    classDef assets fill:#d4edda,stroke:#155724,color:#155724;
    classDef crosscut fill:#fff3cd,stroke:#856404,color:#856404;
    classDef binary fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
