Framework agnostic components/modules = HOW?

Hi guys,

I’m currently doing some research on how best to re-design/re-build one of our systems architecture.

One of the proposals I would like to come up with, is to separate our core business logic into a library of re-usable, interoperable components/modules which are framework agnostic.

Ideally I would like to use a commercial framework such as Zend for the application specific stuff (MVC), but, the modules/components shouldn’t be tied to Zend in any way.

I believe designing it this way gives us a lot more flexibility and scalability!

(How many more buzz words do you think I could fit in)

My question to you fine people is this;

Are there any standards or recommended methods when it comes to developing modules/components in this way?? Ideally I would like these to be easy to plug-in into any framework and later down the line I would like to be able to distribute some if these components to other developers.

The idea sounds great but it sounds like a mammoth task!!

Any help/guidance would be much much appreciated

Peace
Crabby80

I’d say this is what you should be striving for anyway for testability.

You could very easily make all of your models framework independant (If you’re using real models, and not the simple DAO kind implemented by most frameworks) but what about framework tools such as ORMs, form processing classes, etc? Are you restricting yourself from those too?

Michael Morris has posted quite a bit about moving all the business logic to the database via stored procedures, views, etc. Although the technical aspects are different, the separation of concerns is identical.

Are there any standards or recommended methods when it comes to developing modules/components in this way?? Ideally I would like these to be easy to plug-in into any framework and later down the line I would like to be able to distribute some if these components to other developers.

No, not that I am aware of anyway. There are some problems which would need to be addressed.

WordPress has a wildly different architecture from drupal. Joomla is also significantly different from both of those. In order to “share” modules or components between these distinct systems would be no trivial task.

First off, many of these systems provide a library of code for generating forms, validating data, building interfaces (menus/lists/etc). To complicate matters they are often tightly coupled to the specific architecture.

Now if you wanted to use a “framework” (in the truest sense of the word) such as Zend you would be limited i what you could reuse. Joomla may allow you to swap it’s controllers with a Zend controller class but it would have to implement the same interface as the Joomla controllers; think adapter pattern.

Drupal and WordPress do not really have a distinct controller architecture but instead consist of a series of modules which are implemented as hooks that get invoked at various points of execution.

Modules are (in Drupal) a folder with specific files in it. The module code itself is implemented as standard functions so using Zend controller is out of the question.

There would be no re-use of the front controller architecture in any of the above as each already provides it’s own implementation or something very similar.

The best you could realistically achieve, is using Zend/CodeIgnitor as a library for sending mail, or working with RESTful service or LDAP, etc.

Drupal for instance, offers it’s own FORM API - which if you overrode with Zend would probably cause mass confusion amongst people who download your module and try and manipulate it using the Drupal builtin FORM API.

While it’s technically possible the practical side of me don’t even bother. If you are seeing a business market in writing a components/module once and having it run in Drupal, Joomla and WordPress, you are in for a big challenge.

The most practical approach to solving this would be to follow GTK+ or similar corss-platform framework that can compile and run under Linux, Mac and Windows. Having a component run under WordPress, Joomla or Drupal is very much the same at least at first glance.

Joomla is far more adherent to MVC design pattern than say Drupal/WordPress so bridging that gap would prove very difficult I’m sure.

You would have an easier time making a module cross-platform in WordPress or Drupal because of their similar architecture.

Cheers,
Alex

I would not use Wordpress or Joomla as examples of well thought out architectures. Frankly, the code for both is a mess.

I can’t comment on Drupal though.

Thanks for your replies guys,

Check this out Stuart Herbert On PHP - » Series: Beyond Frameworks – PHP Components

Great articles, I saw this guy at the London PHP conference 2011, his talk inspired me to investigate his approach.

I think this method makes perfect sense, it’s just learning and understanding how to implement it in our architecture

I would not use Wordpress or Joomla as examples of well thought out architectures. Frankly, the code for both is a mess.

I can’t comment on Drupal though.

Ignoring code, the architecture of Joomla is MVC based. Drupal and WordPress use a hook/callback architecture which allows for interesting extension but sloppy full stack solutions. In Joomla you download CRM solutions, Drupal you build something more custom by pulling togather various existing modules and configuring them accordingly.

The code for WP or Drupal architecturally is less than ideal, there are a lot of cross cutting concerns, as there are in Joomla, but Drupal code is consistent and clean which is why I think so many people think it’s superior. :stuck_out_tongue:

Cheers,
Alex