Understanding Laravel Directory Structure (Laravel 5+)
Once you've installed Laravel, the next step is understanding its directory structure. Laravel follows a clean and organized architecture, making it easy to locate and manage different parts of your application.
This guide will walk you through the default Laravel directory structure and explain the role of each folder and key file.
The Folders
app/
-
The heart of your application.
-
Contains Models, Controllers, Middleware, and Service Providers.
-
You'll spend most of your time here writing business logic.
bootstrap/
-
Bootstraps the Laravel framework.
-
Includes the
app.php
file that loads the framework and configuration.
config/
-
Contains all configuration files (e.g.,
app.php
,database.php
,mail.php
). -
Each file returns an array of config values for specific services.
database/
-
Contains migrations, factories, and seeders.
-
Used for version-controlling and seeding your database.
public/
-
The entry point of the application (
index.php
lives here). -
Contains public assets: CSS, JavaScript, images, etc.
resources/
-
Contains non-PHP assets like:
-
Blade templates (views)
-
Language files
-
SASS/Less
-
JavaScript source files
-
routes/
-
Defines all application routes.
-
Laravel separates routes by type:
web.php
,api.php
,console.php
,channels.php
.
storage/
-
Used for logs, compiled views, file cache, and user file uploads.
-
Includes
app/
,framework/
, andlogs/
subfolders.
tests/
-
Contains all test cases (unit, feature, etc.).
-
Laravel uses PHPUnit for testing.
vendor/
-
Holds all Composer-managed dependencies.
-
This folder is git-ignored and regenerated via
composer install
.
The Files
.env
& .env.example
-
Environment configuration files.
-
.env
contains sensitive data per environment (DB credentials, app key, etc.). -
.env.example
is a template for sharing config structure (without sensitive info).
artisan
-
Command-line interface for Laravel.
-
Used for tasks like running migrations, generating code, clearing cache, etc.
.gitignore
& .gitattributes
-
Git configuration files.
-
.gitignore
tells Git which files/folders not to track.
composer.json
& composer.lock
-
composer.json: Lists PHP package dependencies.
-
composer.lock: Locks those dependencies to specific versions for consistency.
package.json
-
Similar to
composer.json
, but for Node.js front-end packages (e.g., via NPM/Yarn).
phpunit.xml
-
Configuration for PHPUnit, Laravel's default testing framework.
README.md
-
Describe the project, installation steps, and other basic info.
server.php
-
A fallback server file used when running Laravel with PHP's built-in server.
webpack.mix.js
-
Contains Webpack configuration using Laravel Mix for compiling assets.
Final Thoughts
Understanding the Laravel directory structure helps you write cleaner, more maintainable code. Whether you're building APIs, full-stack apps, or admin dashboards, knowing what goes where is the first step toward mastering Laravel.