Understanding the Directory Structure of Laravel 4.2


In this post I’ll try to explain the over all directory structure of . I think the understanding of the directory structure will proved to be helpful in order to create your websites and/or web applications. Let’s begin without wasting time anymore.

The general directory or application structure of laravel 4.2 is given below:

laravel 4.2
     --app
     --bootstrap
     --public
     --vendor
       composer.json
       composer.lock
       server.php

app directory

This directory is very important and we may say it the soul of our laravel application as it holds all the main and necessary components of our application which must not be public in any case. These important components are controllers, models, migrations, views, routes file, configuration files, storage and etc.

bootstrap directory

This directory contains the files needed to auto load classes, bootstrapping the application and creating/instantiating new application object.

public directory

This directory contains all the directories used as our assets such as css, js, img and fonts and files which are directly accessible by the user. That’s why we must not put any sensitive data containing files in this directory.

vendor directory

This directory contains all the directories and files produced by the framework vendor. This is not of our concerns until unless you want t some advanced stuffs.

App Directory

laravel 4.2
     --app
         --commands
         --config
         --controller
         --database
         --lang
         --models
         --start
         --storage
         --tests
         --views
           filters.php
           routes.php

commands directory

This directory is used to store your custom commands for the artisan.

config directory

This directory contains the files and folders used to configure your application. You can also configure database, view, mail, sessions, local environment (in local directory) and etc.

controllers directory

This directory holds your controller class files.

database directory

This directory holds your migrations and seeding class files.

lang directory

This directory contains language packages. You can use your own local language in the application.

model directory

This directory holds your model class files.

start directory

This directory contains a file named artisan.php to register your custom artisan commands and another file named global.php to autoload controllers and models in case you don’t want to use composer autoloading.

storage directory

This directory contains folders to save logs, cache, sessions and view files temporarily created at runtime. So, you should assign write permission to this directory in order to write these file.

test directory

If you want to test your laravel application you can easily do that using laravel testing tool. For this purpose you need to create some classes which should be saved in this directory.

views directory

As its name is describing this directory holds all of your views.

filters.php

This file is used to store predefined and/or custom filters.

routes.php

This file is used to store our routes for our website. It provides a way to  handle our sites’ routes at a single place. In this way it becomes easy to handle our routes.

Bootstrap Directory

laravel 4.2
     --bootstrap
           autoload.php
           path.php
           start.php

autoload.php

This file, as its name explaining, contains stuffs related to the autoloading and loads of different classes.

path.php

This file contains paths to different places in our app such as App Path, Base Path, Storage Path and etc.

start.php

This file is very important as it does a lot of duty for us such as creating application instance, binding the path, detecting environment, loading application and returning the application instance.

Public Directory

laravel 4.2
     --public
         --css
         --fonts
         --img
         --js
         --locales
         --packages
           .htacess
           index.php
           robots.txt

css directory

This directory holds css files.

fonts directory

This directory holds fonts used in our website.

img directory

This directory stores images being used in our website.

js directory

This directory holds our JavaScript files.

local directory

This directory holds files related to local languages other than English.

packages directory

This directory holds all the assets (css, js, img, fonts etc) of your package/s if you’ve included any.

.htaccess

This file makes sure that whenever a route is provided to laravel , it will always start from index.html file from the public directory which enhance the security of your application.

index.php

This is the file which we may say that handles all of our routes. Whenever a route is passed to laravel index.php is the first file which is used to show other views.

Vendor Directory

laravel 4.2
     --vendor

vendor directory

This directory, as mentioned above, holds all the files, directories, APIs, artisan commands and every thing provided by the laravel framework itself or is got from any other framework like Symfony.

That’s all from this post. I hope this will help you to understand the best PHP Framework Laravel! Feel free to comment and/or ask question via comments. 

Leave a Reply

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