Complete Laravel Project Directory Structure: MVC Architecture

Introduction to Laravel and Its Role in MVC Architecture

Laravel is one of the most popular PHP frameworks in the world of web development. Known for its elegant syntax and developer-friendly features, Laravel aims to make common web development tasks, like authentication, routing, sessions, and caching, much easier and more intuitive. Created by Taylor Otwell, Laravel has evolved into a full-fledged MVC (Model-View-Controller) framework, making it the go-to choice for modern web applications.

What is MVC Architecture?

The MVC (Model-View-Controller) architecture is a design pattern that separates the application logic into three interconnected components:

  • Model: Represents the data and business logic of the application.
  • View: Handles the display and presentation of the data.
  • Controller: Acts as an intermediary between the Model and the View, handling user input and interactions.

Laravel follows this pattern to ensure that the application is clean, organized, and maintainable.

In this article, we will explore the complete directory structure of a Laravel project, specifically focusing on the MVC architecture and how each part contributes to the development process. By looking at the latest Laravel 11 directory structure, you'll be able to understand how Laravel enforces separation of concerns and keeps your codebase easy to scale and maintain.

Laravel 11 Directory Structure Overview

A standard Laravel project comes with a pre-defined structure that supports an MVC workflow, organized in a way that facilitates easy management of both backend and frontend logic. Below is the comprehensive directory structure of Laravel 11, broken down with explanations of the core directories and files you will encounter in a typical Laravel application.

