|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Creating a pull request |
| 6 | + |
| 7 | +1. Strictly follow the format in `.github/PULL_REQUEST_TEMPLATE.md` file |
| 8 | +2. Fill in PR description with a similar writing style to the author's PRs in May |
| 9 | +3. Add `For WOOMOB-###` based on the branch name at the beginning |
| 10 | +4. Add `Just one review is required.` under the For WOOMOB-###` above |
| 11 | +5. Don't include `🤖 Generated with Claude Code / Co-Authored-By: Claude [email protected]` etc. |
| 12 | +6. Use "merchants" instead of "users" in PR description |
| 13 | + |
| 14 | + |
| 15 | +## WooCommerce iOS Architecture |
| 16 | + |
| 17 | +This is a modular iOS application built with Swift that follows a clean architecture pattern with clear separation of concerns across multiple frameworks: |
| 18 | + |
| 19 | +### Core Architecture Layers |
| 20 | + |
| 21 | +1. **WooCommerce (Main App)** - UI and app-specific business logic |
| 22 | +2. **Yosemite.framework** - Business logic layer using Action/Store pattern (similar to Flux), but modern use cases have been using service pattern that enables async/await support that Action/Store enum cannot. |
| 23 | +3. **Networking** (`Modules/Sources/Networking`) - REST API client for WooCommerce endpoints. Ideally using async throws interface. |
| 24 | +4. **Storage.framework** - CoreData abstraction layer |
| 25 | +5. **Hardware.framework** - External hardware integrations (card readers, printers) |
| 26 | +6. **Experiments.framework** - Feature flag and A/B testing system |
| 27 | + |
| 28 | +### Key Patterns |
| 29 | + |
| 30 | +- **Immutable ReadOnly Entities**: The main app only accesses ReadOnly versions of data models |
| 31 | +- **Action/Store Pattern**: Business logic is handled through Actions dispatched to Stores |
| 32 | +- **Service Locator**: Global dependencies accessed via `ServiceLocator` class. But generally we want to only use Service Locator dependencies when necessary. |
| 33 | +- **Dependency Injection**: Constructor injection preferred over service locator where possible |
| 34 | + |
| 35 | +## Essential Commands |
| 36 | + |
| 37 | +### Setup and Dependencies |
| 38 | +```bash |
| 39 | +# Initial setup - installs Ruby deps and third-party dependencies |
| 40 | +bundle install && bundle exec rake dependencies |
| 41 | + |
| 42 | +# Install/update dependencies only |
| 43 | +rake dependencies |
| 44 | +``` |
| 45 | + |
| 46 | +### Building |
| 47 | +```bash |
| 48 | +# Standard build |
| 49 | +rake build |
| 50 | + |
| 51 | +# Clean build |
| 52 | +rake clean |
| 53 | + |
| 54 | +# Build for App Store |
| 55 | +bundle exec fastlane build_for_app_store_connect |
| 56 | +``` |
| 57 | + |
| 58 | +### Testing |
| 59 | +```bash |
| 60 | +# Run all tests |
| 61 | +rake test |
| 62 | + |
| 63 | +# Run specific test suites (without building) |
| 64 | +bundle exec fastlane test_without_building name:UITests |
| 65 | +bundle exec fastlane test_without_building name:UnitTests |
| 66 | + |
| 67 | +# Build for testing (creates .xctestrun files) |
| 68 | +bundle exec fastlane build_for_testing |
| 69 | +``` |
| 70 | + |
| 71 | +### Linting and Code Quality |
| 72 | +```bash |
| 73 | +# Run SwiftLint |
| 74 | +rake lint |
| 75 | + |
| 76 | +# Auto-fix linting issues |
| 77 | +rake lint:autocorrect |
| 78 | + |
| 79 | +# Run code generation tasks |
| 80 | +rake generate |
| 81 | +``` |
| 82 | + |
| 83 | +## Project Structure |
| 84 | + |
| 85 | +- **WooCommerce.xcworkspace** - Main workspace file (use this to open project) |
| 86 | +- **Modules/** - Swift Package with modular components (Networking, TestKit, etc.) |
| 87 | +- **WooCommerce/** - Main iOS app target |
| 88 | +- **Yosemite/** - Business logic framework |
| 89 | +- **Storage/** - CoreData abstraction framework |
| 90 | +- **Hardware/** - Hardware integration framework |
| 91 | +- **Networking/** - Legacy networking framework (being migrated to Modules) |
| 92 | +- **Fakes/** - Test fakes and mocks |
| 93 | +- **BuildTools/** - Swift Package for build tooling (SwiftLint, Sourcery) |
| 94 | + |
| 95 | +## Test Configuration |
| 96 | + |
| 97 | +The project uses Xcode Test Plans (.xctestplan files) for organizing different test suites: |
| 98 | + |
| 99 | +- **UnitTests.xctestplan** - Main app unit tests |
| 100 | +- **UITests.xctestplan** - UI/integration tests |
| 101 | +- **NetworkingTests.xctestplan** - Networking layer tests |
| 102 | +- **WooFoundation.xctestplan** - Foundation utilities tests |
| 103 | +- **Experiments.xctestplan** - Feature flag tests |
| 104 | + |
| 105 | +## Code Generation |
| 106 | + |
| 107 | +The project uses Sourcery for code generation: |
| 108 | +- Run `rake generate` to generate Copiable, Fakeable, and other protocol implementations |
| 109 | +- Code generation is configured in `BuildTools/.sourcery.yml` |
| 110 | + |
| 111 | +## Authentication Setup |
| 112 | + |
| 113 | +For external contributors, API credentials need to be configured: |
| 114 | +1. Create WordPress.com developer app at https://developer.wordpress.com/apps/ |
| 115 | +2. Fill in generated `WooCommerce/DerivedSources/ApiCredentials.swift` with Client ID and Secret |
| 116 | +3. Never commit these credentials |
| 117 | + |
| 118 | +## Key Development Notes |
| 119 | + |
| 120 | +- The app follows Swift 5.7+ and requires Xcode 14+ |
| 121 | +- Uses Ruby tooling managed via Bundler - always run commands with `bundle exec` |
| 122 | +- SwiftLint configuration is extensive with custom rules for localization and UI |
| 123 | +- The project uses Fastlane for build automation and deployment |
| 124 | +- CoreData models should be updated through the Model Editor, not manually |
| 125 | +- All network requests go through the Networking layer - never make direct URLSession calls from the main app |
| 126 | +- UI components should only interact with Yosemite.framework, not Storage or Networking directly |
| 127 | + |
| 128 | +## Modular Architecture Benefits |
| 129 | + |
| 130 | +- **Testability**: Each layer can be tested independently with mocks |
| 131 | +- **Thread Safety**: Immutable ReadOnly entities prevent CoreData threading issues |
| 132 | +- **Separation of Concerns**: Clear boundaries between UI, business logic, storage, and networking |
| 133 | +- **Reusability**: Frameworks can be shared across targets and extensions |
| 134 | + |
| 135 | +## Formatting code |
| 136 | + |
| 137 | +- Lines should not have trailing whitespace |
| 138 | + |
| 139 | +## Build Guidelines |
| 140 | + |
| 141 | +- **DO NOT** use `xcodebuild` commands directly to build or test the project |
| 142 | +- Always use the provided rake commands instead: |
| 143 | + - Use `rake build` for building |
| 144 | + - Use `rake test` for testing |
| 145 | + - Use `rake lint` for linting |
| 146 | +- The project build system is complex and requires proper setup through rake/fastlane |
| 147 | +- Direct xcodebuild usage may fail due to missing dependencies or incorrect configurations |
0 commit comments