Laravel Directory Structure Deep Dive
A fresh Laravel project contains a carefully organized directory structure. Every folder has a specific purpose, and understanding this structure is critical for knowing where to put your code. Laravel follows convention over configuration — if you place files in the expected locations, the framework automatically discovers and registers them. This is one of the biggest productivity gains over raw PHP, where you'd need to manually configure autoloading and file organization.
Top-Level Directory Structure
my-laravel-app/
├── app/ # Your application code (Models, Controllers, etc.)
│ ├── Http/ # Controllers, Middleware, Form Requests
│ ├── Models/ # Eloquent model classes
│ ├── Providers/ # Service providers (app bootstrapping)
│ └── Console/ # Custom Artisan commands
├── bootstrap/ # Framework bootstrap files (cache)
├── config/ # All configuration files (app, database, mail, etc.)
├── database/ # Migrations, seeds, factories
│ ├── migrations/ # Database schema version files
│ ├── seeders/ # Test/initial data seeders
│ └── factories/ # Model factories for testing
├── public/ # Web server document root (index.php, assets)
├── resources/ # Views (Blade templates), raw CSS/JS, lang files
├── routes/ # Route definitions (web.php, api.php)
├── storage/ # Logs, compiled views, file uploads, cache
├── tests/ # PHPUnit/Pest test files
├── vendor/ # Composer dependencies (never edit)
├── .env # Environment configuration
├── artisan # CLI entry point
└── composer.json # Project dependenciesKey Directories Explained
- app/ — The heart of your application. Models go in app/Models/, controllers in app/Http/Controllers/, middleware in app/Http/Middleware/. As your app grows, you'll add directories like app/Services/, app/Repositories/, app/Actions/ for clean architecture
- config/ — Every aspect of Laravel is configurable through PHP files here: database.php (connections), mail.php (email drivers), cache.php (cache stores), queue.php (queue connections). Values typically read from .env for environment-specific settings
- database/ — Version-controlled database management. Migrations define schema changes, seeders populate data, factories generate fake data for testing. Run php artisan migrate to apply, php artisan db:seed to populate
- routes/ — web.php for browser routes (with sessions, CSRF), api.php for stateless API routes (with throttling). Routes are the entry point for all HTTP requests — they map URLs to controller actions
- resources/views/ — Blade template files (.blade.php). Laravel's template engine with template inheritance, components, and directives. Views are compiled to plain PHP and cached for performance
- storage/ — Framework-generated files: compiled views (storage/framework/views/), session files, cache, file uploads (storage/app/), and logs (storage/logs/laravel.log). The storage/app/public/ directory is symlinked to public/storage for serving uploaded files
Tip
Tip
Practice Laravel Directory Structure Deep Dive in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Technical diagram.
Practice Task
Note
Practice Task — (1) Write a working example of Laravel Directory Structure Deep Dive from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Laravel Directory Structure Deep Dive is skipping edge case testing — empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready laravel code.
Key Takeaways
- A fresh Laravel project contains a carefully organized directory structure.
- app/ — The heart of your application. Models go in app/Models/, controllers in app/Http/Controllers/, middleware in app/Http/Middleware/. As your app grows, you'll add directories like app/Services/, app/Repositories/, app/Actions/ for clean architecture
- config/ — Every aspect of Laravel is configurable through PHP files here: database.php (connections), mail.php (email drivers), cache.php (cache stores), queue.php (queue connections). Values typically read from .env for environment-specific settings
- database/ — Version-controlled database management. Migrations define schema changes, seeders populate data, factories generate fake data for testing. Run php artisan migrate to apply, php artisan db:seed to populate