# lessup/fq-compressor architecture

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

- Interactive diagram: https://gitdiagram.com/lessup/fq-compressor
- Repository: https://github.com/lessup/fq-compressor

## Overview

#### Purpose and Entry Points
`fq-compressor` is a C++23 CLI for lossless, bounded-memory FASTQ compression, decompression, and integrity verification. It supports plain and gzip FASTQ, stdin/stdout pipelines, and paired inputs while preserving pair adjacency. The executable entry point is `src/main.cpp`; the production binary is built through `CMakeLists.txt` and `src/CMakeLists.txt`.

#### CLI Dispatch and Operation Engine
`src/main.cpp` parses global and subcommand options, then routes `compress`, `decompress`, and `verify` into one v2 archive engine. The shared engine is the central control boundary: compression turns FASTQ records into sequential archive frames; decompression emits canonical interleaved FASTQ; verification fully reads and validates archives without producing output.
- `include/fqc/commands/v2_archive_engine.h`
- `src/commands/v2_archive_engine.cpp`
- `src/main.cpp`

#### FASTQ Input and Stream Abstraction
Input handling separates transport/compression from logical FASTQ parsing. A stream factory opens files or standard streams; compressed-stream support handles `.gz`; the parser validates and yields FASTQ records. This boundary lets the engine work consistently with files, gzip input, and pipes.
- `include/fqc/io/stream_factory.h`
- `include/fqc/io/compressed_stream.h`
- `src/io/fastq_parser.cpp`

#### Sequential V2 Archive Format
The archive layer owns the wire format: checked global header, independent frames, and a checked footer. Frames hold logical ID/comment, sequence, and quality streams; the reader rejects unsupported versions/codecs, oversized or inconsistent frames, checksum failures, truncation, and trailing data. There is intentionally no v1 compatibility or random access.
- `include/fqc/format/v2_archive.h`
- `src/format/v2_archive.cpp`
- `ARCHITECTURE.md`

#### Codec and Memory Model
Compression uses Zstd level 1 for framed metadata, packed sequences, and quality streams. Sequences use 2-bit uppercase A/C/G/T representation plus exact exceptions for lowercase and other IUPAC symbols. XXH64 protects headers, frames, and footer totals. The archive engine admits frame work against the configured hard memory budget, keeping operation memory bounded rather than performing global analysis.
- `src/commands/v2_archive_engine.cpp`
- `src/format/v2_archive.cpp`
- `include/fqc/common/types.h`

#### Pairing, Profiles, and Data Integrity
For paired input, the engine consumes R1/R2 together, preserves adjacency, and ensures frames contain complete pairs; output is one interleaved stream. Dataset profile detection/override (`illumina`, `ont`, `pacbio-hifi`, `pacbio-clr`) is persisted in the archive, though all currently use the validated fallback codec. Errors and status reporting are centralized rather than exposed as raw lower-layer failures.
- `include/fqc/common/error.h`
- `src/common/error.cpp`
- `src/common/logger.cpp`

#### Build, Dependencies, and Performance Governance
CMake builds the native CLI, with Conan supplying dependencies/toolchains and C++23 compiler requirements. The material external libraries implied by the format are Zstd, gzip/zlib support, and XXH64. Python benchmark tooling runs dataset/workload manifests, adapters, evidence collection, and codec admission reporting; it is a governance path separate from the production CLI.
- `conanfile.py`
- `benchmark_v2/unified_runner.py`
- `benchmark_v2/CODEC_GATES.md`

