What is the benefit of a pub directory in Magento 2
The pub directory is a security measure in order block public access to your root directory assets, namely the app directory. The reason that index.php is also located in the root directory is presumed to address individuals whose webhost make it difficult or impposible to change your webroot.
When utilizing the pub/index.php the app source folder will not be able to be accessed while it could be it be if index.php was being ran from the root directory. This practice is also seen in Symfony and Zend 2.
This way none of the Magento application configurations, templates, etc are exposed.
Generally, knowledge of the architecture in regards to the pub index.php vs root index.php are not needed for frontend developers on a team but understanding its basics are good to know.
Magento 2 comes with two index.php files where one file is inside root folder and another one is inside /pub folder. Magento 2 offers to run your application using any one of this file. If you choose to run your application using /pub/index.php then it is a good decision for security point of view as it restrict unauthorized direct access of application files.
As side note it's good to keep in mind that the /index.php
file is used when running as developer mode and /pub/index.php
is used when running as production mode