avatarMehmet Ozkaya

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

5597

Abstract

hem always. And If we expand our <b>Patterns & Principles</b>, we can see that</p><ul><li><b>DRY</b></li><li><b>KISS</b></li><li><b>YAGNI</b></li></ul><p id="6aa3">And also we have learned and added below principles for this chapter;</p><ul><li><a href="https://readmedium.com/software-architecture-design-principles-soc-solid-98611997c30e"><b>SoC — Separation of Concerns</b></a></li><li><a href="https://readmedium.com/software-architecture-design-principles-soc-solid-98611997c30e"><b>SOLID</b></a></li></ul><p id="f474">We are going to consider these principles when design our architecture. So for now we have learned only these items and load our design toolbox with these items. But with continue our course we will <b>discover new architectures, patterns and principles</b>.</p><p id="945a">According to our <b>design toolbox</b>, now lets design the <b>first version of our e-commerce application</b> with using <b>Layered architecture</b>.</p><h2 id="ad03">Design: Layered Monolithic Architecture Steps</h2><p id="b472">Here you can see the our <b>monolithic architecture evolution</b>. You can see that we have start very basic of architecture with putting only 1 application server and manage all business logic inside of that. After that we will <b>separate client application</b> and continue to apply layered architecture with <b>separating logical layers for UI, Business Logic and Data Access layers</b>. Also we can separate additional logical layers like adding Domain layer and separating Application and Business Layers one more step.</p><figure id="3a43"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*pZq7XY3YHXHqBzY_hYve9Q.png"><figcaption>Layered Monolithic Architectures</figcaption></figure><h2 id="0650">Design Layered Architecture — E-Commerce App</h2><p id="85bc">Here you can see the <b>final architecture design</b> for our e-commerce application which is applying <b>Layered architecture.</b></p><figure id="6019"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*z5bz4CvlIG59997-h99taQ.png"><figcaption>Layered Architecture</figcaption></figure><p id="f017">Let me explain flow of request in our architecture:</p><ul><li>Client will be send request from web, and this request <b>accommodate from our big monolithic application server</b> but our project <b>organized by layered architecture</b> which every layers concerns their own responsibilities and<b> perform database calls</b> in order to persist data on relational database.</li></ul><p id="9eb7">So for now this is one of the best architecture for us because if this architecture handle our requirements with FR and N-NR, there is no need to design more complex one.</p><h2 id="287a">Adapt Technology Stack — E-Commerce App — Layered Architecture</h2><p id="377c">We will implement possible Technology choices. As you know that we have designed our architecture with applying Layered Architecture and Design principles which is <b>SOLID </b>and <b>SoC principles</b>.</p><p id="550f">You can see image of “<a href="https://readmedium.com/software-architecture-way-of-learning-for-microservices-527c992b5b85"><b>Way of Learning — The Design Flow</b></a>” of our articles: According to Flow, now its time to Adapting Technology Chooses.</p><figure id="2240"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*lxutABvV06UySZMpWiyyvw.png"><figcaption></figcaption></figure><p id="559c">In this step we will Apply Software Tools, Application Frameworks and Databases for our current design. So, I have created <b>2 different Technology stack</b>, one for <b>Java </b>another for <b>Microsoft .Net</b> ecosystem:</p><figure id="d589"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*gYesORut-s0YtO8Lsg9UNw.png"><figcaption></figcaption></figure><p id="2754">As you can see the image, for <b>Java Technology stack</b>. I have added Tomcat Web Server to deploy our monolithic application into this. And Developing our application with Java Enterprise Edition and created 1 big jar or war file to deploy to our Tomcat web server Application , Java Single WAR Artifact and Tomcat Container. And perform database operations with relational database which is MySQL, or you can pick PostgreSQL or Oracle in here. If we look at the<b> Microsoft .Net ecosystem: </b>tools changed a bit: We use IIS for Web Server for .Net applications. We use Asp.Net as an application framework when developing our layered architecture and we use SQL Server as a relational database for performing database crud operations.</p><p id="6302">As you can see that we have design and adapt with technology stack for our e-commerce application.</p><h2 id="7f20">DEMO: Layered Monolithic Architecture Code Review — E-Commerce App</h2><p id="d6bf">We are going to<b> code review</b> of e-commerce application which is implemented with<b> .net ecosystem</b> and asp.net and use SQL server for relational databases. This is <b>Asp.Net e-commerce web application</b> I have developed this repository a long time ago but it is still relevant for our topic.</p><p id="f755">Here you can see 2 GitHub link at below. In the first link we go to GitHub repository page: <b>Code review of Asp.Net e-commerce web application:</b></p><ul><li><a href="https://github.com/aspnetrun/run-aspnetcore-basics"><b>https://github.com/aspnetrun/run-aspnetcore-basics</b></a></li><li><a href="https://github1s.com/aspnetrun/run-aspnetcore-basics"><b>https://github1s.com/aspnetrun/run-aspnetcore-basics</b></a></li></ul><p id="da73">Please goto links and examine <b>Readme file</b>. With <b>Seco

