Contribute to help us improve!

Are there edge cases or problems that we didn't consider? Is there a technical pitfall that we should add? Did we miss a comma in a sentence?

If you have any input for us, we would love to hear from you and appreciate every contribution. Our goal is to learn from projects for projects such that nobody has to reinvent the wheel.

Let's collect our experiences together to make room to explore the novel!

To contribute click on Contribute to this page on the toolbar.

Service Layer

The logic layer is the heart of the application and contains the main business logic. It knows everything about the business logic, but it does not know about the response to the client and the HTTP errors. That’s why this layer is separated from the controller layer.

How to implement the service layer

This layer is implemented by services, a specific kind of providers. Let’s see one example:

export class CoffeeService {
  constructor(private readonly coffeeService: CoffeeService) {}

  async searchCoffees(@InjectRepository(Coffee) coffeeRepository: Repository<Coffee>): Promise<Array<Coffee>> {
    const coffees = this.coffeeRepository.find();

    return doSomeBusinessLogic(coffees);

This is the CoffeeService that we inject in the example of controller layer. As you can see, a service is a regular class with the Injectable decorator. Also, it inject as dependency the data access layer (in this specific case, the Repository<Coffee>).

The services expose methods in order to transform the input from the controllers by applying some business logic. They can also request data from the data access layer. And that’s all.