High-level Magento Architecture. Magento 2 vs Magento 1

Sep 21, 2017950
High-level Magento Architecture. Magento 2 vs Magento 1

The article is dedicated to the basic Magento architecture as well as its comparison with both Magento versions.  As for Magento 1 structure, all relevant description you can find in the article Magento Module StructureAs for Magento 2 structure, it is shown in the picture below.

High-level Magento architecture. Magento 2 vs Magento 1

If compared with Magento 1, the structure has changed. But registration.php and etc/module.xml are still obligatory.

In Magento 2 the structure is not as strict as in Magento 1, so the folder may have any subfolder. Additionally, the developer is allowed to place a file in any subfolder. However, the listed folders correspond to different class types, so this structure is historical and should be retained.

One of the significant distinctions between Magento 1 and Magento 2 is the lack of codepools in Magento 2. The code here can be placed in the app/code and vendor directories.

The most general module structure in Magento 2 is the following:

  • Block: For blocks
  • Controller: For controller actions
  • Helper: For helpers
  • Model: Where models and resource models are located
  • Setup: For installing and upgrading scripts
  • View: For layout XML files, templates, and static view files

NOTE: The file name should repeat the folder structure, starting from <Vendor>/<ModuleName>. For example, the PHP class in the file app/code/Magento/Catalog/Model/Product.php should have the name Magento/Catalog/Model/Product.

Let’s see how Magento 2 processes the request. In Magento 2 we’ll initiate the request by going to the index.php file.

The first part of the code is similar to the code we’ve had in Magento 1. It uses the bootstrap.php file, which requires autoload.php.

Note that the autoload file registers the autoloader:

Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Vlad

The autoloader is quite important because all your classes will be downloaded with it. Magento has a few autoloaders, but the main one (\Composer\Autoload\ClassLoader) is similar to the one we’ve had in Magento 1. It takes the path to the class and converts it to the physical path to the file.

In Magento 2, we no longer have a factory method, that’s why it calls all classes by full names making the process a bit easier.

Partner With Us Looking for a partner that will help you to grow your business? We are the right company to develop your webstore. Feel free to get in touch with us. We will be happy to discuss your business opportunities and provide you with a Free Quote. Talk to Vlad

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *