Directory structure in Laravel projects

Author
By Darío Rivera
Posted On in Laravel

One of the most cumbersome aspects to assimilate when starting with Laravel is its directory structure. Personally, when I started with Laravel, I thought that the directory structure could be somewhat exaggerated. However, it only took a few weeks working fully with the framework to understand that Laravel's scaffolding is designed for both large and small projects. Many of the directories are really necessary in all types of projects. The following table shows a brief description of each one of them.

Directory Meaning
/app Contains the application logic. In particular, it contains the controllers and models.
/bootstrap Contains the app.php file that starts the application.
/config Contains all configuration files.
/database Contains database migrations, model factories, and seeders.
/public Contains the index.php file, which is the entry point for all requests. It also contains assets such as CSS, JS, and others.
/resources Contains the plain views, decompiled assets (LESS, SASS, ...), and language translation files.
/routes Contains the application routing configuration (web.php, api.php, console.php, channels.php).
/storage Contains compiled blade files, session files, and other files generated by the framework.
/storage/app This directory can be used to store files generated by the application.
/storage/app/public This directory can be used to store files generated by the application's users and should be publicly accessible.
/storage/framework Contains framework-generated cache files.
/storage/logs Contains the application log files.
/tests Contains application automated tests.

The most important thing about this is to keep in mind that you don't have to memorize this directory structure completely, at least not at the beginning. As we use the framework for one or another application, it will be very easy to gradually become familiar with this structure.

If you observe carefully, some directories may pose unforeseen challenges in learning Laravel. For me, one of these challenges was learning to use style processors like LESS or SASS, and JavaScript execution environments like Node.Js. These files are hosted in the resources directory and are compiled to generate a single CSS or JAVASCRIPT file with all the necessary dependencies for the execution of our project. This on the one hand reduces server calls when we have a considerable amount of JavaScript and CSS files. On the other hand, it helps manage dependencies in client languages. Another challenge could be learning about generating log files with the PSR-3 standard.

The ultimate goal of this post is to illustrate the directory structure of a Laravel project in a simple way and encourage the developer to review each of these directories. When starting with Laravel, it is very helpful to enter, for example, the /config folder and review each of the files to detect how the application is configured. I hope this post has cleared up some doubts for you and has at least aroused curiosity about the new concepts you could learn, until next time!


Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.