Magento 2 for Beginners
Project Structure Overview
Project Structure Overview
Directory structure of any framework can be challenging to jump on and understand. Magento 2 Open Source is not an exception here and it is important to understand project structure before doing any development.
In this lesson we will learn Magento 2 Open Source project structure. It will help you to know files and directories, where to look at every time you work with Magento 2 Open Source project.
Let's have a look at the Magento 2 Open Source project structure.
First of all, we have to understand that this is a list of files and directories come when you install Magento 2 Open Source application. Not all files are required for development. Moreover, not all files are required to run Magento 2 Open Source application.
There are files you might never open during your development journey. Other files are necessary to change and modify quote frequently.
In this lesson, we will cover all Magento 2 Open Source project files which are on the top level of the project structure. However, there are thousands of files and PHP classes which will not be covered in this lesson. During the Mage Mastery education journey and next Magento 2 for Beginners lessons we are going to cover different classes and functionality related to different Magento 2 Open Source modules.
Application Entry Point
The number one file we have to start is
index.php file. This is an entry point of your application.
Every time Magento 2 Open Source application receives an incoming HTTP request it is processed by the
Depending on your server document root configuration, you may also configure a similar
index.php file located in the
For security reasons it is recommended to configure the document root of a Magento 2 Open Source application to point to the
All your debugging activities should start with the
index.php file. From this file, you can go deeper into the application execution process in order to find out how Magento 2 Open Source works and what part of the application processes a HTTP request.
The app directory
app directory is responsible for storing all configuration files, any themes installed in a Magento 2 Open Source application.
Also, inside the
app directory you can find source code files. There are currently no files in the
code directory as of an empty Magento 2 Open Source installation.
Usually, all additional customizations happen inside the
app/etc directory holds all default configuration settings for a Magento 2 Open Source application.
Upon the application installation the
This is a primary file where you can find database connection settings, cache related settings and other settings which are going to be covered in the next lessons.
Magento 2 platform uses XML files for storing configuring settings and dependency injection (Service Container) configuration.
di.xml file located in the
app/etc directory is a good example of dependency injection configuration.
We are going to discuss different types of XML files in order to provide configuration settings used to create or customize functionality.
config.php file which provides all available Magento 2 modules which are available for a Magento 2 Open Source application.
Each module has a active/disabled status allowing Magento 2 Open Source to include a module's functionality.
The bin directory
bin directory provides a Magento CLI (Command Line Interface) tool. It provides an interface via CLI to different Magento 2 commands to perform changes in Magento 2 application.
An example of such command can be a cache clean or compilation.
The dev directory
dev directory holds all tests which come together with Magento 2 Open Source.
Magento 2 includes 8 different types of tests inside
Each of the directory includes tests of a particular type and additional code which helps to execute tests.
dev/tools directory provides different tools and its configuration such as Grunt and other non-commonly used files.
The generated directory
This directory holds all auto-generated PHP classes. Magento 2 relies on PHP code generation.
From time to time, we are going to look into the
generated directory in order to understand logic which is used to perform a certain operation.
The lib directory
The directory includes
internal directory is not something we are going to work with. And the
web directory provides frontend or web related files.
web includes CSS/LESS files as well as UI documentation.
The phpserver directory
It provides a simple PHP server which can be used for development. It is not recommended to use the
router.php as part of Magento 2 Open Source production configuration.
The pub directory
Next directory which comes with Magento 2 Open Source is a
This is a server root directory of a Magento 2 application.
index.php is a primary file responsible for processing HTTP requests.
All media content which is going to be uploaded whether via Magento Admin or some programmatically is stored in the
Every time you would have to check the result of Import execution or want to look up a media file you have to check this directory.
The setup directory
This directory is used to provide a Web Setup Wizard and other setup related scripts.
It is a second way on how you can install Magento 2 Open Source in addition to command line installation which we have performed in a previous lesson. Usually, this is not a directory we are going to work with.
The var directory
You can find cache of Magento 2 application and session directory. In case your configuration says that all sessions have to be stored in a filesystem, the
var/session directory will hold all user session files.
var/log directory where all errors, PHP exceptions will be created and stored.
The vendor directory
This directory includes all 3rd-party dependencies installed. It also include Magento 2 source files under the
vendor/magento directory. We are going to look into the directory quite often during development.
Magento 2 Open Source provides different sample configuration files for Apache server and Nginx.
For example files
The last one is the
composer.json file. It provides all dependencies in Magento 2 application. Whether we want to install additional Magento 2 module or test the application. During development, this file is going to be used frequently.
This is what I wanted to show you in this lesson. We are going to work and learn more about each project directory and file during Mage Mastery lessons.
Subscribe to the Mage Mastery newsletter to hear first about new lessons and courses.