Options

nd link </b>you can open repository as a <b>project folder view</b>. This is implementation of aspnetrun-basic template on real-world basic e-commerce web application project; You can see the animation we have developed for all FR of our e-commerce application like listing products, add to basket, checkout order and so on.</p><p id="cb27">The idea of this project one project for <b>fastest idea implementations </b>to building modern web applications with latest ASP.NET Core & EF Core technologies. So this is <b>the reason why monolithic architecture still valid</b> in software industry. See Layers:</p><p id="5deb"><b>Data Folder: </b>Includes Entity Framework Core Context and tables in this folder. When new entity created, it should add to context and configure in context. The Infrastructure project depends on Microsoft.EntityFrameworkCore.SqlServer and EF.Core related nuget packages, you can check nuget packages of Infrastructure layer. If you want to change your data access layer, it can easily be replaced with a lighter-weight ORM like Dapper.</p><p id="ffd7"><b>Repository Folder: </b>Implementation of Core interfaces in this project with Entity Framework Core and other dependencies. Most of your application’s dependence on external resources should be implemented in classes defined in the Infrastructure project. These classes must implement the interfaces defined in Core. If you have a very large project with many dependencies, it may make sense to have more than one Infrastructure project (eg Infrastructure.Data), but in most projects one Infrastructure project that contains folders works well.</p><p id="fba7"><b>Pages UI Folder: </b>Development of UI Logic with implementation. Interfaces drives business requirements and implementations in this layer. The application’s main starting point is the ASP.NET Core web project. This is a classical console application, with a public static void Main method in Program.cs.</p><h2 id="7b51">Evaluate: Layered Monolithic Architecture</h2><p id="853a">If we <b>evaluate </b>the <b>current Layered Architecture </b>for E-Commerce Application, you can see the <b>Benefits </b>and <b>Drawbacks </b>at below :</p><figure id="0f3e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*9LexHSHSI4edAToIERRJ1w.png"><figcaption></figcaption></figure><p id="f65d">That means, even we have separate logical layers, it has lots of Drawbacks.</p><h2 id="a645">Problem: Highly Coupling Dependent Layers</h2><p id="dd7e">We are going to <b>discover Problems </b>of current <b>Layered Architecture </b>— E-Commerce Application. So when we are in discover Problem step, we should ask ourselves</p><ul><li><b>What’s wrong with this current architecture ?</b></li><li><b>How can we improve the current design when project goes more advanced level ?</b></li></ul><p id="8eb0">Here you can see Problems and potential solutions of current design:</p><figure id="b51a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*C0F1iXsPa85vP1cHbEsFjw.png"><figcaption></figcaption></figure><p id="f2f0">If you look at the design image, you can see that <b>UI directly dependent to Business layer, Business Layer dependent Data Access Layer</b>. We should <b>broke </b>these <b>dependencies </b>and organize the code with loosely coupling services and <b>provide flexibility </b>of our codebase with shifting different frameworks. And the solutions are</p><ul><li><a href="https://readmedium.com/clean-architecture-with-dependency-rule-dff96d479a60"><b>Clean Architecture</b></a></li><li><b>The Dependency Rule</b></li></ul><h2 id="1aef">Design Microservice Architecture — E-Commerce App</h2><p id="cc3e">If we design<b> e-commerce application</b> with <b>Microservice architecture</b>, you can see the image below:</p><figure id="4eb4"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*ybaWczC1TZO8CyW-.png"><figcaption></figcaption></figure><p id="50b0">Product microservice can use NoSQL document database Shopping Cart microservice can use NoSQL key-value pair database and Order microservice can use Relational database as per microservice data storage requirements.</p><h2 id="b238">What’s Next ?</h2><ul><li><a href="https://readmedium.com/clean-architecture-with-dependency-rule-dff96d479a60"><b>Clean Architecture Design with Dependency Rule</b></a></li><li><a href="https://readmedium.com/macro-services-to-nano-services-evolution-of-software-architecture-424f927b63cb"><b>Macro-services to Nano-services: Evolution of Software Architecture</b></a></li><li><a href="https://readmedium.com/microservices-architecture-problems-and-solutions-with-pattern-and-principles-b673f342dc10"><b>Microservices Architecture: Problems and Solutions with Pattern and Principles</b></a></li></ul><h2 id="8fd1">Step by Step Design Architectures w/ Course</h2><figure id="b826"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*rPggKGieCVai4Bb_.png"><figcaption></figcaption></figure><p id="a1c8"><a href="https://www.udemy.com/course/design-microservices-architecture-with-patterns-principles/?couponCode=FEBR23"><b>I have just published a new course — Design Microservices Architecture with Patterns & Principles.</b></a></p><p id="bdf6">In this course, we’re going to learn <b>how to Design Microservices Architecture</b> with using <b>Design Patterns, Principles</b> and the <b>Best Practices. </b>We will start with designing <b>Monolithic </b>to<b> Event-Driven Microservices</b> step by step and together using the right architecture design patterns and techniques.</p></article></body>

