|
6 | 6 |
|
7 | 7 | Common interfaces for PHP Complex Heart SDK. |
8 | 8 |
|
9 | | -## Domain Modeling |
10 | | - |
11 | | -- Aggregate |
12 | | -- Entity |
13 | | -- ValueObject |
14 | | -- Identity |
15 | | - |
16 | | -## Service Bus |
17 | | - |
18 | | -- ServiceBus |
19 | | -- Command |
20 | | -- CommandBus |
21 | | -- CommandHandler |
22 | | -- Event |
23 | | -- EventBus |
24 | | -- EventHandler |
25 | | -- Query |
26 | | -- QueryBus |
27 | | -- QueryHandler |
28 | | -- QueryResponse |
| 9 | +## Domain Layer |
| 10 | + |
| 11 | +### Model |
| 12 | +Core building blocks for domain-driven design: |
| 13 | +- **Aggregate** - Root entity with domain event publishing |
| 14 | +- **Entity** - Domain object with unique identity |
| 15 | +- **ValueObject** - Immutable domain value with equality |
| 16 | +- **Identifier** - Unique identifier representation |
| 17 | + |
| 18 | +### Events |
| 19 | +Domain event interfaces following ISP (Interface Segregation Principle): |
| 20 | +- **Event** - Base domain event (eventId, eventName, payload, occurredOn) |
| 21 | +- **Traceable** - Distributed tracing (correlationId, causationId) |
| 22 | +- **Sourceable** - Event sourcing (aggregateId, aggregateType, eventVersion) |
| 23 | +- **EventBus** - Publishes domain events |
| 24 | + |
| 25 | +## Application Layer |
| 26 | + |
| 27 | +### Command |
| 28 | +Write operations (CQRS): |
| 29 | +- **Command** - Marker interface for state-changing operations |
| 30 | +- **CommandBus** - Dispatches commands to handlers |
| 31 | +- **CommandHandler** - Executes commands |
| 32 | + |
| 33 | +### Query |
| 34 | +Read operations (CQRS): |
| 35 | +- **Query** - Marker interface for data retrieval |
| 36 | +- **QueryResponse** - Marker interface for query results |
| 37 | +- **QueryBus** - Routes queries to handlers |
| 38 | +- **QueryHandler** - Executes queries and returns responses |
| 39 | + |
| 40 | +### Handler |
| 41 | +Event handlers: |
| 42 | +- **EventHandler** - Reacts to domain events |
| 43 | + |
| 44 | +### Service Bus |
| 45 | +Unified message bus facade: |
| 46 | +- **ServiceBus** - Provides access to CommandBus, QueryBus, and EventBus |
| 47 | + |
| 48 | +## Architecture |
| 49 | + |
| 50 | +This library follows Clean Architecture principles with explicit layer separation: |
| 51 | +- **Domain → Application** - Domain layer is independent, Application depends on Domain |
| 52 | +- **Layer-Explicit Namespaces** - Clear architectural boundaries in namespace structure |
| 53 | +- **Interface Segregation** - Compose only needed capabilities (e.g., Event + Traceable + Sourceable) |
| 54 | + |
| 55 | +### Architecture Testing |
| 56 | + |
| 57 | +The project includes automated architecture tests using Pest PHP: |
| 58 | + |
| 59 | +```bash |
| 60 | +composer test |
| 61 | +``` |
| 62 | + |
| 63 | +Tests enforce: |
| 64 | +- Domain layer independence (no Application dependencies) |
| 65 | +- Correct interface placement and usage |
| 66 | +- Clean Architecture dependency rules |
| 67 | +- PHP and security best practices (via arch presets) |
0 commit comments