# irakr/minimal-file-compression-tool architecture

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

- Interactive diagram: https://gitdiagram.com/irakr/minimal-file-compression-tool
- Repository: https://github.com/irakr/minimal-file-compression-tool

## Overview

##### Project Type and Purpose
- This is a command-line file compression tool specialized for ASCII text files.
- Its core functionality is driven by the Huffman Coding algorithm implemented in C++11.
- Although decompression is under development, the current focus is on compression.

##### File Structure
- Key Directories:
- Sample-inputs: Provides example files (both plain and pre-compressed) to help illustrate typical inputs and outputs.
- src: Contains the C++ source code. Notice how the hierarchy groups related files:
⁃ Main entry point (main.cpp).
⁃ Core modules: compression-driver.cpp/h (orchestrates compression), huffman-compressor.*, huffman-encoder.*, huffman-decoder.*, and auxiliary modules (logger, min-heap, BitVector, header files).
⁃ A separate directory for tests in src/tests helps in isolating unit and integration tests.
⁃ A utils folder (BitVector) supports core operations.
- There is also a Makefile at the top level for build management and a bin directory where the output “zz” binary is placed.

##### Specific Components
a. Application Entry Point:
- Main.cpp as the main driver that initializes the process.

b. Compression Controller:
- “compression-driver” (both .cpp and .h): Acts as the coordinator, managing which compression routines to invoke based on file type.

c. Core Compression Modules:
- “huffman-compressor”, “huffman-encoder”, and “huffman-decoder”: These files embody the core Huffman Coding algorithm. Even though decompression is still under development, indicate this component with a note.
- “compressor-base.h”: Likely serves as an abstract interface or base class for compression techniques.

d. Utility Components:
- “min-heap.cpp/h” is probably used to support the Huffman tree building process.
- “logger.cpp/h”: For logging compression process events, aiding in debugging and tracking.
- “BitVector” utilities and tests in both src/utils and src/tests serve as supporting libraries for bit-level operations.

e. Deprecated Components:
- “deprecated” directory: Shows previous approaches for bit manipulation. Mark these as legacy or experimental components.

##### Relationships and Data Flow
- From there, illustrate that the driver interacts with the Huffman algorithm components (encoder and compressor) to perform compression.
- A side branch for logging (logger module) to indicate cross-cutting concerns across these modules.
- For testing, add a separate block that indicates how unit tests (under src/tests) interact with their respective modules to validate functionality.

##### Architectural Patterns and Design Principles
- Apply a layered or modular approach by clearly delineating the control (driver), core processing (Huffman modules), utilities (min-heap, BitVector), and supporting components (logger, tests).
- Separation of concerns: keep the compression logic distinct from I/O and logging.
- That the design might follow a “strategy” pattern where different compression methods could theoretically be integrated (hinted by the existence of compressor-base.h).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("Command-line Invocation"):::entry
    B("Executable \"zz\""):::entry
    C("main.cpp (Entry)"):::module
    D("Compression Controller"):::module

    subgraph "Core Compression Modules"
        E("Huffman Compressor"):::core
        F("Huffman Encoder"):::core
        G("Huffman Decoder (UnderDevelop)"):::core
        H("Compressor Base Interface"):::core
    end

    subgraph "Utility Components"
        I("Min-Heap Module"):::utility
        J("BitVector Utils"):::utility
        K("Logger Module"):::utility
    end

    O("Deprecated Components"):::legacy

    L("Testing Suite (src/tests)"):::test
    M("Documentation"):::doc
    N("Build Artifacts (Makefile)"):::build

    %% Main Flow
    A --> B
    B --> C
    C --> D

    %% Branch from Compression Controller to Core Compression Modules
    D --> E
    D --> F
    D --> G
    D --> H

    %% Branch from Compression Controller to Utility Components
    D --> I
    D --> J
    D --> K

    %% Branch from Compression Controller to Deprecated Components
    D --> O

    %% Convergence of module results into Testing
    E --> L
    F --> L
    G --> L
    H --> L
    I --> L
    J --> L
    K --> L
    O --> L

    %% Follow-up flow
    L --> M
    M --> N

    %% Click Events
    click B "https://github.com/irakr/minimal-file-compression-tool/tree/master/bin/zz"
    click C "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/main.cpp"
    click D "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/compression-driver.cpp"
    click D "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/compression-driver.h"
    click E "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/huffman-compressor.cpp"
    click E "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/huffman-compressor.h"
    click F "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/huffman-encoder.cpp"
    click F "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/huffman-encoder.h"
    click G "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/huffman-decoder.cpp"
    click G "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/huffman-decoder.h"
    click H "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/compressor-base.h"
    click I "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/min-heap.cpp"
    click I "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/min-heap.h"
    click J "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/utils/BitVector.cpp"
    click J "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/utils/BitVector.h"
    click K "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/logger.cpp"
    click K "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/logger.h"
    click O "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/deprecated/bit-manip.cpp"
    click O "https://github.com/irakr/minimal-file-compression-tool/blob/master/src/deprecated/bit-manip.h"
    click O "https://github.com/irakr/minimal-file-compression-tool/tree/master/src/deprecated"
    click L "https://github.com/irakr/minimal-file-compression-tool/tree/master/src/tests"
    click M "https://github.com/irakr/minimal-file-compression-tool/blob/master/Docs/Class-Diagram.mdj"
    click M "https://github.com/irakr/minimal-file-compression-tool/blob/master/Docs/Huffman-Compressor-algorithm.mdj"
    click N "https://github.com/irakr/minimal-file-compression-tool/tree/master/Makefile"

    %% Styles
    classDef entry fill:#f9c,stroke:#333,stroke-width:2px;
    classDef module fill:#ccf,stroke:#333,stroke-width:2px;
    classDef core fill:#cfc,stroke:#333,stroke-width:2px;
    classDef utility fill:#fcf,stroke:#333,stroke-width:2px;
    classDef legacy fill:#ccc,stroke:#333,stroke-width:2px;
    classDef test fill:#cff,stroke:#333,stroke-width:2px;
    classDef doc fill:#ffc,stroke:#333,stroke-width:2px;
    classDef build fill:#fcc,stroke:#333,stroke-width:2px;
```
