One of Laravel’s biggest strengths is its elegant and intuitive folder structure. If you’re a PHP developer wanting to build modern, maintainable applications, understanding Laravel’s directory layout is critical.
This guide is your deep dive into every major folder and file that ships with a Laravel project. Let’s unlock what’s inside the Laravel box!
🔥 Quick Snapshot of the Laravel Folder Tree
Here’s roughly what you’ll see at the root of a fresh Laravel install:
app/
bootstrap/
config/
database/
lang/
public/
resources/
routes/
storage/
tests/
vendor/
artisan
composer.json
.env
Let’s unpack these in detail.
1. app/ — Core Application Logic
This is your domain layer — the place where business logic, models, and services live.
app/Console/
- Holds Artisan console commands.
- Primary file:
Kernel.php, which:- Registers scheduled tasks (via cron)
- Loads custom CLI commands
Example: Create a custom command
php artisan make:command ProcessPayments
Generates:
app/Console/Commands/ProcessPayments.php
app/Exceptions/
- Central place for error handling.
- Main file:
Handler.php.- Handles:
- Logging
- Reporting exceptions
- Rendering custom error responses
- Handles:
- You can override how specific exceptions behave.
app/Http/
This is the “controller” layer in MVC.
Controllers/
- Classes that handle HTTP request logic.
- Example:
php artisan make:controller UserController --resource - Creates methods like:
index()store()update()
Middleware/
- Intercept HTTP requests before they reach controllers.
- Typical uses:
- Auth checks
- CORS handling
- Rate limiting
- Example:
php artisan make:middleware CheckSubscription
Generates:
app/Http/Middleware/CheckSubscription.php
Requests/
- Encapsulate form validation logic.
- Example:
php artisan make:request StoreBlogRequest - Keeps controllers clean and focused on business logic.
app/Models/
- Houses Eloquent models representing your database tables.
- Typically extend:
class Product extends Model { protected $fillable = ['name', 'price']; } - Command to generate a model plus related resources:
php artisan make:model Customer -mfsc-m→ migration-f→ factory-s→ seeder-c→ controller
app/Providers/
- Service providers bootstrap services and perform app-level configuration.
- For example:
- Registering service bindings
- Publishing packages’ configuration files
- Main file:
AppServiceProvider.php
Generate your own:
php artisan make:provider GeocodingServiceProvider
2. bootstrap/ — Framework Bootstrapping
Responsible for getting Laravel started.
app.php— loads the framework, initializes core components.cache/— stores:- Compiled routes
- Config caches
- Optimized performance files
Why it matters: Speeds up production deployments.
3. config/ — Centralized Configuration
All app configuration happens here.
Common files:
app.php— app name, timezone, localedatabase.php— DB connections (MySQL, SQLite, Postgres)filesystems.php— local disks, S3, etc.queue.php— drivers for jobs (database, Redis, SQS)
Pro tip: Environment variables in .env override settings here.
4. database/ — Database Layer
This is where database versioning and seed data live.
migrations/
- Define schema changes.
- Example:
php artisan make:migration add_vat_to_invoices_table --table=invoices
Creates:
database/migrations/2025_07_01_add_vat_to_invoices_table.php
factories/
- Create fake data for testing.
- Great for database seeding or test environments.
Example:
php artisan make:factory OrderFactory --model=Order
seeders/
- Populate tables with data.
- Example:
php artisan make:seeder CountriesSeeder
Runs with:
php artisan db:seed
5. public/ — Web Entry Point
Only folder accessible to the web directly.
Key contents:
index.php— the front controller for all requests.- Compiled assets:
- CSS
- JS
- Images
- Usually, you deploy your web server to point to this directory.
Security benefit: Protects internal files from being publicly accessible.
6. resources/ — Frontend and Views
Your “presentation layer.”
views/
- Contains Blade templates like:
resources/views/welcome.blade.php - Supports layouts, components, slots, and sections.
Example:
php artisan make:component Dashboard/Card
Generates:
resources/views/components/dashboard/card.blade.php
lang/
- Stores translation strings for multilingual apps.
- E.g.:
resources/lang/en/messages.php
js/ & css/
- Contains uncompiled frontend assets:
- Vue, React components
- Sass or CSS files
- These get compiled into the
public/directory via Vite.
7. routes/ — Routing Layer
Organizes your application’s endpoints.
Common files:
web.php— web routes (with sessions, CSRF)api.php— stateless APIsconsole.php— Artisan command registrationchannels.php— broadcasting channels
Example route:
Route::get('/users', [UserController::class, 'index']);
8. storage/ — Generated Files & Caching
Stores runtime and user-generated files.
app/— user uploadsframework/— cache, sessions, viewslogs/— application logs likelaravel.log
Important:
- Public files often symlinked to:
public/storage
9. tests/ — Automated Testing
Your testing suite lives here.
Feature/— test flows across multiple components (e.g. endpoints)Unit/— test small, isolated pieces of code
Example:
php artisan make:test PaymentProcessingTest --pest
Run tests:
php artisan test
10. vendor/ — Composer Dependencies
Contains third-party libraries installed via Composer.
- Autoloading handled via:
vendor/autoload.php - You should never edit vendor files directly.
Key Root-Level Files
.env- Secrets and config per environment
- E.g.:
DB_PASSWORD=secret MAIL_HOST=smtp.mailtrap.io
artisan- Laravel CLI tool
composer.json- PHP package manager dependencies
package.json- Frontend build dependencies
vite.config.js- Configuration for Vite, Laravel’s new default asset bundler
Laravel’s Structural Philosophy
Separation of Concerns
MVC ensures clarity between:
- Models → data logic
- Views → UI
- Controllers → request handling
– Environment Flexibility.env variables let you adapt to any hosting environment without touching code.
– Modern Frontend Workflow
- Vite replaces older Webpack usage.
- Hot module reload speeds up development.
– Security First
- Internal code protected outside the web root.
- Sensitive info locked away from public exposure.
– Testing Culture
- Laravel ships with robust tools for TDD using PHPUnit and Pest.
Artisan Cheat Sheet
| Component | Command |
|---|---|
| Model | php artisan make:model Product -a |
| Controller | php artisan make:controller --api |
| Migration | php artisan make:migration update_users |
| Policy | php artisan make:policy InvoicePolicy |
| Notification | php artisan make:notification PaymentReceived |
| Observer | php artisan make:observer UserObserver |
| Resource | php artisan make:resource UserResource |
Why It All Matters
Laravel’s folder structure:
- Keeps your project organized
- Makes onboarding new developers easier
- Scales beautifully for large projects
- Supports modern tools and best practices
Understanding this structure will help you build clean, maintainable, and high-performance applications. Whether you’re creating a small website or a massive SaaS platform, it all starts right here.
Happy coding with Laravel! 🚀
Would you like this condensed for a blog post, or expanded into a tutorial series? Let me know your audience and goals!