Saturday, 28 July 2018

Reasons for not having a compact structure of an MVC application?

In a web MVC project, I have the following structure:
mymvc/                      -> Project root.
    public/                 -> Document root. The only one folder accessible from web.
        assets              -> Client-side assets. NOT ONLY for global themes and 
libraries, BUT ALSO for each specific "view" controlled by the "src/Application"
 components.
            css/
            js/
            images/
            ...
        index.php           -> Application's entry point.
    src/                    -> UI layer rules.
        Application/
            Controller/
            View/
            ViewModel/
        Dispatcher/         -> Application dispatching - route matching, dispatching to 
the specified controller, etc.
        ...                 -> Other classes used by the components in the "src/Application"
 folder.
    templates/              -> Layout and template files.

Note: All domain model components (entities, repositories, data mappers, services, etc) reside in a folder outside of mymvc directory, so that they can be accessible by any other application, too.
I thought - a lot, actually - about doing the following two steps:
  1. To move the templates directory to src/Application folder.
  2. To move the assets directory to src/Application, to create an alias /assets/ in the web server (Apache) configuration - pointing to the moved folder, and to allow full access from the external world to it.
The globally used assets - like css themes, or js libraries codes, or background images, or etc - could still remain located in the public directory - obviously not in a folder named or aliased assets.
I really find the two steps a very good idea, because, as I see it, both folders contain resources related to the structure from src/Application. So, instead of having something like this:
  • src/Application/Controller/AboutUs.php
  • public/assets/js/AboutUs.js
  • templates/AboutUs/[multiple-layout-and-template-files],
a structure like the following seems to be much better:
  • src/Application/Controller/AboutUs.php
  • src/Application/assets/js/AboutUs.js
  • src/Application/templates/AboutUs/[multiple-layout-and-template-files],
But, after I studied many web frameworks, I realised that all of them keep the two folders (templates and assets) completely separated from the application folder.
So I'd like to ask: Are there any specific reasons, why my proposed moving of the two directories can not, or should not be done?
Thank you.


from Reasons for not having a compact structure of an MVC application?

No comments:

Post a Comment