Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mtarld committed Apr 3, 2022
0 parents commit fbf8949
Show file tree
Hide file tree
Showing 102 changed files with 10,139 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
**/*.log
**/*.md
**/*.php~
**/._*
**/.dockerignore
**/.DS_Store
**/.git/
**/.gitattributes
**/.gitignore
**/.gitmodules
**/docker-compose.*.yaml
**/docker-compose.*.yml
**/docker-compose.yaml
**/docker-compose.yml
**/Dockerfile
**/Thumbs.db
.editorconfig
.env.*.local
.env.local
.env.local.php
.php_cs.cache
bin/*
!bin/console
docker/db/data/
helm/
public/bundles/
var/
vendor/
76 changes: 76 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
# Change these settings to your own preference
indent_style = space
indent_size = 4

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{js,html}]
indent_style = space
indent_size = 2

[*.json]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.php]
indent_style = space
indent_size = 4

[*.sh]
indent_style = tab
indent_size = 4

[*.xml{,.dist}]
indent_style = space
indent_size = 4

[*.{yaml,yml}]
indent_style = space
indent_size = 4
trim_trailing_whitespace = false

[api/helm/api/**.yaml]
indent_style = space
indent_size = 2

[.github/workflows/*.yml]
indent_style = space
indent_size = 2

[.gitmodules]
indent_style = tab
indent_size = 4

[.php_cs{,.dist}]
indent_style = space
indent_size = 4

[.travis.yml]
indent_style = space
indent_size = 2

[composer.json]
indent_style = space
indent_size = 4

[docker-compose{,.*}.{yaml,yml}]
indent_style = space
indent_size = 2

[Dockerfile]
indent_style = tab
indent_size = 4
15 changes: 15 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=6aae3d25d74cc223fc0bfdc801ce12e2
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
DATABASE_URL="postgresql://symfony:[email protected]:5432/app?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###

###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
###< nelmio/cors-bundle ###

###> symfony/messenger ###
###< symfony/messenger ###
16 changes: 16 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
* text=auto eol=lf

*.conf text eol=lf
*.html text eol=lf
*.ini text eol=lf
*.js text eol=lf
*.json text eol=lf
*.md text eol=lf
*.php text eol=lf
*.sh text eol=lf
*.yaml text eol=lf
*.yml text eol=lf
bin/console text eol=lf

*.ico binary
*.png binary
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
133 changes: 133 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# the different stages of this Dockerfile are meant to be built into separate images
# https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage
# https://docs.docker.com/compose/compose-file/#target


# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG PHP_VERSION=8.1
ARG CADDY_VERSION=2

# "php" stage
FROM php:${PHP_VERSION}-fpm-alpine AS symfony_php

# persistent / runtime deps
RUN apk add --no-cache \
acl \
fcgi \
file \
gettext \
git \
;

ARG APCU_VERSION=5.1.21
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
libzip-dev \
zlib-dev \
; \
\
docker-php-ext-configure zip; \
docker-php-ext-install -j$(nproc) \
intl \
zip \
; \
pecl install \
apcu-${APCU_VERSION} \
; \
pecl clear-cache; \
docker-php-ext-enable \
apcu \
opcache \
; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-cache --virtual .phpexts-rundeps $runDeps; \
\
apk del .build-deps

COPY docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck

HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]

RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
COPY docker/php/conf.d/symfony.prod.ini $PHP_INI_DIR/conf.d/symfony.ini

COPY docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf

COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

VOLUME /var/run/php

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1

ENV PATH="${PATH}:/root/.composer/vendor/bin"

WORKDIR /srv/app

# Allow to choose skeleton
ARG SKELETON="symfony/skeleton"
ENV SKELETON ${SKELETON}

# Allow to use development versions of Symfony
ARG STABILITY="stable"
ENV STABILITY ${STABILITY}

# Allow to select skeleton version
ARG SYMFONY_VERSION=""
ENV SYMFONY_VERSION ${SYMFONY_VERSION}

# Download the Symfony skeleton and leverage Docker cache layers
RUN composer create-project "${SKELETON} ${SYMFONY_VERSION}" . --stability=$STABILITY --prefer-dist --no-dev --no-progress --no-interaction; \
composer clear-cache

###> recipes ###
###> doctrine/doctrine-bundle ###
RUN apk add --no-cache --virtual .pgsql-deps postgresql-dev; \
docker-php-ext-install -j$(nproc) pdo_pgsql; \
apk add --no-cache --virtual .pgsql-rundeps so:libpq.so.5; \
apk del .pgsql-deps
###< doctrine/doctrine-bundle ###
###< recipes ###

COPY . .

RUN set -eux; \
mkdir -p var/cache var/log; \
composer install --prefer-dist --no-dev --no-progress --no-scripts --no-interaction; \
composer dump-autoload --classmap-authoritative --no-dev; \
composer symfony:dump-env prod; \
composer run-script --no-dev post-install-cmd; \
chmod +x bin/console; sync
VOLUME /srv/app/var

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]

FROM caddy:${CADDY_VERSION}-builder-alpine AS symfony_caddy_builder

RUN xcaddy build \
--with github.com/dunglas/mercure \
--with github.com/dunglas/mercure/caddy \
--with github.com/dunglas/vulcain \
--with github.com/dunglas/vulcain/caddy

FROM caddy:${CADDY_VERSION} AS symfony_caddy

WORKDIR /srv/app

COPY --from=dunglas/mercure:v0.11 /srv/public /srv/mercure-assets/
COPY --from=symfony_caddy_builder /usr/bin/caddy /usr/bin/caddy
COPY --from=symfony_php /srv/app/public public/
COPY docker/caddy/Caddyfile /etc/caddy/Caddyfile
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Hexagonal API Platform 3

An example projet to use **API Platform 3** following the **hexagonal architecture**.

This example has been explained during the [SymfonyLive Paris 2022](https://live.symfony.com/2022-paris/schedule#session-625)
([slides](https://slides.com/mathiasarlaud/sflive-apip-ddd)).

## Getting started
If you wan't to try to use and tweak that example, you can follow these steps:

1. Run `git clone https://github.com/mtarld/apip-ddd` to clone the project
1. Run `docker-compose build --pull --no-cache` to build fresh images
1. Run `docker-compose up` to up your containers
1. Visit https://localhost and play with your app!

## :warning: Temporary dependencies

As [API platform](https://github.com/api-platform/core) 3 isn't released yet, that repository is using the `dev-main`
branch of `api-platform/core`.
As soon as API Platform is released (it should happen very soon), the `v3` tag must be targetterd and the `minimum-stability` must be updated.

## What's inside?
Following links aim to explain the architecture of the project and the purpose of each classes.

- [Layers](docs/layers.md) (TODO)
- Domain layer
- [Models and repositories](docs/domain/models_and_repositories.md) (TODO)
- Application layer
- [The command/query pattern](docs/application/command_query_pattern.md) (TODO)
- Infrastructure layer
- [API Resource](docs/infrastructure/api_resource.md) (TODO)
- [Custom operation metadata](docs/infrastructure/custom_operation_metadata.md) (TODO)
- [Query providers](docs/infrastructure/query_providers.md)
- [Command processors](docs/infrastructure/command_processors.md) (WIP)
- [CRUD providers/processors](docs/infrastructure/crud_providers_processors.md) (TODO)
- [Command data transformers](docs/infrastructure/command_data_transformers.md) (TODO)
- [Openapi filters](docs/infrastructure/openapi_filters.md) (TODO)
- [Native providers/processors removal compiler pass](docs/infrastructure/native_providers_processors_removal_compiler_pass.md)
- [Messenger buses](docs/infrastructure/messenger_buses.md) (TODO)

## Contributing
That implementation is pragmatic and far for being uncriticable.
It's mainly an conceptual approach to extend API Platform in order to defer operations to command and query buses.

It could and should be improved, therefore feel free to submit issues and pull requests if something isn't relevant to your use cases or isn't clean enough.

## Authors
[Mathias Arlaud](https://github.com/mtarld) with the help of [Robin Chalas](https://github.com/chalasr)
17 changes: 17 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php

use App\Infrastructure\Shared\Symfony\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
};
Loading

0 comments on commit fbf8949

Please sign in to comment.