# ijontan/minirt architecture

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

## Overview

##### Main Components
- Scene/File Input: The project loads scene descriptions from “.rt” files (the rt_files directory) and textures from rt_files/textures.
- Parser Module: Under src_shared/parse, the various files indicate the conversion and validation of scene description files (checking floats, triplets, object lists, materials, etc.).
- Core Raytracing Engine:
– The src_shared/ray and src_shared/ray_tracing directories house initiation of rays and related intersection/calculation logic.
- Rendering Engine:
– The src_shared/render directory contains the drawing routines, pixel filling, and menu overlays to output the final image.
– The image creation and texture loading functionalities live under src_shared/image.
- Camera & Scene Management:
– The src_shared/camera module initializes and manages the camera’s properties and view, while the hooks in src_shared/hooks (keyboard, mouse, and loop actions) support interactive events to change view orientation, trigger animations, etc.
- Utility Modules:

##### Relationships and Data Flow
- The system starts with input from scene description files. These are parsed (src_shared/parse) to create internal representations of objects, materials, lights, and camera settings.
- The camera is then initialized (src_shared/camera), and the parsed scene information is used to configure the rendering pipeline.
- Event handling (src_shared/hooks) plays a role in providing interactive adjustments (e.g., camera movements, object updates) by interfacing with user inputs via keyboard and mouse hooks.
- The project ultimately leverages minilibx (from includes/minilibx_opengl) which provides the windowing and drawing capabilities.

##### Architectural Patterns and Design Principles
- A clear separation between core functionalities (parsing, raytracing, rendering) is visible, with common/shared code placed in src_shared.
- Two parallel “main” entry points exist (src_mandatory/main.c and src_bonus/main.c), suggesting a modular approach where additional features may be activated in the bonus version.
- There’s an MVC-like separation: the “Model” (scene description and objects), the “Controller” (hooks and input processing), and the “View” (rendering and image generation through minilibx).

##### Additional Details
- If necessary, denote submodules (like those in src_shared/hooks split into key actions, loop actions, and mouse actions) with nested blocks to capture their specific responsibilities.
- Use the Makefile as a cue that the overall build system coordinates these components – although you may not detail the build process, it can be noted as responsible for integrating the modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Points
    subgraph "Entry Points"
        M1["Main (Mandatory)"]:::entry
        M2["Main (Bonus)"]:::entry
    end

    %% Input Layer
    subgraph "Input Layer"
        SF["Scene Files (.rt)"]:::input
        TX["Textures"]:::input
    end

    %% Parser Module
    SP["Scene Parser"]:::parser

    %% Core Raytracing Engine
    subgraph "Core Raytracing Engine"
        RI["Ray Initialization"]:::engine
        IS["Intersection & Shading"]:::engine
        subgraph "Shapes Handling"
            SH1["Shapes Primitives (Modules)"]:::engine
            SH2["Shapes Primitives (Shared)"]:::engine
        end
    end

    %% Camera & Scene Management
    subgraph "Camera & Scene Management"
        CI["Camera Initialization"]:::camera
        EH["Event Handling (Input Hooks)"]:::camera
    end

    %% Rendering Engine
    subgraph "Rendering Engine"
        DR["Drawing & Final Image Rendering"]:::render
        IM["Image Creation & Texture Loading"]:::render
        ML["minilibx Interface"]:::render
    end

    %% Utility Modules
    subgraph "Utility Modules"
        VO["Vector Operations"]:::utils
        CF["Color Functions"]:::utils
        GU["General Utilities"]:::utils
    end

    %% Relationships
    M1 --> SF
    M2 --> SF

    SF --> TX
    SF -->|loads and passes| SP
    TX -->|loads textures| SP

    SP -->|parsed scene data| RI
    SP -->|parsed scene data| CI

    RI --> IS
    IS --> SH1
    IS --> SH2

    RI -->|ray results| DR
    IS -->|intersection data| DR
    SH1 -->|shape info| DR
    SH2 -->|shape info| DR

    CI -->|camera view| DR
    EH -->|user input| CI

    %% Utility support (dotted lines)
    VO --- SP
    VO --- RI
    VO --- CI
    CF --- DR
    GU --- SP
    GU --- RI
    GU --- CI
    GU --- DR

    %% Click Events
    click SF "https://github.com/ijontan/minirt/tree/main/rt_files"
    click TX "https://github.com/ijontan/minirt/tree/main/rt_files/textures"
    click SP "https://github.com/ijontan/minirt/tree/main/src_shared/parse"
    click RI "https://github.com/ijontan/minirt/tree/main/src_shared/ray"
    click IS "https://github.com/ijontan/minirt/tree/main/src_shared/ray_tracing"
    click SH1 "https://github.com/ijontan/minirt/tree/main/includes/modules/shapes"
    click SH2 "https://github.com/ijontan/minirt/tree/main/src_shared/shapes"
    click DR "https://github.com/ijontan/minirt/tree/main/src_shared/render"
    click IM "https://github.com/ijontan/minirt/tree/main/src_shared/image"
    click CI "https://github.com/ijontan/minirt/tree/main/src_shared/camera"
    click EH "https://github.com/ijontan/minirt/tree/main/src_shared/hooks"
    click VO "https://github.com/ijontan/minirt/tree/main/src_shared/vector"
    click CF "https://github.com/ijontan/minirt/tree/main/src_shared/color"
    click GU "https://github.com/ijontan/minirt/tree/main/src_shared/utils"

    %% Styles
    classDef entry fill:#FFDAB9,stroke:#D2691E,stroke-width:2px;
    classDef input fill:#FFEC8B,stroke:#DAA520,stroke-width:2px;
    classDef parser fill:#ADD8E6,stroke:#1E90FF,stroke-width:2px;
    classDef engine fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef camera fill:#E6E6FA,stroke:#8A2BE2,stroke-width:2px;
    classDef render fill:#98FB98,stroke:#32CD32,stroke-width:2px;
    classDef utils fill:#E0EEEE,stroke:#20B2AA,stroke-width:2px;
```
