Overview
Camera Workflow is a secure, parallel media converter written in Go that converts images to modern formats (AVIF, WebP) and videos to efficient codecs (H.265, AV1). The system is designed as a monorepo containing both a Go-based conversion engine and a Raycast UI extension.Monorepo Structure
Core Architecture
Entry Point Flow
The application follows a clear execution flow:- main.go → Minimal entry point that delegates to cmd package
- cmd/root.go → CLI interface using Cobra, flag binding, and pre-run validation
- internal/converter/ → Main conversion orchestrator
Component Overview
Configuration
Package:
internal/config/- Viper-based configuration management
- YAML file support (
$HOME/.media-converter.yaml) - Layered configuration: defaults → config file → env vars → CLI flags
- Validation and sanitization
Conversion Engine
Package:
internal/converter/- Orchestrates the entire conversion process
- Manages worker pools with semaphores
- Parallel processing for images and videos
- Progress tracking and statistics
Security Layer
Package:
internal/security/- Disk space checks (platform-specific)
- File integrity verification
- Conversion timeouts
- Process marker management
- Corruption detection and recovery
Logging System
Package:
internal/logger/- Structured logging (Logrus)
- Dual output: console + file
- Colored output for terminal
- JSON mode for Tauri integration
Utilities
Package:
internal/utils/- File handling and validation
- Dependency checks (FFmpeg, ImageMagick)
- Format detection
- Date extraction from metadata
- Hardware acceleration detection
Checksum
Package:
internal/checksum/- xxHash64 implementation
- File integrity verification
- Duplicate detection
- Checksum tracking
API Layer
Package:
internal/api/- JSON event streaming
- Tauri frontend integration
- Structured event types
- Real-time progress updates
Internal Package Details
Configuration (internal/config/config.go)
The configuration system uses a layered approach with clear precedence:
- Command line flags
- Environment variables
- YAML config file
- Default values
Converter (internal/converter/converter.go)
The main conversion orchestrator manages the entire workflow:
Key Responsibilities:
- File discovery and categorization
- Worker pool management (semaphore-based)
- Progress tracking and statistics
- Safety tests before batch processing
- Recovery and cleanup operations
Image Conversion (internal/converter/image.go)
Handles photo conversions using ImageMagick:
- Supports AVIF and WebP output formats
- Quality settings per format (AVIF: 80, WebP: 85)
- Metadata preservation
- Output file validation
Video Conversion (internal/converter/video.go)
Handles video conversions using FFmpeg:
- Codec support: H.265, H.264, AV1
- Hardware acceleration detection (macOS VideoToolbox, Linux VAAPI/NVENC)
- Progress tracking with time-based progress bars
- AWS S3 cost estimation
- Adaptive worker management
Security Checker (internal/security/security.go)
Provides comprehensive safety mechanisms:
File Integrity:
VerifyOutputFile()- Validates converted files using external toolsIsFileCorrupted()- Detects corrupted existing filesVerifyFileIntegrity()- Comprehensive integrity checks
CreateProcessingMarker()- Marks files being processed (PID + timestamp)RemoveProcessingMarker()- Cleans up after successful conversionFindAbandonedMarkers()- Detects dead processesCleanupAbandonedFiles()- Removes orphaned .tmp files
- Platform-specific implementations (Unix/Windows)
- Pre-conversion space validation
- Estimates needed space (50% of source for safety)
Logger (internal/logger/logger.go)
Structured logging with dual modes:
Normal Mode:
- Colored terminal output
- Progress bars and statistics
- File logging to
{destination}/conversion.log
- Structured events to stdout
- File logging (no colors)
- Tauri frontend integration
started- Conversion beginsprogress- Overall progress updatesfile_start- Individual file processing startsfile_end- Individual file processing completeslog- General log messageserror- Error eventscomplete- Conversion finishedstatistics- Detailed stats
Utilities (internal/utils/utils.go)
Date Extraction (GetFileDate()):
Extraction priority order:
- macOS
mdlsmetadata (most reliable for RAW files) - EXIF data via ImageMagick (
EXIF:DateTimeOriginal) - Video metadata via FFmpeg (
creation_time) - File modification time (with validation)
CreateDestinationPath()- Generates organized pathsGetMonthName()- Multi-language month names (EN, FR, ES, DE)ShouldSkipSystemEntry()- Filters system files/directories
- FFmpeg and ffprobe
- ImageMagick (magick command)
- Hardware acceleration detection
Checksum (internal/checksum/checksum.go)
Fast file integrity verification:
- xxHash64 implementation (faster than MD5/SHA256)
- Stream-based calculation (low memory usage)
- Duplicate detection
- Copy-mode verification
API (internal/api/json_writer.go)
JSON event streaming for frontend integration:
Adaptive Worker Management
For video conversions, the system supports adaptive worker scaling based on system resources: Components:AdaptiveLimiter- Dynamic semaphore with adjustable limitsResourceMonitor- Tracks CPU and memory usageAdaptiveController- Adjusts worker count based on thresholds
Safety and Idempotence
The system is designed to be 100% safe and idempotent:Idempotent Operations
- Run multiple times safely - already converted files are skipped
- Resume after interruption (Ctrl+C, crashes, failures)
- Atomic conversions via
.tmpfiles + atomic rename
Safety Guarantees
- Originals preserved by default (
--keep-originals=true) - Triple verification before deletion
- Processing markers track active conversions
- Automatic recovery from crashes
- Corruption detection
Recovery System
When resuming after interruption:- Skips successfully converted files
- Cleans up temporary files from interrupted conversions
- Re-converts partially processed or corrupted files
- Continues from where it left off
Platform-Specific Code
Several packages have platform-specific implementations:internal/security/diskspace_*.go- Disk space checks (Unix/Windows)internal/security/process_check_*.go- Process existence checks (Unix/Windows)internal/converter/resource_*.go- Resource monitoring (Darwin/Linux/Stub)
External Dependencies
Required Tools
- FFmpeg - Video conversion and metadata extraction
- FFprobe - Video analysis
- ImageMagick (magick) - Image conversion and EXIF data
Go Dependencies
github.com/spf13/cobra- CLI frameworkgithub.com/spf13/viper- Configuration managementgithub.com/sirupsen/logrus- Structured logginggithub.com/fatih/color- Terminal colorsgolang.org/x/sync- Semaphore for worker poolsgithub.com/cespare/xxhash/v2- Fast checksum calculation
Next Steps
Building
Learn how to build the project from source
Testing
Run tests and check coverage
Contributing
Contribute to the project