|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Brightroom is a composable image editor library for iOS, powered by Metal for high-performance image processing. It provides both low-level image editing capabilities and high-level UI components. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +### Running Demo Apps |
| 12 | +```bash |
| 13 | +# Open the development workspace |
| 14 | +open Dev/Brightroom.xcodeproj |
| 15 | + |
| 16 | +# Build using Fastlane |
| 17 | +fastlane ios build_demo_apps |
| 18 | +``` |
| 19 | + |
| 20 | +### Running Tests |
| 21 | +```bash |
| 22 | +# Run all tests via Fastlane |
| 23 | +fastlane ios run_all_tests |
| 24 | + |
| 25 | +# Or via Swift Package Manager |
| 26 | +swift test |
| 27 | +``` |
| 28 | + |
| 29 | +### Building the Package |
| 30 | +```bash |
| 31 | +# Build the Swift package |
| 32 | +swift build |
| 33 | +``` |
| 34 | + |
| 35 | +## Architecture |
| 36 | + |
| 37 | +### Core Modules |
| 38 | + |
| 39 | +1. **BrightroomEngine** - Core image processing engine |
| 40 | + - `Sources/BrightroomEngine/Core/` - Core data models (EditingStack, ImageProvider) |
| 41 | + - `Sources/BrightroomEngine/Filter/` - Image filters and effects |
| 42 | + - `Sources/BrightroomEngine/Engine/` - Metal-based rendering pipeline |
| 43 | + - Uses Verge for reactive state management |
| 44 | + |
| 45 | +2. **BrightroomUI** - UI components for image editing |
| 46 | + - `Sources/BrightroomUI/Shared/` - Shared UI utilities and components |
| 47 | + - `Sources/BrightroomUI/Built-in/` - Pre-built editor UIs (ClassicImageEdit) |
| 48 | + - Provides both UIKit and SwiftUI interfaces |
| 49 | + |
| 50 | +3. **BrightroomUIPhotosCrop** - iOS Photos app-style cropping UI |
| 51 | + - Specialized cropping interface matching system Photos app behavior |
| 52 | + |
| 53 | +### Key Concepts |
| 54 | + |
| 55 | +- **EditingStack**: Central state container that manages editing history and coordinates rendering. Think of it as a "headless browser" for image editing. |
| 56 | +- **ImageProvider**: Abstraction for various image sources (UIImage, URL, Data) |
| 57 | +- **Renderer**: Metal-based rendering system that applies filters and transformations |
| 58 | +- **Component-based UI**: All UI components can be used standalone or composed together |
| 59 | + |
| 60 | +### State Management |
| 61 | + |
| 62 | +The project uses Verge (swift-state-graph) for state management. When modifying state-related code: |
| 63 | +- Look for `@Observable` macro usage |
| 64 | +- State changes flow through EditingStack |
| 65 | +- UI components observe EditingStack changes reactively |
| 66 | + |
| 67 | +## Development Guidelines |
| 68 | + |
| 69 | +### Adding New Filters |
| 70 | +1. Create new filter class in `Sources/BrightroomEngine/Filter/` |
| 71 | +2. Inherit from appropriate base class (e.g., `CIImageFilter`) |
| 72 | +3. Define parameters as properties |
| 73 | +4. Implement `apply(to:)` method |
| 74 | +5. Register in `FilterPresets` if it should appear in UI |
| 75 | + |
| 76 | +### Working with Metal |
| 77 | +- Metal shaders are in `Sources/BrightroomEngine/Engine/` |
| 78 | +- Performance-critical operations use Metal instead of Core Image |
| 79 | +- Check `MetalImageView` for Metal rendering pipeline |
| 80 | + |
| 81 | +### Testing |
| 82 | +- Unit tests are in `Dev/Tests/BrightroomEngineTests/` |
| 83 | +- Focus on testing image processing logic, not UI |
| 84 | +- Use provided test images in Resources for consistency |
| 85 | + |
| 86 | +### Demo Apps |
| 87 | +- **UIKit Demo**: `Dev/Sources/Demo/` - Traditional UIKit implementation |
| 88 | +- **SwiftUI Demo**: `Dev/Sources/SwiftUIDemo/` - Modern SwiftUI examples |
| 89 | +- Both demos showcase all major features and serve as implementation references |
| 90 | + |
| 91 | +## Common Tasks |
| 92 | + |
| 93 | +### Implementing Custom Image Editor |
| 94 | +```swift |
| 95 | +// 1. Create EditingStack with image |
| 96 | +let stack = EditingStack(imageProvider: .init(image: uiImage)) |
| 97 | + |
| 98 | +// 2. Use built-in UI or create custom |
| 99 | +let editor = ClassicImageEditViewController(editingStack: stack) |
| 100 | + |
| 101 | +// 3. Handle completion |
| 102 | +editor.handlers.didEndEditing = { stack in |
| 103 | + let rendered = try! stack.makeRenderer().render().uiImage |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +### Adding Custom UI Component |
| 108 | +1. Create component in `Sources/BrightroomUI/` |
| 109 | +2. Accept `EditingStack` as dependency |
| 110 | +3. Observe stack changes using Verge |
| 111 | +4. Update stack through appropriate methods |
| 112 | + |
| 113 | +## Platform Requirements |
| 114 | +- iOS 16.0+ |
| 115 | +- Xcode 15.2+ |
| 116 | +- Swift 5.9+ |
| 117 | +- Supports iPhone and iPad |
0 commit comments