Separation of concerns: example with a Nodejs-Fastify-MongoDB stack. In this article we will go through some maintainability issues and techniques to avoid them, using a nodejs web server built with Fastify (web framework) and Mongodb (database) as example.
Building software that works is one thing, building software that last is another, especially when the code size increases rapidly together with the number of people involved in its development.
In this article we will go through some maintainability issues and techniques to avoid them, using a nodejs web server built with Fastify (web framework) and Mongodb (database) as example.
This particular service is a simple CRUD store for movies, but for many web services, you can scatter in the same way their various components somewhere along a line:
The bits on the left are very common and have probably little added value for your specific application. The relative value of your service lies in the data you have/collect and what you do with this data (the business logic).
It is important to note that the borders between the layers are not strict and may vary for different projects.
For example, a team with high skills in RDMS can do data aggregation and statistical calculation within a SQL query/function while another team will chose to do the same in the application code, finding it easier to maintain and test.
However, separating the different concerns will ease the maintainability of the codebase anyway, that is what we are going to review here.
In this article, we’ll look at 5 tips for making your NodeJS code easier to read and understand. How to Make Your Node.js Code Easier to Read