# liamtannerr/raytracer architecture

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

- Interactive diagram: https://gitdiagram.com/liamtannerr/raytracer
- Repository: https://github.com/liamtannerr/raytracer
- Video tour (about a minute): https://gitdiagram.com/liamtannerr/raytracer/video

## Overview

This is a C++ sphere ray tracer. The implemented workflow is a hardcoded scene built in `main`, rendered by the camera through recursive ray hits and material scattering, then emitted as PPM text. The README also documents JSON scene input, PPM conversion, and animation tooling, but the supplied tree/source does not expose their implementation; those are shown only as documented capabilities, not wired into the runtime flow.

Main entry points: [`inc/camera.h`](https://github.com/liamtannerr/raytracer/blob/main/inc/camera.h) (Camera Renderer), [`inc/scene_element_list.h`](https://github.com/liamtannerr/raytracer/blob/main/inc/scene_element_list.h) (Scene Collection), [`src/main.cc`](https://github.com/liamtannerr/raytracer/blob/main/src/main.cc) (Scene Setup), [`inc/sphere.h`](https://github.com/liamtannerr/raytracer/blob/main/inc/sphere.h) (Sphere Geometry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_scene["Scene Model"]
  node_main["Scene Setup<br/>[main.cc]"]
  node_world["Scene Collection"]
  node_sphere["Sphere Geometry<br/>[sphere.h]"]
  node_materials["Surface Materials<br/>[material.h]"]
  node_json["JSON Scene Input"]
end

subgraph group_render["Render Engine"]
  node_camera["Camera Renderer<br/>[camera.h]"]
end

subgraph group_core["Ray Primitives"]
  node_scene_element["Hit Interface<br/>[scene_element.h]"]
  node_ray["Ray<br/>[ray.h]"]
  node_vectors["Vector Math<br/>[vec3.h]"]
end

subgraph group_output["Image Output"]
  node_colour["Colour Encoding<br/>[colour.h]"]
  node_ppm["PPM Stream"]
  node_imagemagick["ImageMagick"]
  node_ffmpeg["ffmpeg"]
end

node_user(("Operator"))

node_user -->|"launches"| node_main
node_main -->|"populates"| node_world
node_main -->|"calls render"| node_camera
node_world -->|"tests hits"| node_sphere
node_sphere -->|"implements hit"| node_scene_element
node_camera -->|"queries hits"| node_world
node_camera -->|"creates rays"| node_ray
node_camera -->|"calls scatter"| node_materials
node_camera -->|"encodes pixels"| node_colour
node_camera -->|"writes PPM"| node_ppm
node_sphere -->|"records material"| node_materials
node_ray -->|"uses math"| node_vectors
node_json -.->|"defines scene"| node_world
node_ppm -.->|"converts image"| node_imagemagick
node_ppm -.->|"supplies frames"| node_ffmpeg

click node_main "https://github.com/liamtannerr/raytracer/blob/main/src/main.cc"
click node_world "https://github.com/liamtannerr/raytracer/blob/main/inc/scene_element_list.h"
click node_sphere "https://github.com/liamtannerr/raytracer/blob/main/inc/sphere.h"
click node_materials "https://github.com/liamtannerr/raytracer/blob/main/inc/material.h"
click node_camera "https://github.com/liamtannerr/raytracer/blob/main/inc/camera.h"
click node_scene_element "https://github.com/liamtannerr/raytracer/blob/main/inc/scene_element.h"
click node_ray "https://github.com/liamtannerr/raytracer/blob/main/inc/ray.h"
click node_vectors "https://github.com/liamtannerr/raytracer/blob/main/inc/vec3.h"
click node_colour "https://github.com/liamtannerr/raytracer/blob/main/inc/colour.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_world,node_sphere,node_materials,node_json toneBlue
class node_camera toneAmber
class node_scene_element,node_ray,node_vectors toneMint
class node_colour,node_ppm,node_imagemagick,node_ffmpeg toneRose
class node_user toneIndigo
```

## Components

### Scene Model

- [Scene Setup](https://github.com/liamtannerr/raytracer/blob/main/src/main.cc): `src/main.cc`
- [Scene Collection](https://github.com/liamtannerr/raytracer/blob/main/inc/scene_element_list.h): `inc/scene_element_list.h`
- [Sphere Geometry](https://github.com/liamtannerr/raytracer/blob/main/inc/sphere.h): `inc/sphere.h`
- [Surface Materials](https://github.com/liamtannerr/raytracer/blob/main/inc/material.h): `inc/material.h`
- **JSON Scene Input**

### Render Engine

- [Camera Renderer](https://github.com/liamtannerr/raytracer/blob/main/inc/camera.h): `inc/camera.h`

### Ray Primitives

- [Hit Interface](https://github.com/liamtannerr/raytracer/blob/main/inc/scene_element.h): `inc/scene_element.h`
- [Ray](https://github.com/liamtannerr/raytracer/blob/main/inc/ray.h): `inc/ray.h`
- [Vector Math](https://github.com/liamtannerr/raytracer/blob/main/inc/vec3.h): `inc/vec3.h`

### Image Output

- [Colour Encoding](https://github.com/liamtannerr/raytracer/blob/main/inc/colour.h): `inc/colour.h`
- **PPM Stream**
- **ImageMagick**
- **ffmpeg**

### Other components

- **Operator**

## Connections

- Operator → Scene Setup: launches
- Scene Setup → Scene Collection: populates
- Scene Setup → Camera Renderer: calls render
- Scene Collection → Sphere Geometry: tests hits
- Sphere Geometry → Hit Interface: implements hit
- Camera Renderer → Scene Collection: queries hits
- Camera Renderer → Ray: creates rays
- Camera Renderer → Surface Materials: calls scatter
- Camera Renderer → Colour Encoding: encodes pixels
- Camera Renderer → PPM Stream: writes PPM
- Sphere Geometry → Surface Materials: records material
- Ray → Vector Math: uses math
- JSON Scene Input → Scene Collection: defines scene
- PPM Stream → ImageMagick: converts image
- PPM Stream → ffmpeg: supplies frames
