Main frontend menu generation in Magento 2

Magento 2 Development
If you are familiar with Magento 1.x menu generation, you will be surprised how similar is the appropriate Magento 2 process. There are 9 steps of menu generation.

magento/magento2/blob/22629abe10f9c640fe47b6081d57fedccdea8e0f/app/code/Magento/Theme/view/frontend/templates/html/topmenu.phtml#L18

magento/magento2/blob/22629abe10f9c640fe47b6081d57fedccdea8e0f/app/code/Magento/Theme/Block/Html/Topmenu.php#L72-L75

magento/magento2/blob/22629abe10f9c640fe47b6081d57fedccdea8e0f/app/code/Magento/Catalog/Observer/AddCatalogToTopmenuItemsObserver.php#L54

magento/magento2/blob/22629abe10f9c640fe47b6081d57fedccdea8e0f/app/code/Magento/Catalog/Helper/Category.php#L115

magento/magento2/blob/22629abe10f9c640fe47b6081d57fedccdea8e0f/app/code/Magento/Catalog/Model/Category.php#L947

magento/magento2/blob/22629abe10f9c640fe47b6081d57fedccdea8e0f/app/code/Magento/Catalog/Model/ResourceModel/Category.php#L628-L640

magento/magento2/blob/487f5f45/app/code/Magento/Theme/view/frontend/requirejs-config.js#L27-L27

magento/magento2/blob/487f5f45/app/code/Magento/Theme/view/frontend/templates/html/topmenu.phtml#L21-L24

magento/magento2/blob/487f5f45/lib/web/mage/menu.js#L14-L17

magento/magento2/blob/487f5f45/lib/web/jquery/jquery-ui.js#L11439-L11439

Source

More tips from Magento 2 cookbook