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
- For storefront themes, use
- For Admin themes, use
- For language packages, use
- For modules, use
<Magento install directory>/vendor: You will find this location for installations that use the
composer create-projectto 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
vendor directory. But we recommend adding your components to the
app/code directory. If you put your component in the
vendor directory, Git will ignore it because Magento adds the
vendor directory to the
All components require these three files:
registration.php: This file registers your component with Magento. It uses the component’s root directory name as the component name. By default, the composer installs components in the
<Magento root dir>/vendordirectory. For more information, see Component registration.
etc/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
composer.json: This file defines the dependencies that the component needs at runtime. For more information, see Composer integration.