tag:robotlegs.tenderapp.com,2009-10-18:/discussions/suggestions/36-postmortem-mvcs-folder-structure-sucks-suggestion-use-a-modular-folder-structure-tied-to-your-projectRobotlegs: Discussion 2012-02-02T12:01:49Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/28687232010-09-07T16:28:13Z2010-09-07T17:36:54ZMVCS folder vs Modular folder structure<div><p>After doing various projects using the following folder structure-type,<br />
<a href="http://knowledge.robotlegs.org/faqs/reference-mvcs-implementation/robotlegs-mvcs-folder-structure">http://knowledge.robotlegs.org/faqs/reference-mvcs-implementation/r...</a><br />
,
many people in my company have complained it's very hard to find stuff with such a file structure. I realised this is because such a structure is based off a generic and abstract model/view/controller pattern, and not based off the <em>concrete</em> <em>specific</em> features & requirements of a particular project. There's a tendency to dump all your view component code into the view.ui folder( which can lead to a huge bloat in files in just one folder), or otherwise having to create many sub-folders within each core root view/model/controller folder to narrow down specifics within each core folder. It becomes impossible to find out which ui component class is being used for which page of a given Flash site, and the only way is to check the library symbol linkages in the Flash IDE, which makes it extremely troublesome. (you know how bad the Flash IDE can be...).</p>
<p>The thing is: Why not do away with the abstract core "model", "view", "controller", "event", "services" folders? They tend to present a monolithic triad of classes that are all spread all over the place, having to view all these separate folder branches (which aren't really meaningful except to follow an obscenely abstract MVCs structure) just to find out how a particular view component, page, or module implementation works in relation to the rest of the application. What's the point of having such folders when such folders hold no purpose whatsoever as far as an application/website is concerned? Shouldn't folder structures reflect how a project is like and what features it has ? In a typical MVCS folder structure, the user won't know how a project is like at a simple glance (from the folder structure alone), but only until he looks into all these tier-based sub-folders, views the main context mappings (and class implementations with mapped commands), than he only gets a rough idea of it's features and the connected dependencies. For those not familiar with such a structure, it becomes a total loss in being unable to find anything.</p>
<p>Wouldn't it be better to place all model, view, command, service/controller classes and events in specific theme-based folders with a specific purpose? For example, say your application/website needs to manage the loading and handling of post data, you simply create a folder like:<br />
com.project.posts.<em><br />
PostContext<br />
PostModel<br />
PostEvent<br />
PostService<br />
com.project.posts.cmd.</em><br />
SendPost<br />
AddPost<br />
CancelPost</p>
<p>And for specific Calendar management:<br />
com.project.calendar.<em><br />
CalendarModel<br />
CalendarEvent<br />
com.project.calendar.cmd.</em><br />
PostToCalendar</p>
<p>And for specific Facebook management.<br />
com.project.facebookconnect.*<br />
FaceBookAccount</p>
<p>This way, all dependencies for that particular module are all located in one place.</p>
<p>For general stuff like utilities and services that can be reused across different projects as well, you dump those here</p>
<p>com.project.utils.*<br />
(Any generic utilities and services that aren't application-specific go here. Note that I don't have a services folder. A standard utils folder would suffice for that.)</p>
<p>Base/abstract classes and such go here in the following format:</p>
<p>com.project.baseui.<em><br />
com.project.basepage.</em></p>
<p>Any specific view implementations within each page are all organised as below in a thematic format. For example:</p>
<p>com.project.pages.eventcalendar.<em><br />
EventCalendarContext<br />
EventCalendarPage<br />
CalendarDetailsPage<br />
CalendarDetailsPageMediator<br />
CalendarListMediator<br />
com.project.pages.eventcalendar.ui.</em><br />
CalendarList<br />
CalendarListItem<br />
EventListItem<br />
EventList</p>
<p>com.project.pages.forumpage.<em><br />
ForumPageContext<br />
ForumPage<br />
ForumPageMediator<br />
com.project.pages.forumpage.ui.</em><br />
.... (do likewise as above, any specific ui elements for the forum page)</p>
<p>In this way, you narrow down specific implementations used for a particular project into modules. Also, this forces developers to duplicate unique view component class implementations for other pages to allow further customization across the various pages (even if their behaviours are similar). Every view component is encouraged to be tied to it's own page module in most circumstances (except for baseui sharing..., though this should be kept to the minimal because code duplication allows for better standalone customisation/monkey patching compared to extending from a base class which is more restrictive), so that each view component within each page can have varying degrees of uniqueness and customisation when requirements change for different pages. The MVC pattern doesn't need to be followed strictly in each of the specific folders, 'except it should be organised with clean-cut separation of concerns.</p>
<p>Also, there's no need to use model/view/controller sub-folders within each module folder since each module is meant to be kept as small as possible and involves classes prefixed with the usual "Model"/"Event"/"Service" to denote specific implementations, and a convenient "cmd" sub folder to represent the Commands triggered mainly through the module package's core Event payload. In this way,it becomes easier for the user to (at a single glance), view all the tiers of operations being used (event,command,etc.) for a module, without having to open 3-4 separate folders just to see how it's being done. In some cases, there is no command tier and the service is used directly. Since each module can be particularly small, the command tier can be skipped if the service tier is sufficient enough.</p>
<p>In fact, this means it's also right to place models/services/controllers in the same module folder, assuming such models/services/controllers are tied to that module only, such an approach is still fair game. There's no need to filter stuff into meaningless "mvcs/event" sub-folders. Let the viewer see all the relevant classes at once for that module, since in reality, all tiers are important as a whole.</p>
<p>Additionally, not to be confused with Modular Contexts in RL, the "Context" class within each page/module folder doesn't necessarily need to use the above-mentioned in RL, it may just be a static class to help quickly wire up the mappings within that package.</p>
<p>For example, in PostContext.as:</p>
<p>import com.project.posts.cmd.*<br />
public static function wireToInjector(injector:IInjector):void {<br />
</p>
<pre><code>injector.mapSingleton(PostModel);
injector.mapSingleton(PostServices);
com.project.utils.AutoWireCommands(
AddPost,
SendPost,
CancelPost
);</code></pre>
<p>}</p>
<p>And the above static function can be called from the MainContext, so the MainContext doesn't need to be crowded with too many mappings . It just needs to import the com.project.posts.PostContext class to perform the static mapping.</p>
<p>The thing is, why not do it the regular RL way and trigger a Command through an event to perform module-specific mappings? Yes, that can be done, but this means having to map 1 startup command and 1 event signature for each module. Also, if one places all these commands in a generic "commands" folder, you tend to get a over-crowded commands folder. (Of course, one can place this in a subfolder like com.project.controller.startups), but this forces the user to know that such a sub-folder exists within the controller folder. Again, it's all just too vague and too much work to simply wire up dependencies.</p>
<p>What's the point of MVCS if it has no clear purpose? Ultimately, even though the purpose of MVCs is to provide a clean seperation of concerns between all these 4 tiers, yet it's ultimately purpose is to have all these tied together to fufill a particular agenda (so those files should be placed together in the same place). As a result, I feel the thematic folder-package approach is far more meaningful and makes things easier to find for outside parties. When one needs to change a particular module in an application, that particular module's folder is right there at the project root in front of his nose. You'd know explicitly which view components, commands, and application services are tied that module, rather than having to open up 3-5 generically-named folders "just to see how it's all connected" through those "grrrr...mappings" on a "grrrr...MainContext".</p>
<p>When one simply dumps any Event-based class into the "event" folder...or dumps any view component-based class into a "view.ui" folder or dumps any Service-based class into the "services" folder, or dumps a Controller-based command into the "commands" folder, it is done with the assumption that such classes are extremely generic and is normally used for any purpose across the entire site. Or is it? It turns out, in order to determine how these "generics" work together in (usually-specific) application-contexts, all these folders (and the MainContext) must be opened and I must "spot the connection" between all these files which are distributed across various folders that don't mean much except for what they're based upon (which is normally stated in the class name suffix anyway). For me, that's easy. But for others, not too obvious. Why not place all these in a single purpose-driven thematic package folder which others can use if required? That way, there's a "clear objective" to the "program" being created. A package is created with a specific purpose.</p>
<p>Generally, as far as folder structure is concerned for most projects, 80% of the files/folders would turn out specific to the project, while the remaining 20% is just generic. So, why create a folder structure that "pretends" every file within it is generic(ie. through root "services, views, models","controller","events" etc.) when in reality, it rarely isn't? Such a folder structure (a forced MVCS pattern) on a generic MainContext, obfuscates the code, makes things harder to find and encourages laziness on the developer's part in actually not arranging his folder structure in a proper modular format from the root location. After all, isn't good coding about clearly defining specifics, not obscuring it? Just my 2 cents.</p>
<p>I haven't tested the direct modular folder structure approach for RL, but I think it might be better since that worked for other projects, since it allowed everyone to find whatever is needed for each particular module/subject.</p></div>glidiastag:robotlegs.tenderapp.com,2009-10-18:Comment/28687232010-09-07T17:28:26Z2010-09-07T17:28:26ZMVCS folder vs Modular folder structure<div><p>Hi Glidias,</p>
<p>I use the</p>
<p>functionalarea-> restricted-> mvcs approach</p>
<p>and of course</p>
<p>functionalarea-> api</p>
<p>package for classes that can be used by other functional area (which can be checked using FlexPMD).</p>
<p>You'll find a long post with people discussing just this somewhere back a few months ago.</p>
<p>If my functional area has only a handful of classes, they sit just there. mvcs only comes in where there's enough to justify it (most of the time there is).</p>
<p>I think you'll find that on anything except the smallest projects projects most people would agree with (and already be using) what you're describing. It's the AS3 'best practice' instruction I believe.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/28687232010-09-07T21:49:49Z2010-09-07T21:49:49ZMVCS folder vs Modular folder structure<div><p>Hey Glidias,</p>
<p>Agreed! Nice post. I think a good portion of the RL documentation (best practices, recommendations etc) needs re-visiting.</p>
<p>Regarding this bit: "why not do it the regular RL way and trigger a Command through an event to perform module-specific mappings? Yes, that can be done, but this means having to map 1 startup command and 1 event signature for each module."</p>
<p>You could also just invoke the command directly from your "main" context, something like: <code>commandMap.execute(SomeModuleConfigCommand);</code> - just a variation on the static method approach in the same number of files & lines.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/28687232010-09-17T12:40:27Z2010-09-17T12:40:27ZMVCS folder vs Modular folder structure<div><p><a href="http://stackoverflow.com/questions/533102/what-strategy-do-you-use-for-package-naming-in-java-projects-and-why">http://stackoverflow.com/questions/533102/what-strategy-do-you-use-...</a></p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/28687232010-09-20T15:50:52Z2010-09-20T15:51:37ZMVCS folder vs Modular folder structure<div><p>I always use a functionalArea->mvcs approach. If you are consistant within a project it all shakes out in the end. I do agree that monolithic applications are poor, and think that we should be "modular" in our development generally.</p>
<p>The problem manifests in these trivial example applications because they are <em>only</em> one module by nature.</p>
<p>I like <a href="http://opensource.adobe.com/wiki/display/cairngorm/Creating+Functional+Areas">this article in the Cairngorm 3 documentation</a>.</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/28687232011-01-12T20:33:34Z2011-01-12T20:33:35ZMVCS folder vs Modular folder structure<div><p>Here's is a good explanation about the advantages of
Package-by-Feature (Functional Areas)<br>
<a href=
"http://www.javapractices.com/topic/TopicAction.do;jsessionid=0BF4844350780B6F55476E1137FF4893?Id=205">
http://www.javapractices.com/topic/TopicAction.do;jsessionid=0BF484...</a></p>
<p>I think is neccesary to update the best practices, and to put
some examples with the new structure.<br>
I've read about it, but I couldn't find any good and complete
example so I'm a bit confused about the implementation, for example
in the article posted by Joel, the recommendation is to use a thin
API for the communication between packages, but that's very
confusing to me without an example.</p></div>Enriquetag:robotlegs.tenderapp.com,2009-10-18:Comment/28687232011-01-13T10:06:25Z2011-01-13T10:06:25ZMVCS folder vs Modular folder structure<div><p>Thanks for the link, Enrique, that's a helpful explanation
indeed. I<br>
especially like the comparison to other domains.</p>
<p>And you're right: The examples need updating to reflect
packaging best<br>
practices. If you're feeling up to it, please fork the examples
and<br>
have a go at refactoring them accordingly.</p>
<p>It's not like we don't want to do it ourselves, we just don't
have the<br>
time to actually do it. So any help in that area would be
greatly<br>
appreciated. And if you feel like you need additional guidance
or<br>
simply want advance feedback before sending out a pull request:
Just<br>
shout.</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/28687232011-01-13T16:14:43Z2011-01-13T16:14:44ZMVCS folder vs Modular folder structure<div><p>Hi tschneidereit, I think I can't help with this because I don't
know how.<br>
I was hoping an example, tested and working, from someone on the
list.<br>
I never used Package-By-Feature in my projects, but I think is the
way to go...<br>
No body works with Package-By-Feature before in any project?</p></div>Enriquetag:robotlegs.tenderapp.com,2009-10-18:Comment/28687232011-01-14T14:58:01Z2011-01-14T14:58:01ZMVCS folder vs Modular folder structure<div><p>Hi Enrique,</p>
<p>don't worry: We'll eventually get around to it. I'm afraid I
can't<br>
guide you to any up-to-date Robotlegs-specific examples right
now,<br>
though.</p></div>Till Schneidereit