# nafis-muktashid/crunchfs architecture

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

- Interactive diagram: https://gitdiagram.com/nafis-muktashid/crunchfs
- Repository: https://github.com/nafis-muktashid/crunchfs

## Overview

CrunchFS-2 is a FUSE filesystem that presents compressed, persistent files through a mount point. The documented workflow is: the daemon prepares the backing directory and starts FUSE; filesystem callbacks resolve logical paths, serve reads and writes, and update metadata and compressed chunks. Reads dispatch chunk work to a thread pool, while `/.cfs_stats` exposes storage totals. The active architecture is documented in the README; `src/passthrough_cfs.cpp` is a substantial separate implementation not listed in the current build architecture. Connections involving the unsampled compression wrapper are limited to relationships visible in the excerpts and source index.

Main entry points: [`src/fuse_ops.cpp`](https://github.com/nafis-muktashid/crunchfs/blob/main/src/fuse_ops.cpp) (FUSE operations), [`src/metadata.cpp`](https://github.com/nafis-muktashid/crunchfs/blob/main/src/metadata.cpp) (Metadata index), [`src/main.cpp`](https://github.com/nafis-muktashid/crunchfs/blob/main/src/main.cpp) (Daemon bootstrap), [`src/chunk_store.cpp`](https://github.com/nafis-muktashid/crunchfs/blob/main/src/chunk_store.cpp) (Compressed chunks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Mount runtime"]
  node_daemon["Daemon bootstrap<br/>[main.cpp]"]
  node_pool["Worker pool<br/>[thread_pool.cpp]"]
end

subgraph group_filesystem["Filesystem operations"]
  node_ops["FUSE operations<br/>[fuse_ops.cpp]"]
  node_file_io["File I/O callbacks<br/>[fuse_ops.cpp]"]
  node_stats["Stats endpoint<br/>[fuse_ops.cpp]"]
end

subgraph group_storage["Persistent storage"]
  node_metadata[("Metadata index<br/>[metadata.cpp]")]
  node_chunks[("Compressed chunks<br/>[chunk_store.cpp]")]
  node_compression["Compression wrapper<br/>[conpresslib.cpp]"]
  node_codec_api["Codec interface<br/>[interface.hpp]"]
  node_zstd["Zstd backend<br/>[zstd_backend.cpp]"]
end

subgraph group_alternate["Separate implementation"]
  node_legacy["Separate passthrough implementation"]
end

node_user(("Filesystem user"))
node_fuse(("FUSE runtime"))

node_user -->|"uses mount"| node_fuse
node_daemon -->|"starts"| node_fuse
node_daemon -->|"registers"| node_ops
node_fuse -.->|"dispatches callbacks"| node_ops
node_ops -->|"manages metadata"| node_metadata
node_ops -->|"handles file requests"| node_file_io
node_ops -->|"serves stats"| node_stats
node_file_io -->|"resolves paths"| node_metadata
node_file_io -->|"reads and writes"| node_chunks
node_file_io -->|"dispatches reads"| node_pool
node_stats -->|"accumulates totals"| node_metadata
node_chunks -->|"compresses chunks"| node_compression
node_compression -.->|"uses codec API"| node_codec_api
node_codec_api -->|"implemented by"| node_zstd

click node_daemon "https://github.com/nafis-muktashid/crunchfs/blob/main/src/main.cpp"
click node_ops "https://github.com/nafis-muktashid/crunchfs/blob/main/src/fuse_ops.cpp"
click node_file_io "https://github.com/nafis-muktashid/crunchfs/blob/main/src/fuse_ops.cpp"
click node_stats "https://github.com/nafis-muktashid/crunchfs/blob/main/src/fuse_ops.cpp"
click node_pool "https://github.com/nafis-muktashid/crunchfs/blob/main/src/thread_pool.cpp"
click node_metadata "https://github.com/nafis-muktashid/crunchfs/blob/main/src/metadata.cpp"
click node_chunks "https://github.com/nafis-muktashid/crunchfs/blob/main/src/chunk_store.cpp"
click node_compression "https://github.com/nafis-muktashid/crunchfs/blob/main/src/conpresslib.cpp"
click node_codec_api "https://github.com/nafis-muktashid/crunchfs/blob/main/src/compression/interface.hpp"
click node_zstd "https://github.com/nafis-muktashid/crunchfs/blob/main/src/compression/zstd_backend.cpp"
click node_legacy "https://github.com/nafis-muktashid/crunchfs/blob/main/src/passthrough_cfs.cpp"

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_daemon,node_pool,node_user toneBlue
class node_ops,node_file_io,node_stats toneAmber
class node_metadata,node_chunks,node_compression,node_codec_api,node_zstd toneMint
class node_legacy toneRose
class node_fuse toneIndigo
```

## Components

### Mount runtime

- [Daemon bootstrap](https://github.com/nafis-muktashid/crunchfs/blob/main/src/main.cpp): `src/main.cpp`
- [Worker pool](https://github.com/nafis-muktashid/crunchfs/blob/main/src/thread_pool.cpp): `src/thread_pool.cpp`

### Filesystem operations

- [FUSE operations](https://github.com/nafis-muktashid/crunchfs/blob/main/src/fuse_ops.cpp): `src/fuse_ops.cpp`
- [File I/O callbacks](https://github.com/nafis-muktashid/crunchfs/blob/main/src/fuse_ops.cpp): `src/fuse_ops.cpp`
- [Stats endpoint](https://github.com/nafis-muktashid/crunchfs/blob/main/src/fuse_ops.cpp): `src/fuse_ops.cpp`

### Persistent storage

- [Metadata index](https://github.com/nafis-muktashid/crunchfs/blob/main/src/metadata.cpp): `src/metadata.cpp`
- [Compressed chunks](https://github.com/nafis-muktashid/crunchfs/blob/main/src/chunk_store.cpp): `src/chunk_store.cpp`
- [Compression wrapper](https://github.com/nafis-muktashid/crunchfs/blob/main/src/conpresslib.cpp): `src/conpresslib.cpp`
- [Codec interface](https://github.com/nafis-muktashid/crunchfs/blob/main/src/compression/interface.hpp): `src/compression/interface.hpp`
- [Zstd backend](https://github.com/nafis-muktashid/crunchfs/blob/main/src/compression/zstd_backend.cpp): `src/compression/zstd_backend.cpp`

### Separate implementation

- [Separate passthrough implementation](https://github.com/nafis-muktashid/crunchfs/blob/main/src/passthrough_cfs.cpp): `src/passthrough_cfs.cpp`

### Other components

- **Filesystem user**
- **FUSE runtime**

## Connections

- Filesystem user → FUSE runtime: uses mount (evidence: `README.md`)
- Daemon bootstrap → FUSE runtime: starts (evidence: `src/main.cpp`)
- Daemon bootstrap → FUSE operations: registers (evidence: `src/main.cpp`)
- FUSE runtime → FUSE operations: dispatches callbacks
- FUSE operations → Metadata index: manages metadata (evidence: `src/fuse_ops.cpp`)
- FUSE operations → File I/O callbacks: handles file requests (evidence: `src/fuse_ops.cpp`)
- FUSE operations → Stats endpoint: serves stats (evidence: `src/fuse_ops.cpp`)
- File I/O callbacks → Metadata index: resolves paths (evidence: `src/fuse_ops.cpp`)
- File I/O callbacks → Compressed chunks: reads and writes (evidence: `src/fuse_ops.cpp`)
- File I/O callbacks → Worker pool: dispatches reads (evidence: `src/fuse_ops.cpp`)
- Stats endpoint → Metadata index: accumulates totals (evidence: `src/fuse_ops.cpp`)
- Compressed chunks → Compression wrapper: compresses chunks (evidence: `src/chunk_store.cpp`)
- Compression wrapper → Codec interface: uses codec API
- Codec interface → Zstd backend: implemented by (evidence: `src/compression/zstd_backend.cpp`)
