Skip to content

Backend Development

Ophir Katz edited this page Jun 22, 2018 · 2 revisions

The server side development's goals is split into two:

  1. Provide the web application with services for data requests.
  2. Manage data dependencies as they are represented in the database.

In order to implement these goals, the server is build in a programming language (Java) that offer accessible frameworks which we use in order to make the programming, testing and evaluation process more convenient and easy.

To ensure the first goal, we are required to implement a server technology for the client-server paradigm. For that we used Spring MVC.

Spring MVC, as written in this section, is a Java framework that allows to program MVC web applications, and it offers a very nice, approachable API to do so. The Spring MVC API offers several layers as a standard to follow, and define our services by them.

Spring is indeed layered, and each layer holds a reference to the layer below it (besides the top most layer, which is run by an HTTP server driver). Since these reference dependencies are injected automatically by Spring (by using the proper coding conventions and Java annotations and configurations), the entire management is almost obscured from the programmer.

The Controller Layer:

The top most layer of the server. This layer externalizes the REST API the server provides the clients. Implemented by Java classes, annotated with the @RestController annotation (for proper injection), each class refers to a specific type of service the system defines, and or a resource the server offers the clients (Test, Block, Manager and so on...). Since each controller is associated with a service, all controller classes should inherit the generic AbstractController class that holds the parameter typed service.

The Service Layer:

The second layer from the top. This layer's role is to provide with the system and business logic of the server's services to the clients. This layer can provide resources (defined by request) to the requesting client, while using the services of the bottom layer (to be discussed), or just offer basic information on the state of the database to the clients. These classes can be injected by using the @Service annotation.

This layer is the main one being tracked and logged for errors (both database errors and user input error) in the system. These errors, as results of whatever mistake/system failure/bad input occurred, are always revealed to the developer/tester, and some of them reflect as client bad input error in the web-site as well. Logs should be the main go-to for every developer facing a problem/bug in the system. More on the in the testing the system section.

The Data Access Object Layer:

This layer is the bottom-most layer of the server. It represents the ORM implementation of our data. It consists of several classes, annotated with @Repository annotation for injection, for each resource we support, or will support, in the database. The classes represent, in Java code, the structure of the resources, and they offer an interface to use from the service layer in order to execute queries on the database.


Expanding The Backend:

In order to expand the backend by adding a new or extending an existing service, one should following steps:

  • Define the proper data in the databases in the database.sql file of the project.

  • Implement the corresponding entity classes for the new data, place these in the entities package.

  • Define the business logic of the service (on paper).

  • Implement the corresponding dao classes for the new database access. Place these classes in the dao package.

  • Implement the corresponding service class for the new service. This class should be placed in the service package. This class should use the database access methods defined in the dao classes described earlier.

  • Implement the corresponding controller class for the new entry point of the new service. This class should use the service methods defined earlier. Place this class in the controller package.

  • Test each layer of the expansion - controllers, services, daos, entities, integration testing.

  • Make sure the build passes and code coverage is at-least 85%.

  • Remember to update all the dependencies and to deploy the updated logic.

Clone this wiki locally