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

jlmmns's avatar
Level 12

What folder/file structure should I use for my application?

Hi all!

Currently playing and researching a lot about Laravel, as I will be using it for our application. However, since I've never really used a framework before, I have this question about what folder structure I should use for my own files.

To summarize our application:

Our app exists of several modules: Contacts, Projects, Invoices, Quotes, Agenda, To-do's

These modules need to be able to function on their own, as well as work together, obviously. I've heard about 'bundles', to separate each module's code into its own package? Although I don't want to over-complicate things. I'm actually afraid of using bundles, since it's a new concept for me.

Should I use my own custom namespace folder? (Acme? AppName?) And place all my code under that directory? Or simply use Laravel's default folders?

Currently, it's as straightforward as this:

#  App
--------
controllers/app/... (eg: DashboardController, InvoicesController, ContactsController)
models/app/...
views/app/...

#  Website
------------
controllers/site/... (eg: PagesController)
models/site/...
views/site/...

As you can imagine, it's quite a big application, so I want the best possible folder structure, to be able to easily maintain it for years to come.

0 likes
2 replies
alenabdula's avatar

As far as I understand it you can structure your files anyway you want. Since Laravel uses PRS-4 for autoloading. You can place your files anywhere in the app directory. You would probably want to create ex. ACME folder and go from there.

DraperStudio's avatar

Recently I had to figure out the same for an application that consist of 19 "Modules" of which each is quite large and got separated into it's own folder. As soon as Laravel 5 will be released these Modules will be moved into packages.

The structure of these modules looks pretty much like this, though it required that the BusServiceProvider had to be modified to keep the commands working.

public function boot(Dispatcher $dispatcher)
{
    $dispatcher->mapUsing(function ($command) {
        $commandsPath = str_replace(class_basename($command), null, get_class($command));

        return Dispatcher::simpleMapping($command, $commandsPath, $commandsPath.'Handlers');
    });
}
app/
    /Modules
        /Contacts
            /Commands
                CreateContactCommand.php
                /Handlers
                    CreateContactCommandHandler.php
            /Contracts
                ContactRepository.php
            /Controllers
                ContactsController.php
            /Events
                ContactWasCreated.php
                /Handlers
                    ContactWasCreatedHandler.php
            /Models
                Contact.php
            /Providers
                ContactServiceProvider.php
            /Requests
                CreateContactRequest.php
                UpdateContactRequest.php
            /Services
            /Traits
            /Views
                index.blade.php
                create.blade.php
                read.blade.php
                update.blade.php
                destroy.blade.php
            /Repositories
                ContactRepository.php
2 likes

Please or to participate in this conversation.