|
| 1 | +# CLAUDE.md - WooCommerce Payments Repository Guide |
| 2 | + |
| 3 | +This file provides context about the WooCommerce Payments repository to help Claude Code assist more effectively. |
| 4 | + |
| 5 | +## Repository Overview |
| 6 | + |
| 7 | +WooCommerce Payments (WCPay) is a WordPress plugin that provides payment processing capabilities for WooCommerce stores. It's a complex project combining PHP backend code with a React-based admin interface. |
| 8 | + |
| 9 | +**Key Info:** |
| 10 | +- Plugin Name: WooPayments |
| 11 | +- License: GPL-3.0-or-later |
| 12 | +- Repository: github:Automattic/woocommerce-payments |
| 13 | + |
| 14 | +**Version & Requirements:** |
| 15 | +- See `woocommerce-payments.php` header for current version and WordPress/WooCommerce/PHP requirements |
| 16 | +- See `package.json` for Node.js version requirements (engines field) |
| 17 | + |
| 18 | +## Directory Structure |
| 19 | + |
| 20 | +### PHP Code |
| 21 | +- **`src/`** - Modern PHP code using PSR-4 autoloading and dependency injection |
| 22 | + - Uses a service `Container` for dependency injection |
| 23 | + - Preferred location for new PHP code |
| 24 | +- **`includes/`** - Legacy PHP codebase organized by feature |
| 25 | + - `admin/`, `payment-methods/`, `subscriptions/`, `multi-currency/`, etc. |
| 26 | + - Still actively used but prefer `src/` for new code |
| 27 | + |
| 28 | +### Frontend Code |
| 29 | +- **`client/`** - React/TypeScript frontend application |
| 30 | + - `components/` - Reusable UI components |
| 31 | + - `settings/`, `checkout/`, `onboarding/` - Feature areas |
| 32 | + - `data/` - Redux state management (@wordpress/data) |
| 33 | + - Uses React 18.3 and TypeScript |
| 34 | + |
| 35 | +### Tests |
| 36 | +- **`tests/unit/`** - PHP unit tests (PHPUnit) |
| 37 | +- **`tests/js/`** - JavaScript test configuration |
| 38 | +- **`tests/e2e/`** - End-to-end tests (Playwright) |
| 39 | +- JS tests are co-located with source files in `client/**/__tests__/` |
| 40 | + |
| 41 | +### Build & Config |
| 42 | +- **`webpack/`** - Modular webpack configuration (shared, production, development, HMR) |
| 43 | +- **`tasks/`** - Build and release automation |
| 44 | +- **`bin/`** - Helper scripts |
| 45 | +- **`docker/`** - Docker development environment |
| 46 | + |
| 47 | +## Technology Stack |
| 48 | + |
| 49 | +**Backend:** PHP, WordPress APIs, WooCommerce hooks, Composer |
| 50 | +**Frontend:** React, TypeScript, @wordpress/data (Redux), SCSS |
| 51 | +**Build:** Webpack, Babel, PostCSS, @wordpress/scripts |
| 52 | +**Testing:** PHPUnit, Jest, Playwright, React Testing Library |
| 53 | +**Quality:** ESLint, PHPCS, Psalm, TypeScript, Prettier |
| 54 | + |
| 55 | +*See `composer.json`, `package.json`, and `woocommerce-payments.php` for specific version requirements* |
| 56 | + |
| 57 | +## Common Commands |
| 58 | + |
| 59 | +### Development |
| 60 | +```bash |
| 61 | +npm install # Install dependencies |
| 62 | +npm start # Watch JS changes (alias: npm run watch) |
| 63 | +npm run hmr # Hot module replacement server |
| 64 | +npm run up # Start Docker environment |
| 65 | +npm run dev # Start Docker + watch mode |
| 66 | +``` |
| 67 | + |
| 68 | +### Testing |
| 69 | + |
| 70 | +**PHP Tests:** |
| 71 | +```bash |
| 72 | +# Standard approach |
| 73 | +npm run test:php # Run all PHP tests in Docker |
| 74 | +npm run test:php-watch # Watch mode |
| 75 | +npm run test:php-coverage # With coverage |
| 76 | +``` |
| 77 | + |
| 78 | +**JavaScript Tests:** |
| 79 | +```bash |
| 80 | +npm run test:js # Run all JS tests |
| 81 | +npm run test:watch # Watch mode |
| 82 | +npm run test:debug # Debug mode |
| 83 | +npm run test:update-snapshots # Update snapshots |
| 84 | +``` |
| 85 | + |
| 86 | +**E2E Tests:** |
| 87 | +```bash |
| 88 | +npm run test:e2e # Run E2E tests |
| 89 | +npm run test:e2e-ui # UI mode |
| 90 | +npm run test:e2e-up # Setup test environment |
| 91 | +npm run test:e2e-down # Teardown |
| 92 | +``` |
| 93 | + |
| 94 | +### Build & Quality |
| 95 | +```bash |
| 96 | +npm run build:client # Build production JS |
| 97 | +npm run build # Build release package |
| 98 | +npm run lint # Run all linters |
| 99 | +npm run lint:js # ESLint + TypeScript |
| 100 | +npm run lint:php # PHPCS |
| 101 | +npm run lint:php-fix # Auto-fix PHP issues |
| 102 | +npm run format # Format with Prettier |
| 103 | +npm run psalm # PHP static analysis |
| 104 | +``` |
| 105 | + |
| 106 | +### Other |
| 107 | +```bash |
| 108 | +npm run changelog # Add changelog entry |
| 109 | +npm run i18n:pot # Generate translations |
| 110 | +``` |
| 111 | + |
| 112 | +## Development Workflows |
| 113 | + |
| 114 | +### Code Organization |
| 115 | +- **New PHP code:** Use `src/` with dependency injection |
| 116 | +- **Legacy PHP:** Lives in `includes/`, prefer refactoring to `src/` |
| 117 | +- **Frontend:** React components in `client/` with TypeScript |
| 118 | +- **Tests:** Mirror source structure in `tests/unit/` for PHP |
| 119 | + |
| 120 | +### Testing Conventions |
| 121 | +- PHP tests use PHPUnit and follow WordPress testing practices |
| 122 | +- JS tests use Jest with @wordpress/scripts preset |
| 123 | +- Co-locate JS tests with source files or in `__tests__/` directories |
| 124 | +- PHP tests run in Docker via `npm run test:php` (see `bin/run-tests.sh`) |
| 125 | + |
| 126 | +### Git Workflow |
| 127 | +- Main branch for PRs: `develop` |
| 128 | +- Release branch: `trunk` |
| 129 | +- Husky manages git hooks |
| 130 | +- **Before creating a PR:** |
| 131 | + - Must run `npm run changelog add` and commit the changelog entry (choose 'patch' if change is not significant) |
| 132 | + - Changelog must be committed and pushed before creating the PR |
| 133 | +- Use PR template from `.github/PULL_REQUEST_TEMPLATE.md` when creating pull requests |
| 134 | + - Include testing instructions |
| 135 | + - Check mobile testing requirement |
| 136 | + - Link to release testing docs post-merge |
| 137 | + |
| 138 | +### Docker Environment |
| 139 | +- WordPress: http://localhost:8082 |
| 140 | +- phpMyAdmin: http://localhost:8083 |
| 141 | +- MySQL: localhost:5678 |
| 142 | +- Xdebug ready (requires IDE path mapping) |
| 143 | + |
| 144 | +### Dependency Management |
| 145 | +- WordPress dependencies extracted automatically via webpack plugin |
| 146 | +- External packages added via `requestToExternal` and `requestToHandle` in webpack.config.js |
| 147 | +- Use Composer for PHP dependencies |
| 148 | +- Use npm for JavaScript dependencies |
| 149 | + |
| 150 | +### Changelog |
| 151 | +- Use `npm run changelog` to add entries |
| 152 | +- Types: Add, Fix, Update, Dev |
| 153 | +- Entries go in `changelog/` directory |
| 154 | + |
| 155 | +## Important Configuration Files |
| 156 | + |
| 157 | +| File | Purpose | |
| 158 | +|------|---------| |
| 159 | +| `package.json` | npm scripts and dependencies | |
| 160 | +| `composer.json` | PHP dependencies and autoloading | |
| 161 | +| `webpack.config.js` | Main webpack entry | |
| 162 | +| `phpunit.xml.dist` | PHPUnit configuration | |
| 163 | +| `phpcs.xml.dist` | PHP coding standards | |
| 164 | +| `tests/js/jest.config.js` | Jest configuration | |
| 165 | +| `tests/e2e/playwright.config.ts` | E2E test config | |
| 166 | +| `tsconfig.json` | TypeScript configuration | |
| 167 | +| `.eslintrc` | ESLint rules | |
| 168 | + |
| 169 | +## Version Support Policy |
| 170 | +- WordPress: Strict L-2 (supports current and 2 previous major versions) |
| 171 | +- WooCommerce: Loose L-2 |
| 172 | +- See `docs/version-support-policy.md` for details |
| 173 | + |
| 174 | +## Documentation |
| 175 | +- `README.md` - Main setup and overview |
| 176 | +- `CONTRIBUTING.md` - Contribution guidelines |
| 177 | +- `tests/README.md` - Testing guide |
| 178 | +- `docker/README.md` - Docker setup |
| 179 | +- `includes/core/README.md` - Extensibility docs |
| 180 | +- `docs/` - Additional documentation |
| 181 | + |
| 182 | +## Tips for Claude |
| 183 | +- Prefer editing existing files over creating new ones |
| 184 | +- Check both `src/` and `includes/` when searching for PHP code |
| 185 | +- React components follow WordPress coding patterns (@wordpress packages) |
| 186 | +- Test files mirror source structure |
| 187 | +- PHP tests require Docker - ensure it's running before executing tests |
| 188 | +- Use `npm run test:php` to run all tests or edit the command to pass PHPUnit filters |
0 commit comments