---
title: "Clean Laravel Code in a SaaS Starter Kit: What to Check"
description: "What clean Laravel code means in a SaaS starter kit: modules, thin controllers, services, Data objects, typed routes, Larastan, Pint, Pest and CI."
pageClass: blog-page
date: 2026-11-21
author: annu-gupta
category: architecture
tags: [Clean Code, Architecture, Starter Kits]
---
# What "Clean Laravel Code" Means in a SaaS Starter Kit
Almost every Laravel SaaS starter kit says its code is clean. It's hard to argue with, and hard to check from a sales page. But it matters more in a kit than almost anywhere else: you don't install a kit like a package, you take over its code. Every controller, service and test becomes yours to read, extend and debug, and your AI coding agent will copy whatever patterns it finds there.
So what does "clean" actually mean in a kit? In this post I'll break it into things you can check: folder structure, thin controllers, service classes, validated input, typed routes, static analysis, formatting, tests, CI and guidelines for AI agents. For each one I'll show short, real code from our own Vue kit (Laravel 13, Inertia v3), trimmed for length, and end with a checklist you can use on any kit before you buy.
## Why code quality matters more in a kit
A package hides its internals behind an API. A kit doesn't. On day one you'll add a module next to the ones that shipped, and you'll copy the shape of the closest existing file. If the kit's controllers run queries, send emails and build arrays inline, yours will too. If its services are small and typed, yours will probably be the same.
That's the real test of clean code in a kit: **is it a good example to copy?**
## 1. A structure you can find things in
Our kits split the backend into modules under `Modules/`, such as Auth, Menu, RolePermission, Settings, Tenant and User. Most have their own routes, controllers, Data objects and services:
```text
Modules/User/
├── Data/ UserData.php, AcceptUserInvitationData.php
├── Http/Controllers/ UserController.php, UserInvitationController.php
├── Notifications/ UserInvitationNotification.php
├── Providers/ UserServiceProvider.php
├── Services/ UserService.php
└── routes/web.php
```
It's plain PSR-4 in `composer.json`, no module package:
```json
"Modules\\": "Modules/"
```
Each module's service provider loads its own routes. When you need to change how users are invited, you open one folder. If you want the reasoning behind this layout, read [modular Laravel architecture](/blog/modular-laravel-architecture.html).
Modules aren't the only clean structure. A kit that follows Laravel's default `app/` layout consistently is fine too. What you want to avoid is a mix, where half the logic is in `app/` and half in some other place with no rule.
## 2. Thin controllers
A clean controller reads like a summary: take validated input, call a service, return a response. Here's `store` and `update` from `Modules/User/Http/Controllers/UserController.php`:
```php
public function store(UserData $data): RedirectResponse
{
$user = $this->userService->createUser($data);
Inertia::flash('toast', [
'type' => 'success',
'message' => $data->sendInvitation
? __('modules/user.toasts.invited', ['email' => $user->email])
: __('modules/user.toasts.created'),
]);
return to_route('users.index');
}
public function update(UserData $data, User $user): RedirectResponse
{
$this->userService->updateUser($user, $data);
Inertia::flash('toast', ['type' => 'success', 'message' => __('modules/user.toasts.updated')]);
return back();
}
```
No validation rules, no queries and no transaction in the controller. Permission checks sit on the routes as middleware. Our post on [thin controllers](/blog/laravel-thin-controllers.html) goes through how to get there from a fat one.
## 3. Business logic in service classes
The work happens in `Modules/User/Services/UserService.php`:
```php
public function createUser(UserData $data): User
{
$user = DB::transaction(function () use ($data): User {
$user = new User([
'name' => $data->name,
'email' => $data->email,
'password' => $data->sendInvitation ? Str::random(40) : $data->password,
]);
$user->invited_at = $data->sendInvitation ? now() : null;
$user->save();
if ($data->role) {
$this->permissionService->assignRole($user, $data->role);
}
return $user;
});
if ($data->sendInvitation) {
$this->sendInvitation($user);
}
return $user;
}
```
Two details are worth looking for in any kit. The user and their role are saved in one transaction, so you never get a user without a role. And the invitation email goes out **after** the transaction, so nobody gets an email for a user that was rolled back. Services also get typed return values and PHPDoc where types aren't enough, like `@return LengthAwarePaginator`.
Clean doesn't mean a layer for everything. The Tenant module has repositories for its read queries; the User module doesn't need them, so it doesn't have them. The [service layer pattern](/blog/laravel-service-layer-pattern.html) post covers where to draw that line.
## 4. Validated input as typed objects
In the Inertia kits, input arrives as a [spatie/laravel-data](/blog/laravel-data-objects.html) object. `UserData` holds the typed properties and the validation rules in one place (trimmed):
```php
#[TypeScript]
#[MapName(SnakeCaseMapper::class)]
class UserData extends Data
{
public function __construct(
public string $name,
public string $email,
public ?string $password = null,
public ?string $role = null,
public bool $sendInvitation = false,
// ...
) {}
public static function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class, 'email')->ignore($userId)],
// ...
];
}
}
```
The `#[TypeScript]` attribute means the same class becomes a TypeScript type for the frontend, so the form and the backend can't quietly drift apart:
```ts
export type UserData = {
name: string;
email: string;
password: string | null;
role: string | null;
send_invitation: boolean;
// ...
};
```
The Livewire kit uses classic Form Requests instead (`Modules/User/Http/Requests/UserRequest.php`) with matching rules. Either is clean. What isn't clean is `$request->all()` passed straight into a model.
## 5. Typed routes on the frontend
Hard-coded URLs like `'/users/' + id` break silently when a route changes. The Inertia kits use [Laravel Wayfinder](/blog/laravel-wayfinder-typed-routes.html), which generates TypeScript functions from your Laravel routes. From `pages/users/Partials/UserFormModal.vue`:
```ts
import { store, update } from '@/routes/users';
const formAction = computed(() =>
selectedUser.value ? update(selectedUser.value.id) : store(),
);
```
That `formAction` goes straight into Inertia's `