{"id":13828050,"url":"https://github.com/hgraca/explicit-architecture-php","last_synced_at":"2026-01-24T14:29:25.669Z","repository":{"id":40593420,"uuid":"112103110","full_name":"hgraca/explicit-architecture-php","owner":"hgraca","description":"This repository is a demo of Explicit Architecture, using the Symfony Demo Application.","archived":false,"fork":false,"pushed_at":"2021-06-15T15:42:28.000Z","size":8473,"stargazers_count":664,"open_issues_count":4,"forks_count":133,"subscribers_count":46,"default_branch":"master","last_synced_at":"2024-02-15T16:34:18.087Z","etag":null,"topics":["architecture","demo","explicit-architecture","symfony"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hgraca.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-26T17:38:39.000Z","updated_at":"2024-02-06T14:19:05.000Z","dependencies_parsed_at":"2022-07-13T16:44:28.775Z","dependency_job_id":null,"html_url":"https://github.com/hgraca/explicit-architecture-php","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hgraca%2Fexplicit-architecture-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hgraca%2Fexplicit-architecture-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hgraca%2Fexplicit-architecture-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hgraca%2Fexplicit-architecture-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hgraca","download_url":"https://codeload.github.com/hgraca/explicit-architecture-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225486521,"owners_count":17481917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["architecture","demo","explicit-architecture","symfony"],"created_at":"2024-08-04T09:02:30.122Z","updated_at":"2026-01-24T14:29:25.662Z","avatar_url":"https://github.com/hgraca.png","language":"PHP","funding_links":[],"categories":["PHP","Architectural Style"],"sub_categories":["🔖 Samples"],"readme":"# Explicit Architecture \n\n[![Author][Author]](https://www.herbertograca.com)\n[![Software License][License]](LICENSE)\n\n[![Build Status][Build]](https://scrutinizer-ci.com/g/hgraca/explicit-architecture-php/build-status/master)\n[![Scrutinizer Code Quality][Score]](https://scrutinizer-ci.com/g/hgraca/explicit-architecture-php/?branch=master)\n[![CodeCov][CodeCov]](https://codecov.io/gh/hgraca/explicit-architecture-php)\n\n[![Code Intelligence Status][CodeInt]](https://scrutinizer-ci.com/code-intelligence)\n\n## Symfony Demo Application\n\nThe \"Symfony Demo Application\" is a reference application created to show how\nto develop Symfony applications following the recommended best practices.\n\nThis repository is a demo of [Explicit Architecture][1], using the [Symfony Demo Application][2].\n\nThere is code in this project that not used and therefore it would be removed in a real project, nevertheless \nit was included here as examples.\n\n### Explicit Architecture\n\nI explained [Explicit Architecture][1] in one of my blog posts, as a result of my understanding of several architectural\n ideas such as (but not limited to) [EBI Architecture][11], [DDD][12], [Ports \u0026 Adapters Architecture][13], \n [Onion Architecture][14] and [Clean Architecture][15].\n \n[![Explicit Architecture](https://docs.google.com/drawings/d/e/2PACX-1vQ5ps72uaZcEJzwnJbPhzUfEeBbN6CJ04j7hl2i3K2HHatNcsoyG2tgX2vnrN5xxDKLp5Jm5bzzmZdv/pub?w=960\u0026amp;h=657)][2]\n\n#### Package by component\n\n[![Package by component](https://docs.google.com/drawings/d/e/2PACX-1vQjEj4dKKUaQEUcNDq2UO58oIUu6pehqrE99q4gSRk0DY9KPIuhgG9Yg3qJGgW4ybrL5Ql8_Xo5z3yq/pub?w=960\u0026h=720)][17]\n\n#### Dependencies directions\n\n[![Dependencies](https://docs.google.com/drawings/d/e/2PACX-1vQyv5xAx5hFJPhiK19AGl_2t256M0yKcDSliH8etojltE3tBlEnCndwfsUr1UsXvv5PKGVtrBHkQX3h/pub?w=913\u0026amp;h=129)][16]\n\n#### Folder structure\n\n- **bin** (_application binaries, however the dependencies binaries should go in vendor/bin_)\n- **build** (_artifacts needed for building the application prior to running it_)\n- **config** (_all the config needed to run the application_)\n- **docs** (_application documentation_)\n- **lib** (_libraries used by the application, which are specific to this application and/or not distributable_)\n    - **php-extension**  (_code to be used as if it was part of the language itself_)\n        - _src_\n        - _tests_\n- **public** (_the entry point to the application, and public frontend artifacts like CSS and JS files_)\n- **src**\n    - **[Core][10]** (_the application core_)\n        - **[Component][5]** (_the application components/bounded contexts_)\n        - **[Port][8]** (_the ports, to be implemented by the infrastructure adapters_)\n        - **[SharedKernel][6]** (_application and domain code shared among all components/bounded contexts_)\n    - **[Infrastructure][9]** (_the port adapters for the infrastructure tools_)\n    - **[Presentation][7]** (_the presentation layer with the several user facing applications, controllers, views and related code units_)\n        - **Console** (_the CLI UI_)\n        - **Web** (_the web UI_)\n            - **Core** (_the web UI core_)\n                - **Component** (_the web UI core components_)\n                - **Port** (_the web UI core ports, used only in the web UI_)\n            - **Infrastructure** (_the web UI infrastructure, used only in the web UI_)\n- **tests**\n    - **Fixture** (_data to put in the DB and use in the tests_)\n    - **Framework** (_support code to run the tests, like base test classes and assertions_)\n    - **TestCase** (_unit, integration, functional, acceptance tests, with **only one** folder tree mimicking the src folder_)\n- **translations**\n- **var** (_volatile artifacts like logs, cache, temporary test databases, generated code, ..._)\n- **vendor** (_distributable libraries_)\n\n#### Dependencies testing and documentation\n\nSince the code organization, its structure, is quite explicit we can _easily_ have an architectural integrity test \nsuite to make sure we are not breaking the architecture.\n\nThis project architectural integrity test suite consists of three tests, which are executed using [deptrac]. \nDeptrac can also generate some nice graphs with the dependencies tree, which makes it great as a documentation artifact.\n\n1. **_Layer_ dependencies integrity**\n\n    This tests the code layers dependency integrity, making sure the dependencies always goes inwards, \n    when matched to the layers in the Explicit Architecture diagram on top.\n    \n    ![Layer dependencies](docs/images/dependencies/deptrac_layers.png)\n\n2. **_Component_ dependencies integrity**\n\n    This test makes sure that the components are decoupled between them.\n    \n    ![Component dependencies](docs/images/dependencies/deptrac_components.png)\n\n3. **_Class type_ dependencies integrity**\n\n    This test goes to a class level dependency integrity check, specially useful for classes in the same layer and component.\n    For example, the application services, query objects and repositories all belong to the Application Layer, \n    and they all exist within each component. However, there are rules that must be followed:\n    1. A service can depend on query objects and repositories;\n    2. A query object should not depend on a service nor a repository, \n    3. A repository should not depend on a service nor a query object. \n    4. And, of course, none of them should depend on a controller, although that can be tested using the layers dependency \n    test, because the controllers belong in the UI layer.\n    \n    ![Class type dependencies](docs/images/dependencies/deptrac_class.png)\n\n## Usage\n\nYou need to have docker installed in your host OS. \n\nExecute the following commands to prepare the project locally:\n\n```bash\n$ composer install\n$ make box-build-prd\n$ make dep_analyzer-install\n```\n\nExecute this command to run the tests suite: \n\n```bash\n$ make test\n```\n\nExecute this command to run the app in dev mode: \n\n```bash\n$ make up\n```\n\nor this command to run the app in production mode: \n\n```bash\n$ make up-prd\n```\n\nAccess the application in your browser at \u003chttp://localhost:8000\u003e.\n\nYou can also test the error pages at `http://localhost:8000/index.php/_error/{statusCode}.{format}`,\n ie. \u003chttp://localhost:8000/index.php/_error/400.html\u003e.\n\nTo see all commands available run:\n\n```bash\n$ make\n```\n\n### Tests\n\nTo be able to run the architecture integrity tests, you first need to install deptrac:\n\n```bash\n$ make dep_analyzer-install\n```\n\nExecute this command to run tests:\n\n```bash\n$ make test\n```\n\nOr this command to run tests and get the coverage:\n\n```bash\n$ make test_cov\n```\n\n### Integration with PHPStorm\n\nIntegration with PHPStorm is straight forward.\n\nConfigure the servers so we can debug a request made from the browser:\n![PHPStorm servers config](docs/IDE/PHPStorm/IDE_PHPSTORM_servers.png)\n\nConfigure the CLI so we can run the tests:\n![PHPStorm CLI config](docs/IDE/PHPStorm/IDE_PHPSTORM_cli_interpreter.png)\n\nConfigure the test run itself:\n![PHPStorm tests config](docs/IDE/PHPStorm/IDE_PHPSTORM_tests_run.png)\n\n### Debug\n\nThe dev container has xDebug installed and you can use it out of the box, provided that you have your IDE configured\n appropriately.\n \nCheck the screenshots in the `docs/IDE/PHP_Storm/` folder, to check how to configure PHP Storm to work with xDebug, as\n it is set up in the dev docker image.\n \nTo run the tests with xDebug enabled, you need to enable it in `container/tst/xdebug.ini:1` prior to running the tests.\n\n[1]: https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together/\n[2]: https://docs.google.com/drawings/d/1E_hx5B4czRVFVhGJbrbPDlb_JFxJC8fYB86OMzZuAhg/edit?usp=sharing\n[5]: http://ddd.fed.wiki.org/view/welcome-visitors/view/domain-driven-design/view/bounded-context\n[6]: http://ddd.fed.wiki.org/view/welcome-visitors/view/domain-driven-design/view/shared-kernel\n[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\n[8]: https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together/#ports\n[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\n[10]: https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together/#application-core-organisation\n[11]: https://herbertograca.com/2017/08/24/ebi-architecture/\n[12]: https://herbertograca.com/2017/09/07/domain-driven-design/\n[13]: https://herbertograca.com/2017/09/14/ports-adapters-architecture/\n[14]: https://herbertograca.com/2017/09/21/onion-architecture/\n[15]: https://herbertograca.com/2017/09/28/clean-architecture-standing-on-the-shoulders-of-giants/\n[16]: https://docs.google.com/drawings/d/1DGiP9qyBpRHPDPKRJoXdElw1DXwmJoR-88Qvtf6hBNA/edit?usp=sharing\n[17]: https://docs.google.com/drawings/d/1QurViCcaZ4Eh1CgBvel9aK5RLBkw2TaOAnO-Lhu4pfw/edit?usp=sharing\n\n[Author]: http://img.shields.io/badge/author-@hgraca-blue.svg?style=flat-square\n[License]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square\n\n[Build]: https://scrutinizer-ci.com/g/hgraca/explicit-architecture-php/badges/build.png?b=master\n[Score]: https://scrutinizer-ci.com/g/hgraca/explicit-architecture-php/badges/quality-score.png?b=master\n[CodeCov]: https://codecov.io/gh/hgraca/explicit-architecture-php/branch/master/graph/badge.svg\n[CodeInt]: https://scrutinizer-ci.com/g/hgraca/explicit-architecture-php/badges/code-intelligence.svg?b=master\n\n[deptrac]: https://github.com/sensiolabs-de/deptrac\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhgraca%2Fexplicit-architecture-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhgraca%2Fexplicit-architecture-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhgraca%2Fexplicit-architecture-php/lists"}