๐Ÿ“‚ laravel-advanced-project/
โ”‚โ”€โ”€ ๐Ÿ“‚ app/
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Console/
โ”‚   โ”‚   โ”‚โ”€โ”€ Kernel.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Events/
โ”‚   โ”‚   โ”‚โ”€โ”€ PostCreated.php
โ”‚   โ”‚   โ”‚โ”€โ”€ UserRegistered.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Exceptions/
โ”‚   โ”‚   โ”‚โ”€โ”€ Handler.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Http/
โ”‚   โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Controllers/
โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ API/
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ PostController.php
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ UserController.php
โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Web/
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ HomeController.php
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ ProfileController.php
โ”‚   โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Middleware/
โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ Authenticate.php
โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ RedirectIfAuthenticated.php
โ”‚   โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Requests/
โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ UserRequest.php
โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ PostRequest.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Models/
โ”‚   โ”‚   โ”‚โ”€โ”€ User.php
โ”‚   โ”‚   โ”‚โ”€โ”€ Post.php
โ”‚   โ”‚   โ”‚โ”€โ”€ Comment.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Notifications/
โ”‚   โ”‚   โ”‚โ”€โ”€ NewCommentNotification.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Policies/
โ”‚   โ”‚   โ”‚โ”€โ”€ PostPolicy.php
โ”‚   โ”‚   โ”‚โ”€โ”€ CommentPolicy.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Providers/
โ”‚   โ”‚   โ”‚โ”€โ”€ AppServiceProvider.php
โ”‚   โ”‚   โ”‚โ”€โ”€ AuthServiceProvider.php
โ”‚   โ”‚   โ”‚โ”€โ”€ EventServiceProvider.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Services/
โ”‚   โ”‚   โ”‚โ”€โ”€ UserService.php
โ”‚   โ”‚   โ”‚โ”€โ”€ PostService.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Traits/
โ”‚   โ”‚   โ”‚โ”€โ”€ ApiResponse.php
โ”‚โ”€โ”€ ๐Ÿ“‚ bootstrap/
โ”‚   โ”‚โ”€โ”€ app.php
โ”‚โ”€โ”€ ๐Ÿ“‚ config/
โ”‚   โ”‚โ”€โ”€ app.php
โ”‚   โ”‚โ”€โ”€ auth.php
โ”‚   โ”‚โ”€โ”€ database.php
โ”‚โ”€โ”€ ๐Ÿ“‚ database/
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ factories/
โ”‚   โ”‚   โ”‚โ”€โ”€ UserFactory.php
โ”‚   โ”‚   โ”‚โ”€โ”€ PostFactory.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ migrations/
โ”‚   โ”‚   โ”‚โ”€โ”€ 2024_01_01_000000_create_users_table.php
โ”‚   โ”‚   โ”‚โ”€โ”€ 2024_01_01_000001_create_posts_table.php
โ”‚   โ”‚   โ”‚โ”€โ”€ 2024_01_01_000002_create_comments_table.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ seeders/
โ”‚   โ”‚   โ”‚โ”€โ”€ DatabaseSeeder.php
โ”‚   โ”‚   โ”‚โ”€โ”€ UserSeeder.php
โ”‚   โ”‚   โ”‚โ”€โ”€ PostSeeder.php
โ”‚โ”€โ”€ ๐Ÿ“‚ lang/
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ en/
โ”‚   โ”‚   โ”‚โ”€โ”€ auth.php
โ”‚   โ”‚   โ”‚โ”€โ”€ validation.php
โ”‚โ”€โ”€ ๐Ÿ“‚ public/
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ css/
โ”‚   โ”‚   โ”‚โ”€โ”€ app.css
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ js/
โ”‚   โ”‚   โ”‚โ”€โ”€ app.js
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ images/
โ”‚   โ”‚โ”€โ”€ index.php
โ”‚โ”€โ”€ ๐Ÿ“‚ resources/
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ views/
โ”‚   โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ layouts/
โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ app.blade.php
โ”‚   โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ users/
โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ index.blade.php
โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ show.blade.php
โ”‚   โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ posts/
โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ index.blade.php
โ”‚   โ”‚   โ”‚   โ”‚โ”€โ”€ show.blade.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ js/
โ”‚   โ”‚   โ”‚โ”€โ”€ app.js
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ sass/
โ”‚   โ”‚   โ”‚โ”€โ”€ app.scss
โ”‚โ”€โ”€ ๐Ÿ“‚ routes/
โ”‚   โ”‚โ”€โ”€ api.php
โ”‚   โ”‚โ”€โ”€ web.php
โ”‚โ”€โ”€ ๐Ÿ“‚ storage/
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ app/
โ”‚   โ”‚   โ”‚โ”€โ”€ uploads/
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ logs/
โ”‚   โ”‚   โ”‚โ”€โ”€ laravel.log
โ”‚โ”€โ”€ ๐Ÿ“‚ tests/
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Feature/
โ”‚   โ”‚   โ”‚โ”€โ”€ UserTest.php
โ”‚   โ”‚   โ”‚โ”€โ”€ PostTest.php
โ”‚   โ”‚โ”€โ”€ ๐Ÿ“‚ Unit/
โ”‚   โ”‚   โ”‚โ”€โ”€ UserServiceTest.php
โ”‚   โ”‚   โ”‚โ”€โ”€ PostServiceTest.php
โ”‚โ”€โ”€ .env
โ”‚โ”€โ”€ .gitignore
โ”‚โ”€โ”€ artisan
โ”‚โ”€โ”€ composer.json
โ”‚โ”€โ”€ package.json
โ”‚โ”€โ”€ phpunit.xml
โ”‚โ”€โ”€ README.md
โ”‚โ”€โ”€ webpack.mix.js

Directory Breakdown

1. app/ โ€“ The Application Directory

