Laravel Directory Structure for Beginners

NatureNature
6 min read

βœ… Laravel Folder Structure


πŸ“ app/

This folder contains the main code of your application.

  • Http/ – Your controllers and middleware live here (handles user requests).

  • Models/ – These are used to talk to the database (like User.php).

  • Providers/ – These files help start services like routes, events, etc.


πŸ“ bootstrap/

Used to boot (start) your Laravel app.

  • It also contains a cache folder to store compiled files for faster loading.

πŸ“ config/

All the settings of your app are here.

Examples:

  • app name

  • timezone

  • mail configuration

  • database info, etc.


πŸ“ database/

Contains everything related to your database.

  • migrations/ – Code for creating or changing tables.

  • seeders/ – Used to add sample data.

  • factories/ – Generate fake data for testing.


πŸ“ public/

This is the only folder visible to the user in the browser.

  • index.php is the file that starts Laravel.

  • You can also store images, CSS, and JavaScript here.


πŸ“ resources/

This folder has your HTML views and frontend files.

  • views/ – Contains Blade templates (Laravel’s HTML files).

  • css/ and js/ – For custom styles and scripts.


πŸ“ routes/

This is where you define URLs for your app.

  • web.php – For browser routes (like homepage, about page).

  • console.php – For Artisan CLI commands.

Example:

Route::get('/', function () {
  return view('welcome');
});

πŸ“ storage/

Used to store files, like:

  • logs

  • uploaded files

  • cache files

Laravel uses this folder for internal data.


πŸ“ tests/

Write tests here to check if your app works properly.


πŸ“ vendor/

Contains all the Laravel files and libraries installed via Composer.

πŸ‘‰ Don't touch this folder manually.


πŸ”§ Important Files

  • .env – Important settings like database, mail, app key, etc.

  • artisan – Command line tool to run Laravel commands.

  • composer.json – Keeps track of all PHP libraries.

  • vite.config.js – Settings for CSS/JS build tools.

  • package.json – Used for JavaScript packages (NPM).


βœ… Summary Table

Folder/FileWhat it Does
app/Main app logic (controllers, models)
bootstrap/Starts Laravel app
config/App settings
database/Migrations and sample data
public/Browser-visible files
resources/Views and frontend code
routes/Defines URLs
storage/Stores logs, files, cache
tests/App testing code
vendor/Laravel framework and packages
.envEnvironment settings
artisanLaravel command line tool

Explanation in Hinglish


βœ… Main Laravel Project Structure

your-project/
β”‚
β”œβ”€β”€ app/
β”œβ”€β”€ bootstrap/
β”œβ”€β”€ config/
β”œβ”€β”€ database/
β”œβ”€β”€ public/
β”œβ”€β”€ resources/
β”œβ”€β”€ routes/
β”œβ”€β”€ storage/
β”œβ”€β”€ tests/
β”œβ”€β”€ vendor/
β”‚
β”œβ”€β”€ .env
β”œβ”€β”€ artisan
β”œβ”€β”€ composer.json
β”œβ”€β”€ vite.config.js
└── ...

πŸ“ app/ – Your core application code

Yeh folder Laravel ka core hota hai, jisme controller, models, and logic rehta hai.

  • Http/ – Controllers, Middleware, and requests yahan hote hain.

  • Models/ – Aapke database models (e.g., User.php) yahan bante hain.

  • Providers/ – Laravel ki services register karne ke liye.


πŸ“ bootstrap/

Laravel ko boot (start) karne ke liye yeh folder use hota hai.

  • app.php – Framework start karne ka file.

  • cache/ – Laravel ka optimization aur caching data.


πŸ“ config/

Saare configuration files yahan hote hain (like mail, database, app name, etc.)

Example: app.php, database.php, mail.php, etc.


πŸ“ database/

Database se related saari cheezein:

  • migrations/ – Table create/edit ka code.

  • seeders/ – Sample data insert karne ke liye.

  • factories/ – Fake data generate karne ke liye (testing).


πŸ“ public/

Yeh folder web-accessible hota hai. Jab user aapka site kholta hai, yeh folder serve hota hai.

  • index.php – Laravel ka entry point.

  • css/, js/ – Static assets like images, JS, CSS.


πŸ“ resources/

Views aur frontend assets ke liye.

  • views/ – Blade templates (like HTML) yahan likhte hain.

  • css/ & js/ – Frontend code likhne ke liye.


πŸ“ routes/

Saare URL routes yahan define hote hain.

  • web.php – Browser ke routes (GET, POST).

  • console.php – Artisan CLI ke liye.

  • api.php (not shown here but usually present) – API ke routes ke liye.

🧠 Example route in web.php:

Route::get('/', function () {
    return view('welcome');
});

πŸ“ storage/

Logs, user uploads, and framework data ke liye.

  • logs/ – Errors and logs.

  • app/ – Uploaded files.

  • framework/ – Cache, sessions, views storage.


πŸ“ tests/

Application ke test cases likhne ke liye (PHPUnit ya Pest use karke).


πŸ“ vendor/

All packages and Laravel framework files jo Composer install karta hai.

❌ Never touch this manually.


πŸ”§ Important Root Files:

  • .env – Project ke environment/config (DB, mail, etc.)

  • artisan – Laravel CLI tool. Use it to run commands:

      php artisan serve
      php artisan migrate
    
  • composer.json – Installed PHP packages ka record.

  • vite.config.js – Frontend build configuration (Vite for assets).

  • package.json – NPM packages list (for JS & CSS).


πŸ”š Summary in Hinglish

Folder/FileKaam (Use)
app/Controllers, Models, Logic
bootstrap/Laravel ko start karne ka system
config/App ke settings/configs
database/Tables banane ka code + test data
public/Browser se visible files (index.php)
resources/Views (HTML) + frontend code
routes/URLs define karne ke liye
storage/Logs, uploads, cache
tests/App testing
vendor/All Laravel + 3rd party libraries

…..


βœ… Main Folders You Should Work On First

1. πŸ“ routes/web.php

πŸ”Ή Why?
This is where you define your website's URLs and actions.

πŸ”Έ Example:

phpCopyEditRoute::get('/', function () {
    return view('welcome');
});

➑️ Start here to create routes like /about, /contact, etc.


2. πŸ“ resources/views/

πŸ”Ή Why?
This folder contains your Blade templates – basically the HTML pages of your app.

πŸ”Έ Example:
Create a file like about.blade.php to design your "About Us" page.


3. πŸ“ app/Http/Controllers/

πŸ”Ή Why?
This is where you write your logic for routes using Controllers.

πŸ”Έ Example:
If you want to handle form submissions, database access, etc.

➑️ Use php artisan make:controller PageController to create a controller.


4. πŸ“ app/Models/

πŸ”Ή Why?
If you're using a database, Models help you interact with tables.

πŸ”Έ Example:

phpCopyEdit$user = User::all(); // Gets all users

➑️ Use php artisan make:model Post to create a model.


5. πŸ“ resources/css/ and resources/js/ (optional at first)

πŸ”Ή If you’re adding custom styles or JS, you can update these.

10
Subscribe to my newsletter

Read articles from Nature directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nature
Nature