# macdee661/huffman architecture

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

- Interactive diagram: https://gitdiagram.com/macdee661/huffman
- Repository: https://github.com/macdee661/huffman

## Overview

This is a small C command-line Huffman compressor and decompressor. The user selects a file operation at the CLI; compression counts byte frequencies, builds a Huffman tree and codes, writes a frequency-table header, then encodes bits. Decompression reads that header, rebuilds the tree, and decodes the declared number of bytes. The graph shows the priority queue and bit-I/O helpers as internal layers. Relationships are based on the README and sampled source; unsampled test and measurement code is excluded.

Main entry points: [`src/huffman.c`](https://github.com/macdee661/huffman/blob/main/src/huffman.c) (Compression), [`src/main.c`](https://github.com/macdee661/huffman/blob/main/src/main.c) (CLI dispatch), [`src/bitio.c`](https://github.com/macdee661/huffman/blob/main/src/bitio.c) (Bit I/O), [`src/priority_queue.c`](https://github.com/macdee661/huffman/blob/main/src/priority_queue.c) (Priority queue)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Command line"]
  node_cli["CLI dispatch<br/>[main.c]"]
end

subgraph group_codec["Huffman codec"]
  node_compress["Compression<br/>[huffman.c]"]
  node_decompress["Decompression<br/>[huffman.c]"]
  node_frequency["Frequency scan<br/>[huffman.c]"]
  node_tree["Tree and codes<br/>[huffman.c]"]
  node_priority["Priority queue<br/>[priority_queue.c]"]
  node_header["Archive header<br/>[huffman.c]"]
  node_encode["Bit encoding<br/>[huffman.c]"]
  node_decode["Bit decoding<br/>[huffman.c]"]
end

subgraph group_io["I/O helpers"]
  node_bitio["Bit I/O<br/>[bitio.c]"]
end

node_user(("User"))
node_files["Input/output files"]

node_user -->|"selects operation"| node_cli
node_cli -->|"dispatches compress"| node_compress
node_cli -->|"dispatches decompress"| node_decompress
node_compress -->|"reads input, writes archive"| node_files
node_compress -->|"counts bytes"| node_frequency
node_compress -->|"builds tree, codes"| node_tree
node_tree -->|"queues nodes"| node_priority
node_compress -->|"writes header"| node_header
node_compress -->|"encodes input"| node_encode
node_encode -->|"writes bits"| node_bitio
node_decompress -->|"reads archive, writes output"| node_files
node_decompress -->|"reads header"| node_header
node_decompress -->|"rebuilds tree"| node_tree
node_decompress -->|"decodes bytes"| node_decode
node_decode -->|"reads bits"| node_bitio

click node_cli "https://github.com/macdee661/huffman/blob/main/src/main.c"
click node_compress "https://github.com/macdee661/huffman/blob/main/src/huffman.c"
click node_decompress "https://github.com/macdee661/huffman/blob/main/src/huffman.c"
click node_frequency "https://github.com/macdee661/huffman/blob/main/src/huffman.c"
click node_tree "https://github.com/macdee661/huffman/blob/main/src/huffman.c"
click node_priority "https://github.com/macdee661/huffman/blob/main/src/priority_queue.c"
click node_header "https://github.com/macdee661/huffman/blob/main/src/huffman.c"
click node_encode "https://github.com/macdee661/huffman/blob/main/src/huffman.c"
click node_decode "https://github.com/macdee661/huffman/blob/main/src/huffman.c"
click node_bitio "https://github.com/macdee661/huffman/blob/main/src/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_cli,node_user toneBlue
class node_compress,node_decompress,node_frequency,node_tree,node_priority,node_header,node_encode,node_decode toneAmber
class node_bitio toneMint
class node_files toneIndigo
```

## Components

### Command line

- [CLI dispatch](https://github.com/macdee661/huffman/blob/main/src/main.c): `src/main.c`

### Huffman codec

- [Compression](https://github.com/macdee661/huffman/blob/main/src/huffman.c): `src/huffman.c`
- [Decompression](https://github.com/macdee661/huffman/blob/main/src/huffman.c): `src/huffman.c`
- [Frequency scan](https://github.com/macdee661/huffman/blob/main/src/huffman.c): `src/huffman.c`
- [Tree and codes](https://github.com/macdee661/huffman/blob/main/src/huffman.c): `src/huffman.c`
- [Priority queue](https://github.com/macdee661/huffman/blob/main/src/priority_queue.c): `src/priority_queue.c`
- [Archive header](https://github.com/macdee661/huffman/blob/main/src/huffman.c): `src/huffman.c`
- [Bit encoding](https://github.com/macdee661/huffman/blob/main/src/huffman.c): `src/huffman.c`
- [Bit decoding](https://github.com/macdee661/huffman/blob/main/src/huffman.c): `src/huffman.c`

### I/O helpers

- [Bit I/O](https://github.com/macdee661/huffman/blob/main/src/bitio.c): `src/bitio.c`

### Other components

- **User**
- **Input/output files**

## Connections

- User → CLI dispatch: selects operation (evidence: `src/main.c`)
- CLI dispatch → Compression: dispatches compress (evidence: `src/main.c`)
- CLI dispatch → Decompression: dispatches decompress (evidence: `src/main.c`)
- Compression → Input/output files: reads input, writes archive (evidence: `src/huffman.c`)
- Compression → Frequency scan: counts bytes (evidence: `src/huffman.c`)
- Compression → Tree and codes: builds tree, codes (evidence: `src/huffman.c`)
- Tree and codes → Priority queue: queues nodes (evidence: `src/huffman.c`)
- Compression → Archive header: writes header (evidence: `src/huffman.c`)
- Compression → Bit encoding: encodes input (evidence: `src/huffman.c`)
- Bit encoding → Bit I/O: writes bits (evidence: `src/huffman.c`)
- Decompression → Input/output files: reads archive, writes output (evidence: `src/huffman.c`)
- Decompression → Archive header: reads header (evidence: `src/huffman.c`)
- Decompression → Tree and codes: rebuilds tree (evidence: `src/huffman.c`)
- Decompression → Bit decoding: decodes bytes (evidence: `src/huffman.c`)
- Bit decoding → Bit I/O: reads bits (evidence: `src/huffman.c`)
