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 is the top-level directory for that component under which its folders and files are located. Depending on how your Magento development environment was installed, your component’s root directory can be located in two places:
<Magento install directory>/app: This is the recommended location for component development. You can easily set up this type of environment by Cloning the Magento 2 GitHub repository.
- For modules, use
- For storefront themes, use
- For Admin themes, use
- For language packages, use
- For modules, use
<Magento install directory>/vendor: This location is found in the alternative setups where the
composer create-project. command was used to get a Magento 2 metapackage (which downloads the CE or EE code), or a compressed Magento 2 archive was extracted in order to install Magento.
Any third-party components (and the Magento application itself) are downloaded and stored under the
<Magento install directory>/vendordirectory. If you are using Git to manage your project, this directory is typically added to the
<Magento install directory>/.gitignorefile. Therefore, we recommend you do your customization work in
<Magento install directory>/app/code, not
<Magento install directory>/vendor.
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>/vendordirectory. 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|
||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
||theme.xml||Describes the Magento theme. File specifies a theme name in the
||language.xml||Declares a language translation package.|