# qwertop18/minirt architecture

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

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

## Overview

##### Project Type and Purpose
- MINIRT is a lightweight, command-line ray-tracing renderer written in C.
- It reads a scene description (​.rt files​), builds an in-memory scene graph (cameras, lights, materials, primitives), performs ray-object intersection and shading calculations, and displays the result via the MiniLibX graphics library or logs for debugging.

##### File Structure Analysis
- Top-level directories:
- console, debug – logging/formatting and debug helpers
- incs – all project headers (scene, parse, math, system)
- input – sample and invalid .rt scene files
- libft, list, vector – three custom support libraries
- minilibx – external graphics library
- srcs – core source code, subdivided into:
– interface (MiniLibX hooks, window/pixel management)
– parse (lexing/parsing .rt files into scene objects)
– system.c (initialization, cleanup), raytrace.c, calculate.c, main.c

##### README Insights
- Describes project modules and their roles
- Provides build and run targets (make run, log, val)

##### Diagramming the Architecture
a. Main Components
- External Input: .rt files
- Parser Module: srcs/parse + incs/parse.h
- Math Libraries: vector (C_VECTOR), list (LINKED-LIST), libft (C std-lib replacement)
- Core Engine:
– Intersection Subsystem (srcs/intersection)
– Raytracer (srcs/raytrace.c)
- Rendering Interface: MiniLibX wrapper (srcs/interface)
- Logging & Debug: console/* and debug/*
- System & Utilities: memory management, file I/O (srcs/system.c)

b. Relationships and Data Flow
1. User invokes CLI → system.c initializes subsystems
2. Parser reads .rt file → builds scene graph (using list and vector libs)
3. Main render loop (raytrace.c):
– For each pixel, generate primary ray
– Call intersection subsystem → find nearest hit
4. Interface layer pushes frame buffer to display (MiniLibX)
5. Logging layer can intercept any stage for formatted debug output

c. Architectural Patterns and Principles
– Pipeline pattern: input → parse → scene build → ray-trace → render
– Modular separation: parsing, object model, intersection, shading, rendering
– Reusable utility libraries (vector, list, libft)
– Single-responsibility modules for maintainability

d. Key Technologies and Frameworks
– C (ISO C, organized per-feature in srcs/)
– MiniLibX for window creation and pixel drawing
– Custom math and data-structure libraries
– POSIX file I/O for reading scene files

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Inputs
    EXTERNAL_RT[".rt Files"]:::external

    %% System Initialization
    System["System & Utilities"]:::util

    %% Pipeline
    subgraph "Pipeline"
        Parser["Parser Module"]:::ioModule
        subgraph "Scene Graph / Data Model"
            Camera["Camera"]:::datastore
            Light["Light"]:::datastore
            Material["Material"]:::datastore
            ObjectFactory["Object Factory"]:::datastore
            ColorData["Color Data"]:::datastore
        end
        Raytrace["Raytracer Core"]:::coreEngine
        Intersection["Intersection Subsystem"]:::coreEngine
        Shading["Shading & Color Calc"]:::coreEngine
        FrameBuffer(("Frame Buffer")):::datastore
        Interface["Rendering Interface"]:::ioModule
    end

    %% Utilities
    subgraph "Utilities"
        Vector["Vector Library"]:::util
        ListLib["List Library"]:::util
        Libft["Libft Utilities"]:::util
    end

    %% Logging & Debug
    Logging["Logging Module"]:::logging
    Debug["Debug Helpers"]:::logging

    %% Data Flow
    System -->Parser
    System -->Logging
    System -->Debug

    EXTERNAL_RT -->Parser
    Parser -->Camera
    Parser -->Light
    Parser -->Material
    Parser -->ObjectFactory
    Parser -->ColorData
    Camera -->Raytrace
    Light -->Raytrace
    Material -->Raytrace
    ObjectFactory -->Raytrace
    ColorData -->Raytrace
    Raytrace -->Intersection
    Intersection -->Shading
    Shading -->FrameBuffer
    FrameBuffer -->Interface

    %% Dependencies on Utilities
    Parser -->Vector
    Parser -->ListLib
    Parser -->Libft
    Camera -->Vector
    Light -->Vector
    Material -->Vector
    ObjectFactory -->Vector
    Raytrace -->Vector
    Intersection -->Vector
    Shading -->Vector
    Interface -->Vector
    FrameBuffer -->ListLib

    %% Logging & Debug hooks
    Parser -.->Logging
    Raytrace -.->Logging
    Intersection -.->Logging
    Shading -.->Logging
    Interface -.->Logging
    Parser -.->Debug
    Raytrace -.->Debug
    Intersection -.->Debug
    Shading -.->Debug

    %% Click Events
    click Parser "https://github.com/qwertop18/minirt/tree/main/srcs/parse/"
    click Camera "https://github.com/qwertop18/minirt/blob/main/srcs/object/camera.c"
    click Light "https://github.com/qwertop18/minirt/blob/main/srcs/object/light.c"
    click Material "https://github.com/qwertop18/minirt/blob/main/srcs/object/material.c"
    click ObjectFactory "https://github.com/qwertop18/minirt/blob/main/srcs/object/objects.c"
    click ColorData "https://github.com/qwertop18/minirt/blob/main/incs/color.h"
    click Vector "https://github.com/qwertop18/minirt/tree/main/vector/"
    click ListLib "https://github.com/qwertop18/minirt/tree/main/list/"
    click Libft "https://github.com/qwertop18/minirt/tree/main/libft/"
    click Intersection "https://github.com/qwertop18/minirt/tree/main/srcs/intersection/"
    click Raytrace "https://github.com/qwertop18/minirt/blob/main/srcs/raytrace.c"
    click Shading "https://github.com/qwertop18/minirt/blob/main/srcs/calculate.c"
    click Interface "https://github.com/qwertop18/minirt/tree/main/srcs/interface/"
    click System "https://github.com/qwertop18/minirt/blob/main/srcs/system.c"
    click Logging "https://github.com/qwertop18/minirt/tree/main/console/"
    click Debug "https://github.com/qwertop18/minirt/tree/main/debug/"

    %% Styles
    classDef coreEngine fill:#ADD8E6,stroke:#000,color:#000
    classDef ioModule fill:#90EE90,stroke:#000,color:#000
    classDef util fill:#FFA500,stroke:#000,color:#000
    classDef external fill:#D3D3D3,stroke:#000,color:#000
    classDef logging fill:#F08080,stroke:#000,color:#000
    classDef datastore fill:#E6E6FA,stroke:#000,color:#000
```
