Root directory structure
The Laravel application root contains several directories and configuration files:Core directories
app/ - Application code
app/ - Application code
The
app/ directory contains your application’s core code. This is where you’ll spend most of your development time.HTTP layer
Theapp/Http/ directory contains controllers, middleware, and form requests:app/Http/Controllers/Controller.php
Models
Theapp/Models/ directory contains your Eloquent models:app/Models/User.php
Providers
Theapp/Providers/ directory contains service providers that bootstrap application services:app/Providers/AppServiceProvider.php
bootstrap/ - Framework bootstrapping
bootstrap/ - Framework bootstrapping
Contains files that bootstrap the framework and configure autoloading:The
The
bootstrap/app.php file creates and configures the application instance. This is where routing, middleware, and exception handling are registered.providers.php file lists all service providers:bootstrap/providers.php
config/ - Configuration files
config/ - Configuration files
Contains all application configuration organized by concern:Example database configuration:
config/database.php
database/ - Database files
database/ - Database files
Contains migrations, seeders, and model factories:
Migrations are versioned and timestamped, ensuring they run in the correct order across all environments.
public/ - Web root
public/ - Web root
The only directory accessible from the web. Contains the front controller and public assets:
public/index.php
resources/ - Raw assets
resources/ - Raw assets
Contains uncompiled assets and views:Assets in
resources/css and resources/js are compiled using Vite and output to public/build.routes/ - Route definitions
routes/ - Route definitions
Contains all application route definitions:Example web routes:Example console commands:
routes/web.php
routes/console.php
storage/ - Generated files
storage/ - Generated files
Contains logs, cached files, and uploaded files:
Files in
storage/app/public/ should be symlinked to public/storage using php artisan storage:link.tests/ - Application tests
tests/ - Application tests
Contains PHPUnit tests organized into feature and unit tests:
Organization best practices
Follow PSR-4 autoloading
The
app/ directory follows PSR-4 autoloading with the App namespace:composer.json
Create logical groupings
As your application grows, create additional directories in
app/:app/Services/- Business logic servicesapp/Actions/- Single-purpose action classesapp/Events/- Event classesapp/Listeners/- Event listenersapp/Jobs/- Queueable jobsapp/Mail/- Mailable classesapp/Notifications/- Notification classes
Keep controllers thin
Move business logic to services, actions, or model methods. Controllers should only handle HTTP concerns.
Key files
.env
Environment-specific configuration. Never commit this file.
artisan
Command-line interface for Laravel. Run
php artisan to see available commands.composer.json
PHP dependencies and autoloading configuration.
package.json
JavaScript dependencies managed by npm.
vite.config.js
Asset bundling configuration using Vite.
phpunit.xml
PHPUnit testing framework configuration.