Laravel Application Structure

If you are a beginner in Laravel and you are about to deploy and make your first application, it is a must that you must know its application structure. In this blog, we will show and briefly explain its structure which is, basically the structure of folders, sub-folders and files included in a project.

Once we created a project in Laravel, we will get an overview for its application structure as shown below. The root folder of the Laravel project contains a numerous subfolders and files.

App

It’s the project’s application folder, which contains all of the project’s source code. It includes declarations for events, exceptions, and middleware. The app subdirectory is divided into several subfolders, as shown below.

  1. Console – The artisan commands required by Laravel are available in the console. It includes a directory called Commands, which contains a list of all the commands and their signatures. Kernal.php executes the commands defined in Inspire.php. If we need to call a specific command in Laravel, then we should make appropriate changes in this directory.
  2. Exceptions – This category contains all of the exception-handling methods. It also includes the handle.php file, which handles all exceptions.
  3. Http – Controllers, middleware, and application requests are all subfolders of the Http subdirectory. This folder contains model, controllers, and views created for the specific directories, as Laravel uses the MVC design pattern. The Middleware sub-folder contains the middleware mechanism, which comprises the filter mechanism and response and request communication. All of the application’s requests are in the Request Folder.
  4. Models – Each database table has a “Model” associated with it that is utilized to communicate with it. Models enable you to query your tables for data as well as add new records to the database.
  5. Providers – All of the service providers for your application are included in the Providers directory. Service providers prepare your application for incoming requests by binding services in the service container, registering events, and executing any other actions necessary.

Bootstrap

The app.php file in the bootstrap directory bootstraps the framework. This directory also contains a cache directory, which contains framework-generated performance files such the route and services cache files. You shouldn’t need to change any of the files in this directory very often.

Config

The config directory includes all of your application’s configuration files, as the name implies. Reading over all of these files and becoming familiar with all of the options available to you is a terrific idea.

Database

Your database migrations, model factories, and seeds are all stored in the database directory. You can also use this directory to store a SQLite database if you want.

  1. Factories – This folder is used to generate large number of data records.
  2. Migrations – This folder helps in queries for migrating the database used in the web application.
  3. Seeders – This contains the classes used for unit testing database.

Public

The index.php file, which is the entry point for all requests entering your site and configures autoloading, is located in the public directory. Your assets, such as photos, JavaScript, and CSS, are also stored in this directory. The server configuration is stored in the .htaccess file. Javascript and CSS, on the other hand, are considered assets. The file index.php is essential for a web application’s initialization.

Resources

Your views, as well as any raw, uncompiled materials like CSS or JavaScript, are stored in the resources directory. All of your language files are also stored in this directory.

  1. Assets − The assets folder include files such as LESS and SCSS, that are required for styling the web application.
  2. Lang − This folder includes configuration for localization or internalization.
  3. Views − Views are the HTML files or templates which interact with end users and play a primary role in MVC architecture.

Route

The routes directory holds all of your application’s route definitions. Laravel comes with many route files by default: web.php, api.php, console.php, and channels.php.

  1. web.php – The RouteServiceProvider places routes in the web middleware group, which offers session state, CSRF protection, and cookie encryption, in the web.php file. If your application does not provide a stateless, RESTful API, all of your routes will almost certainly be defined in the web.php file.
  2. api.php – The RouteServiceProvider adds routes to the api middleware group in the api.php file. These routes are designed to be stateless, which means that requests entering the application through them will be authenticated using tokens and will not have access to session state.
  3. channels.php – You can register all of the event broadcasting channels that your application supports in the channels.php file.
  4. console.php – You can define all of your closure-based console commands in the console.php file. Each closure is associated with a command instance, allowing for a straightforward way to communicate with the IO methods of each command. This file defines console-based entry points (routes) into your program, despite the fact that it does not create HTTP routes.

Storage

Your logs, compiled blade templates, file-based sessions, file caches, and other files generated by the framework are all stored under the storage directory. This directory is divided into three sections: app, framework, and logs. Any files generated by your program can be stored in the app directory. Framework produced files and caches are stored in the framework directory. The logs directory includes the log files for your application.

Test

Your automated tests are stored in the tests directory. Out of the package, PHPUnit unit tests and feature tests are included. The term Test should be appended to each test class. You can use the phpunit or php vendor/bin/phpunit commands to perform your tests. Alternatively, you can use the php artisan test to create a more detailed and appealing display of your test findings.

In addition to the above mentioned files, Laravel also includes some other files which play a primary role in various functionalities such as GitHub configuration, packages and third party libraries. These files are shown below

Leave a Comment

Your email address will not be published. Required fields are marked *