DEV Community

david duymelinck
david duymelinck

Posted on

Single directory components in backend frameworks

The rant

At the moment I'm working on some Laravel sites. And I was thinking about the Drupal single directory component.

Why do we need to place all those classes in different directories? Most, if not all, classes have a suffix to identify their role in the application.

In Drupal it revolves around html that is in a twig file. For backend code most classes revole around a model or a controller.

Laravel artisan make commands allow you to bootstrap the different classes. But few of them offer you a path option. So the only thing you can do at the moment is to create the classes and move them manually.

A solution?

To show what it could be I made a make:group command. For now it is proof of concept code. A lot of functionality and refinement is missing.

The command guides you through the creation of a group and the bootstrapping of the controller, model and/or repository.

For the generation of the controller I choose to make it possible to create the methods instead of choosing between a few templates.

When you want to create a repository it will create the class and the interface with the methods you add.

Try it out, let me know what your thoughts are on this way of strucuring the code. And have a good day!

Top comments (0)