The app/ directory is the heart of the application, where most of the business logic is placed. It contains several subdirectories that help in organizing the application components:

  • Console/: Contains console commands. The Kernel.php file defines the application's command schedule.

  • Events/: Houses event classes like PostCreated.php and UserRegistered.php, which are triggered during specific actions in the application.

  • Exceptions/: This directory manages exceptions in your app. The Handler.php file is used for handling exceptions globally.

  • Http/: Contains HTTP-specific files like controllers, middleware, requests, and more.

    • Controllers/: Divided into subdirectories like API/ and Web/ for handling API requests and web views respectively.
    • Middleware/: Handles HTTP request filtering. For example, Authenticate.php checks whether the user is authenticated.
    • Requests/: Contains form request validation classes (e.g., UserRequest.php, PostRequest.php).
  • Models/: Contains the application's model classes (e.g., User.php, Post.php, Comment.php). These models are responsible for interacting with the database.

  • Notifications/: Contains notification classes, like NewCommentNotification.php, that notify users about various events.

  • Policies/: Contains policy classes (e.g., PostPolicy.php) that manage authorization logic for models.

  • Providers/: This directory contains service providers, which are used for bootstrapping various parts of the application. Common examples include AppServiceProvider.php and AuthServiceProvider.php.

  • Services/: Custom service classes (e.g., UserService.php, PostService.php) that are responsible for encapsulating specific application logic.

  • Traits/: Contains reusable code snippets that can be included in models, services, or other classes.

2. bootstrap/ โ€“ Bootstrapping the Application

The bootstrap/ directory is used to configure the application, load configuration files, and set up the initial environment. The app.php file is where the Laravel application is bootstrapped.

3. config/ โ€“ Configuration Files

The config/ directory holds various configuration files such as app.php (application settings), auth.php (authentication settings), and database.php (database configuration).

4. database/ โ€“ Database-Related Files

This directory contains everything related to database migrations, factories, and seeders:

  • factories/: Used for creating fake data for testing.
  • migrations/: Houses migration files that define database schema changes.
  • seeders/: Contains seeder classes, which populate the database with initial data.

5. public/ โ€“ Public Assets

This is the only directory exposed to the web. It contains assets like CSS, JavaScript files, and images. The index.php file is also here, which is the entry point for all requests.

6. resources/ โ€“ Views, Assets, and Language Files

Contains views, assets, and language files:

  • views/: Contains Blade templates, which are used to render views. The layouts/app.blade.php is the main layout file.

  • js/ and sass/: These directories store front-end assets like JavaScript and CSS.

7. routes/ โ€“ Defining Routes

Contains all route definitions for the application. The web.php file handles web routes, while api.php defines routes for APIs.

8. storage/ โ€“ Files, Logs, and Cache

Contains application-generated files, logs, and cache files. The uploads/ directory stores files uploaded by users, while logs/ contains Laravel's log files.

9. tests/ โ€“ Testing

This directory holds all tests for the application:

  • Feature/: Tests for features that involve multiple components working together (e.g., UserTest.php, PostTest.php).
  • Unit/: Unit tests for smaller components (e.g., UserServiceTest.php, PostServiceTest.php).

10. Root Files

  • .env: Contains environment-specific settings like database credentials.
  • .gitignore: Specifies files to be ignored by Git.
  • artisan: The Laravel command-line interface (CLI) file.
  • composer.json: Defines dependencies and configurations for Composer.
  • phpunit.xml: PHPUnit configuration for running tests.
  • webpack.mix.js: Configuration for asset compilation using Laravel Mix.

This breakdown of the Laravel 11 directory structure provides a comprehensive look at how everything is organized, ensuring you can develop clean, scalable, and maintainable applications. From handling requests in the controllers to working with the models and database, the structure follows the principles of MVC architecture, making it easier to manage complex applications.


๐Ÿ“‚ Complete Laravel Directory Structure (All Possible Directories at Any Level and Depth)

Each directory is followed by a brief explanation of its purpose.


๐Ÿ”น 1. Core Laravel Application Directories (/app)

These directories contain the application's core logic.

1๏ธโƒฃ /app โ€“ Main application logic (Models, Controllers, Middleware, Services, etc.).

2๏ธโƒฃ /app/Console โ€“ Custom Artisan commands and CLI-related functionality.

3๏ธโƒฃ /app/Console/Commands โ€“ Subdirectory for custom Artisan commands.

4๏ธโƒฃ /app/Events โ€“ Event classes for Laravel's event system.

5๏ธโƒฃ /app/Exceptions โ€“ Custom exception handling for the application.

