Modules in the Magento 2 file structure

Module files in Magento 2 are located in 2 directories.

1. app/code/<VendorName>/<ModuleName>/
2. vendor/<vendor-name>/<module-name>/

Vendor Name — is the name of the company/person that developed the module. In some cases, the name of the vendor may coincide with the name of the customer's company. Therefore, before developing a new module, the name should be agreed upon. In the examples, we use our name — Magefan

Module files developed on order or modules from other companies installed via FTP are located in the app/code folder.

The vendor folder contains Magento 2 root modules, as well as modules installed using the Web Setup Wizard or Composer. You will find the Magento root modules in the vendor/magento folder.

Interesting to know:
In the Magento 2 repository (dev branch) on GitHub (https://github.com/magento/magento2), all root modules are in the app code/Magento folder. And all PHP libraries are in lib/internal/Magento. 

This structure was used during the Magento 2 development, long before the vendor folder existence and official release. For convenience, this structure is still used on GitHub.

The structure of the Magento 2 module

├── Api // PHP interfaces
├── Block // PHP view classes, in MVC terminology. They contain methods used in .phtml templates;
│    ├── Adminhtml // view-classes of the admin panel;
│    └── SomeBlock.php // view-class (block) used in the storefront;
│
├── Controller // PHP controller-classes (part of MVC);
│    └── Adminhtml // controller classes used in the admin panel;
│
├── Cron // PHP classes, which methods are called when performing cron-tasks;
├── Helper // PHP classes with auxiliary logic. Their methods are used in different parts of the module; ├── Model // PHP model classes (part of MVC); ├── Observer // PHP observers classes; ├── Plugin // PHP classes of interceptors; ├── Setup // PHP classes used when installing, updating and removing the module, allow you to change the data and structure of the database; ├── UI // PHP classes that work with UI-components; ├── etc // module configuration files; │ ├── adminhtml // configuration files that apply only to the admin panel; │ │ ├── admingws.xml // is used for the delimitation of rights at the Store View level (used only in Enterprise version (EE) of Magento 2); │ │ ├── di.xml // plugin settings, virtual types, rewriting models .; │ │ ├── menu.xml // is responsible for building the menu; │ │ ├── routers.xml // route settings; │ │ ├── system.xml // building a settings page Stores> Configuration; │ │ └── events.xml //observers settigns; │ │ │ ├── frontend // configuration files of the storefront;
│ │ ├── di.xml │ │ ├── events.xml │ │ ├── routers.xml │ │ └── events.xml │ │ │ ├── acl.xml // settings for delimitation of rights in the admin panel; │ ├── config.xml // default values ​​for fields in Stores> Configuration;
│   ├── crontab.xml // settings of cron-tasks; │ ├── di.xml │ ├── webapi.xml // REST API settings; │ └── widget.xml // widget settings; │ ├── i18n // CSV localization files; │ ├── en_US.csv │ └── uk_UA.csv │ ├── view // view files: layouts, templates, js, css, html, images, fonts; │ ├── adminhtml // files used in the admin panel; │  ├── frontend // files used in the frontend; │    │ └── layout // xml layout files; │    │ └── templates // phtml-template files; │    │ └── web // static files; │    │ └── css │    │ └── images │    │ └── js │    │
│    └── base // view files used both on the storefront and admin panel;
│ ├── LICENSE.txt // file with the description of the license according to which the module is used; ├── README.md // description of module functionality; ├── composer.json // file that allows to install the module through composer later on; └── registration.php // file that registers the module in the system;

This structure does not have all the possible directories and files Magento 2 module may contain. It only displays the frequently used components of the module.

You can explore the structure of Magento 2 modules on your own. To do this, pay attention to these modules:

- Magento_Cms (vendor/magento/module-cms)
- Magento_Catalog (vendor/magento/module-catalog)