The First Things You Should Do When You Start a New Laravel Project

By Amas
The First Things You Should Do When You Start a New Laravel Project

Starting a new Laravel project always feels great, a blank canvas, clean code, and the freedom to build things the right way this time. But that early excitement can quickly fade if you skip the groundwork. The decisions you make at the very beginning often decide whether your app stays maintainable or turns into a mess a few months down the road.

In this guide, we’ll go through the essential steps to set up a strong foundation for your Laravel project — from architecture and security to tooling, automation, and documentation — so you can build fast without creating future pain.

Let's dive deeper👇

1. Create the Project and Configure the Environment

Start clean:

laravel new project-name

or

composer create-project laravel/laravel project-name

Then immediately configure your .env file:

APP_NAME="My Awesome App"
APP_ENV=local
APP_DEBUG=true
APP_URL=http://myapp.test

And secure your app key:

php artisan key:generate

This ensures that encryption, sessions, and cookies work properly from the start.

Then, initialize the Git repository of your application:

git init
git add .
git commit -m "Initial commit: fresh Laravel install"

And then push your repository to your git remote (or you can do that later).

git push origin/main

 

2. Decide: User-Based or Tenant-Based Architecture

Before writing a single line of code, decide whether your app will be user-based (single-tenant) or tenant-based (multi-tenant).

User-Based (Single Tenant)

In this setup, all users share the same database and application logic, making it ideal for tools that operate within a shared environment, like B2C application, where you only expect your application to be used by 1 person (not a company or a team).

The standard Laravel setup fits perfectly for this type of architecture, keeping things simple and efficient without the extra complexity of multi-tenancy.

Tenant-Based (Multi Tenant)

In a tenant-based (multi-tenant) setup, each customer — or tenant — has fully isolated data, either through separate databases or schemas. This architecture is essential for SaaS platforms that serve independent organizations or B2B applications, where your customer is basically a company (or a team that needs access to some shared data), ensuring that each tenant’s data and configuration remain completely separate and secure.

For that you can use established tenancy libraries:

  • stancl/tenancy -  for database or domain-based tenancy
  • spatie/laravel-multitenancy - another good but simple multi-tenancy package. 
  • SaaSykit Tenancy - a full SaaS starter kit that comes with solid multi-tenancy features like team managements, seat-based billing, tenancy dashboards and much more. 

Defining this early prevents painful migrations later, tenancy touches authentication, billing, storage, and routing.

3. Choose Your Database Engine

Choosing the right database is a key decision that impacts scalability, indexing, and how you handle JSON data.

MySQL or MariaDB are excellent default choices, offering broad support, mature tools, and solid performance for most applications.

PostgreSQL stands out if you need advanced JSON handling with JSONB, complex constraints, or full-text search capabilities.

SQLite, on the other hand, is lightweight and ideal for testing, prototyping, or small-scale projects where simplicity matters most.

 

4. Set Up an AGENTS.md File

Creating an AGENTS.md file at the start of your project is a great way to document its structure, purpose, and coding standards, especially if you plan to leverage AI agents (Claude, Codex, etc) for development or code generation.

This file should describe your project, outline its architecture, and list all the conventions and rules that AI tools should follow when interacting with your code.

By clearly defining these guidelines, you ensure that AI-assisted coding aligns with your expectations and maintains consistency across the project.

Tools like the Laravel Boost library can help streamline the creation of this file and make it easier to integrate AI agents effectively.

 

5. Set Up Local Development Tools

Making your local development environment as close as possible to production helps prevent headaches down the line — no more “works on my machine” surprises.

  • Laravel Sail provides a Dockerized environment that mirrors production, ensuring consistency across all machines and making it easy to manage dependencies.

  • Laravel Herd offers fast, lightweight native setups for macOS or Windows, letting you run Laravel projects without the overhead of full Docker containers.

  • Laravel Telescope gives deep insight into your application’s behavior, including queries, requests, exceptions, and performance metrics, helping you catch issues early.

Using these tools from the start keeps your workflow smooth, reduces bugs, and gives you a better understanding of how your app behaves under real conditions.

 

6. Install Essential Development Packages

Install foundational packages that improve your workflow:

  • barryvdh/laravel-debugbar – Adds a developer toolbar to your app with detailed information about queries, requests, and performance.

  • barryvdh/laravel-ide-helper – Generates helper files to improve IDE auto-completion and make your development smoother.

  • nunomaduro/larastan – A static analysis tool that catches errors and enforces code quality before runtime.

  • laravel/pint – A zero-configuration code style fixer for Laravel projects, ensuring consistent, clean, and readable code across your team.

Run the following:

