Dion Moult Seriously who ever reads this description.

Separating the core application from the delivery framework with Kohana

This post is about developing web applications that don’t depend on the web.

Kohana MVC - A separated delivery mechanism architecture

MVC is probably the most popular architecture for web applications. But what’s interesting about MVC is that it’s not actually an architecture meant for your core application. It is merely a delivery mechanism.

With this in mind – a well developed application treats the delivery mechanism as a plugin and cleanly separates the core application from the web. It should be possible to remove the internet with all of its methods of interaction (eg: its HTTP Request/Response interface), and still have a working “core” application which you can use elsewhere. Say for example to make a desktop or mobile device application.

In short: your business logic doesn’t rely on the internet to exist.

With Kohana, or really any modern MVC framework which supports the PSR-0 standard, this is surprisingly easy to do. I’d like to share the convention I use.

In Kohana, all logic goes in application/classes/ (or equivalent in its CFS). This directory will contain all your delivery logic. This includes Controllers, Views, and any Models, and perhaps some Factories to DI your app.

Your actual core logic is kept in a separate repository to force yourself to remove all dependencies. When combined, I like to store the core logic in application/vendor/. With Git this can be done with a submodule. This way MVC and insert-your-architecture-here is cleanly separated.

You can then add your core application to Kohana’s autoloader (in application/bootstrap.php for convenience via spl_autoload_register(function($class) { Kohana::auto_load($class, 'vendor/Path/To/App/src'); });

And that’s it! With a little discipline we suddenly get a massive benefit of future flexibility.

If you are interested in a project which uses this separation, please see my WIPUP project. (Disclaimer: WIPUP is a side-project and is still in progress). More reading by Bob Martin here.


1 Comment

Paul Schwarz says: (26 February 2014)

Spot on. Uncle Bob would be proud. Even though you mention PHP, Kohana and PSR-0, folks from other languages and frameworks should take note too.

Leave a Comment