This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Build the binary
make build
# Build with Profile-Guided Optimization (PGO)
make build-pgo
# Install to system path
make install
# Install with PGO optimization
make install-pgo
# Generate PGO profile (required before build-pgo)
make profile# Run all tests (excluding large tests)
make test
# Run tests with race detector (quick)
make test-race-short
# Run all tests with race detector
make test-race
# Run large/resource-intensive tests
make test-large
# Run tests with coverage report
make test-coverage
# Run a single test
go test -v -run TestName ./internal/torrent
# Run tests with specific build tags
go test -v -tags=large_tests ./internal/torrent# Run linter (golangci-lint)
make lint
# Clean build artifacts
make cleanmkbrr is a high-performance torrent creation and manipulation tool written in Go. The codebase follows a clean architecture with clear separation of concerns.
- Main Entry (
main.go) - Minimal entry point that delegates to cmd package - Command Layer (
cmd/)root.go: Main CLI structure with ASCII banner and global flagscreate.go: Torrent creation with single/batch/preset modescheck.go: Torrent verification against local filesinspect.go: Torrent metadata inspection with tree/json outputmodify.go: Metadata modification without original contentupdate.go: Self-update functionalityversion.go: Version information display
Torrent Package (internal/torrent/)
types.go: Core data structures (CreateTorrentOptions,ModifyOptions, etc.)create.go: Torrent creation with automatic piece length calculationhasher.go: High-performance parallel hashing with adaptive worker poolsverify.go: Torrent integrity verificationbatch.go: Parallel batch processing for multiple torrentsseasonfinder.go: TV season pack completeness detectionmodify.go: Metadata modification without needing source filesdisplay.go: User interface and progress display logicprogress.go: Progress tracking for operations
Tracker Integration (internal/trackers/)
trackers.go: Centralized tracker-specific constraints- Enforces piece length limits, torrent size limits, and custom rules
- Automatically selects optimal piece size based on tracker requirements
Preset System (internal/preset/)
preset.go: Configuration preset management- YAML-based configuration with JSON schema validation
- Supports default settings with preset-specific overrides
- Options Pattern: All operations use structured options for clean APIs
- Worker Pools: Adaptive parallel processing based on workload characteristics
- Tracker Awareness: Automatic enforcement of tracker-specific requirements
- Error Handling: User-friendly error messages with actionable feedback
- Progress Display: Real-time feedback with multiple display modes
-
Parallel Hashing:
- Adaptive worker count based on file size/count
- Memory-efficient buffer pooling
- Optimized for both small and large file workloads
-
Season Pack Detection:
- Regex-based pattern matching in
seasonfinder.go - Detects missing episodes in TV season packs
- Supports multiple naming conventions
- Regex-based pattern matching in
-
Configuration Files:
- Presets:
presets.yamlfor reusable settings - Batch:
batch.yamlfor multiple torrent operations - JSON Schema validation for both formats
- Presets:
-
File Filtering:
- Include/exclude patterns with precedence rules
- Regex support for complex filtering
- Default exclusions for common non-media files
- Profile-Guided Optimization (PGO) support via Makefile
- Parallel processing with controlled concurrency
- Memory pooling to reduce allocations
- Optimized piece size selection based on content size
- Unit tests alongside implementation files
- Large tests with
large_testsbuild tag for expensive operations - Race condition detection with custom GORACE settings
- Benchmark tests comparing against competitors
# Add a new tracker with specific requirements
# Edit internal/trackers/trackers.go and add to trackerRules map
# Modify season detection patterns
# Edit internal/torrent/seasonfinder.go regex patterns
# Add new command
# Create new file in cmd/ following existing patterns
# Test specific functionality
go test -v -run TestCreateTorrent ./internal/torrentmkbrr/
├── cmd/ # CLI commands
├── internal/ # Core business logic
│ ├── torrent/ # Torrent operations
│ ├── trackers/ # Tracker-specific logic
│ └── preset/ # Configuration presets
├── schemas/ # JSON schemas for validation
└── test/ # Test fixtures and data
- Use Conventional Commit format:
type(scope): description- Types:
fix,feat,chore,docs,test,refactor,perf,style - Example:
fix(torrent): correct piece length calculation for small files - Example:
feat(tracker): add support for new tracker requirements
- Types:
- Keep commits atomic and focused on a single change
- Write clear, descriptive commit messages
- IMPORTANT: Never mention Claude or Claude Code in commit messages