DEV Community

waceera_ngumi
waceera_ngumi

Posted on

Understanding Magento 2 Folder Structure

In this article, I’ll take you through the Magento 2 folder structure and how to navigate through it. If you are coming from Magento 1, knowing where to add your modules or adding a custom theme to change your store appearance can be daunting at first.

Download any Magento version from this link, https://magento.com/tech-resources/download and get the setup instructions from https://devdocs.magento.com/guides/m1x/install/installing_install.html.

app/
This folder contains three sub-directories mainly design, i18n and etc by default. The app/code// directory should contain all the custom modules that you have created. It is also recommended to store all your third party modules here.

Your custom store theme should be stored under app/design/frontend subdirectory while the app/design/adminhtml subdirectory should be used to store all your Admin themes.

app/i18n directory stores language packages. You might want to use this folder if you want to create a multi-language store to suit your customer needs.

The code subdirectory will be missing after a clean install. All Magento core modules are in the vendor directory in order to avoid the mixing of your custom modules with the Magento core modules. Unlike in Magento 1 where one had to commit all their Magento core modules to their Git repository, in Magento 2 the two are separated.

Stores all your packages installed via Composer including Magento core modules. Working from this folder is not advisable since all your changes will be overridden once you upgrade any of your Magento vendor files. Extending the modules under app/code/ or app/design is highly recommended.

phpserver/
This folder contains the Router.php file whose main purpose is to implement the PHP built-in server. Working with this file is discouraged because it has tons of potentially big security holes. See the READMe

bin/
This directory contains the Magento CLI executable script. This script activates Magento commands that help in clearing cache, reindexing etc.

setup/
Contains Magento’s installation setup files.

generated/
Stores all of Magento’s generated code. By default, Magento generates code to create non-existent factory classes if the class is injected in a constructor.

var/
Contains generated classes, cache, sessions, database backups, and cached error reports.This folder has a number of sub directories including var/di whose contents are generated once you run php bin/magento setup:di:compile.

var/log contains magento log files mainly exception.log and system.log files.

var/cache stores all of Magento’s cache. In order to see your developement changes, it is advisable to continuously clear your cache using this command php bin/magento cache:clean

dev/
Contains automated functional tests that the Magento Test Framework runs.

lib/
Stores all Magento and vendor library files. It also contains all the non-module based Magento code. This is mostly system code that aid Magento to run.

pub/
This directory also contains anindex.php file that is used to run the application in production mode. The pub directory offers a security measure whereby public access to the root directory asset is restricted. This folder also contains generated static files of your Magento theme.

Conclusion
At this point, I believe you’ve understood the Magento 2 folder structure and what content goes in each folder. This will help you get started with Magento 2 and easily customize your store within a short period of time. You can always refer to the official Magento documentation to get a deeper understanding of how different Magento components interact with each other.

Top comments (0)