The sandbox api project is a how-to example for implementing a DDD application using cubiche library.
This project implements a conference management system, an example taken from the books "Microservices for everyone" (2017) by Matthias Noback and "Exploring CQRS and Event Sourcing" (2012) by Dominic Betts.
The project contains a graphql endpoints that will be used by the frontend application.
In development mode you will have a graphiql instance to play with it:
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Clone the repository
git clone git@github.com:cubiche/sandbox-api.gitAdd the development domain names
# Get your current ip and add it to the hosts file
sudo pico /etc/hosts
your.current.ip.address sandbox.local www.sandbox.local api.sandbox.local coverage.sandbox.local mongodb.sandbox.localcd sandbox-api
docker-compose up -d
docker exec -it sandbox-api /www-data-shell
composer global require "hirak/prestissimo:^0.3"
composer install --prefer-dist -n
bin/console app:installThe app:install command creates the fixtures to be able to start using the application. You will have a set of countries, languages, currencies, two roles (ADMIN, CUSTOMER) and two users:
- Username: admin Password: admin
- Username: customer Password: customer
- Create conferences
- Manage seats availability for the conference
- Create roles
- Create users
- Create orders
- Login/logout users
The flow to be able to make a graphql query or mutation is the following:
- Go to the graphiql endpoint (http://api.sandbox.local/graphiql)
- You need a user (you can use the "admin" or "customer" users or you can create it using the command line)
- You can make login using the user credentials (you will get a Json Web Token)
- You can make queries or mutations now filling the token input in graphiql using the JWT
We're using full-stack Behavior-Driven-Development, with atoum and Behat. In the root directory, you will find a .quality file, where you can define the code quality rules and all your unit tests suite.
bin/test-unit
# Or if you prefer the tests with colored output
bin/atoum bin/test-unit test_suite_name
# Or if you prefer the tests with colored output
bin/atoum -c src/Sandbox/Directory-Name/.atoum.phpbin/test-generator generate:test:class /path/to/the/file
bin/test-generator generate:test:directory /path/to/the/directorypico quality.ymlAdd a new entry
test:
suites:
test_suite_name:
config_file: 'src/Sandbox/Directory-Name/.atoum.php'
bootstrap_file: ~
directories: ~
triggered_by: 'php'# Follow this steps just once
# Create the coverage directory
mkdir /var/www/coverage
# Make sure the coverage directory is world writable
# Copy the dist file just once
cp .atoum.html.dist .atoum.html.php# Run the tests coverage
bin/test-coverage
# Check it at coverage.sandbox.local# Follow this steps just once
# Create the coverage directory if not exists
mkdir /var/www/coverage
# Make sure the coverage directory is world writable
# Copy the dist file just once
cp src/Sandbox/Directory-Name/.atoum.html.dist src/Sandbox/Directory-Name/.atoum.html.phpbin/atoum -c src/Sandbox/Directory-Name/.atoum.html.phpbin/behat
bin/check-code-style
bin/php-cs-fix-commit fix
Sandbox api is completely free and released under the MIT License.