# crrel/las-rs architecture

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

- Interactive diagram: https://gitdiagram.com/crrel/las-rs
- Repository: https://github.com/crrel/las-rs

## Overview

##### Project type and purpose
- This is a Rust library (crate) called “las-rs” for reading and writing ASPRS LAS/LAZ LiDAR files. It exposes a simple API (`Reader`, `Writer`, `Header`, `Point` etc.) so other Rust code can parse or emit LAS data.

##### File structure
- Top-level files:
- Cargo.toml, rustfmt.toml – crate configuration
- benches/, examples/, tests/ – performance benches, usage samples, and test suites (not part of the runtime architecture)
- src/ subdirectories (the core library):
- reader.rs, writer.rs – high-level I/O interfaces
- header/ – builder and data‐structure definitions for the LAS file header
- raw/ – low-level parsing/unparsing of binary streams (header, VLRs, points)
- compression/ – LASzip compression/decompression support
- point/ – high-level point data (classification, format variants, scan direction)
- vlr.rs – variable length record definitions
- utils.rs, transform.rs, vector.rs – supporting math and utilities
- error.rs – unified error definitions

##### README
- Confirms that the crate’s goal is native Rust support for LAS/LAZ formats.

##### Detailed architectural elements to capture
- The separation between high-level API (`Reader`, `Writer`) and low-level binary handling (raw folder).
- The VLR (variable length record) subsystem as part of header processing.
- The transformation utilities that may be applied to point coordinates.
- Error handling flow (modules signaling errors back to the API).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["External Client"]:::external

    %% I/O Layer
    subgraph "I/O Layer"
        Reader["Reader API"]:::io
        Writer["Writer API"]:::io
    end

    %% Core Format Engine
    subgraph "Core Format Engine"
        subgraph "Raw Parser/Serializer Module"
            Raw["Raw Parser/Serializer"]:::io
        end
        subgraph "Header Module"
            Header["Header Module"]:::data
            VLR["VLR Definitions"]:::data
        end
        subgraph "Point Module"
            Point["Point Module"]:::data
        end
        Compression["Compression Module"]:::compression
    end

    %% Utilities & Error
    subgraph "Utilities & Error"
        Utils["Utilities Module"]:::util
        Transform["Transform Utilities"]:::util
        Vector["Vector Utilities"]:::util
        Error["Error Module"]:::util
    end

    %% File System
    FileSys["File System / I/O"]:::io

    %% Data Flows - Read
    Client -->|"request read"| Reader
    Reader -->|"reads bytes"| FileSys
    FileSys -->|"bytes"| Reader
    Reader -->|"bytes"| Raw
    Raw -->|"parsed header"| Header
    Raw -->|"parsed vlr"| VLR
    Raw -->|"parsed points"| Point
    Raw -->|"if .laz"| Compression
    Compression -->|"decompressed bytes"| Raw
    Point -->|"Vec<Point>"| Client
    Header -->|"Header struct"| Client
    VLR -->|"VLRs"| Client

    %% Data Flows - Write
    Client -->|"request write"| Writer
    Writer -->|"Header struct"| Header
    Writer -->|"VLRs"| VLR
    Writer -->|"Vec<Point>"| Point
    Writer -->|"to raw"| Raw
    Raw -->|"bytes"| Compression
    Compression -->|"compressed bytes"| FileSys

    %% Utilities & Error Usage
    Reader --- Utils
    Writer --- Utils
    Raw --- Utils
    Header --- Utils
    Point --- Utils
    Compression --- Utils
    Reader --- Error
    Writer --- Error
    Raw --- Error
    Header --- Error
    Point --- Error
    Compression --- Error

    %% Click Events
    click Reader "https://github.com/crrel/las-rs/blob/master/src/reader.rs"
    click Writer "https://github.com/crrel/las-rs/blob/master/src/writer.rs"
    click Header "https://github.com/crrel/las-rs/tree/master/src/header/"
    click Raw "https://github.com/crrel/las-rs/tree/master/src/raw/"
    click Compression "https://github.com/crrel/las-rs/blob/master/src/compression/mod.rs"
    click Point "https://github.com/crrel/las-rs/tree/master/src/point/"
    click VLR "https://github.com/crrel/las-rs/blob/master/src/vlr.rs"
    click Utils "https://github.com/crrel/las-rs/blob/master/src/utils.rs"
    click Transform "https://github.com/crrel/las-rs/blob/master/src/transform.rs"
    click Vector "https://github.com/crrel/las-rs/blob/master/src/vector.rs"
    click Error "https://github.com/crrel/las-rs/blob/master/src/error.rs"

    %% Styles
    classDef data fill:#cfe2ff,stroke:#0366d6,stroke-width:1px
    classDef io fill:#d1e7dd,stroke:#0f5132,stroke-width:1px
    classDef compression fill:#fff3cd,stroke:#856404,stroke-width:1px
    classDef util fill:#e2e3e5,stroke:#6c757d,stroke-width:1px
    classDef external fill:#f0efff,stroke:#4b0082,stroke-width:1px
```
