{"id":16674197,"url":"https://github.com/lezhnev74/ddd-generator","last_synced_at":"2025-03-21T18:31:18.924Z","repository":{"id":56752297,"uuid":"84425520","full_name":"lezhnev74/ddd-generator","owner":"lezhnev74","description":"This handy php tool allows me to quickly generate empty primitives","archived":false,"fork":false,"pushed_at":"2019-08-08T04:49:56.000Z","size":455,"stargazers_count":26,"open_issues_count":0,"forks_count":1,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-18T03:22:38.208Z","etag":null,"topics":["clean-architecture","ddd","generator","php"],"latest_commit_sha":null,"homepage":"https://lessthan12ms.com/one-step-towards-clean-architecture-from-rapid-application-development/","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/lezhnev74.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-09T09:49:08.000Z","updated_at":"2023-03-05T02:01:42.000Z","dependencies_parsed_at":"2022-08-16T01:40:20.612Z","dependency_job_id":null,"html_url":"https://github.com/lezhnev74/ddd-generator","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lezhnev74%2Fddd-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lezhnev74%2Fddd-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lezhnev74%2Fddd-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lezhnev74%2Fddd-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lezhnev74","download_url":"https://codeload.github.com/lezhnev74/ddd-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244848492,"owners_count":20520533,"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":["clean-architecture","ddd","generator","php"],"created_at":"2024-10-12T12:29:41.903Z","updated_at":"2025-03-21T18:31:18.388Z","avatar_url":"https://github.com/lezhnev74.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/lezhnev74/ddd-generator/master/LICENSE)\n[![Build Status](https://travis-ci.org/lezhnev74/ddd-generator.svg?branch=master)](https://travis-ci.org/lezhnev74/ddd-generator)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lezhnev74/ddd-generator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/lezhnev74/ddd-generator/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/lezhnev74/ddd-generator/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/lezhnev74/ddd-generator/?branch=master)\n\n\n# DDD Classes Generator for 3-layered Application\nWhen you develop clean and decoupled app you have to deal with many interfaces and objects. Where you had one object in RAPID development flow, you have plenty of objects in DDD flow. To speed things up I use this tool to generate primitives related to ServiceBus pattern, CQRS pattern and Clean Architecture.\nIf you interested - [I blogged about ideas behind this generator](https://lessthan12ms.com/one-step-towards-clean-architecture-from-rapid-application-development/).\n \n**Note:** I use PSR-4 so any folder inheritance leads to namespace inheritance (and vice versa). And also type of slashes is irrelevant - \\ and / will do the same.\n\n**Note:** This tool is designed to be extensible. So while it contains packs to generate widely used primitives like commands, there can be easily added packs to generate http controllers (+tests) and views and anything else.\n\n**Note:** No Windows support in mind.\n \n![](screencast.gif)\n \n## In a nutshell\nThis is a handy tool to generate empty class files + test files from templates and put them in predictable places.\n\n* set the config\n* run command with given config\n \n## What it can generate\n* anything you want\n* CommandBus: command and handler classes\n* QueryBus: request, response and handler\n* VO and Entity\n* Event\n* anything else\n\nEach class is complimented with empty test so I can keep TDD-ing.\n \n## Installation\nVia composer:\n```\ncomposer require lezhnev74/ddd-generator\n```\n \n## Usage\n```\n#Comman API\nbin/dddtool generate \u003clayer_name\u003e \u003cprimitive_type\u003e \u003cprimitive_namespace\u003e\n```\n\nCommand arguments:\n\n* `\u003clayer_name\u003e` - 3 types available: \"app\", \"domain\" or \"infrastructure\"\n* `\u003cprimitive_type\u003e` - \"command\" or anything you set up in the config file\n* `\u003cprimitive_namespace\u003e` - psr-4 inspired path to the file, which also serves as a namespace. F.e. \"Account/Commands/SignUp\"\n\n\nMore usage examples:\n\n```\n# Command generation\nbin/dddtool generate domain command Account\\Commands\\SignUp\n  \n# Specify config\nbin/dddtool generate app event Http\\Event\\HttpRequestRecieved -c path/to/config.php\n\n# Run with no interaction (mind -y flag)\nbin/dddtool generate app event Http\\Event\\HttpRequestRecieved -y\n  \n```\n\n## Config\nYou can set folders where new files will go to.\nYou can configure each primitive - set its alias and set stubs to generate new files from.\n\n\n```php\n$config = [\n    \n    // 3 layers with independent folders for sources and for tests\n    \"layers\" =\u003e [\n        \"app\" =\u003e [\n            \"src\" =\u003e [\n                \"qcn\" =\u003e \"\\\\App\", // What base namespace to use\n                \"dir\" =\u003e __DIR__.\"/src/app\", // Where to put new source files\n            ],\n            \"tests\" =\u003e [\n                \"qcn\" =\u003e \"\\\\Tests\", // what base namespace to use\n                \"dir\" =\u003e __DIR__.\"/tests/app\", // Where to put new tests files\n            ],\n        ],\n        \"domain\" =\u003e [\n            \"src\" =\u003e [\n                \"qcn\" =\u003e \"\\\\Domain\",\n                \"dir\" =\u003e \"src/domain\",\n            ],\n            \"tests\" =\u003e [\n                \"qcn\" =\u003e \"\\\\Tests\",\n                \"dir\" =\u003e __DIR__.\"/tests/domain\",\n            ],\n        ],\n        \"infrastructure\" =\u003e [\n            \"src\" =\u003e [\n                \"qcn\" =\u003e \"\\\\Infrastructure\",\n                \"dir\" =\u003e __DIR__ . \"/src/infrastructure\",\n            ],\n            \"tests\" =\u003e [\n                \"qcn\" =\u003e \"\\\\Tests\",\n                \"dir\" =\u003e __DIR__ . \"/tests/infrastructure\",\n            ],\n        ],\n    ],\n        \n    \"primitives\" =\u003e [\n        \"command\" =\u003e [\n            // these stubs will go to source folder\n            \"src\" =\u003e [\n                \"stubs\" =\u003e [\n                    // See Templates paragraph on placeholders\n                    \"/*\u003cPSR4_NAMESPACE_LAST\u003e*/Command\" =\u003e __DIR__ . \"/stubs/SimpleStub.stub.php\",\n                    \"/*\u003cPSR4_NAMESPACE_LAST\u003e*/Handler.php\" =\u003e __DIR__ . \"/stubs/SimpleStub.stub.php\",\n                ],\n            ],\n            // these files will go to tests folder\n            \"test\" =\u003e [\n                \"stubs\" =\u003e [\n                    \"/*\u003cPSR4_NAMESPACE_LAST\u003e*/CommandTest\" =\u003e __DIR__ . \"/stubs/SimpleTestStub.stub.php\",\n                ],\n            ],\n        \n        ],\n    ],\n    \n];\n```\n\n## Templates\nEach primitive can have multiple templates (stubs). F.e. command has command and handler templates, query has request, response and handler templates. Event will only have event template and test. So configuration explicitly declares which files to generate and in which folder.\n \nTemplate support few placeholders which reflects user input:\n* `/*\u003cBASE_SRC_NAMESPACE\u003e*/` - looks like `\\App` (each layer may have different one)\n* `/*\u003cBASE_TEST_NAMESPACE\u003e*/` - looks like `\\Domain\\Tests`  (each layer may have different one)\n* `/*\u003cLAYER\u003e*/` - app or domain or infrastructure\n* `/*\u003cPRIMITIVE\u003e*/` - the name of the primitive f.e. `event` or `command`\n* `/*\u003cPSR4_NAMESPACE\u003e*/` - looks like `Account\\Command\\SignUp`, see \u003cprimitive_namespace\u003e argument\n* `/*\u003cPSR4_NAMESPACE_BASE\u003e*/` - looks like `Account\\Command` (without final part)\n* `/*\u003cPSR4_NAMESPACE_LAST\u003e*/` f.e. `SignedUp` (just final part)\n* `/*\u003cFILENAME\u003e*/` f.e. `SignedUpCommand` (the final filename for this stub)\n\n\nThis how stub for a test file can look like inside:\n\n```\n\u003c?php\ndeclare(strict_types = 1);\n\n// Full class' namespace is combined from layer's base namespace + user provided namespace (see \u003cprimitive_namespace\u003e argument) \nnamespace /*\u003cBASE_TEST_NAMESPACE\u003e*/\\/*\u003cPSR4_NAMESPACE\u003e*/;\n\nuse PHPUnit\\Framework\\TestCase;\n\n// this is \nclass /*\u003cPSR4_NAMESPACE_LAST\u003e*/ extends TestCase {\n    \n    function test_it_works() {\n        $this-\u003emarkTestIncomplete();\n    }\n    \n}\n```\n\n\n## How it works\nTake for example the config file shown above and let's explain this command:\n`bin/dddtool generate domain command Account\\Commands\\SignUp`\n\nThe script will do this:\n* first, command will detect the layer for which you want to generate new files. In our case it is \"domain\"\n* then layer's config is detected \n* then command analyze the primitive name, in our case it is \"command\"\n* then config for this primitive is being detected\n* then for each stub in the config a new file is prepared. For example, test stub with name `/*\u003cPSR4_NAMESPACE_LAST\u003e*/CommandTest` will actually be created in file `__DIR__ . \"/tmp/tests/Account/Commands/SignUp/SignUpCommandTest.php\"`.\n* user sees the list of files which are supposed to be generated\n* after confirmation real files are generated and put to file system.\n\n## TODO\n* I am thinking about adding conditions to stub configuration, so user can be asked if he wants to skip some optional stubs for a given primitive.\n* I wonder if I can simplify the design of this tool in any way?","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flezhnev74%2Fddd-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flezhnev74%2Fddd-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flezhnev74%2Fddd-generator/lists"}