About component file structure
One of the first things you can do to get started with component development is to understand and set up the file system. Each type of component has a different file structure, although all components require certain files.
In addition, you can choose the component root directory to start development. The following sections have more information.
Root directory location
A component’s root directory matches the component’s name and contains all its subdirectories and files. Based on how you installed Magento, you can put your component’s root directory in one of two places:
-
<Magento install directory>/app
: This is the recommended location for component development. You can set up this environment by Cloning the Magento 2 GitHub repository.- For modules, use
app/code
. - For storefront themes, use
app/design/frontend
. - For Admin themes, use
app/design/adminhtml
. - For language packages, use
app/i18n
.
- For modules, use
-
<Magento install directory>/vendor
: You will find this location for installations that use thecomposer create-project
to install the Magento 2 metapackage (which downloads the CE or EE code). You will also find this location if you install Magento by extracting the compressed Magento 2 archive.Magento installs third-party components in the
<Magento install directory>/vendor
directory. But we recommend adding your components to the<Magento install directory>/app/code
directory. If you add your component to the<Magento install directory>/vendor
directory, Git will ignore it because Magento adds thevendor
directory to the<Magento install directory>/.gitignore
file.
Required files
The following files are required for all components:
registration.php
: Among other things, this file specifies the directory in which the component is installed by vendors in production environments. By default, Composer automatically installs components in the<Magento root dir>/vendor
directory. For more information, see Component registration.composer.json
: Specifies component dependencies and other metadata. For more information, see Composer integration.
Each component has an additional component-specific required file:
Component Type | Required file | Description |
---|---|---|
magento2-module |
module.xml | This file defines basic information about the component, such as component dependencies and version number. Magento uses the version number to determine which schema and data to update when executing bin/magento setup:upgrade . |
magento2-theme |
theme.xml | Describes the Magento theme. File specifies a theme name in the title node, a parent theme (optional), and a theme preview image (optional) in the media/preview_image node. |
magento2-language |
language.xml | Declares a language translation package. |
Related topic