Magento2 Composer Guide

Magento 2 Composer Guide

Magento 2 uses Composer, a PHP dependency manager, to package components and product editions.

Composer is a dependency management for PHP and in Magento 2, so the composer plays the role in gathering components and product editions. When using the Magento 2 composer, there is no requirement of storing all code of each component, and you only need to create composer.json file. And declare the needed components in that file instead that. Immediately, the composer will auto-define and take the corresponding data of those components to run for your project.

The Magento composer.json file defines the name, requirements, version, and other basic information about the component and this file must be placed in the root directory of the module. What’s great, Composer can resolve dependencies on a per-project basis. Thus, developers can control packages for each project and keep the project size in check.

Composer reads a composer.json file in Magento’s root directory to download third-party dependencies listed in the file.

The Component Manager uses the composer.json file in an extension’s root directory to perform the following actions:

To update, uninstall, enable, or disable an extension if installed using Composer (including from Packagist, Magento Marketplace, or other source) and it has a composer.json file. The Component Manager can still enable or disable an extension not installed using Composer. (e.g. custom code) If it has a composer.json file.

Magento recommend you include composer.json in your component’s root directory. Even If you do not intend to distribute it to other merchants using Magento.

Thinking of understanding Magento 2 Composer file, but not sure how to make it for module? Don’t worry, you’re at the right place! Because here is the example files also.


Here is the example of composer.json file.

    "name": "v4u/helloworld",
    "description": "Simple Hello World Module for Magento 2",
    "type": "magento2-module",
    "version": "1.0.0",
    "license": [
    "authors": [
            "email": "[email protected]",
            "name": "Vrajesh Patel"
    "minimum-stability": "dev",
    "require": {
        "php": "~7.1.3||~7.2.0||~7.3.0"
    "autoload": {
        "files": [
        "psr-4": {
            "V4U\\Helloworld\\": ""

Different Composer package types :

– Metapackage :

Technically, a Composer package type, not a Magento component type and a metapackage consists of only a composer.json file that specifies a list of components and their dependencies. For example, both Magento Open Source and Magento Commerce are metapackages.

Package Type : metapackage
Location : composer.json

– Module :

Code that modifies Magento application behaviour and you can upload a single module to the Magento Marketplace so It’s available on Marketplace or your module can be dependent on some parent package. The package is located under app/code/Magento/Module/composer.json,so It’s naming conventions are magento/module-catalog-inventory and magento/module-checkout because It’s type is magento2-module.

Package Type : magento2-module
Location : app/code/VendorName/ModuleName/composer.json,

– Theme :

Code that modifies the look and feel of the storefront because theme is used to change the look and feel of both storefront as well as Magento Admin. The package is located under app/design/area/Magento/theme/composer.json, so It’s naming conventions are magento theme-frontend-blank and magento theme-adminhtml-backend, because It’s type is magento2-theme.

Package Type : magento2-theme
Location : app/design/frontend/VendorName/ThemeName/composer.json,

– Language Package :

Language package translates the store language. The package is located under app/i18n/magento/Language/composer.json,so It’s naming conventions are magento/language-en_us, magento/language-de_de, etc, because It’s type is magento2-language.

Package Type : magento2-language
Location : app/i18n/VendorName/LanguageCode/composer.json

– Library :

Support for libraries located in lib/internal instead of in the vendor directory. The package is located under lib/internal/Magento/Framework/composer.json,so It’s naming convention is magento/framework, because It’s type is magento2-library.

Package Type : magento2-library
Location : lib/internal/Magento/Framework/composer.json

– component :

So the package formed of the files that must be located in root (index.php, .htaccess, etc).This includes dev/tests and setup as well for now.

Package Type : magento2-component
Location : root/


So Home

Tagged , , , ,