Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on. You've got this! π
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