CHES & D layered architecture

Overview

StackSaga introduces a new design pattern called CHES layered architecture. it is an extended version of Spring Three-Layered Architecture. before moving to the CHES & D layered architecture, let’s have a quick overview of the spring Three-Layered Architecture.

Default Spring layered architecture.

you are already using spring Three-Layered Architecture with the following layers.

  1. Controller Layer (Presentation Layer)

  2. Service Layer (Business Logic Layer)

  3. Repository Layer (Data Access Layer)

When you’re moving to microservices architecture, The Data Access Layer is replaced with the client layer when the data is accessed from another service. The client can be either http client or any other protocol that target service supports.

The following diagram shows the layered architecture in microservices' architecture.

spring boot layeard architecture in microservice

  • here you can see orderService uses the StockRepository(Repository Layer) to access the data, and the PaymentService uses the PaymentServiceClient(Client Layer) to access the data from the PaymentService.

Migration to CHES & D layered architecture.

spring boot layeard architecture in microservice

CHES & D layered architecture consists of five layers with 2 new layers called Handler Layer and Executor Layer.

  1. C - Controller Layer

  2. H - Handler Layer

  3. E - Executor Layer

  4. S - Service Layer

  5. D - Data Access Layer

    • Repository Layer

    • Client Layer

Let’s deep dive into each layer one by one.

C—Controller Layer

As usual, The controller layer is the presentation layer. It is responsible for the presentation logic of the application. In stacksaga, this is where you can access the Handler Layer to transform the request to Stacksaga SEC engine. See the implementation.

H—Handler Layer

This is where you can start the transaction and be aware of all the updates of the transaction.

  1. Receive the transaction with initial data and terraform it to the SEC engine.

  2. Receive the event that SEC engine triggers based on the executor executions. Here you can send the updates to the user that the transaction belongs to.