Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

N-Layer Architecture

I'm in the situation that I have to design and implement a system from the scratch. I have some questions about the architecture that I would like your comments and thoughts on.

Quick Info about the project: It's a data centric web application.

The application will be built on Microsoft .NET Framework 4.0 with MS SQL SERVER 2008 database.

Requirement:

  1. Rich UI and robust
  2. Multi-device support (every browser and on every device)
  3. Loosely coupled

Below is the architectural diagram I have built:

enter image description here

Briefing of the architecture

  1. Presentation layer : HTML5/ASP.NET MVC + JQuery (Web application for multi-device support in first version)
  2. Distributed Services : WCF (XML/JSON/JSONP)
  3. Domain Layer(Business Layer) : All business logic
  4. Data persistence (DAL Layer) : Entity Framework 4.0 with database first approach. POCO entities are generated and separated out using T4 template
  5. Infrastructural Layer: Contains common libraries like POCO entities, Exception Handling, logging etc

My Concerns :

  1. As application is to be built loosely coupled so in future if business requirement grows new modules can be easily plugged in without affecting the architecture. So I thought of using the Repository pattern along with IoC and DI (can be Unity/Ninject/Sprint.NET or any other)
  2. WCF with both XML and JSON support
  3. Distributed Service Layer to place IoC & DI
  4. Exception Handling & Logging using Enterprise Library 5.0

Looking for valuable comments and suggestions. If I am doing anything wrong please put me in right direction.

like image 519
coddey Avatar asked Jan 18 '12 09:01

coddey


People also ask

What is N type architecture?

An N-tier architecture divides an application into logical layers and physical tiers. Layers are a way to separate responsibilities and manage dependencies. Each layer has a specific responsibility. A higher layer can use services in a lower layer, but not the other way around.

What is the difference between n-tier and n layer?

N-Tier refers to the actual n system components of your application. On the other hand, N-Layers refer to the internal architecture of your component. N-Tier architecture usually has atleast three separate logical parts, each located on separate physical server. Each tier is responsible for a specific functionality.

What are the 4 layers of architecture?

Although the layered architecture pattern does not specify the number and types of layers that must exist in the pattern, most layered architectures consist of four standard layers: presentation, business, persistence, and database (Figure 1-1).

How many layers are there in N-tier architecture?

When it comes to n-tier architecture, a three-tier architecture is fairly common. In this setup, you have the presentation or GUI tier, the data layer, and the application logic tier.


2 Answers

I would suggest the following comment: right from the outset your approach will create tight coupling. This goes directly against your requirement #3 "Loosely coupled"

In your diagram you have defined two modules. Main module, and Module 2. I would guess that these two modules are quite distinct from each other. What I mean by this is that you could develop them completely separately and then plug them in, because the business concerns they address are different.

However, your current architectural approach:

  • Couples Main Module and Module 2 data into the same database
  • Couples Main Module and Module 2 business objects into the same business layer
  • Couples Main Module and Module 2 services into the same service layer
  • Couples the deployment and management of Main Module and Module 2

What may be worth considering: Build Main Module and Module 2 as separate vertical service stacks.

What I mean is Main Module and Module 2 become Main Service and Service 2

Each service has it's own database, it's own business layer, it's own services layer and it's own UI components.

However, this raises the concern: how can Main Service and Service 2 both work together to create my product?

To address this:

  1. At the UI end, you stitch your front end together by using client-side code to load responses from the Main Service and Service 2 into one view.

  2. At the back end you use publish subscribe messaging to allow Main Service to subscribe to events happening in Service 2 and vice versa.

This will result in an application built from the ground up on top of loosely coupled vertical service stacks, which maintain consistency by the asynchronous exchange of messages.

If you then need to add in a new module to your application, you can create a new service stack which supports the desired capability and wire it up with little or even no change needed to the other stacks (ideally the only reason to change existing stacks would be that they want to subscribe to events from the new module).

It's a very different approach to the one you're suggesting, but one which allows you to meet the requirement for loose coupling better, in my opninion.

like image 104
tom redfern Avatar answered Sep 22 '22 11:09

tom redfern


How come that the architecture diagram doesn't use the domain layer for ASP.NET?

It seems to me that you may be overarchitecturing your application. Also, while it looks great to support 6 (or so) different front-end technologies, the effort to maintain all of them will be horrendous. I'd stick to one technology for the front-end - most likely HTML5 with client-side MVC or similar.

like image 38
Lucero Avatar answered Sep 19 '22 11:09

Lucero