# czotti/niftimath-rs architecture

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

- Interactive diagram: https://gitdiagram.com/czotti/niftimath-rs
- Repository: https://github.com/czotti/niftimath-rs

## Overview

NiftiMath is a command-line tool for evaluating reverse-Polish formulas over scalar values and NIfTI images, then saving the resulting image. The user supplies operands, operations, and an output path; `main` configures threading, applies each formula token through a stack, and writes the final image using the selected datatype. The operator layer parses and evaluates arithmetic and voxel-wise unary operations, with cached image objects and parallel array processing. Edges reflect the shown call sites; NIfTI file nodes represent external inputs and outputs.

Main entry points: [`src/main.rs`](https://github.com/czotti/niftimath-rs/blob/master/src/main.rs) (Run formula), [`src/operator.rs`](https://github.com/czotti/niftimath-rs/blob/master/src/operator.rs) (Formula engine), [`src/utils.rs`](https://github.com/czotti/niftimath-rs/blob/master/src/utils.rs) (Image reader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Command line"]
  node_main["Run formula<br/>[main.rs]"]
  node_threads["Thread setup<br/>[utils.rs]"]
end

subgraph group_compute["Formula computation"]
  node_operator["Formula engine<br/>[operator.rs]"]
end

subgraph group_io["NIfTI I/O"]
  node_input["NIfTI input"]
  node_reader["Image reader<br/>[utils.rs]"]
  node_header["Header reader<br/>[utils.rs]"]
  node_output["NIfTI output"]
end

node_user(("CLI user"))

node_user -->|"provides formula"| node_main
node_main -->|"sets threads"| node_threads
node_main -->|"parses and applies"| node_operator
node_operator -->|"loads image"| node_reader
node_operator -.->|"reads image"| node_input
node_reader -.->|"reads file"| node_input
node_main -->|"reads header"| node_header
node_main -->|"writes result"| node_output

click node_main "https://github.com/czotti/niftimath-rs/blob/master/src/main.rs"
click node_threads "https://github.com/czotti/niftimath-rs/blob/master/src/utils.rs"
click node_operator "https://github.com/czotti/niftimath-rs/blob/master/src/operator.rs"
click node_reader "https://github.com/czotti/niftimath-rs/blob/master/src/utils.rs"
click node_header "https://github.com/czotti/niftimath-rs/blob/master/src/utils.rs"

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_threads,node_user toneBlue
class node_operator toneAmber
class node_input,node_reader,node_header,node_output toneMint
```

## Components

### Command line

- [Run formula](https://github.com/czotti/niftimath-rs/blob/master/src/main.rs): `src/main.rs`
- [Thread setup](https://github.com/czotti/niftimath-rs/blob/master/src/utils.rs): `src/utils.rs`

### Formula computation

- [Formula engine](https://github.com/czotti/niftimath-rs/blob/master/src/operator.rs): `src/operator.rs`

### NIfTI I/O

- **NIfTI input**
- [Image reader](https://github.com/czotti/niftimath-rs/blob/master/src/utils.rs): `src/utils.rs`
- [Header reader](https://github.com/czotti/niftimath-rs/blob/master/src/utils.rs): `src/utils.rs`
- **NIfTI output**

### Other components

- **CLI user**

## Connections

- CLI user → Run formula: provides formula (evidence: `README.md`)
- Run formula → Thread setup: sets threads (evidence: `src/main.rs`)
- Run formula → Formula engine: parses and applies (evidence: `src/main.rs`)
- Formula engine → Image reader: loads image (evidence: `src/operator.rs`)
- Formula engine → NIfTI input: reads image
- Image reader → NIfTI input: reads file
- Run formula → Header reader: reads header (evidence: `src/main.rs`)
- Run formula → NIfTI output: writes result (evidence: `src/main.rs`)