composer require --dev barryvdh/laravel-debugbar
composer require --dev barryvdh/laravel-ide-helper
composer require --dev nunomaduro/larastan
composer require --dev laravel/pint 

These tools improve your development flow, catch hidden bugs, and enforce consistent standards.

 

7. Configure Static Analysis and Type Safety

Add a phpstan.neon.dist file for Larastan:

includes:
  - vendor/nunomaduro/larastan/extension.neon

parameters:
  level: 8
  paths:
    - app
  checkMissingIterableValueType: true
  checkMissingVarReturn: true
  reportUnmatchedIgnoredErrors: true

The run:

php artisan code:analyse

This ensures type correctness, undefined property checks, and more. Static analysis is your first line of defense against subtle logic errors.

 

8. Enforce Strict Models

One of the first things to do when you start a new application is enable strict model behavior.

In the AppServiceProvider, I go to the boot method and set Model::shouldBeStrict().

public function boot(): void
{
    Model::shouldBeStrict();
}

This simple line ensures your models are strict from the start: it prevents lazy loading, stops attributes from being silently discarded, and throws errors when you try to access missing attributes. Enabling this early helps catch potential bugs before they grow into bigger problems and encourages more deliberate, predictable interactions with your models.

 

9. Set Up Testing Early

Testing shouldn’t be an afterthought — it’s a crucial part of building reliable applications. Start by deciding which testing framework fits your workflow: Pest for elegant, readable tests, or PHPUnit if you prefer the classic approach.

Add a simple smoke test to get started:

 
it('loads the homepage', function () {
    $this->get('/')->assertStatus(200);
});

Writing tests early helps catch bugs before they reach production, and one of the best things about AI tools like Claude, Copilot, Codex, etc is that they can generate high-quality tests. I personally think the AI can better write tests than implementing the functionlity because tests are deterministic and they either work or not.

With a few AI prompts and minimal back and forth with AI, you will get some automated tests that ensure your application is bug free, so there’s really no excuse not to write tests for your application.

 

10. Setup Pre-commit Hooks

Keeping your code clean and consistent from day one makes development smoother and reduces unnecessary code reviews. One of the best ways to enforce this in a Laravel project is by using pre-commit hooks with Laravel Pint.

To do that, navigate to your project's Git hooks directory, then run:

mkdir -p .git/hooks

Create a new file for the pre-commit hook:

touch .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

Open the .git/hooks/pre-commit file in a text editor and add the following script:

#!/bin/sh

# Run Laravel Pint to fix code style issues
echo "Fixing code style with Laravel Pint..."

staged_files=$(git diff --cached --name-only --diff-filter=ACM -- '*.php');
vendor/bin/pint $staged_files -q
 
git add $staged_files

This script will pick all the .php files that are being committed, format them using Pint, then do the actual commit. 

For more information on that, check that full tutorial on how to setup github pre-commit hooks.

Additionally, most modern IDEs like PhpStorm or VS Code can be configured to run Pint on save or through a command palette, giving you instant feedback as you code.

 

11. Setup CI/CD Pipelines

A solid CI/CD (Continuous Integration/Continuous Deployment) pipeline ensures that your application stays reliable and maintainable as it grows. Your pipeline could handle tasks like:

  • Running tests — make sure your app behaves as expected before merging code.

  • Static analysis — run PHPStan or Larastan to catch potential bugs and enforce type safety.

  • Database migrations checks — ensure new migrations are applied safely.

  • Optional checks — linting, security audits, dependency updates, or deployments.

By automating these tasks, you catch issues early, maintain code quality, and streamline deployments. Most modern CI/CD platforms like GitHub Actions, GitLab CI, or Bitbucket Pipelines can easily handle these tasks for Laravel projects.

For a complete, step-by-step guide to setting up a Laravel CI/CD pipeline, check out this tutorial: Full Laravel CI/CD Tutorial.

 

Final Thoughts

Starting a Laravel project can feel exciting and a little overwhelming. The choices you make at the beginning, like whether it’s user-based or tenant-based, how you structure your code, and what tools you use to enforce quality, might not seem important now, but they pay off big time later.

Take the time to document your decisions, set up automated checks, and stick to clean coding standards. It might feel like extra work today, but a few smart habits early on will save you (and anyone else who works on the project) countless headaches down the road.

Think of it as giving your future self a gift: a codebase that’s easy to maintain, easy to scale, and actually enjoyable to work on.

Share this post.
Liked that? Subscribe to our newsletter for more
Ship fast & don't reinvent the wheel

Build your SaaS using SaaSykit

SaaSykit is a SaaS boilerplate that comes packed with all components required to run a modern SaaS software.

Don't miss this

You might also like