Magento 2 Folder Structure – File & Module Directory Structure
Just like the operating system in our computer requires the source files, the resources stored on the Magento 2 server power the complete functioning of the online store. Every element of the design, set of functions, modules, database, and other files are stored on the Magento server, making the flawless operations possible for the merchants and the customers.
Have you ever wondered where the default modules reside in the Magento directory? or How the files and resources are structured in the Magento directory? Read this blog post to find out answers to such questions.
Magento 2 stores the source files in a very structured and sophisticated manner. It is essential for the users to understand the directory structure in Magento 2 before diving deep into the versatility of this eCommerce platform. It is also essential for the budding developers to clear the Magento 2 Folder Structure concept, as it will help them better understand how the backend works in Magento 2.
In this article, I have explained the directory structure of Magento 2 in simple words, yet in detail!
Let’s get started!
Magento 2 Folder Structure
The Magento 2 root directory contains the following folders:
- app
- bin
- dev
- generated
- lib
- phpserver
- pub
- setup
- var
- vendor
Each of the folders in the Magento 2 root directory is explained below in brief with subfolders:
/app
The app folder in Magento 2 contains the main Magento code along with the design files. The subfolders of /app folder are explained below in brief.
- app/design subfolder contains all the design resources for both the admin panel and frontend.
- app/design/adminhtml subfolder contains all the LESS & CSS files for the backend admin panel.
- app/design/frontend subfolder contains the design resources responsible for the storefront look.
- app/etc subfolder contains the global di.xml file that includes dependencies and classes required by the object manager.
- app/i18n contains the different language packs installed on your Magento 2 store.
- app/code may also be created while developing new modules in Magento 2.
/bin
The bin folder in Magento includes the Magento file, which contains the Command-line Interface (CLI) script. It is responsible for the basic functionalities, including controlling cache, managing modules, indexing, etc.
/generated
The generated folder in the Magento 2 folder directory contains all the codes generated for creating new classes as required.
/lib
The lib folder in the root directory of Magento 2 contains the non-module-based codes and libraries. It is a pool of codes and libraries apart from the Magento core.
- lib/internal subfolder contains the server-side libraries and fonts.
- lib/web subfolder contains the client-side libraries solely for core Magento resources.
/phpserver
The phpserver folder contains the router.php file used for implementing PHP in the Magento server. It is not advised to tweak the router.php file as it may result in a security loophole in the system.
/pub
As the name suggests, the pub folder contains all the files in Magento 2 that are publicly accessible. It contains all the resources and files required and generated by Magento to create the frontend. The index.php file is also present in this folder.
/setup
The setup folder in the root directory of Magento 2 contains all the resources and files required during the set-up of Magento 2 after installation.
/var
The var folder contains all the logs, cache and error reports of the sessions and the generated classes. Some of the common subfolders generated under this folder are:
- var/log subfolder contains all the log files generated during the sessions, which includes system.log & exception.log.
- var/cache subfolder contains all the Magento cache files.
/vendor
The vendor folder contains the composer.json. The files and folders included under the vendor folder is defined by the composer.json file.
Magento 2 Module Directory Structure
The app folder is where the default modules reside in the Magento 2 directory. The modules are stored in app/code/ directory and contain the following common files and folders:
- Block
- Controller
- etc
- Model
- Observer
- view
Each of the Magento 2 module directory folders is explained below in brief:
/Block
The block folder in the module directory contains the PHP view classes as a part of the Model View Controller(MVC) vertical implementation.
/Controller
The controller folder contains the classes as part of module logic.
/etc
The etc folder includes the configuration files such as module.xml.
/Model
The Model folder contains all the Database-related PHP model classes.
/Observer
The Observer folder contains all the files required for executing the listener’s commands.
/view
The view folder contains the static files such as design templates, email templates, layout files, etc.
The theme file directory also contains a similar folder structure in Magento 2 as the module directory. You may love to read our detailed blog post on creating a child theme in Magento 2.
Conclusion
I hope this blog post will help you get started with Magento 2 folder structure and directory. One thing to mention here is that the Magento 2 community and enterprise versions have slightly different directory structures. You can also refer to the official Magento 2 resources on components structure to understand how the core components interact in Magento 2.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
100+ Best Dropshipping Products [Updated List for 2024]
Magento 2 API – Reset Customer Password
Next