6๏ธโƒฃ /app/Http โ€“ Houses controllers, middleware, and request classes.

7๏ธโƒฃ /app/Http/Controllers โ€“ Controller classes that handle HTTP requests.

8๏ธโƒฃ /app/Http/Controllers/API โ€“ API controllers for RESTful endpoints.

9๏ธโƒฃ /app/Http/Controllers/Web โ€“ Web controllers for handling browser-based requests.

๐Ÿ”Ÿ /app/Http/Middleware โ€“ Middleware that filters HTTP requests.

1๏ธโƒฃ1๏ธโƒฃ /app/Http/Requests โ€“ Custom form request validation classes.

1๏ธโƒฃ2๏ธโƒฃ /app/Models โ€“ Eloquent ORM models interacting with the database.

1๏ธโƒฃ3๏ธโƒฃ /app/Notifications โ€“ Notification classes for emails, SMS, etc.

1๏ธโƒฃ4๏ธโƒฃ /app/Observers โ€“ Model observers that listen for model events.

1๏ธโƒฃ5๏ธโƒฃ /app/Policies โ€“ Authorization policies for defining user access control.

1๏ธโƒฃ6๏ธโƒฃ /app/Providers โ€“ Service providers for bootstrapping application services.

1๏ธโƒฃ7๏ธโƒฃ /app/Services โ€“ Custom service classes to handle business logic.

1๏ธโƒฃ8๏ธโƒฃ /app/Traits โ€“ PHP traits for code reusability.

1๏ธโƒฃ9๏ธโƒฃ /app/Rules โ€“ Custom validation rules for form requests.

2๏ธโƒฃ0๏ธโƒฃ /app/Casts โ€“ Custom attribute casting classes for Eloquent models.


๐Ÿ”น 2. Laravel Bootstrapping (/bootstrap)

Contains files that handle the bootstrapping process.

2๏ธโƒฃ1๏ธโƒฃ /bootstrap โ€“ Bootstraps the Laravel framework.

2๏ธโƒฃ2๏ธโƒฃ /bootstrap/cache โ€“ Stores cached configuration, services, and routes.


๐Ÿ”น 3. Laravel Configuration (/config)

Holds configuration files.

2๏ธโƒฃ3๏ธโƒฃ /config โ€“ Contains various Laravel configuration files.

2๏ธโƒฃ4๏ธโƒฃ /config/auth.php โ€“ Authentication settings.

2๏ธโƒฃ5๏ธโƒฃ /config/cache.php โ€“ Caching configuration.

2๏ธโƒฃ6๏ธโƒฃ /config/database.php โ€“ Database connection settings.

2๏ธโƒฃ7๏ธโƒฃ /config/mail.php โ€“ Email service configuration.

2๏ธโƒฃ8๏ธโƒฃ /config/queue.php โ€“ Queue settings.

2๏ธโƒฃ9๏ธโƒฃ /config/services.php โ€“ External API and service integrations.


๐Ÿ”น 4. Laravel Database Directory (/database)

Manages migrations, factories, and seeds.

3๏ธโƒฃ0๏ธโƒฃ /database โ€“ Contains all database-related files.

3๏ธโƒฃ1๏ธโƒฃ /database/factories โ€“ Model factory classes for test data.

3๏ธโƒฃ2๏ธโƒฃ /database/migrations โ€“ Migration files that manage database schema changes.

3๏ธโƒฃ3๏ธโƒฃ /database/seeders โ€“ Seeder classes to populate database tables.

3๏ธโƒฃ4๏ธโƒฃ /database/sql โ€“ Raw SQL dump files for database backup or restore.


๐Ÿ”น 5. Localization & Language Files (/lang)

3๏ธโƒฃ5๏ธโƒฃ /lang โ€“ Stores language translation files.

3๏ธโƒฃ6๏ธโƒฃ /lang/en โ€“ English translation files.

3๏ธโƒฃ7๏ธโƒฃ /lang/fr โ€“ French translation files.

