Magento 2 Structure

Overview of Directory And Libraries

In this article, we will take a look at the Magento 2 directory structure. Magento 2 structure has been changed a lot from the previous version of Magento.The Magento 2 structure consist of the following three types :

  • Basic Structure
  • Module Structure 
  • Design Structure

Basic Structure

The Basic Structure consist of fo the following files and folders:

/RootDirectory

  • /app
  • /bin
  • /dev
  • /lib
  • /pub
  • /var
  • /vendor

/app

The app is a directory, core files including configuration, modules and theme files are exist in this folder.

/bin

The bin is a directory where the Magento 2 CLI files are located. The CLI help you in installing modules, upgrading the core application, compiling etc.

/dev

dev is a directory, contain the Magento 2 Test Framework tools for developers to test scripts.

/lib

lib is a directory, contain the Magento 2 library files.

/pub

The pub is a directory, contain the files to access the static Magento 2 files. some other directories also exist in 

  • Errors consist of error logs.
  • Media consist the all media files of product, pages etc.
  • Static consist of Magento theme files

/var

var is a directory consist of all temporary files like cache files, logs, sessions and reports.

/vendor 

the vendor is a directory, generated by the composer using the composer.json file.

Module Structure

The third-party modules exist in /app/code. The files for modules are arranged according to the following pattern app/code/{vendor}/{module_name}. 

Module Structure consists of the following files and folders:

etc

etc is a directory, stores all the setting of the module. And includes the configuration files specially module.xml, which is required for the module.

Block

Block is a directory, includes all the blocks with PHP files.

Controller

The controller is a directory, contain all the PHP files of controller classes as part of module implementation.

Model 

Model is a directory, contain all the model classes as part of module implementation.

Setup 

Setup is a directory, contain files for module database structure and data setup. Such as Installschema.php(used for the installation of database structure), InsatllData.php (used for the installation of data in the database), UpgradeData.php (used for update the data in the database), UpgradeSchema.php (used for update the structure of the database).

Plugins

The plugin is a directory, includes all the PHP files for the plugins.

Helper

Helper is a directory, contain aggregated functionality.

Console

The console is a directory, contain all the CLI commands.

API

API is a directory, contain all the API interface classes.

Observer

The observer is a directory, contain the PHP files of observer classes for executing commands.

i18n

i18n is a directory, contain all the localization files.

UI

Ui is a directory, contain the data generation files of PHP and XML.

View

The view is a directory, contain the view files, static view files, templates, design templates and layout files. Internal structure divided into adminhtml, frontend, base. The view is responsible for display the area.

registration.php

This file is used to register your module in Magento. The component root directory name is used as a component name in the registration file.

Design Structure

The design files exist in app/design/, they are divided into adminhtml and frontend.

etc

etc is a directory, contain the theme setting and the view.xml file for the configuration of the image.

media 

media is a directory that contains the preview of your theme(screenshot).

web

The web is a directory, contain the static files organized into the CSS, js, fonts files for the theme.

theme.xml

Required file for the theme, inside it, defines the name of the theme and its parent.

requirejs-config.js

requirejs-config.js is a file, consist of requireJS config.

registration.php

The required file that is used to register the theme in Magento.

composer.json

Composer.json file is used for downloading the theme.

 

If you are looking for Magento Developer, visit the Magento 2 Services.