# milesgranger/cramjam architecture

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

- Interactive diagram: https://gitdiagram.com/milesgranger/cramjam
- Repository: https://github.com/milesgranger/cramjam

## Overview

##### Main Components

a) Core Components:
- Python Interface Layer
- Rust Implementation Layer
- Compression Algorithms
- Buffer Management System
- File I/O System

b) Key Relationships:
- Python → Rust bindings
- Algorithm implementations → Buffer management
- I/O system interactions

**Top Layer: Python Interface**

**Middle Layer: Rust Bindings & Buffer Management**

**Bottom Layer: Compression Algorithm Implementations**

##### Detailed Component Breakdown

a) Python Interface Layer (Top):
- Experimental modules in a separate section
- Buffer and File classes as shared utilities

b) Rust Implementation Layer (Middle):
- Binding layer that connects Python and Rust
- Buffer management system
- I/O handling components

c) Compression Algorithms Layer (Bottom):
- Algorithms into:
- Standard algorithms (snappy, brotli, bzip2, etc.)
- Experimental algorithms (blosc2, igzip, etc.)
- ISA-L backend implementations

##### Additional Details

- Version information
- Supported platforms
- External dependencies (none required)
- Test integration points

##### Implementation Notes

- Compression/decompression flows
- Where buffer management occurs
- Where Python/Rust transitions happen
- Memory management boundaries

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style Definitions
    classDef python fill:#3776AB,color:white
    classDef rust fill:#F74C00,color:white
    classDef algorithm fill:#2ECC71,color:white
    classDef experimental fill:#9B59B6,color:white
    classDef io fill:#F1C40F,color:black
    classDef buffer fill:#E67E22,color:white

    %% Legend
    subgraph Legend
        P[Python Component]:::python
        R[Rust Component]:::rust
        A[Algorithm]:::algorithm
        E[Experimental]:::experimental
        I[I/O & Buffer]:::io
    end

    %% Python Interface Layer
    subgraph Python_Interface
        PythonAPI[Python Public API]:::python
        Testing[Testing Suite]:::python
        Benchmarks[Benchmarking]:::python
    end
    click Testing "https://github.com/milesgranger/cramjam/blob/master/tests/test_integration.py"
    click Benchmarks "https://github.com/milesgranger/cramjam/blob/master/benchmarks/test_bench.py"

    %% Rust Implementation Layer
    subgraph Rust_Core
        RustBindings[Rust Bindings]:::rust
        BufferMgmt[Buffer Management]:::buffer
        IOSystem[I/O System]:::io
        ExceptionHandler[Exception Handler]:::rust
    end
    click RustBindings "https://github.com/milesgranger/cramjam/blob/master/src/lib.rs"
    click IOSystem "https://github.com/milesgranger/cramjam/blob/master/src/io.rs"
    click ExceptionHandler "https://github.com/milesgranger/cramjam/blob/master/src/exceptions.rs"

    %% Compression Algorithms Layer
    subgraph Standard_Algorithms
        Snappy[Snappy]:::algorithm
        Brotli[Brotli]:::algorithm
        Bzip2[Bzip2]:::algorithm
        Gzip[Gzip]:::algorithm
        LZ4[LZ4]:::algorithm
        Zstd[Zstd]:::algorithm
        XZ[XZ]:::algorithm
        Deflate[Deflate]:::algorithm
        Zlib[Zlib]:::algorithm
    end
    click Snappy "https://github.com/milesgranger/cramjam/blob/master/src/snappy.rs"
    click Brotli "https://github.com/milesgranger/cramjam/blob/master/src/brotli.rs"
    click Bzip2 "https://github.com/milesgranger/cramjam/blob/master/src/bzip2.rs"
    click Gzip "https://github.com/milesgranger/cramjam/blob/master/src/gzip.rs"
    click LZ4 "https://github.com/milesgranger/cramjam/blob/master/src/lz4.rs"
    click Zstd "https://github.com/milesgranger/cramjam/blob/master/src/zstd.rs"
    click XZ "https://github.com/milesgranger/cramjam/blob/master/src/xz.rs"
    click Deflate "https://github.com/milesgranger/cramjam/blob/master/src/deflate.rs"
    click Zlib "https://github.com/milesgranger/cramjam/blob/master/src/zlib.rs"

    subgraph Experimental
        Blosc2[Blosc2]:::experimental
        ISAL[ISA-L Backend]:::experimental
    end
    click Blosc2 "https://github.com/milesgranger/cramjam/blob/master/src/blosc2.rs"

    %% Relationships
    PythonAPI --> RustBindings
    RustBindings --> BufferMgmt
    RustBindings --> IOSystem
    RustBindings --> ExceptionHandler
    
    BufferMgmt --> Standard_Algorithms
    IOSystem --> Standard_Algorithms
    
    RustBindings --> Experimental
    
    Testing --> PythonAPI
    Benchmarks --> PythonAPI

    %% Build System
    Build[Build Configuration]:::rust
    click Build "https://github.com/milesgranger/cramjam/blob/master/build.rs"
    Build --> RustBindings
```
