{"id":2582,"date":"2024-08-27T20:23:00","date_gmt":"2024-08-27T20:23:00","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/magento-2-folder-structure-file-module-directory-structure\/"},"modified":"2025-04-24T09:48:06","modified_gmt":"2025-04-24T04:18:06","slug":"magento-2-folder-structure","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/magento-2-folder-structure\/","title":{"rendered":"Magento 2 Folder Structure &#8211; File &#038; Module Directory Structure"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Just like the operating system in our computer requires the source files, the resources stored on the&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/what-is-magento\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2<\/a>&nbsp;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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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&nbsp;<em><strong>Magento 2 Folder Structure<\/strong><\/em>&nbsp;concept, as it will help them better understand how the backend works in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, I have explained the directory structure of Magento 2 in simple words, yet in detail!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s get started!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Magento 2 Folder Structure<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Magento 2 root directory contains the following folders:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>app<\/li>\n\n\n\n<li>bin<\/li>\n\n\n\n<li>dev<\/li>\n\n\n\n<li>generated<\/li>\n\n\n\n<li>lib<\/li>\n\n\n\n<li>phpserver<\/li>\n\n\n\n<li>pub<\/li>\n\n\n\n<li>setup<\/li>\n\n\n\n<li>var<\/li>\n\n\n\n<li>vendor<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/06\/Magento-2-Directory-Structure-1.png\" alt=\"Magento 2 Directory Structure\" class=\"wp-image-50645\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Each of the folders in the Magento 2 root directory is explained below in brief with subfolders:<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; app<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>app<\/strong>&nbsp;folder in Magento 2 contains the main Magento code along with the design files. The subfolders of&nbsp;<strong>\/app&nbsp;<\/strong>folder are explained below in brief.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>app\/design&nbsp;<\/strong>subfolder contains all the design resources for both the admin panel and frontend.\n<ul class=\"wp-block-list\">\n<li><strong>app\/design\/adminhtml&nbsp;<\/strong>subfolder contains all the LESS &amp; CSS files for the backend admin panel.<\/li>\n\n\n\n<li><strong>app\/design\/frontend&nbsp;<\/strong>subfolder contains the design resources responsible for the storefront look.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>app\/etc&nbsp;<\/strong>subfolder contains the global&nbsp;<strong>di.xml&nbsp;<\/strong>file that includes dependencies and classes required by the object manager.<\/li>\n\n\n\n<li><strong>app\/i18n&nbsp;<\/strong>contains the different language packs installed on your Magento 2 store.<\/li>\n\n\n\n<li><strong>app\/code&nbsp;<\/strong>may also be created while developing new modules in Magento 2.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; bin<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; generated<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>generated&nbsp;<\/strong>folder in the Magento 2 folder directory contains all the codes generated for creating new classes as required.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; lib<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>lib&nbsp;<\/strong>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.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>lib\/internal&nbsp;<\/strong>subfolder contains the server-side libraries and fonts.<\/li>\n\n\n\n<li><strong>lib\/web&nbsp;<\/strong>subfolder contains the client-side libraries solely for core Magento resources.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; phpserver<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>phpserver&nbsp;<\/strong>folder contains the&nbsp;<strong>router.php&nbsp;<\/strong>file used for implementing PHP in the&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/move-magento-2-from-localhost-to-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento server<\/a>. It is not advised to tweak the router.php file as it may result in a security loophole in the system.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; pub<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">As the name suggests, the&nbsp;<strong>pub&nbsp;<\/strong>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&nbsp;<strong>index.php&nbsp;<\/strong>file is also present in this folder.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; setup<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>setup&nbsp;<\/strong>folder in the&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/get-root-directory-path-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">root directory of Magento 2<\/a>&nbsp;contains all the resources and files required during the set-up of Magento 2 after installation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; var<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>var<\/strong>&nbsp;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:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>var\/log&nbsp;<\/strong>subfolder contains all the log files generated during the sessions, which includes&nbsp;<strong>system.log&nbsp;<\/strong>&amp;&nbsp;<strong>exception.log<\/strong>.<\/li>\n\n\n\n<li><strong>var\/cache&nbsp;<\/strong>subfolder contains all the Magento cache files.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; vendor<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>vendor<\/strong>&nbsp;folder contains the&nbsp;<strong>composer.json<\/strong>. The files and folders included under the vendor folder is defined by the composer.json file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Magento 2 Module Directory Structure<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>app&nbsp;<\/strong>folder is where the default modules reside in the Magento 2 directory. The modules are stored in&nbsp;<strong>app\/code\/&nbsp;<\/strong>directory and contain the following common files and folders:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Block<\/li>\n\n\n\n<li>Controller<\/li>\n\n\n\n<li>etc<\/li>\n\n\n\n<li>Model<\/li>\n\n\n\n<li>Observer<\/li>\n\n\n\n<li>view<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/06\/Magento-2-Module-Structure-e1654933030161-1.png\" alt=\"Magento 2 Module Structure\" class=\"wp-image-50647\" style=\"width:840px;height:auto\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Each of the Magento 2 module directory folders is explained below in brief:<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; Block<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>block&nbsp;<\/strong>folder in the module directory contains the PHP view classes&nbsp; as a part of the Model View Controller(MVC) vertical implementation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; Controller<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>controller&nbsp;<\/strong>folder contains the classes as part of module logic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; etc<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>etc&nbsp;<\/strong>folder includes the configuration files such as&nbsp;<strong>module.xml<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; Model<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>Model&nbsp;<\/strong>folder contains all the Database-related PHP model classes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; Observer<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>Observer&nbsp;<\/strong>folder contains all the files required for executing the listener\u2019s commands.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#8211; view<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>view&nbsp;<\/strong>folder contains static files such as design templates, email templates, layout files, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/create-child-theme-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">creating a child theme in Magento 2<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-community-vs-enterprise-edition\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 community and enterprise versions<\/a>&nbsp;have slightly different directory structures. You can also refer to the&nbsp;<a href=\"https:\/\/developer.adobe.com\/commerce\/php\/development\/build\/component-file-structure\/\" target=\"_blank\" rel=\"noreferrer noopener\">official Magento 2 resources<\/a>&nbsp;on components structure to understand how the core components interact in Magento 2.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just like the operating system in our computer requires the source files, the resources stored on the&nbsp;Magento 2&nbsp;server power the complete functioning of the online&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-2582","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=2582"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2582\/revisions"}],"predecessor-version":[{"id":12904,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2582\/revisions\/12904"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}