Design Layered Architecture for E-Commerce Applications with Step by Step

In this article, we are going to learn how to design E-Commerce Applications with Layered Architecture and Step by Step.

Layered Monolithic Architectures

Designing an e-commerce application using Layered architecture can be a complex task. We will iterate the architecture design one by one as per requirements. But before designing E-Commerce application, We should ask ourselves: What we have in our design toolbox ?

I have just published a new course — Design Microservices Architecture with Patterns & Principles.

Architecture Design Flow

Before we design any architecture we will always start from Problem which is Business Problem that drive our design considerations.

Software Architecture: Way of Learning

After that, we have learned Architecture Design Patterns and Principles about Layered Architectures that you can check articles below:

So now, according to our Architecture Design flow at above, We are at Design step. But before design our system We should ask ourselves:

  • What we have in our design toolbox ? What we have learned so far ?

So that means, every time when we design our architecture, We should always start with writing down FRs and NFRs. Also its good to write-down Constraints or Limitations of project, for example cost, time and so on.

Architecture Design Toolbox

Here you can see the Architecture Design Toolbox that we will use during the article when designing our E-Commerce application:

Functional Requirements — FRs

Basically we are going to design simple e-commerce application and we need to write down business cases that means write down Functional-requirements:

  • List products
  • Filter products as per brand and categories
  • Put products into the shopping cart
  • Apply coupon for discounts and see the total cost all for all of the items in shopping cart
  • Checkout the shopping cart and create an order
  • List my old orders and order items history

Non-Functional Requirements — N-FRs

After getting requirements, as a Software Architect, we should consider Non-Functional Requirements. Since this is the first iteration of our e-commerce application, we don’t aim to super scalability and handle millions of request. Instead we will start with small and basics thats why I have added to

  • Availability
  • Small number of concurrent users that we should handle in the first design.
  • Maintainability

and also in this for this section, I have added to “Maintainability” which required for the organizing project codes properly.

Architecture Styles

After understanding Functional and Non-Functional requirements, now we can see our Design toolbox which includes Architectures, Patterns, Principles and Best Practices that we have learned and will apply on our project. Lets see which architecture styles that we have learned of course we have using Monolithic architecture style but also we will use Layered (N-Layer) architecture in our design.

As you know that, Layered Architecture also still following Monolithic architecture in terms of server design perspective so we can say that Layered Architecture is a sub-architecture style of Monolithic architecture.

Because we will still have big application server, we won’t decompose servers now, instead we will separate logical layers into our 1 big application server in order to organize our projects better.

Patterns & Principles

Its good to add principles in our picture in order to remember them always. And If we expand our Patterns & Principles, we can see that

  • DRY
  • KISS
  • YAGNI

And also we have learned and added below principles for this chapter;

We are going to consider these principles when design our architecture. So for now we have learned only these items and load our design toolbox with these items. But with continue our course we will discover new architectures, patterns and principles.

According to our design toolbox, now lets design the first version of our e-commerce application with using Layered architecture.

Design: Layered Monolithic Architecture Steps

Here you can see the our monolithic architecture evolution. You can see that we have start very basic of architecture with putting only 1 application server and manage all business logic inside of that. After that we will separate client application and continue to apply layered architecture with separating logical layers for UI, Business Logic and Data Access layers. Also we can separate additional logical layers like adding Domain layer and separating Application and Business Layers one more step.

Layered Monolithic Architectures

Design Layered Architecture — E-Commerce App

Here you can see the final architecture design for our e-commerce application which is applying Layered architecture.

Layered Architecture

Let me explain flow of request in our architecture:

  • Client will be send request from web, and this request accommodate from our big monolithic application server but our project organized by layered architecture which every layers concerns their own responsibilities and perform database calls in order to persist data on relational database.

