How to create a new custom module in magento2 – Part-I

This posts will helpful to create a new module in magento2.
Hope everyone knows, magento 2.x folder structure is different from magento 1.x.
How we create a new module in magento 1.x won’t be suitable to magento 2.x. Have some different will be there. Will see in this post.
Before going to create a magento 2.x module creation, we can check magento 1.x. module creation So that we can get some idea and difference
The way we create a module in magento 1.x
Namespace: Jute
Module Name: Sample
1. Global module declaration. Jute_Sample.xml we have to create and locate into app/etc folder.
2. Create module folder.
app/code/local/Jute/Sample
app/code/local/Jute/Sample/etc/config.xml (module level xml configuration)
app/code/local/Jute/Sample/controllers
app/code/local/Jute/Sample/Helper
app/code/local/Jute/Sample/Block
app/code/local/Jute/Sample/Model
Similarly if required other files like, sql , Controller, adminhtml.xml, system.xml,etc.. We can create and we can use it.
Note: But in magento2.x core files available in following path :magento2\vendor\magento\
3. Declare Frontend template and layout
app/design/frontend/default/MYTHEME/layout/sample.xml
app/design/frontend/default/MYTHEME/template/sample
When we trigger the following the URL http://localhost/magento1x/sample/index/index , magento will render the frontend sample template file output from the browser.
Magento2:
1. Folder app/code includes subfolders like core, local & community. But in Magento2.x app/code includes magento and zend. These two folders are subfolders of the folder core.
2. When we create a module in magento1.x we usually keep inside the app/code/local or community (if required). But in magento 2.x directly into app/code folder.
3. Global module declaration in magento1.x is app/etc/Jute_Sample.xml or Jute_All.xml. But in magento2.x module declaration file name always should be module.xml. Ex:  app/code/Jute/Sample/etc/module.xml
4. Layout and template are saved in folder app/design folder Ex:  app/design/frontend/default/MYTHEME/layout. But in magento2.x layout and template should be inside view folder of the module.
The folder is the same level with some folders like: Block, Controller, Helper, Model, etc. in the module Ex:  app/code/Magento/Hello/view/frontend/layout
Ex Folder structure:
app/code/Jute/Sample
app/code/Jute/Sample/etc
app/code/Jute/Sample/etc/frontend (Frontend configuration xml. Event observer will use one common xml file in magento1.x. But here there are two files like admin & frontend event.xml located appropriate folder)
app/code/Jute/Sample/etc/adminhtml (admin related xml files. Like admin menu setup, system configuration setup)
app/code/Jute/Sample/Block
app/code/Jute/Sample/Controller
app/code/Jute/Sample/Helper
app/code/Jute/Sample/Model/
app/code/Jute/Sample/Observer/ (In magento2.x we have a separate folder for event observer php files. But in magento1.x we will use Model folder.)
app/code/Jute/Sample/view/frontend/layout (Frontend design template)
app/code/Jute/Sample/view/frontend/template (Frontend design template)
app/code/Jute/Sample/view/adminhtml/layout (adminside design template)
app/code/Jute/Sample/view/adminhtml/template (adminside design template)
app/code/Jute/Sample/Api (Api related files will be available in these folder)
app/code/Jute/Sample/i18n (These folder is for language translator purpose. Like in magento1.x we use app/locale/en_US
app/code/Jute/Sample/Test/ (Unit testing purpose. By default magento2.x having PHP unit testing library)
Js and CSS files:
app/code/Jute/Sample/view/frontend/web/css & JS (fronte end related js and css files with respective folder)
app/code/Jute/Sample/view/adminhtml/web/css & JS (admin end related js and css files with respective folder)

CORNER OF BLOG:

“All light is not light; for noble scholars,
truthfulness is the true light of enlightenment.