SciCatProject/backend-v3

Migration to NestJS

Opened this issue · 6 comments

Summary key items for migration to Loopback 4:

  • no matter which framework we are going looking to a complete refactoring of the code base
  • Each endpoint will require a considerable amount work, even after we have developed the knowhow
  • User management should require work only at the beginning while we set it up. It should require minimal effort to integrate it in each end point.
  • Documentation is fragmented and it is not easy to find an end-to-end tutorial
  • As of now, LB4 is still a viable option

Valid reasons to change framework:

  • longer long term support
  • better and easier documentation
  • better tutorials and how-tos
  • wider user base

Notes

There are many frameworks out there, as illustrated by this post:
In one of the posts that I came across, I read about nestjs and next.js, which apparently have wider user base.
I checked nestjs web page, I could not find any info on End-Of-Life and support. I did find their documentation a little easier to read and follow (here is the authentication documentation: )
I also find this post where they compare nestjs with other frameworks, but not with loopback.
This post provide a little info on differences between LB3, LB4 and nestjs:

@henrikjohansson712 and @nitrosx (myself) agreed that a migration to a Loopback4 requires a considerable code refactoring.

We decided to explore implementing datasets endpoint in express.js and nest.js.

This experience allowed us to conclude the following:

  • using either express.js and nest.js was easier to understand the workflow and the framework/library used
  • in both cases, we were able to write code that was easier to understand
  • with nest,js is easier to access the lower level functionalities and data structure than in LB4
  • nest.js documentation is complete although it lack coverage of edge use cases.

We therefore decided to explore nest.js so we could leverage higher level functionalities already present in the framework.

WE continued our exploration of nest.js and implemented a proof-of-concept of the full Datasets endpoint without changing the underline database.
We also implemented authentication.

Implementation of scicat-nestjs is available in nestjs branch

We just successfully tested the scicat migration middleware (S2M for short).
Here is the configuration:

  • S2M configured to listen on port 3000 directing Datasets end point to scicat-nestjs and all other requests to scicat-lb3 (current implementation).
  • scicat-nestjs listening on port 3002
  • scicat-lb3 listening on port 3001
  • common database accessed by scicat-nestjs and scicat-lb3

Tested performed:

  • login (authentication on both backends and tokens management)
  • retrieved all datasets list (directed to and answered by scicat-nestjs)
  • retrieved one dataset by id (directed to and answered by scicat-nestjs)
  • retrieved all proposals list (directed to and answered by scicat-lb3)
  • retrieved one proposal by id (directed to and answered by scicat-lb3)

Congratulations ! Looks like a promising approach .

We are now working to have a functional nestjs endpoint for datasets with authentication and authorization.
Renaming the ticket to Migration to NestJS

I can volunteer to migrate the job endpoint.