3๏ธโƒฃ8๏ธโƒฃ /lang/es โ€“ Spanish translation files.


๐Ÿ”น 6. Public Assets & Entry Point (/public)

3๏ธโƒฃ9๏ธโƒฃ /public โ€“ Publicly accessible files like images, CSS, JS, and the entry index.php.

4๏ธโƒฃ0๏ธโƒฃ /public/css โ€“ CSS stylesheets.

4๏ธโƒฃ1๏ธโƒฃ /public/js โ€“ JavaScript files.

4๏ธโƒฃ2๏ธโƒฃ /public/images โ€“ Static images.

4๏ธโƒฃ3๏ธโƒฃ /public/fonts โ€“ Font files.

4๏ธโƒฃ4๏ธโƒฃ /public/storage โ€“ Public storage linked to /storage/app/public.


๐Ÿ”น 7. Frontend & Views (/resources)

4๏ธโƒฃ5๏ธโƒฃ /resources โ€“ Contains Blade views, JS, and CSS.

4๏ธโƒฃ6๏ธโƒฃ /resources/views โ€“ Blade template files for frontend rendering.

4๏ธโƒฃ7๏ธโƒฃ /resources/css โ€“ CSS files.

4๏ธโƒฃ8๏ธโƒฃ /resources/js โ€“ JavaScript files for frontend behavior.

4๏ธโƒฃ9๏ธโƒฃ /resources/sass โ€“ SASS/SCSS files for styling.


๐Ÿ”น 8. Routing (/routes)

5๏ธโƒฃ0๏ธโƒฃ /routes โ€“ Defines routes for web, API, and console.

5๏ธโƒฃ1๏ธโƒฃ /routes/web.php โ€“ Web routes (frontend).

5๏ธโƒฃ2๏ธโƒฃ /routes/api.php โ€“ API routes (RESTful).

5๏ธโƒฃ3๏ธโƒฃ /routes/console.php โ€“ Custom Artisan commands.

5๏ธโƒฃ4๏ธโƒฃ /routes/channels.php โ€“ Routes for event broadcasting.


๐Ÿ”น 9. Laravel Storage (/storage)

Stores logs, caches, and user uploads.

5๏ธโƒฃ5๏ธโƒฃ /storage โ€“ Stores logs, cache, and uploaded files.

5๏ธโƒฃ6๏ธโƒฃ /storage/app โ€“ Application-specific files (backups, uploads).

5๏ธโƒฃ7๏ธโƒฃ /storage/app/public โ€“ Publicly accessible storage files.

5๏ธโƒฃ8๏ธโƒฃ /storage/framework โ€“ Contains framework-generated files.

5๏ธโƒฃ9๏ธโƒฃ /storage/framework/cache โ€“ Caching data.

6๏ธโƒฃ0๏ธโƒฃ /storage/framework/sessions โ€“ Stores user session data.

6๏ธโƒฃ1๏ธโƒฃ /storage/framework/views โ€“ Compiled Blade templates for fast rendering.

6๏ธโƒฃ2๏ธโƒฃ /storage/logs โ€“ Log files for debugging.


๐Ÿ”น 10. Testing (/tests)

6๏ธโƒฃ3๏ธโƒฃ /tests โ€“ Unit and feature tests for the application.

6๏ธโƒฃ4๏ธโƒฃ /tests/Feature โ€“ Feature tests for app functionalities.

6๏ธโƒฃ5๏ธโƒฃ /tests/Unit โ€“ Unit tests for isolated components.


๐Ÿ”น 11. Composer & Node Dependencies

6๏ธโƒฃ6๏ธโƒฃ /vendor โ€“ Contains all Composer dependencies.


๐Ÿ“Œ Conclusion

This is the most exhaustive list of all possible directories in a Laravel project. Some directories are always present, while others appear based on optional features, third-party packages, or specific configurations.

Understanding these directories helps you master Laravel and makes development more structured and maintainable. ๐Ÿš€