Skip to content

rickintveld/symfony-api-boilerplate

Repository files navigation

Symfony API Boilerplate

Actions Status

Configuration

  • Configure your env.local
DATABASE_NAME=api
DATABASE_USER=root
DATABASE_PASSWORD=root
DATABASE_ROOT_PASSWORD=root

DATABASE_URL=mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@database:3306/${DATABASE_NAME}?serverVersion=mariadb-10.4.21

Installation

// Start the docker instance
docker-compose up -d

// Run the composer install
docker-compose run php-fpm composer install

// create the database tables
docker-compose run php-fpm bin/console doctrine:migration:migrate

Request cycles

  flowchart LR
    A[Request] --> B{Controller}
    B -->|POST| C[RequestHandler]
    B -->|GET| D[Service]
    B -->|PATCH| C[RequestHandler]
    B -->|PUT| C[RequestHandler]
    B -->|DELETE| D[Service]
    C -->|Serializer| E[Repository]
    D -->|onSuccess| E[Repository]

Deptrac

Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects. You can freely define your architectural layers over classes and which rules should apply to them.

docker-compose run php-fpm ./vendor/bin/deptrac

Psalm

Psalm is a static analysis tool for finding errors in PHP applications.

docker-compose run php-fpm ./vendor/bin/psalm

Php-cs

The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards

docker-compose run php-fpm ./vendor/bin/phpcs ./src

Tests

Create tests database

docker-compose run php-fpm bin/console --env=test doctrine:database:create

Create the test tables / columns

docker-compose run php-fpm bin/console --env=test doctrine:schema:create

Run tests

docker-compose run php-fpm bin/phpunit