davidgamboa/magento2-module-scaffold

CLI to scaffold Magento 2 modules in one command

Maintainers

Package info

github.com/gamta/magento2-module-scaffold

Type:project

pkg:composer/davidgamboa/magento2-module-scaffold

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-06-13 05:41 UTC

This package is auto-updated.

Last update: 2026-06-13 05:46:53 UTC


README

CLI to scaffold Magento 2 modules in one command. Installs globally via Composer — no Magento installation required.

composer global require davidgamboa/magento2-module-scaffold
scaffold make Acme/ProductEvents --type=observer --class=ProductSave --event=catalog_product_save_after

Installation

composer global require davidgamboa/magento2-module-scaffold

Make sure ~/.config/composer/vendor/bin (or ~/.composer/vendor/bin) is in your PATH:

export PATH="$PATH:$HOME/.config/composer/vendor/bin"

Usage

scaffold make Vendor/Module --type=<type> [options]

Vendor/Module must follow PascalCase: Acme/ProductEvents, not acme/productevents.

Output directory

The output directory is resolved in this order:

  1. --output=<path> — explicit override
  2. Magento root auto-detection — walks up from your current directory looking for bin/magento, then writes to {magento_root}/app/code/Vendor/Module/
  3. Fallback — {CWD}/Vendor/Module/

Global options

Option Description
--output=<path> Override output directory
--dry-run Print files that would be generated without writing
--force Overwrite if the output directory already exists

Interactive mode

Any missing required argument triggers a prompt:

$ scaffold make MyVendor/MyModule

Module type:
  [0] observer
  [1] plugin
  ...
> 0

Observer class name [MyModuleObserver]: ProductSave
Event name [catalog_product_save_after]:

✓ Generated MyVendor/MyModule (observer) → app/code/MyVendor/MyModule/

Module types

observer

Generates an event observer.

scaffold make Acme/ProductEvents \
  --type=observer \
  --class=ProductSaveObserver \
  --event=catalog_product_save_after \
  --output=app/code/Acme/ProductEvents

Generated files:

registration.php
etc/module.xml
etc/di.xml
etc/events.xml
Observer/ProductSaveObserver.php
composer.json

etc/events.xml registers the observer on the given event. Observer/ProductSaveObserver.php implements ObserverInterface with an execute() stub.

plugin

Generates a Magento plugin (interceptor) for a target class method.

scaffold make Acme/Catalog \
  --type=plugin \
  --class=ProductPlugin \
  --target="Magento\Catalog\Model\Product" \
  --method=getName

Generated files:

registration.php
etc/module.xml
etc/di.xml          ← <type> block with plugin registration
Plugin/ProductPlugin.php
composer.json

The plugin class includes before, after, and around stubs for the target method.

cron

Generates a Magento cron job.

scaffold make Acme/Imports \
  --type=cron \
  --class=ImportProducts \
  --schedule="0 2 * * *"

Generated files:

registration.php
etc/module.xml
etc/di.xml
etc/crontab.xml
Cron/ImportProducts.php
composer.json

graphql

Generates a GraphQL resolver.

scaffold make Acme/ProductGraph \
  --type=graphql \
  --class=ProductResolver \
  --field=products

Generated files:

registration.php
etc/module.xml
etc/di.xml
etc/schema.graphqls
Model/Resolver/ProductResolver.php
composer.json

etc/schema.graphqls adds a field to the Query type. The resolver implements Magento's ResolverInterface.

api

Generates a REST API endpoint with interface, repository implementation, and DI preference binding.

scaffold make Acme/ProductApi \
  --type=api \
  --class=ProductRepository \
  --interface=ProductRepositoryInterface

Generated files:

registration.php
etc/module.xml
etc/di.xml          ← preference binding
etc/webapi.xml      ← GET/POST/DELETE routes
Api/ProductRepositoryInterface.php
Model/ProductRepository.php
composer.json

command

Generates a Magento CLI command (bin/magento my:command).

scaffold make Acme/Tools \
  --type=command \
  --class=ImportCommand \
  --command-name=import:products

Generated files:

registration.php
etc/module.xml
etc/di.xml          ← injects command into CommandListInterface
Console/Command/ImportCommand.php
composer.json

Files generated for every type

Every module type includes these four files:

File Purpose
registration.php Registers the module with Magento's ComponentRegistrar
etc/module.xml Declares the module name and version
composer.json PSR-4 autoload + magento/framework require
etc/di.xml Base DI config (extended by plugin/api/command types)

Requirements

  • PHP >= 8.1
  • Composer

No Magento installation needed. The tool generates files you then drop into any Magento project.

License

MIT