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

dahall4's avatar

L5 large project structure

Hello,

I have a large Laravel 5 app I'm having trouble structuring in a manageable way. I've looked at several different examples, but am hoping for someone who's had experience with this type of setup to throw their two cents in.

The project consists of:

  1. A promotional website and blog
  2. A restful API for mobile app (built with AngularJS)
  3. A CMS for managing the blog and several entities employed by the app

At some point down the road, the promotional site may use data from the app.

Things seem to get pretty tough to sort through with the API, blog and CMS all residing in the same Laravel project. While I love the idea of using Lumen for the API, and separating the various services into their own projects, the projects aught to deploy synchronously since they'd be using the same database.

Should I split these into separate code repositories, or is their a good way to organize these within a single Laravel project?

Any input would be appreciated!

0 likes
5 replies
helmerdavila's avatar
// Uppercase = ex. folders dont use uppercase notation
Site
    Controllers
        API
            (if you manage roles you can create roles folder for controllers)
        CMS
            ... more subfolder for role or simply controllers
        BLOG
        WEB
// same for views...
milon's avatar

go for single page application, then you could use the same api for both web and mobile

dahall4's avatar

Thanks for the replies! I've got things separated into different folders like @helmerdavila suggested, and am definitely considering doing the whole thing as a SPA app, with one API for everything.

The folders/namespaces work fine for controllers, requests and views, but do you guys bother separating things like repositories? They seem to get rather bloated with all the methods for web/api/cms/etc... or am I just overthinking this?

jekinney's avatar

I set each unique feature in it's own folder under app. Like for a blog I use a trait that holds all the user relationships for the blog under Blog/Traits and use it in the user modal. You can go as far as all your controllers, events and even routes. Just include them in and/or proper namespaces. This way in theory to add or remove a feature is easier along with updating etc with out having to dig into many folders and files.

luddinus's avatar

I would do the API in a different project, and then from the web app call the API using GuzzleHttp for example.

If you do all the things in the same project, I would separate by "modules"

--User
------Http
---------Controllers
------------API
---------------UsersController.php
---------Request
---------Middleware
------resources
---------views
---------lang
------User.php // model

// etc

You can get some ideas from this packages:

https://github.com/caffeinated/modules

https://github.com/pingpong-labs/modules

1 like

Please or to participate in this conversation.