Play !> and 3-tier, n-tier architecture – Part I

Play!► is based on the MVC application model. This model, as named, is an application model, but in an enterprise ecosystem, you’ll have to integrate your application with the Information System, and apply 3-tier physical architecture, or n-tier architecture

The 3-tier architecture

The 3-tier architecture can be imposed by architects and/or CISO for scalability and security reasons. The 3-tier is briefly described in the diagram below, each tier having to be hosted in a separated server. As you can see, there’s no exchange between the Presentation tier and the Data tier.

You’ll can also have to build a n-tier application, as your application has to be integrates differents service of the enterprise, such as legacy database and so one.  An e-commerce web site for example, the service provided to the client will need the services of a Stock application (the products available), a Billing application (to charge the client), an Order application (to prepare and send the order).

An e-commerce n-tier architecture

In these 2 cases, the top most level of the application are very similar ; it calls services to other tiers. In the case of a 3-tier application, you’ll have also the Logic tier to develop.

the Logic tier

Building a logic tier with Play! framework is really easy. All you have to do is use the appropriate view to deliver a service (render as xml or json for example). The easiest os to render as json, as there’s no template to code, just a call to renderJSON.

So the work is on the Presentation tier

the Presentation tier

This tier will be explained on a service returning the list of accounts (see this article on Json and Java about the model). One possibility, as the services of the logic tier is performed, is to make an Ajax application, with javascript calls to the logic tier (with JQuery for example).

The code will then be somethong similar to this : a part in the view to present the action

<div id="accounts" class="btn primary">Get accounts</div>
<div id="accounts_list">

And a JQuery code to perform the request and render the response :


$('#accounts_list').html('<p><img src="@{'/public/images/ajax-loader.gif'}" width="220" height="19" /></p>');

$.getJSON('http://localhost:9011/api/accounts', function(accounts) {
// $("#results").empty();
var textToInsert = [];
var i = 0;
$("#accounts_list").append('<table id="account_table" class="table-bordered table-condensed table-striped"> ' +
'<thead><tr><th>Account number</th><th>Balance</th><th>Label</th></tr></thead><tbody></tbody></table>');

$.each(accounts, function(title, acc) {
textToInsert[i++] = '<tr><td ><a href="#" class="acc_ref" onclick="account_details('+ +')" >'+acc.number+'</a></td><td>'+

As you can see, the code is verbose, not easily maintainable and it will be heavy to do this for all the services in the Logic tier (or the services performed by others applications).

In addition, you’l have to allow Cross-Origin Resource Sharing on the logic tier.

Moreover, this solution is prohibited by the 3-tier architecture, as the thin client makes calls to the logic tier, and probably will not work as there will be a firewall in front of the application that will authorize only request to the presentation.

The part II will explain how to do the Presentation tier with the MVC application model of Play! framework and respect the 3-tier architecture with no need of CORS.


About this entry