Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shivamyadav's avatar

what folder structure patterns have you found most effective ?

In Laravel projects, what folder structure patterns have you found most effective for keeping interfaces (contracts) and their implementations maintainable as the codebase grows?

Specifically, how do you balance:

  • feature-based organization vs layer-based organization
  • discoverability vs separation of concerns

Any examples from production applications would be helpful.

0 likes
4 replies
alihamzahq's avatar

I usually prefer a feature/domain-based structure, with small layer-based folders inside each domain.

Instead of one global Services, Actions, or Contracts folder, I like keeping related code together:

app/
  Domain/
    Offers/
      Actions/
      States/
      Contracts/

    Listings/
      Actions/
      Services/
      Contracts/

    Billing/
      Actions/
      Services/
      Contracts/

  Http/
    Controllers/
      Offers/
      Listings/
      Billing/

    Requests/
      Offers/
      Listings/
      Billing/

That gives a good balance: the business logic is grouped by feature, but each feature still has clear separation between actions, services, contracts, states, etc.

A good public example of this style is:

github.com/alihamzahq/pulsepass-api

It follows a similar domain-style flow, with business logic grouped under app/Domain/ and HTTP concerns kept separately under app/Http/.

My general rule is: structure the app first by business capability, then by technical role inside that capability.

martinbean's avatar
martinbean
Best Answer
Level 80

@shivamyadav I’ve worked on probably hundreds of Laravel projects over more than 10 years now, and at companies of all sizes (from SMEs to Fortune 500s). The projects that fell apart and became unmaintainable messes were the ones where developers decided to be “clever” and create their own folder structure, or do “modules”, “domains”, or whatever.

Seriously, stick to Laravel’s default directory structure:

  • Put interfaces in an app/Contracts directory, which follows the framework’s convention.
  • Use managers for things that can have multiple providers (i.e. payment gateways). Think how Laravel uses managers for components you interact with (cache, queue, etc) where the code doesn’t change if you swap providers (i.e. from Redis to database). Try to strive for the same in your application where you’re relying on interfaces and managers rather than a specific provider.
  • If you have different “areas” in your application, then you can sub-namespace controllers (i.e. App\Http\Controllers\Admin).
  • For interactions with third-party services, I create a dedicated namespace in an app/Services directory (i.e. App\Services\Mux). I then treat this folder as a package, so it may have its own Artisan commands, Eloquent models, controllers, routes, etc with a service provider to register those resources.

It Just Works™ and scales, and your Artisan make:* commands still work without having to install horrible “glue” packages. And with the rise in AI-assisted development, sticking to the default directory structure will only help that given that’s what LLMs will be trained on.

1 like
imrandevbd's avatar

I'm completely with @martinbean on this one. Over the last decade building large-scale SaaS and ERP systems, every time my team tried to force a strict DDD or custom modular folder structure, we ended up fighting the framework.

Laravel's default structure is incredibly scalable if you just lean into sub-namespaces.

For interfaces, sticking to app/Contracts works perfectly. If a feature has multiple implementations (like different payment gateways or SMS providers), build a Manager class. It mimics how Laravel handles its own core components and makes swapping implementations painless.

Please or to participate in this conversation.