# chksum-rs/lib architecture

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

- Interactive diagram: https://gitdiagram.com/chksum-rs/lib
- Repository: https://github.com/chksum-rs/lib

## Overview

##### Project Type Analysis
This is a Rust library crate that provides hash function implementations with both synchronous and asynchronous capabilities. The project is focused on providing a unified interface for different hash algorithms.

##### Main Components

a. Core Components:
- Hash Algorithm Implementations (MD5, SHA-1, SHA-2 family)
- Core Interface Layer
- I/O Processing Layer
- Async Runtime Support (Tokio)

b. Feature Modules:
- Reader Module
- Writer Module
- Algorithm-specific Modules

**┌─ Public API Layer ─────────────────────┐**
- chksum() / async_chksum()             │
- ┬─┘

**┌─ Hash Algorithm Layer ───────────────┴─┐**
- ┌─────┐ ┌─────┐ ┌──────────────────┐  │
- MD5 │ │SHA-1│ │    SHA-2 Family  │  │
- ┘ └─────┘ │ 224/256/384/512  │  │
- ┬┘  │
- ┬─┘

**┌─ I/O Processing Layer ──────────┴─────┐**
- ┌────────┐  ┌────────┐  ┌─────────┐  │
- Reader │  │ Writer │  │  Async  │  │
- ┘  └────────┘  │ Support │  │
- ┘   │
- ┘

##### Important Elements to Highlight

a. Feature Flags:
- md5
- sha1
- sha2 (and its sub-features)
- reader
- writer
- async-runtime-tokio

b. Data Flow:
- Input data flow from client code through the public API
- Processing through the selected hash algorithm
- Output digest generation

##### Implementation Details

Notes for:
- Error handling (reference error.rs)
- Supported input types (bytes, files, directories)
- Async/sync interface options

##### Integration Points
How the library integrates with:
- Tokio runtime (when async feature is enabled)
- File system operations
- Standard Rust I/O traits

##### The seamless integration of async support

Remember to include a note about the error handling strategy and how it propagates through the different layers of the architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Public API Layer"
        API["Public Interface<br/>chksum() / async_chksum()"]:::api
    end

    subgraph "Hash Algorithm Layer"
        MD5["MD5 Implementation"]:::hash
        SHA1["SHA-1 Implementation"]:::hash
        SHA2["SHA-2 Family<br/>(224/256/384/512)"]:::hash
    end

    subgraph "I/O Processing Layer"
        Reader["Reader Module"]:::io
        Writer["Writer Module"]:::io
        AsyncSupport["Async Runtime<br/>(Tokio)"]:::async
    end

    subgraph "Core Components"
        CoreInterface["Core Interface"]:::core
        ErrorHandler["Error Handling"]:::core
    end

    %% Relationships
    API --> CoreInterface
    CoreInterface --> MD5
    CoreInterface --> SHA1
    CoreInterface --> SHA2
    CoreInterface --> ErrorHandler
    
    MD5 --> Reader
    MD5 --> Writer
    SHA1 --> Reader
    SHA1 --> Writer
    SHA2 --> Reader
    SHA2 --> Writer
    
    Reader --> AsyncSupport
    Writer --> AsyncSupport

    %% Click Events
    click CoreInterface "https://github.com/chksum-rs/lib/blob/master/src/lib.rs"
    click ErrorHandler "https://github.com/chksum-rs/lib/blob/master/src/error.rs"
    click MD5 "https://github.com/chksum-rs/lib/blob/master/examples/md5.rs"
    click SHA1 "https://github.com/chksum-rs/lib/blob/master/examples/sha1.rs"
    click SHA2 "https://github.com/chksum-rs/lib/blob/master/examples/sha2-256.rs"
    click AsyncSupport "https://github.com/chksum-rs/lib/blob/master/examples/sha2-256-async-runtime-tokio.rs"

    %% Styling
    classDef api fill:#f9f,stroke:#333,stroke-width:2px
    classDef hash fill:#bbf,stroke:#333,stroke-width:1px
    classDef io fill:#bfb,stroke:#333,stroke-width:1px
    classDef async fill:#fb9,stroke:#333,stroke-width:1px
    classDef core fill:#ddd,stroke:#333,stroke-width:1px

    %% Legend
    subgraph Legend
        L1["API Component"]:::api
        L2["Hash Implementation"]:::hash
        L3["I/O Component"]:::io
        L4["Async Support"]:::async
        L5["Core Component"]:::core
    end
```
