Scaffolding Magento modules with Bricklayer generate-* tools and dry_run

Just enough scaffolding to let Your AI agent create Magento boilerplate the same way every time.

Agents can write a registration.php and a module.xml from memory, and most of the time they get it right. Most of the time is the problem. A typo in the module name, a wrong namespace in composer.json, a db_schema.xml that does not match the model, and You lose more time than the scaffold saved.

Bricklayer has four generators that produce Magento-compliant boilerplate deterministically, with conflict detection and a preview mode. The agent asks for a module, it gets the same files a human would get from the same tool.

They are disabled by default, in every deploy mode. Switch on only those You want:

vendor/bin/bricklayer config:set tools.generate-module.enabled true
vendor/bin/bricklayer config:set tools.generate-model.enabled true

The generators

Tool Required Optional (default) Generates
generate-module vendor, module version (1.0.0) registration.php, etc/module.xml, composer.json
generate-model vendor, module, entity, table fields ("") model, resource model, collection, etc/db_schema.xml
generate-controller vendor, module action (index), area (frontend), route (custom) controller, routes.xml, layout XML, .phtml template
generate-api vendor, module, resource method (GET), path ("") interface, implementation, webapi.xml, di.xml preference

All four accept dry_run and force, both false by default:

  • dry_run=true - nothing is written, You get the file list and content, each file marked new or exists
  • without force - if any target file exists, the call fails with a conflict error listing the paths. Nothing gets silently overwritten
  • force=true - overwrite, only when You really mean it

Preview first, always:

generate-module vendor="Inchoo" module="CustomPricing" dry_run=true

Looks right? Same call without dry_run:

generate-module vendor="Inchoo" module="CustomPricing"
generate-model vendor="Inchoo" module="CustomPricing" entity="Rule" table="inchoo_pricing_rule" dry_run=true

Output paths are checked with realpath() boundaries, files can only land in app/code and app/design.

Workflow

  1. module-list - make sure the name is not taken
  2. database-schema - before generate-model, check the table name is free
  3. generate-* with dry_run=true, read the preview
  4. same call without dry_run
  5. validate-module - checks registration.php, module.xml, composer.json and strict_types
  6. bin/magento module:enable Inchoo_CustomPricing && bin/magento setup:upgrade
  7. Bricklayer sees app/etc/config.php changed and reinitializes on the next call, so module-list now shows Your module

The scaffold is the start, not the module. Load development-context for what comes next (category=model, category=rest-api…) and category=coding-standards before the agent touches the generated PHP.

  • Generated code goes to app/code; if You ship modules via Composer, move it to its own package afterwards
  • In production, generators refuse to write unless explicitly enabled. Leave it that way

Start coding!

Source: GitHub · Code generation wiki