feat(core): Implement DDD, CQRS, and Event Sourcing architecture

- Add project README and Composer configuration with PSR-4 autoloading
- Implement domain layer with AggregateRoot base class for event sourcing
- Create Carrier aggregate with CarrierRegistered domain event
- Add application layer with RegisterCarrierCommand and RegisterCarrierHandler
- Implement infrastructure layer with EventStore interface and CassandraEventStore
- Add CommandBus and Router for request handling and routing
- Create demo test file to showcase carrier registration workflow
- Establish foundation for event-driven architecture with Cassandra persistence
This commit is contained in:
m.jalmoudy
2025-12-02 14:58:22 +03:30
parent d963da40e1
commit 6b5222ad84
13 changed files with 406 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use DistributingCarriers\Infrastructure\CommandBus;
use DistributingCarriers\Infrastructure\Router;
use DistributingCarriers\Infrastructure\CassandraEventStore;
use DistributingCarriers\Application\Commands\RegisterCarrierCommand;
use DistributingCarriers\Application\Handlers\RegisterCarrierHandler;
// Initialize Infrastructure
// Note: In a real app, you'd configure the Cassandra session here.
// For this demo, we'll mock it or assume it's passed in.
// Since we don't have a running Cassandra instance we can connect to easily without extension,
// we will assume the $session is created.
// $cluster = Cassandra::cluster()->build();
// $session = $cluster->connect('distributing_carriers');
// Mocking session for demonstration if extension is missing, or just placeholder.
$session = null; // Placeholder
$eventStore = new CassandraEventStore($session);
$commandBus = new CommandBus();
// Register Handlers
$commandBus->register(RegisterCarrierCommand::class, new RegisterCarrierHandler($eventStore));
// Router
$router = new Router();
$router->add('POST', '/register-carrier', function () use ($commandBus) {
// In a real app, parse body.
// For demo, we'll just create a dummy command.
$command = new RegisterCarrierCommand("Test Carrier", "test@example.com");
$commandBus->dispatch($command);
});
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
$uri = $_SERVER['REQUEST_URI'] ?? '/';
$router->dispatch($method, $uri);