Skip to content

Leaf + MVC

Leaf MVC

Structure for real apps, without the framework weight.

Leaf MVC gives your project controllers, models, routes, views, services, and environment conventions from day one, while keeping the codebase small enough for humans and AI assistants to understand.

1 map

for humans and AI

0 lock-in

just PHP

Best for

Products with real users

Dashboards, portals, CMS projects, admin tools, and apps that need room to grow.

Teams and AI assistants

A predictable code map makes changes easier to review, extend, and generate.

APIs and full-stack apps

Keep backend logic organized while using the frontend stack you already like.

What is MVC?

MVC stands for Model-View-Controller. It separates your application into the parts that hold data, display interfaces, and respond to requests.

01 / ModelData and rulesModels represent your data, query storage, and keep business rules close to the records they affect.
02 / ViewThe interfaceViews render HTML, Blade, BareUI, Inertia, React, Vue, or any frontend your product needs.
03 / ControllerRequest handlingControllers receive requests, call the right logic, and return responses without burying intent.
New to MVC?

MVC is a simple way to keep application code organized. Models talk to data, views present the interface, and controllers coordinate requests. Traversy Media has a useful overview if you want a broader introduction before building with Leaf.

Watch the MVC overview

MVC in Leaf

Leaf MVC is a minimal setup for building structured applications. It adds the folders and commands most projects need, but avoids forcing your app into a heavy framework model.

Request flow

A route receives the request, a controller decides what should happen, models and services handle the work, and a view or JSON response returns the result. That predictable flow is why Leaf MVC works well for teams and AI-assisted changes.

Route receives request
app/routes/index.php
php
app()->get('/dashboard', 'DashboardController@index');
Controller coordinates work
Model or service handles logic
app/controllers/DashboardController.php
php
return response()->view('dashboard', [
  'data' => db()->select('frames')->get()
]);
View or JSON returns result
app/views/dashboard.blade.php
blade
<h1>Dashboard</h1>
<ul>
  @foreach ($data as $frame)
    <li>{{ $frame->name  }}</li>
  @endforeach
</ul>

Directory Structure

Leaf MVC's directory structure is inspired by Rails and Laravel, but it stays lightweight and flexible. A fresh app starts with the places most product code naturally belongs.

Default starter

app/
controllers/
database/
models/
routes/
views/
public/

app/

Your controllers, models, views, routes, database files, and application logic.

public/

The only browser-exposed directory, usually for bundled CSS, JavaScript, and images.

Modules may also generate folders like storage for logs, cache, and temporary files.

Configuring Leaf MVC

Leaf MVC works out of the box. Most projects only need a few environment variables, so there is no config directory until you publish one.

$ leaf config:publish
$ leaf config:publish <config-file>
ConfigUse case
appcore app behavior
authauthentication
databasedatabase connections
viewview rendering
mailmail delivery
queuequeued jobs
corscross-origin requests
csrfCSRF protection

Application Environment

Leaf MVC ships with a .env.example file that is copied to .env during installation. Values are automatically loaded and available through the _env() helper.

php
$database = _env('DB_DATABASE');
$databaseWithDefault = _env('DB_DATABASE', 'leaf');

Do not commit your .env file. Leaf MVC already adds it to .gitignore because it can contain database credentials, API keys, and other secrets.

Building with Leaf MVC

Leaf MVC gives you structure without taking away your choices. Build a full-stack app, serve a frontend with Inertia or Blade, or expose a clean JSON API for any client.