Magento 2 Folder Structure

In the first lesson, I want to introduce to you the folder structure of Magento 2 and the function of each of those directories. This is a very important lesson in this series. If you know the functions of each of these folders, it will become easier to absorb the following lessons.

Magento 2 Root Folder

When you install Magento 2, you will see the folders appear in it.

app

Contains all code (modules), templates, configuration files, languages. It also contains the theme, the default settings of the system.

  • app/code: contains modules.
  • app/design/frontend: contains storefront themes.
  • app/design/adminhtml: contains Admin themes.
  • app/i18n: contains language packages.

bin

Contains the Magento CLI executable script. The script activates a console with a set of handy options: clear cache, enable/disable modules, reindexing,etc.

dev

This directory contains automated functional tests and a few tools for development.

generated

It contains all of the Magento generated code.

lib

Stores all Magento and vendor library files.

pub

Contains an index.php controller, generated static files of your Magento theme.

var

This directory contains generated classes, cache, sessions, database backups, and cached error reports.
Because of this directory, we can run commands: bin/magento setup:di:compile, bin/magento cache:clean, etc.

Module file structure

Common directories

  • Block: contains classes that view PHP as part of the Model View Controller (MVC) logic implementation.
  • Controller: Contains PHP controller classes as part of MVC’s vertical module logic implementation.
  • etc: contains configuration files; especially module.xml, is required.
  • Model: contains PHP model classes as part of MVC’s vertical module logic implementation.
  • Setup: contains classes for modular database structure and set up data called upon installation or upgrade.

Additional directories

  • Api: contains any PHP class displayed with API.
  • Console: contains CLI commands. For more information, see Add a CLI command.
  • Cron: contains cron job definition.
  • CustomerData: contains section files.
  • Helper: contains the aggregate function.
  • i18n: contains localization files
  • Observer: contains files to execute commands from the listener.
  • Plugin: contains any necessary plugins.
  • UI: contains data creation files.
  • view: contains view files, including static view files, design templates, email templates and layout files.

I hope through this series you can create your own complete module. Good luck!

In addition to Magento 2 Folder Structure, you can read the articles How To Create New Custom Module in Magento 2.

Follow us for the more helpful article!

We hope this is a useful series for you.

Thank you for reading!

3.7 6 votes
Article Rating

Aaron LX

Aaron is a passionate writer, crazy about shopping, eCommerce and trends. Besides his outstanding research skills and a positive mind, Aaron eagerly shares his experience with the readers.

Leave a Reply or put your Question here

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x