|
| 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 | +BEAR.FastlyModule is a PHP library providing Fastly CDN integration for the BEAR.Sunday framework. It implements cache purging functionality through Fastly's API using a dependency injection module pattern. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Testing and Quality Assurance |
| 12 | +- `composer test` - Run PHPUnit tests |
| 13 | +- `composer coverage` - Generate test coverage with Xdebug |
| 14 | +- `composer pcov` - Generate coverage with PCOV extension |
| 15 | +- `composer cs` - Check coding standards (PHP_CodeSniffer) |
| 16 | +- `composer cs-fix` - Fix coding standards violations |
| 17 | +- `composer sa` - Run static analysis (PHPStan + Psalm) |
| 18 | +- `composer metrics` - Generate code metrics report |
| 19 | + |
| 20 | +### Composite Commands |
| 21 | +- `composer tests` - Full QA suite (coding standards + static analysis + tests) |
| 22 | +- `composer build` - Complete build process (clean + cs + sa + coverage + metrics) |
| 23 | +- `composer clean` - Clear analysis caches |
| 24 | + |
| 25 | +## Architecture |
| 26 | + |
| 27 | +### Core Design Patterns |
| 28 | +- **Dependency Injection**: Uses Ray.Di container with modules extending `AbstractModule` |
| 29 | +- **Interface-Based Design**: `FastlyCachePurgerInterface` with concrete `FastlyCachePurger` implementation |
| 30 | +- **Module Composition**: `FastlyPurgeModule` (core) + `FastlyEnableSoftPurgeModule` (feature toggle) |
| 31 | +- **Callable Objects**: Cache purger implements `__invoke()` for functional interface |
| 32 | + |
| 33 | +### Key Components |
| 34 | +- `FastlyCachePurger`: Main purging implementation with `__invoke(string $tag)` |
| 35 | +- `PurgeApi`: Fastly SDK wrapper for API communication |
| 36 | +- DI Attributes: `#[ServiceId]`, `#[SoftPurge]`, `#[FastlyApi]` for dependency qualification |
| 37 | + |
| 38 | +### Module Structure |
| 39 | +``` |
| 40 | +src/ |
| 41 | +βββ Attribute/ # DI qualifier attributes |
| 42 | +βββ Exception/ # Custom exceptions |
| 43 | +βββ FastlyPurgeModule.php # Main DI module |
| 44 | +βββ FastlyEnableSoftPurgeModule.php # Soft purge feature module |
| 45 | +βββ FastlyCachePurgerInterface.php # Core contract |
| 46 | +βββ FastlyCachePurger.php # Implementation |
| 47 | +``` |
| 48 | + |
| 49 | +### Testing Structure |
| 50 | +- **Test Doubles**: Extensive fakes in `tests/Fake/` |
| 51 | +- **Integration Tests**: Uses actual DI container with module bindings |
| 52 | +- **Fake Application**: Complete BEAR.Sunday app in `tests/Fake/fake-app/` |
| 53 | +- **Module Override Pattern**: `$module->override(new FakeFastlyPurgeModule())` for testing |
| 54 | + |
| 55 | +## PHP Requirements |
| 56 | +- **PHP 8.0+** (uses modern attributes) |
| 57 | +- **Strict Types**: All files use `declare(strict_types=1)` |
| 58 | +- **Maximum Static Analysis**: PHPStan level max, Psalm strict mode |
| 59 | + |
| 60 | +## Development Workflow |
| 61 | +1. Write tests first using fake modules for isolation |
| 62 | +2. Run `composer cs-fix` to fix coding standards |
| 63 | +3. Run `composer sa` for static analysis |
| 64 | +4. Run `composer test` for full test suite |
| 65 | +5. Use `composer build` for complete verification before commits |
| 66 | + |
| 67 | +## Integration Points |
| 68 | +- **BEAR.Sunday**: Integrates with resource caching via `Header::SURROGATE_KEY` |
| 69 | +- **Fastly SDK**: Supports versions 1.0-5.0 with flexible HTTP client configuration |
| 70 | +- **DI Container**: Ray.Di with attribute-based dependency qualification |
0 commit comments