When you will create your fresh Laravel application, it will contain a large number of folders as shown in image below:
Each of these folders fulfills a specific task for the overall functioning of the framework. The purpose of each of these folders is explained below but before that let’s look at each of them once:
Directory Structure:
- app directory
- bootstrap directory
- config directory
- database directory
- public directory
- resources directory
- routes directory
- storage directory
- tests directory
- vendor directory
Purpose of each of these directories:
1. app directory: This directory is the heart of the framework and backend developers mostly work on this directory. It contains all the backend code of our web application like Controllers, Broadcasts, Providers, Custom Artisan Commands, Middlewares, etc. This directory further contains many sub-directories like shown in the image below:
The App Directory:
Directory | Purpose |
---|---|
Console | This directory contains all Artisan commands which are created by us. These commands can be generated using the php artisan make:command command. |
Exceptions | This directory contains the application’s exception handling files. Here you can create your own specific exceptions to be thrown by our application. |
Http | This directory contains our controllers, middleware, and form requests. Almost all of the backend to handle requests entering our application will be placed here. |
Providers | This directory contains all of the service providers for the application. Service providers bootstrap our application by making services available to us by registering them. |
Broadcasting | This directory is not there by default but can be created by using the php artisan make:channel command. It contains all of the broadcast channel classes for our application to broadcast your events. |
Events | This directory is not there by default but can be created by using the php artisan make:event command. This directory contains event classes which can be used to give signals to other parts of the application or vice-versa. |
Jobs | This directory is not there by default but can be created by using the php artisan make:job command. This directory contains lineup jobs for our application. |
Listeners | This directory is not there by default but can be created by using the php artisan make:listener command. This directory contains the classes that handle our events. |
This directory is not there by default but can be created by using the php artisan make:mail command. This directory contains all of our classes that represent emails sent by application. | |
Notifications | This directory is not there by default but can be created by using the php artisan make:notification command. This directory contains all of the “transactional” notifications that are sent by our application. |
Policies | This directory is not there by default but can be created by using the php artisan make:policy command. This directory contains the authorization policy classes which are used to determine if a user can access or change a specific data or not. |
Rules | This directory is not there by default but can be created by using the php artisan make:rule command. This directory contains the self-created validation rule objects which are used to encapsulate complicated validation logic in a simple object. |
2. bootstrap directory: This directory contains app.php from where the whole framework bootstraps. This directory also contains the cache directory which is used to store framework generated files for performance optimization.
3. config directory: This directory contains all the configuration files related to database, mail, session, services, etc.
4. database directory: This directory contains database migrations, model factories, and seeds.
5. public directory: This directory contains the index.php file which is the entry point and handles all requests received by the application and configures autoloading too. Apart from this, this directory also contains assets used in the application like images, javaScript, and CSS.
6. resources directory: This directory contains the frontend of the application. All the HTML code which makes the frontend of application is present here in the form of Blade templates which is a templating engine Laravel comes with.
7. routes directory: This directory contains all the route definitions of the application.
8. storage directory: This directory contains the compiled Blade templates, file based sessions, file caches, and other files generated by framework.
9. tests directory: This directory contains all of our automated tests which are required to ensure that the application is working as per expectations or not.
10. vendor directory: This directory contains all the dependencies downloaded through Composer needed by our framework.