Laravel Directory Structure Explained
When you create a new Laravel project, you'll notice many folders and files. At first, the project structure may seem overwhelming, but each directory has a specific purpose.
In this tutorial, we'll explore the Laravel directory structure and understand what each folder is used for.
Why Understanding the Directory Structure Matters
Knowing where Laravel stores controllers, models, views, routes, and configuration files helps you:
- Navigate projects more efficiently
- Follow Laravel best practices
- Debug issues faster
- Organize your code properly
Let's break down the most important directories.
Root Directory Structure
A fresh Laravel installation looks similar to this:
app/
bootstrap/
config/
database/
public/
resources/
routes/
storage/
tests/
vendor/
.env
artisan
composer.json
Each folder serves a specific purpose.
app Directory
The app directory contains the core application code.
app/
├── Http/
├── Models/
├── Providers/
app/Http
Contains:
- Controllers
- Middleware
- Form Requests
Example:
app/Http/Controllers
This is where you'll create controllers using:
php artisan make:controller UserController
app/Models
Stores Eloquent models.
Example:
class User extends Model { // }
Models interact with database tables.
app/Providers
Contains service providers that bootstrap your application.
Example:
AppServiceProvider.php
bootstrap Directory
The bootstrap folder is responsible for starting Laravel.
bootstrap/
Important subdirectory:
bootstrap/cache
Laravel stores cached configuration and route files here for better performance.
Normally, you won't modify anything inside this folder.
config Directory
Contains all application configuration files.
config/
Examples:
config/
├──app.php
├──database.php
├──mail.php
├──cache.php
├──queue.php
Example
Database configuration:
config/database.php
Application name:
config/app.php
You can access config values using:
config('app.name');
database Directory
Contains everything related to the database.
database/
├── factories/
├── migrations/
├── seeders/
Migrations
Database structure files.
Example:
php artisan make:migration create_posts_table
Location:
database/migrations
Seeders
Insert sample or default data.
Location:
database/seeders
Factories
Generate fake data for testing.
Location:
database/factories
public Directory
This is Laravel's web root directory.
public/
Contains:
public/
├──index.php
├──favicon.ico
├──robots.txt
The index.php file is the entry point of your application.
Any publicly accessible files should be stored here.
Examples:
- Images
- Generated assets
- Uploaded files (via storage link)
resources Directory
Contains frontend resources.
resources/
├── css/
├── js/
├── views/
resources/views
Stores Blade templates.
Example:
resources/views/home.blade.php
resources/css
Contains CSS files.
Example:
app.css
resources/js
Contains JavaScript files.
Example:
app.js
routes Directory
Contains all route definitions.
routes/
Important files:
routes/
├──web.php
├──api.php
├──console.php
├──channels.php
web.php
Web application routes.
Route::get('/', function () { return view('welcome'); });
api.php
API routes.
Example:
Route::get('/users', function () { return User::all(); });
storage Directory
Stores generated files and application data.
storage/
Contains:
storage/
├──app/
├──framework/
├──logs/
logs
Application log files.
Example:
storage/logs/laravel.log
Useful for debugging errors.
app
Stores uploaded files and generated content.
tests Directory
Contains application tests.
tests/
Includes:
tests/
├──Feature/ Unit/
Feature Tests
Test complete application functionality.
Unit Tests
Test individual classes and methods.
Run tests:
php artisan test
vendor Directory
Contains all Composer packages and Laravel framework files.
vendor/
Generated automatically when running:
composer install
⚠️ Never edit files inside the vendor directory because Composer may overwrite them during updates.
.env File
Stores environment-specific settings.
Example:
APP_NAME=Laravel
APP_ENV=local
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
Important information such as:
- Database credentials
- Mail settings
- API keys
- Application environment
is stored here.
Never commit sensitive .env data to a public repository.
artisan File
Laravel's command-line interface.
Example commands:
php artisan serve
php artisan migrate
php artisan make:model Post
php artisan cache:clear
Artisan helps automate common development tasks.
composer.json
Defines project dependencies.
Example:
{ "require": { "laravel/framework": "^13.0" } }
Composer uses this file to install packages.
Quick Summary
| Directory/File | Purpose |
|---|---|
| app | Application code |
| bootstrap | Framework bootstrap files |
| config | Configuration files |
| database | Migrations, seeders, factories |
| public | Public web files |
| resources | Views, CSS, JavaScript |
| routes | Route definitions |
| storage | Logs and uploaded files |
| tests | Application tests |
| vendor | Composer dependencies |
| .env | Environment configuration |
| artisan | Laravel CLI |
| composer.json | Dependency management |
Conclusion
Understanding Laravel's directory structure is one of the first steps toward becoming a productive Laravel developer. Once you know where controllers, models, views, routes, and configuration files live, building and maintaining Laravel applications becomes much easier.