In this article, we are going to talk about the similarities and differences between the Magento 1 and the Magento 2 module structure. This allows you to bring conventions over from your knowledge of Magento 1 over into Magento 2. This also lets you know about what differences to expect in Magento 2’s module structure.
Typical Magento 1 Module Structure
Here is what the typical Magento 1 module structure looks like:
Magento 1 had class types. Class types defined what each class was responsible for. For example, blocks contained logic for the view layer. Helpers were auxiliary classes, and so on. Casing also mattered in the folder structure, due to how the autoloader worked in Magento 1.
There are two separate controller folders in this module. One was for actual controllers. The other was for abstract or base controller functionality. One is capitalized so the autoloader could pick it up. The other one is in the lowercase folder because the router resolves this particular class.
The etc/ folder holds all xml files necessary for the module.
The data/ and sql/ folders hold all installation and upgrade scripts for structure and data.
Magento 2 Module Structure
The Magento 2 module structure, looks similar, but there are a number of key differences.
There are a lot more folders in Magento 2 modules. That is because you are no longer bound by class types in Magento 2. You can organize your classes according to whatever makes the most logical sense in Magento 2.
The etc/ folder now holds xml files, but they also have subfolders according to their appropriate scope. For example, there will be a frontend/ and adminhtml/ subfolders under this folder.
The sql/ and data/ folders are no longer present. It has been replaced by the Setup/ folder. You no longer have separate files for installation. This folder holds the installation and upgrade classes for both schema and data.
All files are now contained within their own module. Things like your module registration file, template and layout files, translations, and web assets are all within the module itself. It is much easier to maintain files this way. They are held within respective folders such as etc/, view/, Ui/, and i18n/.
There is only one Controller/ folder now. They have consolidated how controllers were resolved and loaded in Magento 2, so there is no need to have two separate folders.
The Observer/ and Plugin/ folders would’ve been in the Model/ folder in Magento 1. Now they are in their own folders for better organization.
There is now a Test/ folder in your modules. This holds all of your unit tests in Magento 2.
The root of the module now holds composer.json, README.md, and registration.php files. These files help with dependency management, module declaration and other auxiliary functionality.