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

Ranx99's avatar

How to structure folders ?

I am planning to create a site, which Its files and classes will grow big in the future...

I have :

  • Admin dashboard
  • User dashboard
  • Front site

Whats the best way to structure these folders? I was thinking of something like:

  • App\Admin
  • App\User
  • App\Front

That will help me when I want to add some new feature to Admin dashboard, I just go to App\Admin and add it. clean and maintainable..

Is it a good idea to do this?

  • Where each folder will have its own Http/ Providers/ .. etc. basically i will copy everything in app\ and paste it to 3 different folders names.
  • What if there is a provider in which it will be shared by all of these 3 folders?
  • Lets say there is a User model which will be used by both 3 folders? where to put it?

What are your experiences on this?

0 likes
6 replies
jlrdw's avatar

I have had very good luck with the folder structure out of the box.

App\Admin App\User

And if the admin or user has more than one role. But I kind of understand what you are looking at.

Large enterprise, i.e., Humana Military, Has separate logins and sections for Doctors vs patients.

But your folder structure would work, just namespace all correctly.

Are you using separate login tables for users and admins, or same table.

Users and admins seem kind of simple, a large company could even have an accounting department.

I have a situation where an admin can view account data, but only the bookkeeper can add, edit, delete.

Ranx99's avatar

Yeah both

  • App\Admin
  • App\User

Will have the same database table ( users table ), which has relationship with "roles" table

  • Admin role
  • User role
  • etc ..

But how to structure this folder, I was thinking of (DDD) style.. but I don't know how to apply it here.

pramanadiputra's avatar

@ranx99

This is how I structured my folder, it's a DDD style (just the folder structure). I'm not using Data Mapper such as Laravel Doctrine, and still utilizing the best of Eloquent ORM.

  • App
  • App\Admin
  • App\User
  • App\Vacancy
  • App\Profession

and so on.

On each App{entity} e.g

- App\Vacancy
-- Events
-- Listeners
-- Jobs
-- Notifications
-- Policies
-- Http
--- Controllers
--- Requests
--- Services
-- Vacancy.php (model) 

Currently the Views are still in resources/views/* but I will move them soon to its entity directory, leave resources folder for web assets like js, css, and static images.

1 like
Ranx99's avatar

@pramanadiputra I like it, But I think this doesnt suite my use case? My case :

  • App\Admin ( admin dashboard )
  • App\User ( user dashboard )
  • App\Front ( front site)

Will use same database tables and models... for example:

There is a category model which will be used for (index, show etc) to Front and User namespaces, but the same model also will be used in the Admin dashboard (create, edit, delete).

This where I am confused, since in your DDD everything is separated entirely.

Hope that makes sense..

pramanadiputra's avatar

@RANX99 - If that so, I think you should use the default project structure. As there some category that will be used by either Admin, User, and Front.

At the moment, I don't have any suggestion.

Please or to participate in this conversation.