Modular Monolith Laravel

The sample e-commerce application for Laracon Online Winter 2022.

System requirements

Docker is installed on your machine.

Setup local environment

Copy example env file

cp .env.example .env

Start docker compose

docker compose up -d

Install composer dependencies

docker compose exec app composer install

Generate app key and places inside the .env file

docker compose exec app php artisan key:generate

Run DB migration

docker compose exec app php artisan migrate:fresh --seed

Now you can access the app via http://localhost.

To stop Docker containers

docker compose down

Laravel Sail command (optional)

This repository uses Laravel Sail for the local docker environment. You can use the sail command by configuring a bash alias below.

alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'

The sail command is an shortcut for docker compose exec app php which runs a given command within the docker container. The docker compose commands in the previous section can be shortened like this.

sail composer install
sail artisan key:generate
sail artisan migrate:fresh --seed

Testing

This repository uses Pest for writing tests. Pest is a testing framework with a simpler syntax like Jest and better reporting. Since it's powered by PHPUnit, it supports all the PHPUnit syntaxes as well.

Running tests

sail test

Filtering tests

sail test --filter OrderControllerTest

Display code coverage

sail test --coverage --min=80

Static code analysis to enforce domain boundaries

Deptrac is a static code analysis tool for PHP that helps you define architectual layers over classes and rules on which layer can access which layer.

You can run deptrac with the command below.

sail exec app ./vendor/bin/deptrac

You can also visualize the dependency graph by exporting the analysis result as an image.

sail exec app ./vendor/bin/deptrac --formatter=graphviz-image --output="./deptrac.png"