# purgatoryforcookies/file-checker architecture

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

- Interactive diagram: https://gitdiagram.com/purgatoryforcookies/file-checker
- Repository: https://github.com/purgatoryforcookies/file-checker

## Overview

##### Project type and purpose
- This is a CLI file‐checking tool written in Rust.
- Purpose: given two directories (“source” and “destination”), compute a Blake3 hash of each file in both, then report which source files are missing or altered in the destination.

##### File structure
- Top‐level files:
- Cargo.toml / Cargo.lock: Rust project descriptor and dependency lockfile
- src/main.rs: the CLI entry point
- src/scan.rs: directory scanning logic
- src/file.rs: file abstraction and hashing logic
- src/core.rs: comparison logic (comparing hash sets)
- A fixtures folder under src/__fixtures__ used for testing.
- CI configurations in .github/workflows.
- README.md, CHANGELOG.md for docs.

##### README for additional insights
- Describes three main steps: scan source & hash, scan destination & hash, compare.
- Writes a result.txt in the current working directory.
- Uses clap (or similar) via Cargo run with --source and --destination flags.

a. Main components
- CLI Parser (main.rs)
- Directory Scanner (scan.rs)
- Hasher (file.rs, Blake3 crate)
- Comparator (core.rs)
- Result Writer (core.rs or main.rs)
- File System (OS interface)
- External library: blake3
b. Relationships and interactions
- CLI Parser → invokes Directory Scanner twice (source & destination)
- Directory Scanner → yields File records to Hasher
- Hasher → produces HashSet for each directory
- Comparator → takes two HashSets, computes missing items
- Result Writer → writes missing‐file list to result.txt in working directory
c. Architectural patterns / design principles
- Layered pipeline: Input → Processing → Output
- Single Responsibility: each module handles one concern
- Dependency injection via function parameters
d. Relevant technologies / libraries
- Rust std::fs for file I/O
- blake3 crate for hashing
- clap or structopt (inferred) for argument parsing
- cargo for build/testing

##### Elements
- Clear labels: “CLI Parser”, “Scanner Module”, “Hasher Module”, “Comparator”, “Result Writer”
- CLI Parser → Scanner
- Scanner → Hasher
- Hasher → Comparator
- Comparator → Result Writer
- Rectangles for internal modules
- Rounded rectangles for external crates (blake3)

##### Detailed breakdown of components
- CLI Parser (main.rs)
- Parses --source / --destination
- Orchestrates scan, hash, compare, write
- Scanner (scan.rs)
- Recursively walks a directory
- Emits file paths
- Hasher (file.rs)
- Reads file content
- Computes blake3 hash
- Returns (path, hash) pair
- Comparator (core.rs)
- Builds two hash maps/sets
- Determines hashes present in source but missing in destination
- Formats the list of missing files
- Result Writer (core.rs or main.rs)
- Opens/creates result.txt
- Writes each missing file record

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Core Pipeline
    CLI["CLI Parser"]:::internal
    subgraph "Source Processing"
        ScanSrcScan["Directory Scanner"]:::internal
        ScanSrcHash["Hasher Module"]:::internal
    end
    subgraph "Destination Processing"
        ScanDstScan["Directory Scanner"]:::internal
        ScanDstHash["Hasher Module"]:::internal
    end
    Compare["Compare Hash Sets"]:::internal
    Write["Write result.txt"]:::io

    %% External & I/O
    FS["File System"]:::io
    ExtHash["blake3 crate"]:::external

    %% Metadata
    ProjectDesc["Cargo.toml / Cargo.lock"]:::meta
    Docs["README.md / CHANGELOG.md"]:::meta
    CI[".github/workflows/"]:::meta
    Fixtures["src/__fixtures__/"]:::meta

    %% Connections
    CLI --> ScanSrcScan
    CLI --> ScanDstScan
    ScanSrcScan --> FS
    ScanDstScan --> FS
    ScanSrcScan --> ScanSrcHash
    ScanDstScan --> ScanDstHash
    ScanSrcHash --> ExtHash
    ScanDstHash --> ExtHash
    ScanSrcHash --> Compare
    ScanDstHash --> Compare
    Compare --> Write
    FS --> Write

    %% Click Events
    click CLI "https://github.com/purgatoryforcookies/file-checker/blob/master/src/main.rs"
    click ScanSrcScan "https://github.com/purgatoryforcookies/file-checker/blob/master/src/scan.rs"
    click ScanDstScan "https://github.com/purgatoryforcookies/file-checker/blob/master/src/scan.rs"
    click ScanSrcHash "https://github.com/purgatoryforcookies/file-checker/blob/master/src/file.rs"
    click ScanDstHash "https://github.com/purgatoryforcookies/file-checker/blob/master/src/file.rs"
    click Compare "https://github.com/purgatoryforcookies/file-checker/blob/master/src/core.rs"
    click Write "https://github.com/purgatoryforcookies/file-checker/blob/master/src/main.rs"
    click Fixtures "https://github.com/purgatoryforcookies/file-checker/tree/master/src/__fixtures__/"
    click ExtHash "https://github.com/purgatoryforcookies/file-checker/blob/master/Cargo.toml"
    click CI "https://github.com/purgatoryforcookies/file-checker/tree/master/.github/workflows/"
    click ProjectDesc "https://github.com/purgatoryforcookies/file-checker/blob/master/Cargo.toml"
    click Docs "https://github.com/purgatoryforcookies/file-checker/blob/master/README.md"

    %% Styles
    classDef internal fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1;
    classDef external fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20,stroke-dasharray: 5 5;
    classDef io fill:#E0E0E0,stroke:#424242,color:#424242;
    classDef meta fill:#FFECB3,stroke:#FF6F00,color:#FF6F00;
```
