Explanation of App/Code vs Vendor Directories in Magento 2.1

composermagento-2.1

I'm looking for an explanation of the app/code/[vendor] and vendor/[vendor] directories? (For M2.1)

Some online sources (such as inchoo) say to put a new module in app/code/[vendor], yet in 2.1 there is no such directory, and modules are conspicuously in vendor/[vendor]. Meanwhile the official doc page on the Magento file system say "information will be added later".

Which is correct? What's the history — did this change at some point? Can I read docs that refer to app/code and just do the same thing in vendor/?

Best Answer

Magento 2 advocates the use of composer for managing modules, when you install a module through composer it is added to vendor/<vendor-name>/<module>.

You should not edit any code inside the vendor folder. If you’re developing your own module or if you want to continue development of an existing module you add your files or clone a git repo to app/code/<vendor-name>/<module>.

If you later want to distribute this custom module you initialize a git repo and create a composer package. Now others will be able to download and install your module as a composer package, in their <vendor> folder.

Related Topic