alexandrebulete/ddd-foundation

Pure PHP DDD Foundation - Domain, Application, and InMemory infrastructure for building DDD projects

Installs: 0

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/alexandrebulete/ddd-foundation

1.0.0 2025-12-20 17:40 UTC

This package is auto-updated.

Last update: 2025-12-20 17:42:15 UTC


README

Pure PHP DDD Foundation for building Domain-Driven Design projects. This package provides the core building blocks: Domain layer (ValueObjects, Repository interfaces, Exceptions), Application layer (Command/Query/Handler), and InMemory infrastructure for testing.

Installation

composer require alexandrebulete/ddd-foundation

Structure

src/
├── Domain/
│   ├── Exception/
│   │   └── EntityNotFoundException.php
│   ├── Repository/
│   │   ├── PaginatorInterface.php
│   │   └── RepositoryInterface.php
│   └── ValueObject/
│       ├── DatetimeVO.php
│       ├── IdentifierInterface.php
│       ├── IdentifierVO.php
│       └── StringVO.php
├── Application/
│   ├── Command/
│   │   ├── AsCommandHandler.php
│   │   ├── CommandBusInterface.php
│   │   └── CommandInterface.php
│   ├── Handler/
│   │   ├── QueryCollectionHandler.php
│   │   └── QuerySingleHandler.php
│   └── Query/
│       ├── AsQueryHandler.php
│       ├── QueryBusInterface.php
│       └── QueryInterface.php
└── Infrastructure/
    └── InMemory/
        ├── InMemoryPaginator.php
        └── InMemoryRepository.php

Usage

Value Objects

use AlexandreBulete\DddFoundation\Domain\ValueObject\IdentifierVO;
use AlexandreBulete\DddFoundation\Domain\ValueObject\StringVO;

// Generate a new identifier
$id = IdentifierVO::generate();

// Create from string
$id = IdentifierVO::fromString('01HZXYZ...');

// String value object
$title = StringVO::fromString('My Title');

Repository Interface

use AlexandreBulete\DddFoundation\Domain\Repository\RepositoryInterface;

class PostRepository implements RepositoryInterface
{
    // Implement the interface methods
}

Command/Query Bus

use AlexandreBulete\DddFoundation\Application\Command\CommandInterface;
use AlexandreBulete\DddFoundation\Application\Command\AsCommandHandler;

// Define a command
readonly class CreatePostCommand implements CommandInterface
{
    public function __construct(
        public string $title,
        public string $content,
    ) {}
}

// Define a handler
#[AsCommandHandler]
readonly class CreatePostHandler
{
    public function __invoke(CreatePostCommand $command): void
    {
        // Handle the command
    }
}

Related Packages

Bridges (pure PHP, no framework dependency)

  • alexandrebulete/ddd-doctrine-bridge - Doctrine ORM integration
  • alexandrebulete/ddd-apiplatform-bridge - API Platform integration

Bundles (Symfony integration)

  • alexandrebulete/ddd-symfony-bundle - Symfony Messenger integration
  • alexandrebulete/ddd-doctrine-bundle - Doctrine bundle for Symfony
  • alexandrebulete/ddd-apiplatform-bundle - API Platform bundle for Symfony
  • alexandrebulete/ddd-sylius-bundle - Sylius Stack integration