What is a Magento module?
Short answer
A Magento module groups the configuration and code for a feature under a name such as Vendor_Module. Its conventional identification files are registration.php and etc/module.xml. The directories it needs depend on the feature. Knowing the structure helps you locate a change; it does not replace dependency declarations, a deployment process or behavior tests.
- Identify the module and its package 01
- Register the component location 02
- Declare dependencies and load order 03
- Put files where the framework expects them 04
- Deploy and test the actual behavior 05
Watch for this Editing installed vendor source as the fix
Read a module from identity to behavior
Start with the component name and package, then follow registration, dependencies, feature files and deployment requirements.
-
01
Identify the module and its package
A module uses a Magento name such as
Vendor_Module. A Composer package can have a different package name, such asvendor/module-example. Keep the Magento declaration, registration and PHP namespaces consistent. Anapp/codedirectory and a Composer-installed package use different distribution workflows. -
02
Register the component location
At the module root,
registration.phpcallsComponentRegistrar::register()with the module name and its directory. This records the component location. It is not itself a universal PHP autoloader or an instruction to enable the module. Composer packages normally include the registration file through their autoload configuration. -
03
Declare dependencies and load order
etc/module.xmldeclares the Magento module name and can list a<sequence>. Composer requirements express package dependencies; sequence contributes component load order for supported configuration, view and setup files. It does not replace explicit patch dependencies or control the loading of ordinary PHP classes. -
04
Put files where the framework expects them
Use
etcfor configuration,Controllerfor actions, andview/frontendorview/adminhtmlfor the appropriate presentation files. AddApi,Model,PluginorObserveronly when needed. The component structure reference explains the main directories. -
05
Deploy and test the actual behavior
Registration, enablement, dependency installation and database setup are separate concerns. Review the required deployment steps for the change; setup updates can alter persistent data. New schema or data patches need deliberate dependencies and recovery planning. A familiar folder structure is useful, but it does not make an extension safe to install without review.
When a change belongs in a module
Use a cohesive module for application behavior and versioned configuration. Some presentation-only changes belong in the theme instead.
-
The change belongs to application behavior
A module can hold a controller, service, configuration field or integration that a theme change alone cannot provide. Keep its responsibility understandable and testable. A small, cohesive customization does not require an arbitrary one-module-per-class rule.
-
A feature needs versioned distribution
For code installed across projects, a Composer package provides a dependency and release workflow. Declare compatible requirements and the appropriate autoload/registration configuration. Do not copy another installation's
vendortree as a release process. -
Existing behavior needs an extension point
A plugin or observer belongs in a module with the configuration that activates it. Choose a suitable supported extension point and area. Not every public method is interceptable, and disabling a module is not an automatic reversal of its stored data changes.
-
A persistent change needs a recorded migration
Data and schema patches are mechanisms for reviewed setup changes. Their class identities and dependencies matter because applied history affects later upgrades. Test installation, upgrade and failure behavior; do not delete production patch history as a way to make a change run again.
Module assumptions that make upgrades harder
Keep installed package ownership, dependency mechanisms and class loading distinct. A familiar directory tree is only the starting point.
-
Editing installed vendor source as the fix
Installed package files are owned by the dependency workflow. A local edit can disappear during installation and is difficult to reproduce. Prefer an appropriate extension point or a reviewed package change through its source and release process. Keep installation inputs and code changes traceable.
-
Treating sequence as a universal dependency switch
Composer requirements, component sequence and patch
getDependencies()solve different problems. Use explicit patch dependencies when one setup operation relies on another. Do not assume an alphabetical directory order or a sequence declaration makes every database migration safe. -
Confusing discovery, autoloading and enablement
A registered component can still be disabled, and a class reference can still fail to autoload. Check registration, module name, package autoload rules, case-sensitive paths and enabled configuration separately. A namespace name alone does not explain every class-loading failure.
Magento module structure, frequently asked questions
-
What files identify a Magento module?
A conventional module has a rootregistration.phpandetc/module.xml. Composer-distributed modules also need their package and autoload configuration. The rest of the directories depend on the feature; an empty module does not need every directory shown in a large example. -
Should a custom module live in app/code or vendor?
Project-owned code can live underapp/code/Vendor/Module. Composer installs managed packages into its configured installation location, commonly undervendor. Choose a reproducible source and release workflow. Do not hand-edit files in an installed package to turn them into project-owned customizations. -
Does registration.php enable or autoload the module?
It registers the component name and location. Enablement and PHP class loading are separate mechanisms. Composer uses its autoload configuration, and Magento has registration support for non-Composer components. Check each layer rather than assuming registration creates a namespace mapping for every class. -
What does module.xml sequence do?
It declares component load order for the framework's relevant configuration, view and setup processing. It does not affect normal PHP class loading. Adobe's load-order guide explains the distinction. Declare package dependencies and exact patch dependencies where they are required as well. -
Are data patches safe to run again?
Magento records applied patch identities so normal setup processing can skip them. That history is not proof that arbitrary patch code is repeatable or reversible. Review the change and recovery plan before applying it, and do not delete history to force a production patch to run again. -
Where should I learn to build a complete module?
This page explains the anatomy and responsibilities of the files. For a worked implementation, use the custom module tutorial. Verify examples against your Magento version and installed dependencies, then test behavior as well as registration and compilation.
Planning or reviewing a Magento module?
Share the requirement, current Magento version and the relevant source. The extension-development page explains how to discuss scope, integration and review needs.