Your code should have layers, like an onion

Onion with some slices cut off
Onion with some slices cut off
Photo by Mockup Graphics on Unsplash

Some time ago I read a brilliant article, “Tactical Domain-Driven Design with Angular and Monorepos?” by Manfred Steyer. I was delighted with the content I found there, and as a big fan, I would like to translate this knowledge to NestJS ground.

Despite Angular and Nest being comparable frameworks, the environments they run on are very different. This article addresses this difference by explaining how to apply the aforementioned concepts in a server-side setting.

Before reading the rest of the article, I advise you to familiarize yourself with Manfred’s article. Additionally, skimming through other articles in the “Domain-Driven Design with…

Keeping your modules separate and your abstractions detail-free

Nest and Angular logos
Nest and Angular logos
Photo by the author.

In the NestJS documentation, we can find the following sentence:

“Nest provides an out-of-the-box application architecture which allows developers and teams to create highly testable, scalable, loosely coupled, and easily maintainable applications.”

Let’s test this statement by checking if Nest allows us to easily follow one of the SOLID principles: the Dependency Inversion Principle.

Nest is highly inspired by Angular, so all recipes in this article work in Angular as well.

For a quick reminder, the principle states:

  1. High-level modules should not depend on low-level modules. Both should depend on abstractions (e.g. interfaces).
  2. Abstractions should not depend on details. Details…

NestJS, Angular, and Nx

Photo by the author.

React With Express and Angular With Nest

The most popular framework for Node.js is still Express.js. On the front end, there are three kings: Angular, React, and Vue. After adding the most popular NoSQL (which is similar to JavaScript objects), MongoDb, we get a combination of the most popular stacks for JavaScript developers: MEAN, MERN, and MEVN.

We can find a lot of similarities between React and Express. Both solutions are minimalistic, based on JavaScript, and they provide only the most essential functionalities in their core version. They offer great flexibility in choosing tools and structuring applications.

For Angular, the server-side equivalent is NestJS, whose creators were…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store