Laravel Folder Structure

Laravel Folder Structure

Share and Enjoy !

Shares

Table of Contents

  1. Project Root Directory
    1. App Directory
    2. Bootstrap Directory
    3. Config Directory
    4. Database Directory
    5. Public Directory
    6. Resource Directory
    7. Route Directory
    8. Storage Directory
    9. Test Directory
    10. Vendor Directory

In this post, we will discuss the folder structure and its role in the application. Laravel Folder Structure is created in such a way that it is suitable for all types of small and large projects. Hence best part of the Laravel framework is that it allows a developer to create their own Laravel Folder Structure. In other words, there is no compulsion on Application structure, Only we have to look to the composer to autoload all our classes.

Project Root Directory

App Directory

The first directory in the Laravel Folder Structure is the App folder.  It is an important folder because it contains the core code of the Laravel Application. Therefore all the important classes of the project reside in this folder. The app folder has subdirectories like console, HTTP, Exception, Models and Providers which are used to handle the exception and build the application.

Bootstrap Directory

The next directory in the Laravel Folder Structure is Bootstrap. This Bootstrap folder is totally different from Bootstrap CSS. This folder is responsible for the framework starting and functioning correctly. Bootstrap contains an app.php file, which is managed to autoload the framework. It also stores framework-generated cash files in the cache folders which extends performance optimization.

Config Directory

This folder helps you to control and understand the framework. As per the name, this directory stored all the files used to configure OR set up the project environment. For example, if a developer wants to debug then he needs to enable debug mode in the app.php file. Another file called database.php access all variables from the .env file for the database functionality. So we will study it in another blog post.

Database Directory

This folder stored all database functionality-related files. It has three sub-directories .i.e Factories, Migrations and Seeders. For example, if a developer wants to change database structure then with the help of artisan command i.e. php artisan make: migration generate migration file. Thus this migration file will take care of it.

Public Directory

The public directory is the entry point of your web application. Therefore this folder also stores WEB assets which the browser will access directly like images, JavaScript, CSS and other files. This means your domain should point to this folder. Hence Index.php will receive all requests and will initialize the process of autoloading events.

Resource Directory

This folder stores all un-compiled files like LESS, SCSS or JavaScript in the js and CSS respectively. And If your application is developing for multilingual then the lang folder stores all language files.  

The view is one of the essential folders of the Laravel Folder Structure. The view folder is a sub-folder of the resource directory and it stores HTML presentation logic. Laravel uses its own blade templating engine. It is a simple but powerful system so you can create sections in your view and inherits layouts from other layout template files.

Route Directory

The route is one of the important folders of Laravel. Here developer will define the URL for web requests and route for them. Laravel installation creates some default route files like web.php, api.php, channels.php and console.php in the route directory. But Laravel also allows a developer to create custom route files as per project requirements.

Now let’s look at the first file web.php in the route folder. All the requests for a web application, are handled by the web.php route file and it auto-loaded by app/Providers/RouteServiceProvider.php. This route file is a member of a web middleware group, so it is responsible for providing features like a session state, protection from cross-site request forgery attacks, cookies etc. 

The next file is api.php, it is also auto-loaded by app/Providers/RouteServiceProvider.php and kept in the API middleware group. Hence it is responsible to provide stateless to avoid tracking transactions. Basically, the route is set up to secure and verify transactions using a token system and restrict access to the session state.

The console.php file allows the developer to define Closure-based Artisan Commands. Earlier such commands need to define the class after that registering it in the console kernel. We will learn more about it in some other posts.

The channel.php helps you to define and register broadcasting channels which our application is going to use.

Storage Directory

This storage folder stored cache, session and compiled files generated by the framework. So storage folder has three subfolders app, framework and logs which stored files accordingly to names. App directory stores files which are generated by applications like user profiles and other details which are publicly available. The Framework directory stores all files generated by the laravel framework like templates, file-based sessions and cache. The log directory stores all logs generated by the application.

Test Directory

The test directory saves our automated tests. A developer can run all tests using an artisan command which generates the most detailed results.

Vendor Directory

Laravel application works with many libraries and composers for dependency management. Hence Vendor folder stores composer dependencies and packages.

Learn how to

We hope you understand the Laravel Folder Structure. We discussed the folder structure and its roles. This post will help you in your development. You can find the community on laravel.io, Laracasts Discuss, LaraChat, Discord, Reddit and laracon.net.

Visit our other Laravel Post: Install Laravel on Ubuntu.

79 / 100

Share and Enjoy !

Shares

Leave a Reply