Please watch this full video for the Billing System code walk-thru and System design and demo

https://youtu.be/PlGqs9XTSqc

Presentation Layer

The following are part of the Presentation layer component.

com.itgarden.controller and com.itgarden.dto

The Controller package contains only the Controller class where we can implement all Rest end-point

The presentation layer focused only on Client-side logic which related to Presentation Layer. For Example. It handles Request, Response data, and Client Headers, etc.

We have two main Components in Client-side which are RestController class where we implementing the Rest Endpoint and Value object which known as DTO (Data Transfer Object) classes. All DTO classes under in the following Package “com.itgarden.dto

I don’t want to expose the Entity objects in the Presentation Layer. it should available only in Service Layer. The Service class converts Entity objects as DTO class which is visible for Presentation Layer. These DTO classes designed for Client-side response. Spring Boot converts DTO to JSON data and sends it to the client-side as a response. The Entity object has unnecessary values that are not required for the Client-side so, those values are eliminated in DTO classes. This strategy is known as DTO Design Pattern.

Request Handling

The controller receives the request from the client and maps it to DTO Class, i.e. The client data tightly coupled with DTO classes. The client should follow the DTO class attributes as request data for their JSON Request.

User DTO Object' Attributes
private String firstName;
private String middleName;
private String lastName;
private String mobileNo;
JSON Attributes
{
"firstName": "Suresh1",
"middleName":"test",
"lastName": "Stalin",
"mobileNo": "987652553",
"emailId": "suresh@gmail.com"
}

The above example UserDTO object used in the Presentation layer. The same attributes used in Client-side JSON Attributes. This is the Contract between client and server. The client and Server strictly follow this data format for the data exchange. This Concept called as Content Negotiation in the Web Service world

Response Handling

The Controller sends all responses in the form for the following type.

ResponseEntity<ResponseMessage>.

We don’t want to change the response type for each endpoint so, I came up with a Generic Response Type for all the endpoints available in the System. In the future, if you want to develop any Rest Service, This response type is compatible(Accepted).

ResponseMessage class contains the following three attributes and three different static method

@Data
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PUBLIC)
@RequiredArgsConstructor(access = AccessLevel.PUBLIC)
public class ResponseMessage<T> {

    @NonNull
    private T responseClassType;

    private String message;

    private String messageType;

    public static <T> ResponseMessage<T> withResponseData(T classType, String message,String messageType) {
        return new ResponseMessage<T>(classType, message, messageType);
    }

    public static <T> ResponseMessage<T> withResponseData(T classType) {
        return new ResponseMessage<T>(classType);
    }

    public static ResponseMessage<Void> empty() {
        return new ResponseMessage<>();
    }
}

@NoArgsConstructor

@AllArgsConstructor(access = AccessLevel.PUBLIC)

@RequiredArgsConstructor(access = AccessLevel.PUBLIC)

The meaning of the above three annotations is, the Lombok create three different constructors for this class which are….

#software-architecture #software-development #billing-system #billing-software #spring-boot

Billing System Architecture and System flow
2.00 GEEK