Workspace structure
The project is organized into three distinct crates, each with specific responsibilities:zb_core
Core data models and domain logic for zerobrew. Responsibilities:- Formula resolution and dependency closure calculation
- Bottle selection logic (platform, architecture, OS version matching)
- Build system detection and planning
- Data types for formulas, bottles, and build configurations
- Error handling types
formula: Formula parsing, bottle selection, and dependency resolutionbuild: Build planning and install method determinationcontext: Configuration and path managementerrors: Error types used across the system
zb_io
I/O operations including network, storage, and filesystem operations. Responsibilities:- API client for Homebrew’s formula and bottle metadata
- Download orchestration with parallel chunked downloads
- Archive extraction (tar.gz, tar.xz, tar.zst, zip)
- Content-addressable storage management
- Cellar materialization with APFS clonefile support
- Binary patching for Homebrew path placeholders
- Database operations for tracking installed packages
- Source builds using Homebrew’s Ruby DSL
network: API client, download manager, HTTP cachingstorage: Blob cache, content-addressable store, SQLite databasecellar: Keg materialization and linkingextraction: Archive unpacking and binary patchinginstaller: High-level installation orchestrationbuild: Source build execution
zb_cli
Command-line interface and user-facing commands. Responsibilities:- CLI argument parsing
- Command implementations (install, uninstall, bundle, etc.)
- User interaction and progress display
- Shell initialization and completion generation
commands: Individual command implementationscli: Argument parsing and command routinginit: Shell setup and PATH configurationutils: Shared utilities for CLI operations
Directory structure
zerobrew organizes its runtime data in a structured hierarchy:The store directory uses content-addressable storage, meaning bottles with the same SHA-256 hash are stored only once, even if multiple packages reference them.
Data flow
Here’s how the components work together during package installation:-
Formula resolution (zb_core)
- Parse user request and resolve formula name
- Fetch formula metadata from Homebrew API
- Calculate dependency closure
- Select appropriate bottle for current platform
-
Download (zb_io)
- Check blob cache for existing download
- Download bottle using parallel chunked downloads
- Verify SHA-256 checksum
- Store in content-addressable blob cache
-
Storage (zb_io)
- Extract bottle to store directory (keyed by SHA-256)
- Handle concurrent access with file locks
- Increment reference count in database
-
Materialization (zb_io)
- Copy package files from store to cellar using APFS clonefile (macOS) or hardlinks
- Patch Homebrew placeholders in binaries
- Code sign and strip extended attributes (macOS)
-
Linking (zb_io)
- Create symlinks in prefix/bin for executables
- Track linked files in database
- Detect and handle conflicts
-
Recording (zb_io)
- Record installation in SQLite database
- Update store reference counts
- Track linked files for later cleanup
Concurrency and parallelism
zerobrew is designed for high concurrency:- Global download concurrency: 20 simultaneous connections (configurable)
- Chunked downloads: Large files (>10MB) use 6 parallel chunks
- Racing connections: 3 concurrent attempts per download with 200ms stagger
- Parallel unpacking: 4 concurrent extraction operations
- Parallel materialization: 4 concurrent cellar operations
Database schema
zerobrew uses SQLite to track installations: installed_kegs: Tracks which packages are installedname(PRIMARY KEY): Package nameversion: Installed versionstore_key: SHA-256 hash or source build identifierinstalled_at: Unix timestamp
store_key(PRIMARY KEY): SHA-256 hashrefcount: Number of kegs using this store entry
name,linked_path(PRIMARY KEY): Package and link locationversion: Package versiontarget_path: Actual file location in cellar
Build systems
When pre-built bottles aren’t available, zerobrew falls back to source builds:- Homebrew Ruby DSL: Executes formula install methods
- Environment isolation: Separate build environment per package
- Dependency tracking: Ensures build dependencies are available
- Source caching: Downloads cached in blob storage
store_key starting with source: instead of a SHA-256 hash.