Directory Structure
Introduction
A new Laravel application already has a place for your routes, handlers, models, and page components, so you, your teammates, and the agents that write code with you know where to find each part.
As you work, a few paths appear that Git ignores: Cargo's build output in target/, node_modules/, the assets Vite builds into public/build/, the SSR bundle in bootstrap/ssr/, and your .env file.
The root directory
| Path | What it holds |
|---|---|
Cargo.toml |
Your project's name, its dependencies, and the framework's Cargo features, such as the database driver. |
build.rs |
Rebuilds your application when you add a migration, because your migrations compile into the binary. |
.env |
Your environment configuration, such as your database URL and encryption key. |
package.json |
Your frontend dependencies and the npm scripts, such as npm run dev. |
vite.config.ts |
Vite's configuration: its plugins, your frontend's entry point, and the formatting and lint rules that npm run check applies. |
database/migrations/ |
Your migrations, one Rust file per change. |
database/seeders/ |
Your seeders, which fill a database with rows. |
src/ |
Your application's Rust code. |
resources/ |
Your frontend's source, such as page components and styles. |
public/ |
Files your application serves as they are, such as favicon.ico and the assets in public/build/. |
storage/ |
Files your application writes as it runs, such as uploads and logs. |
bootstrap/ssr/ |
The server-side rendering bundle that npm run build:ssr builds. |
tests/ |
Your tests. |
You may rename your project in the [package] section of Cargo.toml. Keep the [lib] name app, though, because Laravel and your tests find your code by that name, as in use app::models::User.
The resources directory
The resources directory holds your frontend's source, which Vite builds into public/build/:
| Path | What it holds |
|---|---|
resources/js/app.tsx |
Your frontend's entry point, which starts Inertia. |
resources/js/pages/ |
Your Inertia page components. A handler renders one by name, so inertia::render("Welcome", ...) renders Welcome.tsx. Error.tsx renders your application's error pages. |
resources/views/app.html |
The root view, the HTML document that every page renders in. Your other views live in resources/views too. |
resources/css/app.css |
Your styles, which import Tailwind. |
resources/images/ |
Images your pages import. Vite bundles them with your other assets. |
The storage directory
The storage directory holds the files your application writes, and Git ignores what's inside. storage/app/ is for files your application keeps, such as uploads or a SQLite database. The public disk stores its files in storage/app/public, and Laravel serves them at /storage, so a user can download an avatar stored at avatars/1.png from /storage/avatars/1.png. The local disk keeps private files in storage/app/private.
In production, you'll usually store uploads in object storage instead, so every server sees the same files and they survive a redeploy. Laravel Cloud Object Storage works out of the box with no extra Cargo features, and you can also use any S3-compatible disk by enabling Laravel's s3 feature.
storage/logs/ holds log files when you use the daily log channel. By default, logs go to standard error, so the directory stays empty until you change that setting.
The tests directory
The tests directory holds your tests. Cargo compiles each file in it as a separate crate that depends on your application, so a test sees only the modules src/lib.rs declares pub. Your application starts with two: welcome.rs tests the welcome page, and api.rs tests the /api/version route. Run them with cargo test. They need a PostgreSQL database, as Refreshing the database explains.
The src directory
Most of your code lives in src, with a module for each kind of code, such as routes for your route files and models for your models.
Configuring your application
src/app.rs configures your application. Its configure function registers your migrations, your packages' service providers, your authentication guard, your route files, and your middleware. You'll come back to it whenever you register something new.
src/main.rs runs that configuration. With no arguments, it serves your application, and with a command name, such as laravel migrate, it runs that console command.
src/testing.rs starts from the same configure function, so your tests run the application you ship. It calls for_testing to read .env.testing or .env, applies your test environment overrides, and enables refresh_database, which gives each test its own database. #[laravel::test] calls its create function, so add test-only overrides there, as Configuring your tests describes.
src/lib.rs declares your application's modules, as Adding your own modules describes.
Routes, handlers, and middleware
The src/routes directory holds your route files. Most routes belong in web.rs, whose routes run with sessions, encrypted cookies, CSRF protection, and Inertia. Routes in api.rs are stateless, and Laravel prefixes their URIs with /api, so the /version route in api.rs responds at /api/version. channels.rs decides who may subscribe to your private and presence broadcast channels. Routing covers the route files in detail.
Routes point at handlers, the async functions in src/http/handlers that turn a request into a response. Give each resource its own module, such as handlers::posts for the routes that list, show, and store posts. src/http/middleware holds your middleware, including HandleInertiaRequests, which shares data with every page, and an example #[middleware] function you may replace.
Models
The src/models directory holds your models. A model is a struct that reads and writes one of your database tables. Your application starts with a User model for its users table, which authentication uses to log users in.
Configuration files
The src/config directory holds your configuration files. Most settings come from your .env file, so a new application only has three: database.rs for your database connections, cors.rs for cross-origin requests, and services.rs for your own sections, such as your Sentry DSN. When you need to change something environment variables can't express, such as adding a cache store, you add a file here.
Console commands and the schedule
The src/console directory holds your console commands. src/console/mod.rs declares each command's file and holds your schedule.
Your application starts with an example inspire command in inspire.rs, which prints an inspiring quote when you run laravel inspire, and a schedule that runs it every hour. It's there to show you a command's shape, so you may delete it once you've written your own. Remove its mod line and its schedule entry from src/console/mod.rs too.
Events and listeners
The src/events directory holds your events, the structs that describe something your application did, such as UserRegistered. The src/listeners directory holds the #[listener] functions that respond to them. For example, a send_welcome_email listener might email each new user. Your application starts with one of each, ExampleEvent and handle_example, to show their shape.
Adding your own modules
As your application grows, you'll write code your application has no module for yet. Give each kind its own module. These are the usual ones:
| Module | What it holds |
|---|---|
src/jobs/ |
Your queued jobs. |
src/mail/ |
Your mailables. |
src/notifications.rs |
Your notifications. |
src/policies/ |
Your authorization policies. |
src/services/ |
Your services, registered with #[singleton] or #[bind]. |
src/features.rs |
Your feature flags. |
Declare each new module in src/lib.rs, and declare its files in the module's mod.rs. This jobs module holds a SendWelcomeEmail job in src/jobs/send_welcome_email.rs:
1// src/lib.rs2pub mod jobs;1// src/lib.rs2pub mod jobs;
1// src/jobs/mod.rs2mod send_welcome_email;34pub use send_welcome_email::SendWelcomeEmail;1// src/jobs/mod.rs2mod send_welcome_email;34pub use send_welcome_email::SendWelcomeEmail;
Declare a module pub when your tests need its items, such as a job your test checks was dispatched. Your application keeps console private, because tests run commands by name.
You may also group a larger feature into a module of its own rather than splitting it across kind-based directories. For example, src/services/ works well for standalone API clients, while a src/billing/ module can keep its payment client, configuration section, middleware, and queued jobs together in one place.
Laravel finds your commands, schedule, listeners, jobs, services, feature flags, and config sections by their attributes in any declared module, so you don't register them in src/app.rs. Rust compiles only the modules you declare, though. If you forget a mod line, Rust skips the file without a warning, and nothing in it runs.