Please note this article is currently a work in progress!
What are modules?
Modules provide all the core functionality Magento offers that builds on top of the framework code and also the way for developers to add their own extended functionality to the platform.
As their name suggests they are modular collections of code designed to work independently from one another, or in many cases, depend on other modules and extend their functionality.
A module can contain many different types of code for a wide variety of purposes, which we'll cover below.
Generally speaking, small, concise modules with minimal dependencies make for better code maintainability and interpolation, but in the Magento core modules can range from micro to monolithic.
Core Magento 2 module examples
Magento_Catalog- contains all key functionality in relation to products and categories (and more!)
Magento_Checkout- contains all key functionality in relation to the cart and checkout process
Magento_Cms- contains all key functionality in relation to CMS pages and blocks
Note all the Magento modules above contained 'Magento', followed by an underscore then a descriptive word relating to the module (e.g. 'Checkout'). These form a modules name, broken down as follows:
<Vendor> is the name of the module provider / creator and
<ModuleName> is the name of the module.
So, for example a module that adds image banners to CMS pages by a company called 'My Awesome Company' might be named
Some informational tip
Note the CamelCasing used in the modules vendor and name. Camel casing is not required, but follows how Magento name their core modules. However both the vendor and module name should begin with a capital letter at a minimum.
By default, modules can be included in 2 places within a Magento 2 project:
- Within the
- Within the
vendordirectory (this is where all modules installed via composer reside)
Let's build a module!
The following guide will run through how to build a basic module and register it with Magento 2 via the command line.
The finished example can be found on Github.
Create `registration.php` file
'MageQuest_MyFirstModule', __DIR__ );\Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE,
Create `etc/module.xml` file
- Trials test your knowledge of the current topic via a multiple choice quiz.
- You'll receive a score upon completion and feedback on the answers you got right or wrong along with further guidance.
- Ensure to read up on the concepts within the 'Story' and complete the 'Quest' before attempting!
What files are required for a module?
i.e. the minimum files needed to register / enable a module