Skip to content

Commit 2cbbe87

Browse files
committed
Refactor/Update namespaces and interfaces for clarity and consistency
1 parent 9e7549a commit 2cbbe87

25 files changed

+176
-107
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ on:
88

99
jobs:
1010
test:
11+
name: Test on PHP ${{ matrix.php-version }}
1112
runs-on: ubuntu-latest
1213

1314
strategy:
1415
matrix:
15-
php-version: [ '8.1', '8.2', '8.3' ]
16+
php-version: [ '8.2', '8.3', '8.4' ]
1617

1718
steps:
1819
- name: Checkout source code
@@ -28,7 +29,7 @@ jobs:
2829
tools: composer:v2
2930

3031
- name: Cache dependencies
31-
uses: actions/cache@v2
32+
uses: actions/cache@v4.3.0
3233
with:
3334
path: ~/.composer/cache
3435
key: php-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
@@ -37,9 +38,15 @@ jobs:
3738
- name: Validate composer.json and composer.lock
3839
run: composer validate
3940

40-
- name: Install dependencies
41+
- name: Install Dependencies
4142
if: steps.composer-cache.outputs.cache-hit != 'true'
42-
run: composer install --prefer-dist --no-progress --no-suggest
43+
run: composer install --prefer-dist --no-progress
44+
45+
- name: Check Code Style
46+
run: composer pint-test
4347

4448
- name: Execute Static Code analysis
45-
run: composer analyse
49+
run: composer analyse
50+
51+
- name: Execute Unit, Integration and Acceptance Tests
52+
run: composer test

.gitignore

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
composer.phar
22
/vendor/
33
.idea/
4-
/infrastructure
4+
/infrastructure/
5+
/coverage/
56
*[N|n]o[G|g]it*
6-
*coverage*
7+
coverage.xml
8+
test.xml
79
.phpunit.result.cache
810
composer.lock
11+
wiki/Home.md
12+
/.phpunit.cache
13+
.phpactor.json
14+
/.serena/

README.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,48 @@ Domain event interfaces following ISP (Interface Segregation Principle):
2020
- **Event** - Base domain event (eventId, eventName, payload, occurredOn)
2121
- **Traceable** - Distributed tracing (correlationId, causationId)
2222
- **Sourceable** - Event sourcing (aggregateId, aggregateType, eventVersion)
23+
- **EventBus** - Publishes domain events
2324

2425
## Application Layer
2526

2627
### Command
2728
Write operations (CQRS):
2829
- **Command** - Marker interface for state-changing operations
30+
- **CommandBus** - Dispatches commands to handlers
31+
- **CommandHandler** - Executes commands
2932

3033
### Query
3134
Read operations (CQRS):
3235
- **Query** - Marker interface for data retrieval
3336
- **QueryResponse** - Marker interface for query results
37+
- **QueryBus** - Routes queries to handlers
38+
- **QueryHandler** - Executes queries and returns responses
3439

3540
### Handler
36-
Message handlers:
37-
- **CommandHandler** - Executes commands
38-
- **QueryHandler** - Executes queries and returns responses
41+
Event handlers:
3942
- **EventHandler** - Reacts to domain events
4043

41-
### Messaging
42-
Message bus implementations:
43-
- **CommandBus** - Dispatches commands
44-
- **QueryBus** - Asks queries
45-
- **EventBus** - Publishes events
46-
- **ServiceBus** - Unified bus facade
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)

composer.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,29 @@
1111
],
1212
"minimum-stability": "stable",
1313
"require": {
14-
"php": "^8.1"
14+
"php": "^8.2"
1515
},
1616
"require-dev": {
1717
"phpstan/phpstan": "^1.0",
1818
"phpstan/extension-installer": "^1.3",
19-
"laravel/pint": "^1.25"
19+
"laravel/pint": "^1.25",
20+
"pestphp/pest": "^3.8.4",
21+
"pestphp/pest-plugin-arch": "^3.1.1"
2022
},
2123
"autoload": {
2224
"psr-4": {
2325
"ComplexHeart\\": "src/"
2426
}
2527
},
2628
"scripts": {
27-
"analyse": "vendor/bin/phpstan analyse src --no-progress --level=9",
28-
"pint": "vendor/bin/pint --preset psr12"
29+
"test": "vendor/bin/pest --configuration=phpunit.xml --coverage --coverage-clover=coverage.xml --log-junit=test.xml",
30+
"analyse": "vendor/bin/phpstan analyse src --no-progress --memory-limit=4G --level=9",
31+
"pint-test": "vendor/bin/pint --preset=psr12 --test",
32+
"pint": "vendor/bin/pint --preset=psr12"
2933
},
3034
"config": {
3135
"allow-plugins": {
36+
"pestphp/pest-plugin": true,
3237
"phpstan/extension-installer": true
3338
}
3439
}

phpunit.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
bootstrap="vendor/autoload.php"
4+
colors="true"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
6+
cacheDirectory=".phpunit.cache">
7+
<coverage>
8+
<report>
9+
<clover outputFile="./coverage.xml"/>
10+
</report>
11+
</coverage>
12+
<testsuites>
13+
<testsuite name="unit">
14+
<directory>./tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<logging/>
18+
<source>
19+
<include>
20+
<directory suffix=".php">./src</directory>
21+
</include>
22+
</source>
23+
</phpunit>

src/Application/Command/Command.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
* Commands represent the intention to change the system state.
1212
*
1313
* @author Unay Santisteban <usantisteban@othercode.io>
14-
* @package ComplexHeart\Application\Command
1514
*/
1615
interface Command
1716
{

src/Application/Messaging/CommandBus.php renamed to src/Application/Command/CommandBus.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@
22

33
declare(strict_types=1);
44

5-
namespace ComplexHeart\Application\Messaging;
6-
7-
use ComplexHeart\Application\Command\Command;
5+
namespace ComplexHeart\Application\Command;
86

97
/**
108
* Interface CommandBus
119
*
1210
* @author Unay Santisteban <usantisteban@othercode.io>
13-
* @package ComplexHeart\Application\Messaging
1411
*/
1512
interface CommandBus
1613
{
1714
/**
1815
* Dispatch the given command.
19-
*
20-
* @param Command $command
2116
*/
2217
public function dispatch(Command $command): void;
2318
}

src/Application/Handler/CommandHandler.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@
1010
* Interface CommandHandler
1111
*
1212
* @author Unay Santisteban <usantisteban@othercode.io>
13-
* @package ComplexHeart\Application\Handler
1413
*/
1514
interface CommandHandler
1615
{
1716
/**
1817
* Handle the command execution.
19-
*
20-
* @param Command $command
2118
*/
2219
public function __invoke(Command $command): void;
2320
}

src/Application/Handler/EventHandler.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@
1010
* Interface EventHandler
1111
*
1212
* @author Unay Santisteban <usantisteban@othercode.io>
13-
* @package ComplexHeart\Application\Handler
1413
*/
1514
interface EventHandler
1615
{
1716
/**
1817
* Handle the event execution.
19-
*
20-
* @param Event $event
2118
*/
2219
public function __invoke(Event $event): void;
2320
}

src/Application/Handler/QueryHandler.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@
1111
* Interface QueryHandler
1212
*
1313
* @author Unay Santisteban <usantisteban@othercode.io>
14-
* @package ComplexHeart\Application\Handler
1514
*/
1615
interface QueryHandler
1716
{
1817
/**
1918
* Handle the query execution.
20-
*
21-
* @param Query $query
22-
*
23-
* @return QueryResponse
2419
*/
2520
public function __invoke(Query $query): QueryResponse;
2621
}

0 commit comments

Comments
 (0)