1.1 Magento module-based architecture

Keep it simple

There are a lot of good articles that wrote about this topic. But there are some better and more understandable. I prefer:

  1. Magento 2 Module-based Architecture by Andrey Matveev
  2. The official Magento 2.3 architecture guide

You should read through the articles above but you don’t have to understand all of them. Just keep the keywords in mind and use them to research later.

Create a simple module

I usually use a module generator to create Magento modules especially MAGE2GEN. You can visit this link to create one, it has a lot of option like API, Block, Cache. But first, we only focus on the very basic:

Vendor name: Your name or your company name follow CamelCase style.

Module name: Your module name, it should be a name that says what the purpose of this module in short. It follows the CamelCase style too.

License: Visit Choose a License to know what license you need.

Copyright: Type whatever you want.

Description: Describe the module purpose here.

Finally, Click Save and download Module on the right.

Basic module structure

After I download the generated module above, extract it and this is my module structure:

  • composer.json
    Every M2 module is a composer package. “Composer” is a tool for dependency management in PHP. It allows you to declare the libraries your project/package/module depends on and it will manage.
  • module.xml
    Declare the module name and other required configuration parameters, such as the module’s schema version.
  • registration.php
    Regis the module with Magento system through the Magento ComponentRegistrar class.

Example of files content:

I’ve just created a module that actually does nothing. But don’t be rushed, we will create a useful module later, now you only need to understand what the minimal requirement of a module and how to create them is enough.

One Reply to “1.1 Magento module-based architecture”

Leave a Reply