# czotti/nifti-rs architecture

> Architecture diagram of the GitHub repository czotti/nifti-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/nifti-rs
- Repository: https://github.com/czotti/nifti-rs

## Overview

NIFTI-rs is a Rust library for reading NIfTI-1.1 files and exposing their headers, extensions, and voxel volumes. The principal workflow is a caller selecting a reader, which produces an object containing parsed metadata and either an in-memory or streamed volume; callers can then inspect voxels or optionally convert a volume to ndarray. The graph also retains affine transforms and writing as distinct capabilities. Relationships are based on README statements and the cited source references; some implementation details were not sampled.

Main entry points: [`src/object.rs`](https://github.com/czotti/nifti-rs/blob/master/src/object.rs) (NIfTI Object), [`src/volume/inmem.rs`](https://github.com/czotti/nifti-rs/blob/master/src/volume/inmem.rs) (In-Memory Volume), [`src/header.rs`](https://github.com/czotti/nifti-rs/blob/master/src/header.rs) (Header Parser), [`src/volume/mod.rs`](https://github.com/czotti/nifti-rs/blob/master/src/volume/mod.rs) (Volume API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_reading["File Reading"]
  node_object["NIfTI Object<br/>[object.rs]"]
  node_writer["Volume Writer<br/>[writer.rs]"]
end

subgraph group_metadata["Format Metadata"]
  node_header["Header Parser<br/>[header.rs]"]
  node_extensions["Extensions<br/>[extension.rs]"]
  node_affine["Affine Transforms<br/>[affine.rs]"]
end

subgraph group_volumes["Voxel Volumes"]
  node_volume_api["Volume API<br/>[mod.rs]"]
  node_inmem["In-Memory Volume<br/>[inmem.rs]"]
  node_streamed["Streamed Volume<br/>[streamed.rs]"]
  node_shape["Volume Shape<br/>[shape.rs]"]
  node_ndarray["ndarray Conversion<br/>[ndarray.rs]"]
end

subgraph group_support["Data Support"]
  node_typedef["NIfTI Types<br/>[typedef.rs]"]
  node_elements["Voxel Elements<br/>[element.rs]"]
  node_utilities["Format Utilities<br/>[util.rs]"]
  node_errors["Error Types<br/>[error.rs]"]
end

node_caller(("Library Caller"))

node_caller -->|"reads files"| node_object
node_object -->|"parses header"| node_header
node_object -->|"loads extensions"| node_extensions
node_object -->|"creates volume"| node_inmem
node_object -->|"creates volume"| node_streamed
node_object -->|"exposes volume"| node_volume_api
node_header -->|"uses transforms"| node_affine
node_header -->|"validates codes"| node_typedef
node_header -->|"validates fields"| node_utilities
node_inmem -->|"validates dimensions"| node_shape
node_inmem -->|"decodes voxels"| node_elements
node_inmem -->|"reads volume fields"| node_header
node_streamed -->|"indexes slices"| node_shape
node_streamed -->|"produces slices"| node_inmem
node_volume_api -->|"defines implementation"| node_inmem
node_volume_api -->|"defines implementation"| node_streamed
node_ndarray -->|"converts volumes"| node_volume_api
node_ndarray -->|"converts elements"| node_elements
node_typedef -->|"rescales values"| node_elements

click node_object "https://github.com/czotti/nifti-rs/blob/master/src/object.rs"
click node_header "https://github.com/czotti/nifti-rs/blob/master/src/header.rs"
click node_extensions "https://github.com/czotti/nifti-rs/blob/master/src/extension.rs"
click node_affine "https://github.com/czotti/nifti-rs/blob/master/src/affine.rs"
click node_volume_api "https://github.com/czotti/nifti-rs/blob/master/src/volume/mod.rs"
click node_inmem "https://github.com/czotti/nifti-rs/blob/master/src/volume/inmem.rs"
click node_streamed "https://github.com/czotti/nifti-rs/blob/master/src/volume/streamed.rs"
click node_shape "https://github.com/czotti/nifti-rs/blob/master/src/volume/shape.rs"
click node_ndarray "https://github.com/czotti/nifti-rs/blob/master/src/volume/ndarray.rs"
click node_writer "https://github.com/czotti/nifti-rs/blob/master/src/writer.rs"
click node_typedef "https://github.com/czotti/nifti-rs/blob/master/src/typedef.rs"
click node_elements "https://github.com/czotti/nifti-rs/blob/master/src/volume/element.rs"
click node_utilities "https://github.com/czotti/nifti-rs/blob/master/src/util.rs"
click node_errors "https://github.com/czotti/nifti-rs/blob/master/src/error.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_object,node_writer toneBlue
class node_header,node_extensions,node_affine toneAmber
class node_volume_api,node_inmem,node_streamed,node_shape,node_ndarray toneMint
class node_typedef,node_elements,node_utilities,node_errors toneRose
class node_caller toneIndigo
```

## Components

### File Reading

- [NIfTI Object](https://github.com/czotti/nifti-rs/blob/master/src/object.rs): `src/object.rs`
- [Volume Writer](https://github.com/czotti/nifti-rs/blob/master/src/writer.rs): `src/writer.rs`

### Format Metadata

- [Header Parser](https://github.com/czotti/nifti-rs/blob/master/src/header.rs): `src/header.rs`
- [Extensions](https://github.com/czotti/nifti-rs/blob/master/src/extension.rs): `src/extension.rs`
- [Affine Transforms](https://github.com/czotti/nifti-rs/blob/master/src/affine.rs): `src/affine.rs`

### Voxel Volumes

- [Volume API](https://github.com/czotti/nifti-rs/blob/master/src/volume/mod.rs): `src/volume/mod.rs`
- [In-Memory Volume](https://github.com/czotti/nifti-rs/blob/master/src/volume/inmem.rs): `src/volume/inmem.rs`
- [Streamed Volume](https://github.com/czotti/nifti-rs/blob/master/src/volume/streamed.rs): `src/volume/streamed.rs`
- [Volume Shape](https://github.com/czotti/nifti-rs/blob/master/src/volume/shape.rs): `src/volume/shape.rs`
- [ndarray Conversion](https://github.com/czotti/nifti-rs/blob/master/src/volume/ndarray.rs): `src/volume/ndarray.rs`

### Data Support

- [NIfTI Types](https://github.com/czotti/nifti-rs/blob/master/src/typedef.rs): `src/typedef.rs`
- [Voxel Elements](https://github.com/czotti/nifti-rs/blob/master/src/volume/element.rs): `src/volume/element.rs`
- [Format Utilities](https://github.com/czotti/nifti-rs/blob/master/src/util.rs): `src/util.rs`
- [Error Types](https://github.com/czotti/nifti-rs/blob/master/src/error.rs): `src/error.rs`

### Other components

- **Library Caller**

## Connections

- Library Caller → NIfTI Object: reads files (evidence: `README.md`)
- NIfTI Object → Header Parser: parses header (evidence: `src/object.rs`)
- NIfTI Object → Extensions: loads extensions (evidence: `src/object.rs`)
- NIfTI Object → In-Memory Volume: creates volume (evidence: `src/object.rs`)
- NIfTI Object → Streamed Volume: creates volume (evidence: `src/object.rs`)
- NIfTI Object → Volume API: exposes volume (evidence: `src/object.rs`)
- Header Parser → Affine Transforms: uses transforms (evidence: `src/header.rs`)
- Header Parser → NIfTI Types: validates codes (evidence: `src/header.rs`)
- Header Parser → Format Utilities: validates fields (evidence: `src/header.rs`)
- In-Memory Volume → Volume Shape: validates dimensions (evidence: `src/volume/inmem.rs`)
- In-Memory Volume → Voxel Elements: decodes voxels (evidence: `src/volume/inmem.rs`)
- In-Memory Volume → Header Parser: reads volume fields (evidence: `src/volume/inmem.rs`)
- Streamed Volume → Volume Shape: indexes slices (evidence: `src/volume/streamed.rs`)
- Streamed Volume → In-Memory Volume: produces slices (evidence: `src/volume/streamed.rs`)
- Volume API → In-Memory Volume: defines implementation (evidence: `src/volume/mod.rs`)
- Volume API → Streamed Volume: defines implementation (evidence: `src/volume/mod.rs`)
- ndarray Conversion → Volume API: converts volumes (evidence: `src/volume/ndarray.rs`)
- ndarray Conversion → Voxel Elements: converts elements (evidence: `src/volume/ndarray.rs`)
- NIfTI Types → Voxel Elements: rescales values (evidence: `src/typedef.rs`)