Main entry points: [`src/commands/v2_archive_engine.cpp`](https://github.com/lessup/fq-compressor/blob/master/src/commands/v2_archive_engine.cpp) (V2 archive engine), [`include/fqc/io/stream_factory.h`](https://github.com/lessup/fq-compressor/blob/master/include/fqc/io/stream_factory.h) (Stream factory), [`src/format/v2_archive.cpp`](https://github.com/lessup/fq-compressor/blob/master/src/format/v2_archive.cpp) (Archive reader/writer), [`conanfile.py`](https://github.com/lessup/fq-compressor/blob/master/conanfile.py) (Conan toolchain)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Native CLI"]
  node_main["CLI entry point<br/>C++ executable<br/>[main.cpp]"]
  node_errors["Errors and status<br/>diagnostics<br/>[error.h]"]
end

subgraph group_io["Input pipeline"]
  node_stream_factory["Stream factory<br/>input transport<br/>[stream_factory.h]"]
  node_gzip_stream["Compressed streams<br/>gzip transport"]
  node_fastq_parser["FASTQ parser<br/>record parser<br/>[fastq_parser.cpp]"]
end

subgraph group_archive["Archive engine"]
  node_engine_api["Archive engine API<br/>command interface"]
  node_engine["V2 archive engine<br/>operation controller"]
  node_pairing["Pair handling<br/>record policy"]
  node_memory_budget["Memory admission<br/>resource policy"]
  node_v2_format["V2 archive format<br/>wire format<br/>[v2_archive.h]"]
  node_archive_reader_writer["Archive reader/writer<br/>format implementation<br/>[v2_archive.cpp]"]
  node_codec["Frame codec<br/>compression codec<br/>[v2_archive.cpp]"]
  node_profile["Dataset profile<br/>archive metadata"]
end

subgraph group_governance["Build &amp; governance"]
  node_cmake["CMake build<br/>build system<br/>[CMakeLists.txt]"]
  node_conan["Conan toolchain<br/>dependency manager<br/>[conanfile.py]"]
  node_bench_runner["Benchmark runner<br/>Python governance tool<br/>[unified_runner.py]"]
  node_codec_gates["Codec gates<br/>admission policy<br/>[CODEC_GATES.md]"]
  node_native_deps{{"Zstd, zlib, XXH64<br/>native dependencies"}}
end

node_conan -->|"supplies toolchain"| node_cmake
node_cmake -->|"builds"| node_main
node_conan -->|"provides"| node_native_deps
node_main -->|"dispatches commands"| node_engine_api
node_engine_api -->|"implements"| node_engine
node_engine -->|"opens input"| node_stream_factory
node_stream_factory -->|"wraps gzip input"| node_gzip_stream
node_stream_factory -->|"feeds streams"| node_fastq_parser
node_fastq_parser -->|"yields records"| node_pairing
node_pairing -->|"complete pairs"| node_engine
node_engine -->|"admits frame work"| node_memory_budget
node_engine -->|"detects or overrides"| node_profile
node_engine -->|"reads and writes frames"| node_archive_reader_writer
node_archive_reader_writer -->|"enforces"| node_v2_format
node_archive_reader_writer -->|"encodes and validates streams"| node_codec
node_native_deps -->|"implements primitives"| node_codec
node_engine -->|"reports failures"| node_errors
node_codec_gates -->|"governs reporting"| node_bench_runner
node_bench_runner -.->|"evaluates admission"| node_codec

click node_cmake "https://github.com/lessup/fq-compressor/blob/master/CMakeLists.txt"
click node_conan "https://github.com/lessup/fq-compressor/blob/master/conanfile.py"
click node_main "https://github.com/lessup/fq-compressor/blob/master/src/main.cpp"
click node_engine_api "https://github.com/lessup/fq-compressor/blob/master/include/fqc/commands/v2_archive_engine.h"
click node_engine "https://github.com/lessup/fq-compressor/blob/master/src/commands/v2_archive_engine.cpp"
click node_stream_factory "https://github.com/lessup/fq-compressor/blob/master/include/fqc/io/stream_factory.h"
click node_gzip_stream "https://github.com/lessup/fq-compressor/blob/master/include/fqc/io/compressed_stream.h"
click node_fastq_parser "https://github.com/lessup/fq-compressor/blob/master/src/io/fastq_parser.cpp"
click node_pairing "https://github.com/lessup/fq-compressor/blob/master/src/commands/v2_archive_engine.cpp"
click node_memory_budget "https://github.com/lessup/fq-compressor/blob/master/src/commands/v2_archive_engine.cpp"
click node_v2_format "https://github.com/lessup/fq-compressor/blob/master/include/fqc/format/v2_archive.h"
click node_archive_reader_writer "https://github.com/lessup/fq-compressor/blob/master/src/format/v2_archive.cpp"
click node_codec "https://github.com/lessup/fq-compressor/blob/master/src/format/v2_archive.cpp"
click node_profile "https://github.com/lessup/fq-compressor/blob/master/src/commands/v2_archive_engine.cpp"
click node_errors "https://github.com/lessup/fq-compressor/blob/master/include/fqc/common/error.h"
click node_bench_runner "https://github.com/lessup/fq-compressor/blob/master/benchmark_v2/unified_runner.py"
click node_codec_gates "https://github.com/lessup/fq-compressor/blob/master/benchmark_v2/CODEC_GATES.md"

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_main,node_errors toneBlue
class node_stream_factory,node_gzip_stream,node_fastq_parser toneAmber
class node_engine_api,node_engine,node_pairing,node_memory_budget,node_v2_format,node_archive_reader_writer,node_codec,node_profile toneMint
class node_cmake,node_conan,node_bench_runner,node_codec_gates,node_native_deps toneRose
```

## Components

### Native CLI

- [CLI entry point](https://github.com/lessup/fq-compressor/blob/master/src/main.cpp): C++ executable · Parses global and subcommand options. · `src/main.cpp`
- [Errors and status](https://github.com/lessup/fq-compressor/blob/master/include/fqc/common/error.h): diagnostics · Centralizes user-facing failures and reporting. · `include/fqc/common/error.h`

### Input pipeline

- [Stream factory](https://github.com/lessup/fq-compressor/blob/master/include/fqc/io/stream_factory.h): input transport · Opens files and standard streams. · `include/fqc/io/stream_factory.h`
- [Compressed streams](https://github.com/lessup/fq-compressor/blob/master/include/fqc/io/compressed_stream.h): gzip transport · Supports gzip FASTQ input. · `include/fqc/io/compressed_stream.h`
- [FASTQ parser](https://github.com/lessup/fq-compressor/blob/master/src/io/fastq_parser.cpp): record parser · Validates and yields logical FASTQ records. · `src/io/fastq_parser.cpp`

### Archive engine

- [Archive engine API](https://github.com/lessup/fq-compressor/blob/master/include/fqc/commands/v2_archive_engine.h): command interface · `include/fqc/commands/v2_archive_engine.h`
- [V2 archive engine](https://github.com/lessup/fq-compressor/blob/master/src/commands/v2_archive_engine.cpp): operation controller · Coordinates bounded-memory compress, decompress, and verify operations. · `src/commands/v2_archive_engine.cpp`
- [Pair handling](https://github.com/lessup/fq-compressor/blob/master/src/commands/v2_archive_engine.cpp): record policy · Consumes R1/R2 together and preserves interleaved adjacency. · `src/commands/v2_archive_engine.cpp`
- [Memory admission](https://github.com/lessup/fq-compressor/blob/master/src/commands/v2_archive_engine.cpp): resource policy · Admits frame work under the configured hard memory budget. · `src/commands/v2_archive_engine.cpp`
- [V2 archive format](https://github.com/lessup/fq-compressor/blob/master/include/fqc/format/v2_archive.h): wire format · Checked header, independent frames, and checked footer. · `include/fqc/format/v2_archive.h`
- [Archive reader/writer](https://github.com/lessup/fq-compressor/blob/master/src/format/v2_archive.cpp): format implementation · Rejects invalid versions, frames, checksums, truncation, and trailing data. · `src/format/v2_archive.cpp`
- [Frame codec](https://github.com/lessup/fq-compressor/blob/master/src/format/v2_archive.cpp): compression codec · Zstd metadata and streams, 2-bit bases with exact sequence exceptions, and XXH64 checks. · `src/format/v2_archive.cpp`
- [Dataset profile](https://github.com/lessup/fq-compressor/blob/master/src/commands/v2_archive_engine.cpp): archive metadata · Persists detected or overridden sequencing profile. · `src/commands/v2_archive_engine.cpp`

### Build & governance

- [CMake build](https://github.com/lessup/fq-compressor/blob/master/CMakeLists.txt): build system · Builds the C++23 production executable. · `CMakeLists.txt`
- [Conan toolchain](https://github.com/lessup/fq-compressor/blob/master/conanfile.py): dependency manager · `conanfile.py`
- [Benchmark runner](https://github.com/lessup/fq-compressor/blob/master/benchmark_v2/unified_runner.py): Python governance tool · Runs workload manifests, adapters, and evidence collection. · `benchmark_v2/unified_runner.py`
- [Codec gates](https://github.com/lessup/fq-compressor/blob/master/benchmark_v2/CODEC_GATES.md): admission policy · Defines codec admission reporting criteria. · `benchmark_v2/CODEC_GATES.md`
- **Zstd, zlib, XXH64**: native dependencies

## Connections

- Conan toolchain → CMake build: supplies toolchain
- CMake build → CLI entry point: builds
- Conan toolchain → Zstd, zlib, XXH64: provides
- CLI entry point → Archive engine API: dispatches commands
- Archive engine API → V2 archive engine: implements
- V2 archive engine → Stream factory: opens input
- Stream factory → Compressed streams: wraps gzip input
- Stream factory → FASTQ parser: feeds streams
- FASTQ parser → Pair handling: yields records
- Pair handling → V2 archive engine: complete pairs
- V2 archive engine → Memory admission: admits frame work
- V2 archive engine → Dataset profile: detects or overrides
- V2 archive engine → Archive reader/writer: reads and writes frames
- Archive reader/writer → V2 archive format: enforces
- Archive reader/writer → Frame codec: encodes and validates streams
- Zstd, zlib, XXH64 → Frame codec: implements primitives
- V2 archive engine → Errors and status: reports failures
- Codec gates → Benchmark runner: governs reporting
- Benchmark runner → Frame codec: evaluates admission
