• Sun, Jun 2026

Understanding Laravel Folder Structure and MVC Architecture

Understanding Laravel Folder Structure and MVC Architecture

This professional beginner’s guide explains Laravel’s folder structure and MVC (Model-View-Controller) architecture step by step. With practical examples, annotated code snippets, and clear explanations, you’ll learn how Laravel organizes its files and how MVC makes modern PHP development simple and powerful.

When you first open a fresh Laravel project, the folder structure might look intimidating. You’ll see directories like app, routes, resources, and many more. At the same time, you’ll hear terms like “MVC architecture” and wonder how they fit together.

In this guide, we’ll break it all down in a simple and engaging way. Think of this as a tutorial script that walks you through Laravel’s structure, explaining how MVC works in practice, and giving you step-by-step examples along the way.


Why Understanding the Folder Structure Matters

Laravel’s folder structure is carefully designed to follow best practices and make your application maintainable. Knowing where your code belongs saves time, reduces bugs, and helps you work like a professional developer.

  • Consistency: Every Laravel app has the same structure.
  • Organization: Each folder has a specific purpose.
  • MVC integration: The structure directly supports the Model-View-Controller pattern.

Overview of Laravel’s Main Folders

Let’s look at the top-level folders you’ll see in a new Laravel project.

FolderPurpose
app/Main application logic (models, controllers, etc.)
bootstrap/Bootstraps the framework and loads configuration
config/Holds all configuration files
database/Migrations, seeders, and factories
public/Publicly accessible files (index.php, CSS, JS, images)
resources/Views (Blade templates), language files, and frontend assets
routes/All route definitions
storage/Logs, cache, and file uploads
tests/Automated tests
vendor/Composer dependencies

Diving Deeper: Key Folders Explained

1. The app/ Folder

This is the heart of your Laravel application. Inside app/, you’ll find subfolders like Http/, Models/, and Console/.

  • Http/: Controllers, middleware, and requests live here.
  • Models/: Your Eloquent models (representing database tables).
  • Console/: Custom Artisan commands.

2. The routes/ Folder

Routes define how your application responds to different URLs. Laravel provides web.php for web routes and api.php for API routes.


// routes/web.php
use Illuminate\Support\Facades\Route;
Route::get('/hello', function () {
    return "Hello from Laravel!";
});

3. The resources/ Folder

This is where your frontend lives—Blade views, JavaScript, and styles.

<!-- resources/views/welcome.blade.php -->
<!DOCTYPE html>
<html>
<head>
  <title>Welcome</title>
</head>
<body>
  <h1>{{ $message }}</h1>
</body>
</html>

4. The database/ Folder

Laravel migrations and seeders live here, allowing you to manage database schema and test data.

php artisan make:migration create_posts_table --create=posts

// database/migrations/xxxx_xx_xx_create_posts_table.php
public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->text('content');
        $table->timestamps();
    });
}

5. The public/ Folder

This is the only folder accessible to the outside world. The entry point index.php lives here and loads the entire Laravel application.

6. The config/ Folder

All your configuration lives here, like database credentials (config/database.php) or mail settings (config/mail.php).


What is MVC Architecture?

MVC stands for Model-View-Controller. Laravel is built around this design pattern, which helps separate concerns and keep your application organized.

  • Model: Represents the data and database logic.
  • View: Handles the user interface.
  • Controller: Acts as the glue between Model and View, handling logic and requests.

Step-by-Step: MVC in Action

Step 1: Create a Model

php artisan make:model Post -m

This command creates a Post model and a migration file.

Step 2: Migration Example


// database/migrations/xxxx_xx_xx_create_posts_table.php
public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->text('body');
        $table->timestamps();
    });
}

Step 3: Create a Controller

php artisan make:controller PostController

// app/Http/Controllers/PostController.php
namespace App\Http\Controllers;

use App\Models\Post;

class PostController extends Controller
{
    public function index()
    {
        $posts = Post::all();
        return view('posts.index', compact('posts'));
    }
}

Step 4: Define a Route


// routes/web.php
use App\Http\Controllers\PostController;

Route::get('/posts', [PostController::class, 'index']);

Step 5: Create a View

<!-- resources/views/posts/index.blade.php -->
<!DOCTYPE html>
<html>
<head>
  <title>All Posts</title>
</head>
<body>
  <h1>Posts</h1>
  <ul>
    @foreach($posts as $post)
      <li>{{ $post->title }} - {{ $post->body }}</li>
    @endforeach
  </ul>
</body>
</html>

Here’s how it all connects:

  1. User visits /posts.
  2. Route sends request to PostController@index.
  3. Controller fetches data from the Post model.
  4. Controller passes data to the Blade View.
  5. View renders the list of posts in the browser.

Benefits of MVC in Laravel

  • Separation of Concerns: Code is neatly organized into models, views, and controllers.
  • Maintainability: Easier to update or debug without breaking unrelated code.
  • Scalability: The structure supports both small apps and large enterprise systems.
  • Team Collaboration: Developers can work on different layers (UI, logic, database) independently.

Common Mistakes Beginners Make

  • Placing all logic inside routes instead of controllers.
  • Mixing database queries directly inside views.
  • Ignoring the app/Models directory and not using Eloquent models.
  • Not organizing Blade templates properly in subfolders.

By following the MVC pattern and understanding the folder structure, you can avoid these pitfalls.


Conclusion

Laravel’s folder structure and MVC architecture are designed to make your applications clean, maintainable, and professional. Once you understand where each piece of code belongs and how MVC ties it together, you’ll find development more enjoyable and efficient.

Keep practicing, explore each folder, and soon Laravel’s structure will feel second nature!

This website uses cookies to enhance your browsing experience. By continuing to use this site, you consent to the use of cookies. Please review our Privacy Policy for more information on how we handle your data. Cookie Policy