Domain Driven Designed Application example to show the usage of the different soa-php libraries
There are 4 bounded contexts:
- Create a Pull Request
- Assign a Reviewer to a Pull Request
- Approve a Pull Request
- Merge Pull Request
- Pay money
- Collect Money
Merging a Pull Request is an automated process consisting of the next flow:
- When all the assigned reviewers approve the Pull Request, the Pull Request is marked as mergeable
- When the Pull Request is marked as mergeable, the system automatically pays to the reviewers the corresponding reward and charges the creator of the Pull Request a fee.
- When all the payments (collecting and paying the money) are successfully performed the system merges the Pull Request
The Merge Pull Request Process Manager handles this flow.
If you want to play around with the code you just need to:
- Install
docker
anddocker compose
tools. - Run the installation script (it will take long until all dependencies are installed):
./install.sh
- Start mongo and rabbitmq services:
docker-compose -f docker/infra-docker-compose.yml up
- Start bounded context services:
docker-compose -f docker/services-docker-compose.yml up
If you want to test how the application behaves you can send the next HTTP requests:
- Create a Pull Request:
curl -i -X POST \ -H "id:e0ff1d6d-9035-4974-b711-b9805116abad" \ -d \ '{"writer":"aaaa", "code":"some code"}' \ 'http://localhost:8080/pull-requests'
NOTE: Copy the UUID generated from the Location
header returned in the Response and replace the {id}
placeholder from the next CURL calls with the UUID.
- Assign a Reviewer:
curl -i -X PUT \ -H "Content-Type:application/json" \ -H "id:eb59b73b-a0d7-4cc8-9d9e-118b11a5f30c" \ -d \ '{ "reviewer": "a reviewer" }' \ 'http://localhost:8080/pull-requests/{id}/reviewer'
- Assign another Reviewer:
curl -i -X PUT \ -H "Content-Type:application/json" \ -H "id:07d6a393-eb2a-4d00-8351-0e691865fe82" \ -d \ '{ "reviewer": "another reviewer" }' \ 'http://localhost:8080/pull-requests/{id}/reviewer'
- Approve the Pull Request by one Reviewer:
curl -i -X PUT \ -H "Content-Type:application/json" \ -H "id:cc8ea97a-8c90-4023-aeb2-f4387c79bee9" \ -d \ '{ "approver": "a reviewer" }' \ 'http://localhost:8080/pull-requests/{id}/approve'
- Approve the Pull Request by the other Reviwer:
curl -i -X PUT \ -H "Content-Type:application/json" \ -H "id:78ffb2f0-7598-4c9d-abd0-0f06bad29cc2" \ -d \ '{ "approver": "another reviewer" }' \ 'http://localhost:8080/pull-requests/{id}/approve'
- At this point, since all reviewers have approved the Pull Request, the Process Manager starts managing the process to charge and pay the money, and then merge the Pull Request.
You can check the data created by connecting to the Mongo database which is listening at localhost:27017
without user nor password required. You can also check the queues and exchanges created in RabbitMQ by opening in your browser the URL http://localhost:15672/#/
Each Bounded Context has a run.sh
script, if you want to run the unit tests you just need to go to the Bounded Context folder and execute:
cd PullRequest
./run.sh phpunit