|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +### Testing |
| 8 | +```bash |
| 9 | +# Run all tests |
| 10 | +vendor/bin/phpunit |
| 11 | + |
| 12 | +# Run tests with coverage |
| 13 | +vendor/bin/phpunit --coverage-html coverage |
| 14 | + |
| 15 | +# Run a specific test |
| 16 | +vendor/bin/phpunit tests/Adapters/PrestaShopAdapterTest.php |
| 17 | +``` |
| 18 | + |
| 19 | +### Code Quality |
| 20 | +```bash |
| 21 | +# Run PHPStan static analysis |
| 22 | +vendor/bin/phpstan analyse |
| 23 | + |
| 24 | +# Run PHP CodeSniffer |
| 25 | +vendor/bin/phpcs src tests |
| 26 | + |
| 27 | +# Install dependencies |
| 28 | +composer install |
| 29 | + |
| 30 | +# Update dependencies |
| 31 | +composer update |
| 32 | +``` |
| 33 | + |
| 34 | +## Code Architecture |
| 35 | + |
| 36 | +### Core SDK Structure |
| 37 | +The PHP SDK for Brad Search synchronization is organized into a modular architecture: |
| 38 | + |
| 39 | +- **`SynchronizationApiSdk`** - Main SDK class providing the public API for index management and product synchronization |
| 40 | +- **Field Configuration System** - Type-safe field definitions using PHP enums and configuration builders |
| 41 | +- **Validation Layer** - Comprehensive data validation against field configurations before API calls |
| 42 | +- **HTTP Client** - cURL-based client with error handling and authentication |
| 43 | +- **Exception Hierarchy** - Typed exceptions for different error scenarios |
| 44 | + |
| 45 | +### Key Components |
| 46 | + |
| 47 | +#### SynchronizationApiSdk (src/SynchronizationApiSdk.php) |
| 48 | +Main entry point providing methods: |
| 49 | +- `createIndex()` / `deleteIndex()` - Index management |
| 50 | +- `sync()` / `syncBulk()` - Product synchronization (single and batch) |
| 51 | +- `copyIndex()` - Index replication |
| 52 | +- `deleteProductsBulk()` - Bulk product deletion |
| 53 | +- `validateProduct()` / `validateProducts()` - Data validation without syncing |
| 54 | + |
| 55 | +#### Field Configuration (src/Models/) |
| 56 | +- **`FieldConfig`** - Individual field configuration with type and attributes |
| 57 | +- **`FieldConfigBuilder`** - Helper for building common field configurations |
| 58 | +- **`FieldType` enum** - Defines supported field types (TEXT_KEYWORD, HIERARCHY, VARIANTS, etc.) |
| 59 | + |
| 60 | +#### Validation System (src/Validators/) |
| 61 | +- **`DataValidator`** - Validates product data against field configuration |
| 62 | +- Supports all field types including hierarchical categories, variants with attributes, and URL validation |
| 63 | +- Provides detailed error reporting |
| 64 | + |
| 65 | +#### HTTP Layer (src/Client/) |
| 66 | +- **`HttpClient`** - Handles API communication with authentication, timeouts, and error handling |
| 67 | +- Supports all HTTP methods (GET, POST, PUT, DELETE) with JSON encoding |
| 68 | + |
| 69 | +### API Endpoints |
| 70 | +The SDK communicates with these endpoints: |
| 71 | +- `DELETE /api/v1/sync/{index}` - Delete index |
| 72 | +- `PUT /api/v1/sync/` - Create index with field configuration |
| 73 | +- `POST /api/v1/sync/` - Bulk sync products |
| 74 | +- `POST /api/v1/sync/reindex` - Copy/reindex operations |
| 75 | +- `POST /api/v1/sync/delete-products` - Bulk delete products |
| 76 | + |
| 77 | +### Field Types Supported |
| 78 | +- `TEXT_KEYWORD` - Full-text search with keyword matching |
| 79 | +- `TEXT` - Full-text search only |
| 80 | +- `KEYWORD` - Exact keyword matching |
| 81 | +- `HIERARCHY` - Hierarchical categories (e.g., "Clothing > T-Shirts > Premium") |
| 82 | +- `VARIANTS` - Product variants with configurable attributes |
| 83 | +- `NAME_VALUE_LIST` - Key-value pairs (features, specifications) |
| 84 | +- `IMAGE_URL` - Image URLs object with size keys |
| 85 | +- `URL` - Regular URLs with validation |
| 86 | +- `FLOAT`, `INTEGER`, `DOUBLE` - Numeric types |
| 87 | + |
| 88 | +### Data Processing |
| 89 | +- **Field Filtering** - Only configured fields are sent to API |
| 90 | +- **Batch Processing** - Large datasets automatically chunked (default 100 items per batch) |
| 91 | +- **Validation First** - All products validated before any API calls |
| 92 | +- **Embeddable Fields** - Support for localized fields with configurable locales |
| 93 | + |
| 94 | +### PrestaShop Integration |
| 95 | +The SDK includes a PrestaShop adapter (`src/Adapters/PrestaShopAdapter.php`) for e-commerce platform integration, handling product data mapping and synchronization specific to PrestaShop's data structure. |
| 96 | + |
| 97 | +### Dependencies |
| 98 | +- **PHP 8.4+** - Uses modern PHP features (readonly properties, enums, constructor property promotion) |
| 99 | +- **ext-json** - JSON encoding/decoding |
| 100 | +- **ext-curl** - HTTP client functionality |
| 101 | +- **PHPUnit** - Testing framework |
| 102 | +- **PHPStan** - Static analysis |
| 103 | +- **PHP CodeSniffer** - Code style enforcement |
0 commit comments