How laktak/chkbit works
Project Type and Purpose
• chkbit is a Go-based CLI tool for detecting file corruption (via hashing & index checks), plus optional file deduplication and FUSE-backed index merging. It’s not a web app or microservice: it’s a local full-featured command-line utility with a core library and thin front-end.
Architectural Analysis of the File Structure
• cmd/chkbit: the single binary’s entrypoint implementing subcommands (e.g. check, dedup, fuse).
• Top-level .go files (common.go, context.go, fuse.go, hashfile.go, ignore.go, index*.go, worker.go, status.go): the core library providing scanning, hashing, indexing, dedup logic, FUSE integration, and task orchestration.
• cmd/chkbit/util & intutil: helper packages for progress bars, rate calculations, sparkline output, platform‐neutral size formatting, and OS abstractions (os_darwin.go, os_linux.go).
• scripts/: build, lint, test automation.
• Config/deployment: go.mod, CI workflows under .github.
Key Components
a. CLI Front-End
• Arg parser / command dispatcher
• Subcommands: check, dedup, fuse, update
b. Core Controller
• Orchestrates file traversal, hashing tasks, index store operations
• Manages context (via context.go) and status reporting
c. File System Scanner
• Walks directories, applies ignore rules (ignore.go)
• Dispatches file paths to worker pool
d. Worker Pool (worker.go)
• Concurrent hash calculators (hashfile.go)
• Reports results back via channels
e. Index Store
• Index creation and loading (index.go, indexstore.go)
• Supports “split” vs “atom” modes
f. Dedup Engine
• Identifies duplicate hashes, issues system calls to remove/copy files
g. FUSE Interface
• fuse.go implements merging index files into a single mountable view
h. Utilities
• Progress bars, rate calc, spinner, sparkline, sizing, language support
Relationships & Data Flow
• User invokes CLI → Parser → Controller
• Controller launches Scanner → Worker Pool
• Worker Pool → Hash Engine → Channels → Index Store
• Controller ↔ Index Store for read/write checks
• Dedup & Fuse subcommands hook into Controller & Index Store
• Utilities attached to Controller for status output
• OS-specific layers handle file I/O and FUSE bindings
Architectural Patterns & Principles
• Pipeline pattern: scanning → hashing → indexing
• Producer-consumer via Go channels for concurrency
• Layered structure: CLI layer, core logic layer, utility layer, OS-abstraction layer
• Separation of concerns: each package handles distinct responsibilities
Essential Elements Checklist
• Optionally, note CI/build scripts as a sidebar for tooling context