Laravel Application folder structure

Dikshant Rajput
3 min readApr 22, 2021

--

In my previous post, I shared about how to setup Laravel in your system and running the server. If you haven’t read it, I will suggest you to first read that and then carry on with this one.

Link of my previous blog post: https://dikshantraj2001.medium.com/getting-started-with-laravel-5c9191cee5d0

It’s very important to know what all you get from the framework that you are going to learn before starting real coding. You should know what all you are getting and how it’s going to make your life easy. So let’s start…..

Folder structure of laravel application

APP Directory:

It contains the core code and functionality of your application is defined here.

BOOTSTRAP Directory:

It contains the app.php file which bootstraps the framework.

CONFIG Directory:

It contains all the configuration files for your app.

DATABASE Directory:

It contains all your files related to database manipulation like migrations, seedings and model factories.

PUBLIC Directory:

It contains the index.php file and all the other required secondary resources like images, js files, css files etc.

RESOURCES Directory:

It contains the view files i.e all your html related stuff is in this directory.

ROUTES Directory:

It contains the routing for your application.

STORAGE Directory:

It contains the log files, session files, compiled blade templates, caches and other files required to run an application.

The storage/app/public directory may be used to store user-generated files, such as profile avatars, that should be publicly accessible. You should create a symbolic link at public/storage which points to this directory. You may create the link using the php artisan storage:link Artisan command.

TEST Directory:

It contains all the files related to automated tests for your application.

VENDOR Directory:

It contains all the composer dependencies files.

WORKING OF A TYPICAL LARAVEL APPLICATION

DISCLAIMER: These all are just fancy words. Don’t get scared by them!!! :)

index.php

First of all I will tell you about the entry point of a laravel application i.e. public/index.php file. All requests are directed to this file by your web server. There’s not that much code in this file. It is just the starting point for your application.

The index.php file loads the Composer generated autoloader definition, and then retrieves an instance of the Laravel application from bootstrap/app.php. The first action taken by Laravel itself is to create an instance of the application /service container.

HTTP / console kernel

Then the request goes to the HTTP or console kernel file depending on the type of request. All the actions that we want to do on the request before actually accessing is done here. Typically, these classes handle internal Laravel configuration that you do not need to worry about. Middlewares and everything is defined here. Don’t be scare with all these names, you will become familiar soon.

Service Providers

One of the most important kernel bootstrapping actions is loading the service providers for your application. All of the service providers for the application are configured in the config/app.php configuration file's providers array. All the third party libraries are registered here.

Routing

Then comes the routing part. All the routings configurations are in App\Providers\RouteServiceProvider file. All the routes from routes folder are loaded .

Last step

Once the route or controller method returns a response, the response will travel back outward through the route’s middleware, giving the application a chance to modify or examine the outgoing response.

Finally, once the response travels back through the middleware, the HTTP kernel’s handle method returns the response object and the index.php file calls the send method on the returned response. The send method sends the response content to the user's web browser.

Laravel Life Cycle

NOTE: For better understanding go to official Laravel documentation, you will find everything there. ALL THE BEST !!!

--

--

Dikshant Rajput
Dikshant Rajput

No responses yet