# daniakhan337-star/zip-c-huffman architecture

> Architecture diagram of the GitHub repository daniakhan337-star/zip-c-huffman, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/daniakhan337-star/zip-c-huffman
- Repository: https://github.com/daniakhan337-star/zip-c-huffman

## Overview

Zip-C is a command-line Huffman file compressor and decompressor. Its main workflow reads an input file, counts byte frequencies, builds a Huffman tree and codes, then writes a .huff header and bit-packed payload; decompression rebuilds the tree from the header and decodes the payload. The CLI also offers round-trip verification and compression metrics. Source excerpts show the driver’s calls into the tree and bit-I/O layers; the shared header documents the format and interfaces. No README is present.

Main entry points: [`main.c`](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/main.c) (Compress/decompress), [`tree.c`](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/tree.c) (Huffman tree), [`heap.c`](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/heap.c) (Frequency counter), [`bitio.c`](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/bitio.c) (Bit writer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and drivers"]
  node_driver["Compress/decompress<br/>[main.c]"]
  node_verification["Round-trip verification<br/>[main.c]"]
  node_metrics["Compression metrics<br/>[main.c]"]
end

subgraph group_coding["Huffman coding"]
  node_frequency["Frequency counter<br/>[heap.c]"]
  node_heap["Min-heap<br/>[heap.c]"]
  node_tree["Huffman tree<br/>[tree.c]"]
  node_codes["Code generation<br/>[tree.c]"]
end

subgraph group_bitstream["Bitstream I/O"]
  node_bitwriter["Bit writer<br/>[bitio.c]"]
  node_bitreader["Bit reader<br/>[bitio.c]"]
end

node_user(("CLI user"))
node_input["Input file"]
node_archive[".huff archive"]
node_output["Decoded output"]

node_user -->|"runs command"| node_driver
node_driver -->|"reads"| node_input
node_driver -->|"counts bytes"| node_frequency
node_driver -->|"builds tree"| node_tree
node_tree -->|"uses"| node_heap
node_driver -->|"generates codes"| node_codes
node_driver -->|"writes payload"| node_bitwriter
node_driver -->|"writes archive"| node_archive
node_driver -->|"reads archive"| node_archive
node_driver -->|"rebuilds tree"| node_tree
node_driver -->|"reads payload"| node_bitreader
node_driver -->|"writes decoded bytes"| node_output
node_driver -->|"optionally verifies"| node_verification
node_verification -.-> node_metrics
node_driver -->|"prints metrics"| node_metrics

click node_driver "https://github.com/daniakhan337-star/zip-c-huffman/blob/main/main.c"
click node_verification "https://github.com/daniakhan337-star/zip-c-huffman/blob/main/main.c"
click node_metrics "https://github.com/daniakhan337-star/zip-c-huffman/blob/main/main.c"
click node_frequency "https://github.com/daniakhan337-star/zip-c-huffman/blob/main/heap.c"
click node_heap "https://github.com/daniakhan337-star/zip-c-huffman/blob/main/heap.c"
click node_tree "https://github.com/daniakhan337-star/zip-c-huffman/blob/main/tree.c"
click node_codes "https://github.com/daniakhan337-star/zip-c-huffman/blob/main/tree.c"
click node_bitwriter "https://github.com/daniakhan337-star/zip-c-huffman/blob/main/bitio.c"
click node_bitreader "https://github.com/daniakhan337-star/zip-c-huffman/blob/main/bitio.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_driver,node_verification,node_metrics,node_user toneBlue
class node_frequency,node_heap,node_tree,node_codes toneAmber
class node_bitwriter,node_bitreader toneMint
class node_input,node_archive,node_output toneIndigo
```

## Components

### CLI and drivers

- [Compress/decompress](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/main.c): `main.c`
- [Round-trip verification](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/main.c): `main.c`
- [Compression metrics](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/main.c): `main.c`

### Huffman coding

- [Frequency counter](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/heap.c): `heap.c`
- [Min-heap](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/heap.c): `heap.c`
- [Huffman tree](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/tree.c): `tree.c`
- [Code generation](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/tree.c): `tree.c`

### Bitstream I/O

- [Bit writer](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/bitio.c): `bitio.c`
- [Bit reader](https://github.com/daniakhan337-star/zip-c-huffman/blob/main/bitio.c): `bitio.c`

### Other components

- **CLI user**
- **Input file**
- **.huff archive**
- **Decoded output**

## Connections

- CLI user → Compress/decompress: runs command (evidence: `main.c`)
- Compress/decompress → Input file: reads (evidence: `main.c`)
- Compress/decompress → Frequency counter: counts bytes (evidence: `main.c`)
- Compress/decompress → Huffman tree: builds tree (evidence: `main.c`)
- Huffman tree → Min-heap: uses (evidence: `tree.c`)
- Compress/decompress → Code generation: generates codes (evidence: `main.c`)
- Compress/decompress → Bit writer: writes payload (evidence: `main.c`)
- Compress/decompress → .huff archive: writes archive (evidence: `main.c`)
- Compress/decompress → .huff archive: reads archive (evidence: `main.c`)
- Compress/decompress → Huffman tree: rebuilds tree (evidence: `main.c`)
- Compress/decompress → Bit reader: reads payload (evidence: `main.c`)
- Compress/decompress → Decoded output: writes decoded bytes (evidence: `main.c`)
- Compress/decompress → Round-trip verification: optionally verifies (evidence: `main.c`)
- Round-trip verification → Compression metrics (evidence: `main.c`)
- Compress/decompress → Compression metrics: prints metrics (evidence: `main.c`)
