|
| 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 | +RadiantKit is a Swift Package Manager library providing SwiftUI utilities across Apple platforms (iOS 18+, macOS 15+, tvOS 18+, watchOS 11+, visionOS 2+). The package contains four distinct modules with clear separation of concerns. |
| 8 | + |
| 9 | +## Common Commands |
| 10 | + |
| 11 | +### Building and Testing |
| 12 | +```bash |
| 13 | +# Build the package (Swift 6.0+ required) |
| 14 | +swift build |
| 15 | + |
| 16 | +# Run tests |
| 17 | +swift test |
| 18 | + |
| 19 | +# Build for specific platform (requires Xcode) |
| 20 | +xcodebuild -scheme RadiantKit-Package -destination 'platform=iOS Simulator,name=iPhone 16' |
| 21 | + |
| 22 | +# Run single test |
| 23 | +swift test --filter RadiantKitTests.<TestClassName>/<testMethodName> |
| 24 | +``` |
| 25 | + |
| 26 | +### Linting and Formatting |
| 27 | +```bash |
| 28 | +# Run full lint (formats code, adds headers, then validates) |
| 29 | +./Scripts/lint.sh |
| 30 | + |
| 31 | +# Format only (skip validation) |
| 32 | +FORMAT_ONLY=1 ./Scripts/lint.sh |
| 33 | + |
| 34 | +# Strict mode (treats warnings as errors) |
| 35 | +LINT_MODE=STRICT ./Scripts/lint.sh |
| 36 | + |
| 37 | +# Skip linting entirely |
| 38 | +LINT_MODE=NONE ./Scripts/lint.sh |
| 39 | +``` |
| 40 | + |
| 41 | +The lint script uses Mint for dependency management and runs: |
| 42 | +- swift-format (formatting and linting) |
| 43 | +- swiftlint (Swift style validation) |
| 44 | +- header.sh (copyright header management) |
| 45 | + |
| 46 | +### Documentation Generation |
| 47 | +```bash |
| 48 | +# Generate Swift-DocC documentation |
| 49 | +./Scripts/swift-doc.sh |
| 50 | + |
| 51 | +# Watch mode for documentation development |
| 52 | +./Scripts/watch-docc.sh |
| 53 | +``` |
| 54 | + |
| 55 | +### Development Tools |
| 56 | +```bash |
| 57 | +# Install Mint dependencies |
| 58 | +mint bootstrap -m Mintfile |
| 59 | + |
| 60 | +# Run periphery (dead code detection) |
| 61 | +mint run periphery scan |
| 62 | +``` |
| 63 | + |
| 64 | +## Architecture |
| 65 | + |
| 66 | +### Module Structure |
| 67 | + |
| 68 | +**RadiantKit** (Core Foundation) |
| 69 | +- Property wrappers: `@AppStored`, `@DefaultWrapped` for persistent storage patterns |
| 70 | +- View utilities: `IdentifiableView`, `IdentifiableViewBuilder` for collection-based navigation |
| 71 | +- `Binding.map()`: Type-safe binding transformations |
| 72 | +- Platform adapters: NSWindowDelegate wrappers for macOS |
| 73 | +- Custom views: GuidedLabeledContent, SliderStepperView, Video, ValueTextBubble |
| 74 | + |
| 75 | +**RadiantDocs** (depends on RadiantKit) |
| 76 | +- Document management for SwiftUI apps |
| 77 | +- Core protocols: `CodablePackage`, `FileTypeSpecification`, `InitializablePackage` |
| 78 | +- `DocumentFile<FileType>`: Generic, type-safe file wrapper |
| 79 | +- `CodablePackageDocument<T>`: FileDocument implementation for package files |
| 80 | +- File panel abstractions and UTType integration |
| 81 | + |
| 82 | +**RadiantPaging** (depends on RadiantKit) |
| 83 | +- Page-based navigation UI patterns |
| 84 | +- `PageView`: Main component for sequential page display |
| 85 | +- Environment-based actions: `NextPageAction`, `PreviousPageAction`, `CancelPageAction` |
| 86 | +- `PageNavigationAvailability`: Controls which navigation buttons appear |
| 87 | +- Integrates with `IdentifiableView` from RadiantKit |
| 88 | + |
| 89 | +**RadiantProgress** (independent, depends on swift-log for Linux) |
| 90 | +- Progress tracking for file operations and downloads |
| 91 | +- `ProgressOperation<ValueType>`: Protocol for any progress-reporting operation |
| 92 | +- `DownloadOperation`: Observable implementation with URLSession integration |
| 93 | +- `FileOperationProgress`: SwiftUI-friendly wrapper for any ProgressOperation |
| 94 | +- `ObservableDownloader`: Combines Observation and Combine patterns |
| 95 | + |
| 96 | +### Key Architectural Patterns |
| 97 | + |
| 98 | +**Property Wrappers** |
| 99 | +- `AppStored` protocol defines key-based storage contracts |
| 100 | +- `DefaultWrapped` extends AppStored with default value support |
| 101 | +- UserDefaults extensions provide type-safe retrieval |
| 102 | + |
| 103 | +**Generic Type Systems** |
| 104 | +- `DocumentFile<FileType: FileTypeSpecification>`: Type-safe file handling |
| 105 | +- `ProgressOperation<ValueType: BinaryInteger & Sendable>`: Flexible progress reporting |
| 106 | +- Extensive use of generics to prevent runtime errors |
| 107 | + |
| 108 | +**Observable/Reactive** |
| 109 | +- `@Observable` macro for iOS 17+ reactive state |
| 110 | +- MainActor isolation throughout for UI thread safety |
| 111 | +- Sendable conformance for cross-actor communication |
| 112 | + |
| 113 | +**Protocol-Based Design** |
| 114 | +- Interface segregation (small, focused protocols) |
| 115 | +- Protocol extensions for shared functionality |
| 116 | +- Generic constraints for type safety |
| 117 | + |
| 118 | +**SwiftUI Environment Integration** |
| 119 | +- Page navigation actions injected via environment |
| 120 | +- Custom environment keys for cross-view communication |
| 121 | + |
| 122 | +### Module Dependencies |
| 123 | + |
| 124 | +``` |
| 125 | +RadiantKit (foundation) |
| 126 | + ↑ ↑ |
| 127 | + | | |
| 128 | + | | |
| 129 | +RadiantDocs RadiantPaging |
| 130 | +
|
| 131 | +RadiantProgress (independent) |
| 132 | +``` |
| 133 | + |
| 134 | +## Swift 6 & Experimental Features |
| 135 | + |
| 136 | +This project uses Swift 6.0 with multiple experimental features enabled: |
| 137 | +- AccessLevelOnImport |
| 138 | +- BitwiseCopyable |
| 139 | +- IsolatedAny |
| 140 | +- MoveOnlyPartialConsumption |
| 141 | +- NestedProtocols |
| 142 | +- NoncopyableGenerics |
| 143 | +- TransferringArgsAndResults |
| 144 | +- VariadicGenerics |
| 145 | +- FullTypedThrows (upcoming) |
| 146 | +- InternalImportsByDefault (upcoming) |
| 147 | + |
| 148 | +Code must be compatible with strict concurrency checking and Sendable requirements. |
| 149 | + |
| 150 | +## Code Style |
| 151 | + |
| 152 | +### Formatting |
| 153 | +- Uses swift-format (v600.0.0) with configuration in `.swift-format` |
| 154 | +- SwiftLint (v0.58.0) with rules in `.swiftlint.yml` |
| 155 | +- All source files require copyright headers (managed by `Scripts/header.sh`) |
| 156 | + |
| 157 | +### Concurrency |
| 158 | +- All UI components are `@MainActor` isolated |
| 159 | +- Closures crossing actor boundaries must be `@Sendable` |
| 160 | +- Use `nonisolated` sparingly and only when necessary |
| 161 | + |
| 162 | +### Naming Conventions |
| 163 | +- Protocols use descriptive nouns (CodablePackage, ProgressOperation) |
| 164 | +- Generic type parameters use full words (FileType, ValueType) |
| 165 | +- Environment keys follow pattern: `<Action>Key` (NextPageKey, PreviousPageKey) |
| 166 | + |
| 167 | +## Testing |
| 168 | + |
| 169 | +Tests are located in `Tests/RadiantKitTests/`. The CI pipeline runs tests across: |
| 170 | +- Ubuntu (Swift 6.2, nightly 6.3) |
| 171 | +- Windows (Swift 6.2) |
| 172 | +- Android (Swift 6.1, 6.2, nightly-main) |
| 173 | +- macOS/iOS/tvOS/watchOS/visionOS simulators with Xcode 16.1, 16.4, and 26.2 |
| 174 | + |
| 175 | +When adding features: |
| 176 | +1. Add tests to RadiantKitTests targeting the appropriate module |
| 177 | +2. Ensure tests pass on both macOS and Linux (note: RadiantProgress uses swift-log on Linux) |
| 178 | +3. CI enforces strict code coverage requirements via Codecov |
| 179 | + |
| 180 | +## Platform Support |
| 181 | + |
| 182 | +Minimum deployment targets: |
| 183 | +- iOS 18.0 / iPadOS 18.0 |
| 184 | +- macOS 15.0 |
| 185 | +- tvOS 18.0 |
| 186 | +- watchOS 11.0 |
| 187 | +- visionOS 2.0 |
| 188 | +- Mac Catalyst 18.0 |
| 189 | + |
| 190 | +Platform-specific code should use `#if canImport()` or `#if os()` directives. |
| 191 | + |
| 192 | +## Adding New Modules |
| 193 | + |
| 194 | +If creating a new target: |
| 195 | +1. Add to `Package.swift` products and targets arrays |
| 196 | +2. Apply `swiftSettings` for experimental features |
| 197 | +3. Update module dependency graph (RadiantKit as foundation, others can depend on it) |
| 198 | +4. Add corresponding test target |
| 199 | +5. Update `.github/workflows/RadiantKit.yml` if platform-specific testing needed |
0 commit comments