So for now this is one of the best architecture for us because if this architecture handle our requirements with FR and N-NR, there is no need to design more complex one.

Adapt Technology Stack — E-Commerce App — Layered Architecture

We will implement possible Technology choices. As you know that we have designed our architecture with applying Layered Architecture and Design principles which is SOLID and SoC principles.

You can see image of “Way of Learning — The Design Flow” of our articles: According to Flow, now its time to Adapting Technology Chooses.

In this step we will Apply Software Tools, Application Frameworks and Databases for our current design. So, I have created 2 different Technology stack, one for Java another for Microsoft .Net ecosystem:

As you can see the image, for Java Technology stack. I have added Tomcat Web Server to deploy our monolithic application into this. And Developing our application with Java Enterprise Edition and created 1 big jar or war file to deploy to our Tomcat web server Application , Java Single WAR Artifact and Tomcat Container. And perform database operations with relational database which is MySQL, or you can pick PostgreSQL or Oracle in here. If we look at the Microsoft .Net ecosystem: tools changed a bit: We use IIS for Web Server for .Net applications. We use Asp.Net as an application framework when developing our layered architecture and we use SQL Server as a relational database for performing database crud operations.

As you can see that we have design and adapt with technology stack for our e-commerce application.

DEMO: Layered Monolithic Architecture Code Review — E-Commerce App

We are going to code review of e-commerce application which is implemented with .net ecosystem and asp.net and use SQL server for relational databases. This is Asp.Net e-commerce web application I have developed this repository a long time ago but it is still relevant for our topic.

Here you can see 2 GitHub link at below. In the first link we go to GitHub repository page: Code review of Asp.Net e-commerce web application:

Please goto links and examine Readme file. With Second link you can open repository as a project folder view. This is implementation of aspnetrun-basic template on real-world basic e-commerce web application project; You can see the animation we have developed for all FR of our e-commerce application like listing products, add to basket, checkout order and so on.

The idea of this project one project for fastest idea implementations to building modern web applications with latest ASP.NET Core & EF Core technologies. So this is the reason why monolithic architecture still valid in software industry. See Layers:

Data Folder: Includes Entity Framework Core Context and tables in this folder. When new entity created, it should add to context and configure in context. The Infrastructure project depends on Microsoft.EntityFrameworkCore.SqlServer and EF.Core related nuget packages, you can check nuget packages of Infrastructure layer. If you want to change your data access layer, it can easily be replaced with a lighter-weight ORM like Dapper.

Repository Folder: Implementation of Core interfaces in this project with Entity Framework Core and other dependencies. Most of your application’s dependence on external resources should be implemented in classes defined in the Infrastructure project. These classes must implement the interfaces defined in Core. If you have a very large project with many dependencies, it may make sense to have more than one Infrastructure project (eg Infrastructure.Data), but in most projects one Infrastructure project that contains folders works well.

Pages UI Folder: Development of UI Logic with implementation. Interfaces drives business requirements and implementations in this layer. The application’s main starting point is the ASP.NET Core web project. This is a classical console application, with a public static void Main method in Program.cs.

Evaluate: Layered Monolithic Architecture

If we evaluate the current Layered Architecture for E-Commerce Application, you can see the Benefits and Drawbacks at below :

That means, even we have separate logical layers, it has lots of Drawbacks.

Problem: Highly Coupling Dependent Layers

We are going to discover Problems of current Layered Architecture — E-Commerce Application. So when we are in discover Problem step, we should ask ourselves

  • What’s wrong with this current architecture ?
  • How can we improve the current design when project goes more advanced level ?

Here you can see Problems and potential solutions of current design:

If you look at the design image, you can see that UI directly dependent to Business layer, Business Layer dependent Data Access Layer. We should broke these dependencies and organize the code with loosely coupling services and provide flexibility of our codebase with shifting different frameworks. And the solutions are

Design Microservice Architecture — E-Commerce App

If we design e-commerce application with Microservice architecture, you can see the image below:

Product microservice can use NoSQL document database Shopping Cart microservice can use NoSQL key-value pair database and Order microservice can use Relational database as per microservice data storage requirements.

What’s Next ?

Step by Step Design Architectures w/ Course

I have just published a new course — Design Microservices Architecture with Patterns & Principles.

In this course, we’re going to learn how to Design Microservices Architecture with using Design Patterns, Principles and the Best Practices. We will start with designing Monolithic to Event-Driven Microservices step by step and together using the right architecture design patterns and techniques.

Software Architecture
Layered Architecture
Software Development
Microservices
Monolithic Architecture
Recommended from ReadMedium