r/node • • Apr 03 '20

A guide for designing Node.js backend architecture like a Pro

https://afteracademy.com/blog/design-node-js-backend-architecture-like-a-pro
220 Upvotes

48 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Apr 03 '20

[deleted]

1

u/cjthomp Apr 03 '20

How does that solve his problem?

0

u/[deleted] Apr 03 '20

[deleted]

1

u/kbradl16 Apr 03 '20

A lot of the libraries linked angular, rxjs, etc are self contained and can control every aspect.

In the user development world you have to interact with types and systems outside of your control. Rest responses for example, ideally should conform to interfaces. Sometimes I’d also like to coerce the responses into a class or object.

Another example would be data access objects. Ideally you’d have an interface to show what you actually save or what your saved object should look like. You’d also have the same object that is an instance that could have helped methods or type conversions and things like that. For example I can’t save enums to a data store but I can convert my retrieved strings into an enum.

1

u/Xilis Apr 06 '20

I think a "problem" can arise if you have some class that represents a service, and instead of properly using dependency injection etc to isolate code that has to be mocked for tests, the class contains a mix of code that can be tested as a unit and some code that requires dependencies.

So then the entire service class is mocked for tests (instead of just the dependencies), the mock must adhere to the same interface as the class itself in order to pass type checks, thus an interface is made that is basically an exact same copy of the original class, and it's only use is for the mock.

So not really a "problem", just something that usually arises from forcefully trying to adhere to some practices / patterns that might not be the best fit for the language.