Laravel’s Directory Structure

When you open up a directory that contains a skeleton Laravel application, you’ll see the following files and directories:

app/
bootstrap/
config/
database/
public/
resources/
routes/
storage/
tests/
vendor/

.editorconfig
.env
.env.example
.gitattributes
.gitignore
artisan
composer.json
composer.lock
package.json
phpunit.xml
readme.md
vite.config.js

Let’s walk through them one by one to get familiar.

The Folders

The root directory contains the following folders by default:

app

Where the bulk of your actual application will go. Models, controllers, commands, and your PHP domain code all go in here.

bootstrap

Contains the files that the Laravel framework uses to boot every time it runs.

config

Where all the configuration files live.

database

Where database migrations, seeds, and factories live.

public

The directory the server points to when it’s serving the website. This contains index.php, which is the front controller that kicks off the bootstrapping process and routes all requests appropriately. It’s also where any public-facing files like images, stylesheets, scripts, or downloads go.

resources

Where files that are needed for other scripts live. Views, and (optionally) source CSS and source JavaScript files live here.

routes

Where all of the route definitions live, both for HTTP routes and “console routes,” or Artisan commands.

storage

Where caches, logs, and compiled system files live.

tests

Where unit and integration tests live.

vendor

Where Composer installs its dependencies. It’s Git-ignored (marked to be excluded from your version control system) because Composer is expected to run as a part of your deploy me process on any remote servers.

The Loose Files

The root directory also contains the following files:

.editorconfig

Gives your IDE/text editor instructions about Laravel’s coding standards (e.g., the size of indents, the charset, and whether to trim trailing whitespace).

.env and .env.example

Dictate the environment variables (variables that are expected to be different in each environment and are therefore not committed to version control). .env.example is a template that each environment should duplicate to create its own .env file, which is Git-ignored.

.gitignore and .gitattributes

Git configuration files.

artisan

Allows you to run Artisan commands (see Chapter 8) from the command line.

composer.json and composer.lock

Configuration files for Composer; composer.json is user-editable and composer.lock is not. These files share some basic information about the project and also define its PHP dependencies.

package.json

Like composer.json, but for frontend assets and dependencies of the build system; it instructs NPM about which JavaScript-based dependencies to pull in.

phpunit.xml

A configuration file for PHPUnit, the tool Laravel uses for testing out of the box.

readme.md

A Markdown file giving a basic introduction to Laravel. You won’t see this file if you use the Laravel installer.

vite.config.js

The (optional) configuration file for Vite. This file instructs your build system about how to compile and process your frontend assets.


Laravel’s Directory Structure was originally published in Javarevisited on Medium, where people are continuing the conversation by highlighting and responding to this story.

This post first appeared on Read More