This project implements a notification system with the following capabilities:
- Create email notifications via REST API
- List all notifications
- Send notifications asynchronously using Symfony Messenger
- Automatic retry mechanism on failure
- Proper error handling and logging
- RESTful API with JSON responses
- Asynchronous email sending via Symfony Messenger
- Status tracking:
pending
,sent
,failed
- Automatic retry up to 3 attempts
- Input validation with detailed error messages
- OpenAPI/Swagger documentation at
/api/doc
- Comprehensive test suite
- Clean architecture with domain services and DTOs
- Domain-Driven Design: Business logic split into domain services
- SOLID principles: Single responsibility, dependency injection
- DTO pattern: Clean separation between API contracts and entities
- Event-driven architecture: Asynchronous processing with Symfony Messenger
- PHP 8.2+
- Symfony 7.3+
- PostgreSQL 16+
- Docker & Docker Compose (optional)
git clone https://github.com/TheoMoriceEM/Simple-Notification-API.git
cd Simple-Notification-API
docker compose up -d
docker exec -it simple-notification-api-php-1 composer install
# Create database
docker exec -it simple-notification-api-php-1 php bin/console doctrine:database:create
# Run migrations
docker exec -it simple-notification-api-php-1 php bin/console doctrine:migrations:migrate
# Setup Messenger transport tables
docker exec -it simple-notification-api-php-1 php bin/console messenger:setup-transports
docker exec -it simple-notification-api-php-1 php bin/console messenger:consume async
The API is now available at http://localhost
And the Swagger UI at: http://localhost/api/doc
# Setup test database
docker exec -it simple-notification-api-php-1 php bin/console doctrine:database:create --env=test
docker exec -it simple-notification-api-php-1 php bin/console doctrine:schema:create --env=test
# Run all tests
docker exec -it simple-notification-api-php-1 php bin/phpunit
Sending emails synchronously can block HTTP requests and degrade the user experience.
β
Fast API responses
β
Automatic retry on failure
β
Horizontal scalability
Separate business logic from HTTP concerns.
β
Reusable across controllers, CLI commands, and tests
β
Easier to test (no HTTP mocking needed)
Decouple API contracts from database entities.
- NotificationValidation for input validation
- NotificationDto for responses
- Static method
create()
for conversion from entity
Separate email sending logic from message handling.
β
Easy to swap email providers
β
Testable in isolation
β
Reusable across the application
β
Single responsibility principle
Interactive API documentation for developers.
β
Always up-to-date with code
β
Interactive testing via Swagger UI
β
Clear API contract
For this technical test, email sending is simulated with:
- A 3-second delay (mimics usual latency)
- A 10% random failure rate (tests retry mechanism)
/send
API requests will return inconsistent data:
- The
status
will still bepending
although it will switch either tosent
orfailed
3 seconds later. - The
sentAt
timestamp will be undefined although if the sending succeeds, it will be set 3 seconds later as well.