Directory Structure Within Magento 2

The directory structure within Magento 2 has changed compared to earlier versions of Magento.

Learning the locations of the files and folders in Magento 2 might take some time, however there are similarities with the Magento 1 structure.

If you have downloaded Magento from the Magento website, the root directory will look like the following.

Directory Structure Within Magento 2

Magento 2 Directory Structure

Within the app directory consists the following directories and files.

  • The code directory where you will place any third party code not installed via Composer, or your own custom modules. The Magento core code has been moved into the vendor directory.
  • A design directory that contains an adminhtml and frontend directory.
    • The adminhtml directory is used for creating adminhtml themes.
    • The frontend directory is used for creating frontend themes
  • Contains an etc directory that contains two important files:
    • env.php that contains environment configuration such as database, cache and session information.
    • config.php that contains a PHP array of active and inactive modules.

The bin directory contains:

  • This directory contains a magento executable that is used to run common commands such as clearing the cache, running the database upgrade and deploying static content.

Within the dev directory:

  • Contains migration and testing tools for developers.

The lib similar to Magento 1 contains library files.

  • Contains an internal directory that contains the Libertine font files.
  • Contains a web directory that contains multiple directories of assets such as CSS, images and JavaScript files.

phpserver:

  • Contains a router.php file for the php built-in web server.

The pub folder is the preferred document root for the Magento application.

  • The pub directory is a security measure in order block public access to your root directory assets. Therefore it is recommended to set up Magento to route through the index.php file within this directory rather than within the root directory.
  • The media directory contains generated static files and media images uploaded.

setup:

  • Contains files relating to the installation setup of Magento.

The update directory:

  • Contains files that are used when upgrading the Magento application.

The var directory, similar to Magento 1:

  • Contains various directories including session, cache, log and report data.

And lastly, the vendor directory is created via the use of composer commands.

  • Contains the Magento core application and theme code that are installed via Composer. Any third party libraries such as Zend Framework that are installed this way are also present in this directory. Code edits should not be made in any files within the vendor directory as they will get overridden when installing or updating packages.

That covers an overview of the directory structure within Magento 2. With this information you’ll be able to create a module and custom theme to help you get started with using the application.

Note: This article is based on Magento version 2.1.