├── var └── .gitkeep ├── config └── .gitkeep ├── src ├── Core │ ├── Port │ │ └── .gitkeep │ └── Component │ │ ├── CoreDomain │ │ └── .gitkeep │ │ └── GenericSubdomain │ │ └── .gitkeep ├── Infrastructure │ └── .gitkeep └── Presentation │ ├── Lib │ └── .gitkeep │ └── UI │ ├── Cli │ └── .gitkeep │ ├── Api │ ├── Rest │ │ └── .gitkeep │ └── Graphql │ │ └── .gitkeep │ └── Web │ ├── Lib │ └── .gitkeep │ ├── Backoffice │ └── .gitkeep │ └── Public │ └── .gitkeep ├── lib ├── std-lib │ ├── src │ │ └── .gitkeep │ └── tests │ │ └── .gitkeep └── shared-kernel │ ├── src │ └── .gitkeep │ └── tests │ └── .gitkeep ├── bin ├── run ├── test ├── fix_cs └── coverage ├── LICENSE ├── .php_cs.dist ├── Makefile ├── .env.dist ├── composer.json └── README.md /var/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Core/Port/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/std-lib/src/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/std-lib/tests/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Infrastructure/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/shared-kernel/src/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/shared-kernel/tests/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Presentation/Lib/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Presentation/UI/Cli/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Core/Component/CoreDomain/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Presentation/UI/Api/Rest/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Presentation/UI/Web/Lib/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Presentation/UI/Api/Graphql/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Presentation/UI/Web/Backoffice/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Presentation/UI/Web/Public/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Core/Component/GenericSubdomain/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bin/run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | setRiskyAllowed(true) 5 | ->setRules( 6 | [ 7 | '@Symfony' => true, 8 | '@PHP71Migration:risky' => true, 9 | 'phpdoc_align' => false, 10 | 'phpdoc_summary' => false, 11 | 'concat_space' => ['spacing' => 'one'], 12 | 'no_multiline_whitespace_before_semicolons' => true, 13 | 'no_useless_else' => true, 14 | 'no_useless_return' => true, 15 | 'ordered_imports' => true, 16 | 'phpdoc_order' => true, 17 | 'array_syntax' => ['syntax' => 'short'], 18 | 'no_short_echo_tag' => true, 19 | 'pre_increment' => false, 20 | 'return_type_declaration' => ['space_before' => 'none'], 21 | 'void_return' => true, 22 | 'yoda_style' => [ 23 | 'equal' => false, 24 | 'identical' => false, 25 | ], 26 | ] 27 | ) 28 | ->setFinder( 29 | PhpCsFixer\Finder::create() 30 | ->in(['src', 'tests', 'lib']) 31 | ->exclude([]) 32 | ->name('*.php') 33 | ); 34 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CURRENT_BRANCH="$(shell git rev-parse --abbrev-ref HEAD)" 2 | 3 | default: help 4 | 5 | help: 6 | @echo "Usage:" 7 | @echo " make [command]" 8 | @echo "Available commands:" 9 | @grep '^[^#[:space:]].*:' Makefile | grep -v '^default' | grep -v '^_' | sed 's/://' | xargs -n 1 echo ' -' 10 | 11 | build-container-dev: 12 | docker build -t hgraca/lib-name:app.dev.php_7_1 -f ./build/container/dev/app.dockerfile ./build/container/dev 13 | docker push hgraca/lib-name:app.php_7_1 14 | 15 | build-container-prd: 16 | docker build -t hgraca/lib-name:app.prd.php_7_1 -f ./build/container/prd/app.dockerfile ./build/container/prd 17 | docker push hgraca/lib-name:app.php_7_1 18 | 19 | coverage: 20 | bin/coverage 21 | bin/fix_code_standards --dry-run 22 | 23 | cs-fix: 24 | bin/fix_cs 25 | 26 | dep-install: 27 | composer install 28 | 29 | dep-update: 30 | composer update 31 | 32 | run: 33 | bin/run 34 | 35 | test: 36 | bin/test 37 | # bin/humbug 38 | bin/fix_cs --dry-run 39 | 40 | test-acc: 41 | bin/test --testsuite acceptance 42 | bin/fix_cs --dry-run 43 | 44 | test-func: 45 | bin/test --testsuite functional 46 | bin/fix_cs --dry-run 47 | 48 | test-int: 49 | bin/test --testsuite integration 50 | bin/fix_cs --dry-run 51 | 52 | test-unit: 53 | bin/test --testsuite unit 54 | bin/fix_cs --dry-run 55 | -------------------------------------------------------------------------------- /.env.dist: -------------------------------------------------------------------------------- 1 | # This file is a "template" of which env vars needs to be defined in your configuration or in an .env file 2 | # Set variables here that may be different on each deployment target of the app, e.g. development, staging, production. 3 | # https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration 4 | 5 | ENV=dev 6 | 7 | ###> symfony/framework-bundle ### 8 | APP_ENV=dev 9 | APP_DEBUG=1 10 | APP_SECRET=67d829bf61dc5f87a73fd814e2c9f629 11 | ###< symfony/framework-bundle ### 12 | 13 | ###> doctrine/doctrine-bundle ### 14 | # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url 15 | # For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" 16 | # Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls 17 | DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/blog.sqlite 18 | ###< doctrine/doctrine-bundle ### 19 | 20 | ###> symfony/swiftmailer-bundle ### 21 | # For Gmail as a transport, use: "gmail://username:password@localhost" 22 | # For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" 23 | # Delivery is disabled by default via "null://localhost" 24 | MAILER_URL=null://localhost 25 | ###< symfony/swiftmailer-bundle ### 26 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hgraca/lib-name", 3 | "license": "MIT", 4 | "type": "library", 5 | "description": "", 6 | "authors": [ 7 | { 8 | "name": "Herberto Graça", 9 | "email": "herberto.graca@gmail.com" 10 | } 11 | ], 12 | "autoload": { 13 | "psr-4": { 14 | "Hgraca\\LibName\\": "src/" 15 | } 16 | }, 17 | "autoload-dev": { 18 | "psr-4": { 19 | "Hgraca\\LibName\\Test\\": "tests/" 20 | } 21 | }, 22 | "require": { 23 | "php": ">=7.1", 24 | "roave/security-advisories": "dev-master" 25 | }, 26 | "require-dev": { 27 | "friendsofphp/php-cs-fixer": "^2.0", 28 | // "humbug/humbug": "^1.0@alpha", 29 | "mockery/mockery": "v1.0.0-alpha1", 30 | "phpunit/dbunit": "^3.0", 31 | "phpunit/php-code-coverage": "^5", 32 | "phpunit/php-invoker": "^1.1", 33 | "phpunit/phpunit": "^6.0" 34 | }, 35 | "suggest": { 36 | }, 37 | "extra": { 38 | "branch-alias": { 39 | "dev-master": "1.0.x-dev" 40 | } 41 | }, 42 | "config": { 43 | "bin-dir": "vendor/bin", 44 | "preferred-install": "dist" 45 | }, 46 | "scripts": { 47 | "post-install-cmd": [], 48 | "post-update-cmd": [], 49 | "post-create-project-cmd": [] 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /bin/coverage: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | $hostBuildPath/$coverageReportPath"); 38 | } 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hgraca \ Explicit Architecture PHP Skeleton 2 | 3 | This is a skeleton for a project following Explicit Architecture, specifically for a PHP project, 4 | although it can be easily adjusted to any programming language. 5 | 6 | ## Usage 7 | 8 | To use this skeleton we just need to clone this repo, make a few search/replace steps, and understand how/why the 9 | project structure is the way it is, so we can follow The Explicit Architecture principles. 10 | 11 | Clone this repo: 12 | ```bash 13 | git clone git@github.com:hgraca/explicit-architecture-php-skeleton.git lib-name 14 | ``` 15 | 16 | Replace: 17 | 18 | - Hgraca => The vendor name 19 | - '\' => A description for the library 20 | - lib-name => The library name 21 | - LibName => The library namespace 22 | 23 | Go through the README.md and adapt the template below to your situation. 24 | 25 | ### Explicit Architecture 26 | 27 | I explained [Explicit Architecture][1] in one of my blog posts, as a result of my understanding of several architectural 28 | styles such as (but not limited to) [EBI Architecture][11], [DDD][12], [Ports & Adapters Architecture][13], 29 | [Onion Architecture][14] and [Clean Architecture][15]. 30 | 31 | [![Explicit Architecture](https://docs.google.com/drawings/d/e/2PACX-1vQ5ps72uaZcEJzwnJbPhzUfEeBbN6CJ04j7hl2i3K2HHatNcsoyG2tgX2vnrN5xxDKLp5Jm5bzzmZdv/pub?w=960&h=657)][2] 32 | 33 | #### Package by component 34 | 35 | [![Package by component](https://docs.google.com/drawings/d/e/2PACX-1vQjEj4dKKUaQEUcNDq2UO58oIUu6pehqrE99q4gSRk0DY9KPIuhgG9Yg3qJGgW4ybrL5Ql8_Xo5z3yq/pub?w=960&h=720)][17] 36 | 37 | #### Dependencies directions 38 | 39 | [![Dependencies](https://docs.google.com/drawings/d/e/2PACX-1vQyv5xAx5hFJPhiK19AGl_2t256M0yKcDSliH8etojltE3tBlEnCndwfsUr1UsXvv5PKGVtrBHkQX3h/pub?w=913&h=129)][16] 40 | 41 | #### Folder structure 42 | 43 | - **bin** (_application binaries, the dependencies binaries should go in vendor/bin_) 44 | - **build** (_artifacts needed for building the application prior to running it_) 45 | - **config** (_all the config needed to run the application_) 46 | - **docs** (_application documentation_) 47 | - **lib** (_libraries used by the application, which are specific to this application or not distributable (yet)_) 48 | - **[shared-kernel][6]** (_application and domain code shared among all components/bounded contexts_) 49 | - _src_ 50 | - _tests_ 51 | - **std-lib** (_functions and/or classes to be used as if they were part of the language itself_) 52 | - _src_ 53 | - _tests_ 54 | - **src** 55 | - **[Core][10]** (_the application core_) 56 | - **[Component][5]** (_the application components/bounded contexts_) 57 | - **[Port][8]** (_the ports, to be implemented by the infrastructure adapters_) 58 | - **[Infrastructure][9]** (_the port adapters for the infrastructure tools_) 59 | - **[Presentation][7]** (_the presentation layer with the several user facing applications, controllers, views and related code units_) 60 | - **tests** (_unit, integration, functional, acceptance tests_) 61 | - **build** (_artifacts needed for running the application tests, like a test DB template_) 62 | - **var** (_volatile artifacts like logs, cache, temporary test databases, generated code, ..._) 63 | - **vendor** (_distributable libraries_) 64 | 65 | ## Template for this readme.md: 66 | 67 | --- 68 | 69 | # Hgraca \ LibName 70 | [![Author](http://img.shields.io/badge/author-@hgraca-blue.svg?style=flat-square)](https://www.herbertograca.com) 71 | [![Software License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE) 72 | [![Latest Version](https://img.shields.io/github/release/hgraca/php-lib-name.svg?style=flat-square)](https://github.com/hgraca/php-lib-name/releases) 73 | [![Total Downloads](https://img.shields.io/packagist/dt/hgraca/lib-name.svg?style=flat-square)](https://packagist.org/packages/hgraca/lib-name) 74 | 75 | [![Build Status](https://img.shields.io/scrutinizer/build/g/hgraca/php-lib-name.svg?style=flat-square)](https://scrutinizer-ci.com/g/hgraca/php-lib-name/build) 76 | [![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/hgraca/php-lib-name.svg?style=flat-square)](https://scrutinizer-ci.com/g/hgraca/php-lib-name/code-structure) 77 | [![Quality Score](https://img.shields.io/scrutinizer/g/hgraca/php-lib-name.svg?style=flat-square)](https://scrutinizer-ci.com/g/hgraca/php-lib-name) 78 | 79 | \ 80 | 81 | Add here a short description of what is the project. This should explain **what** the project is. 82 | Add here a short description of the motivation behind the creation and maintenance of the project. 83 | This should explain **why** the project exists. 84 | 85 | ## Installation 86 | 87 | To install the library, run the command below and you will get the latest version: 88 | 89 | ```bash 90 | composer require hgraca/lib-name 91 | ``` 92 | 93 | ## Deployment 94 | 95 | Add additional notes about how to deploy this on a live system 96 | 97 | ## Available commands 98 | 99 | ```bash 100 | make run 101 | ``` 102 | 103 | ```bash 104 | make test 105 | make test-acc 106 | make test-func 107 | make test-int 108 | make test-unit 109 | ``` 110 | 111 | ```bash 112 | make coverage 113 | ``` 114 | 115 | ```bash 116 | make cs-fix 117 | ``` 118 | 119 | ```bash 120 | make dep-install 121 | make dep-update 122 | ``` 123 | 124 | ```bash 125 | make build-container-dev 126 | make build-container-prd 127 | ``` 128 | 129 | [1]: https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together/ 130 | [2]: https://docs.google.com/drawings/d/1E_hx5B4czRVFVhGJbrbPDlb_JFxJC8fYB86OMzZuAhg/edit?usp=sharing 131 | [5]: http://ddd.fed.wiki.org/view/welcome-visitors/view/domain-driven-design/view/bounded-context 132 | [6]: http://ddd.fed.wiki.org/view/welcome-visitors/view/domain-driven-design/view/shared-kernel 133 | [7]: https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together/#primary-or-driving-adapters 134 | [8]: https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together/#ports 135 | [9]: https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together/#secondary-or-driving-adapters 136 | [10]: https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together/#application-core-organisation 137 | [11]: https://herbertograca.com/2017/08/24/ebi-architecture/ 138 | [12]: https://herbertograca.com/2017/09/07/domain-driven-design/ 139 | [13]: https://herbertograca.com/2017/09/14/ports-adapters-architecture/ 140 | [14]: https://herbertograca.com/2017/09/21/onion-architecture/ 141 | [15]: https://herbertograca.com/2017/09/28/clean-architecture-standing-on-the-shoulders-of-giants/ 142 | [16]: https://docs.google.com/drawings/d/1DGiP9qyBpRHPDPKRJoXdElw1DXwmJoR-88Qvtf6hBNA/edit?usp=sharing 143 | [17]: https://docs.google.com/drawings/d/1QurViCcaZ4Eh1CgBvel9aK5RLBkw2TaOAnO-Lhu4pfw/edit?usp=sharing 144 | --------------------------------------------------------------------------------