Guides · SaaS · Architecture

How to structure a large Laravel project so it stays maintainable.

Practical Laravel structure for growing apps: thin controllers, form requests, actions or services, policies, events, API resources and how to avoid fat models.

Key takeaways

  • Keep controllers thin: validate, call a class that does the work, return a response.
  • Put business rules in actions or services that you can test without HTTP.
  • Use Form Requests, policies and API resources, which Laravel already provides.
  • Do not over-engineer early. Extract when a file becomes hard to read, not before.

The default structure is fine at first

A new Laravel app puts controllers in app/Http/Controllers, models in app/Models and so on. For a small project, that is enough. Problems start when a controller method grows to a hundred lines, or when the same rule is copied into three places.

Thin controllers

A good controller method reads like an outline:

public function store(StoreBookingRequest $request, CreateBooking $createBooking)
{
    $booking = $createBooking->handle($request->validated(), $request->user());

    return new BookingResource($booking);
}

Validation lives in the Form Request, the rule lives in the action, and the shape of the response lives in the resource.

Actions or services

An action is a small class with one public method that does one thing, such as CreateBooking or CancelSubscription. A service groups related operations, such as PaymentService. Both are plain PHP classes. Pick one style and stay consistent.

Benefits: you can call the same logic from a controller, a console command, a queued job or a test.

Form Requests

Move validation and authorisation out of controllers:

class StoreBookingRequest extends FormRequest
{
    public function authorize(): bool { return $this->user()->can('create', Booking::class); }
    public function rules(): array { return ['date' => ['required', 'date', 'after:today']]; }
}

Policies

Keep "who may do what" in policies, not in if statements scattered around Blade views and controllers. Use $this->authorize() or Gate.

Models: relations and scopes, not everything

Models should describe data: relations, casts, scopes and small accessors. When a model grows long methods that coordinate several tables, move them to an action.

Events and listeners

When an action triggers side effects (send email, update a report, notify an admin), dispatch an event and let listeners respond. This keeps the main action short. Do not add events where a simple method call is clearer.

Folder organisation by feature

Once you have dozens of models, organising by feature can be easier than by type:

app/
  Domain/
    Billing/
    Bookings/
    Hospitals/

Each folder holds its own models, actions and policies. Laravel does not require this, so adopt it only if the flat structure hurts.

Habits that keep it healthy

  1. Write tests around actions, not only HTTP. See how to write Laravel tests that matter.
  2. Avoid queries in Blade. Prepare data in the controller or a view model.
  3. Use enums for fixed sets, such as booking status.
  4. Keep configuration in config/, not hard-coded strings.
  5. Review for N+1 queries when a list page is slow.

Frequently asked questions

Do I need the repository pattern?

Usually no. Eloquent already acts as a data layer, and an extra repository often only adds files. Use one if you truly need to swap storage.

Should every feature have a service class?

No. A one-line controller action does not need one. Extract when logic is reused, long or hard to test.

What about DDD?

It can help in big domains, but adopt only the parts that solve a problem you actually have.

These are the habits behind my SaaS builds.

See the products