A reusable, extensible, and production-ready notification system for PHP
dev-main
2026-07-04 22:10 UTC
Requires
- php: ^8.3
- monolog/monolog: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2026-07-04 22:23:36 UTC
README
A reusable, extensible, and production-ready notification system for PHP.
Installation
composer require notification-hub/hub
Requirements
- PHP >= 8.3
- ext-pdo
- MySQL or SQLite (via PDO)
Quick Start
use NotificationHub\Domain\Aggregate\Delivery; use NotificationHub\Domain\ValueObject\ChannelType; use NotificationHub\Domain\ValueObject\Notification; use NotificationHub\Domain\ValueObject\Recipient; $delivery = new Delivery( id: DeliveryId::generate(), notification: new Notification('Welcome!', 'Hello, friend.'), recipient: new Recipient('user-123', email: 'friend@example.com'), channelType: ChannelType::EMAIL, );
Architecture
Domain (no framework deps)
Aggregate: Delivery (status, attempts, idempotency)
Value Objects: Notification, Recipient, ChannelType, DeliveryStatus
Repository: DeliveryRepositoryInterface
Events: DeliveryCreated, DeliverySent, DeliveryFailed, ...
Application (orchestration)
Commands: SendNotification, CancelDelivery, RetryFailedDelivery
Queries: GetDeliveryHistory, GetPendingDeliveries
Handlers, Event Subscribers, Workers
Infrastructure (concrete implementations)
Persistence: PdoDeliveryRepository
Channels: EmailChannel, SmsChannel
Providers: SendGrid, Twilio (via interfaces)
Features
- Multi-Channel: Email, SMS, Push, Slack, Webhooks
- CQRS: Separate command and query buses
- Retry Logic: Exponential backoff for failed deliveries
- Idempotency: Duplicate detection via idempotency keys
- Event-Driven: Domain events for extensibility
- Metrics Interface: Plug in Prometheus/Datadog
- SQLite/MySQL: Works with both via PDO
Testing
vendor/bin/phpunit
Testing with API + UI
See examples/ and ui/ directories for a working demo.
License
MIT