# tjensen42/42-minirt architecture

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

- Interactive diagram: https://gitdiagram.com/tjensen42/42-minirt
- Repository: https://github.com/tjensen42/42-minirt

## Overview

##### Project type and purpose
- This is a C-based, command-line-launched, lightweight ray-tracer (“miniRT”) that parses a .rt scene file, constructs an in-memory scene graph, performs path-tracing, and displays the rendered image in a window via the MLX/GLFW graphics layer.
- It is a monolithic, full-stackish native application (not client/server), with clearly separated modules for parsing, math, tracing, printing/logging, and graphics.

##### File structure
- Top-level:
- lib/libft: utility library (strings, memory, e.g., ft_split, ft_atoi).
- lib/libmlx: the MLX/GLFW-based graphics engine (glad, shaders, window/input handling).
- scenes/: sample .rt input files (scene descriptions).
- src/: the heart of miniRT, subdivided into:
– parse/: .rt file parser (syntax rules).
– trace/: ray–object intersection, BSDF, light sampling.
– print/: debug/console output of parsed scene.
– graphic/: window creation, render loop, input handling.
– main.c: orchestrates init, parse, trace & graphics.
- Build scripts: Makefile at root invokes libft, libmlx, then compiles src/*.
- No external services; only OS windowing and file I/O.

##### README for additional insights
- Confirms dependency on GLFW (via libmlx).
- Usage: `./miniRT scenes/template.rt`.
- Describes supported scene elements (camera, lights, primitives).

##### Detailed capturing of essential elements
- Break out Parser into sub-components if desired (tokenizer, syntax validator).
- That Scene Data Model is shared read-only by trace and print modules.
- That math routines are stateless helpers.
- Resource directory (scenes/) as input to File I/O.

## Diagram (Mermaid)

```mermaid
graph TB

    subgraph "Layer 1: I/O & CLI"
        CLI["CLI & File I/O"]:::io
        Scenes["Scene Resources"]:::io
    end

    subgraph "Layer 2: Parsing & Scene Model"
        Parser["Parser Module"]:::core
        SceneModel["Scene Data Model"]:::core
    end

    subgraph "Layer 3: Core Compute"
        Math["Math Module"]:::core
        Trace["Trace Engine"]:::core
        Print["Print/Logger"]:::core
    end

    subgraph "Layer 4: Rendering"
        Graphics["Graphics Module (MLX/GLFW)"]:::render
        OS["OS / GPU (GLFW/OpenGL)"]:::platform
    end

    subgraph "Utilities"
        Libft["lib/libft"]:::util
        Libmlx["lib/libmlx"]:::util
    end

    Scenes -->|".rt files"| CLI
    CLI -->|".rt file"| Parser
    Parser -->|"SceneGraph"| SceneModel
    SceneModel -->|"read-only"| Trace
    Math -->|"Vec3 ops"| Trace
    Trace -->|"ImageBuffer"| Graphics
    Parser -->|"parsed data"| Print
    SceneModel -->|"debug data"| Print
    Libft --> Parser
    Libft --> Math
    Libft --> Trace
    Libft --> Print
    Libmlx --> Graphics
    Graphics -->|"draw calls"| OS

    click CLI "https://github.com/tjensen42/42-minirt/blob/main/src/main.c"
    click Parser "https://github.com/tjensen42/42-minirt/tree/main/src/parse/"
    click SceneModel "https://github.com/tjensen42/42-minirt/blob/main/src/mrt_scene.c"
    click Math "https://github.com/tjensen42/42-minirt/tree/main/src/math/"
    click Trace "https://github.com/tjensen42/42-minirt/tree/main/src/trace/"
    click Print "https://github.com/tjensen42/42-minirt/tree/main/src/print/"
    click Graphics "https://github.com/tjensen42/42-minirt/tree/main/src/graphic/"
    click Libft "https://github.com/tjensen42/42-minirt/tree/main/lib/libft/"
    click Libmlx "https://github.com/tjensen42/42-minirt/tree/main/lib/libmlx/"
    click Scenes "https://github.com/tjensen42/42-minirt/tree/main/scenes/"

    classDef io fill:#9f6,stroke:#333,stroke-width:1px
    classDef core fill:#ffeb3b,stroke:#333,stroke-width:1px
    classDef render fill:#2196f3,stroke:#333,stroke-width:1px
    classDef util fill:#9e9e9e,stroke:#333,stroke-width:1px
    classDef platform fill:#bdbdbd,stroke:#333,stroke-width:1px
```
