Using Clean Architecture for Microservice APIs in Node.js with MongoDB and Express

  Рет қаралды 318,668

Dev Mastery

Dev Mastery

Күн бұрын

In this video we talk about Bob Martin's Clean Architecture model and I will show you how we can apply it to a Microservice built in node.js with MongoDB and Express JS.
You can follow along with the code at:
github.com/dev-mastery/commen...
Original Blog Post on Clean Architecture by Bob Martin
blog.cleancoder.com/uncle-bob...

Пікірлер: 604
@DevMastery
@DevMastery 5 жыл бұрын
Any questions about Clean Architecture, Node, Express, or Mongo? Let me know in the comments. I'm happy to help!
@KashifMinhaj
@KashifMinhaj 5 жыл бұрын
By injecting dependencies to function args, aren't we loosing out on intellisense? Is there a better way to inject dependencies ?
@DevMastery
@DevMastery 5 жыл бұрын
+Kashif Minhaj Editors like VS Code do a decent job of guessing after a while, but intellisense still suffers a bit for sure. One option is to use Flow or Typescript along with an Editor that supports it so that you can specify the type of each parameter on the way in. No guessing.
@blackdiz2603
@blackdiz2603 5 жыл бұрын
If we use something like mongoose, should we make entities become mongoose schema? Or we should pass a entity to a function which creates and returns mongoose schema?
@DevMastery
@DevMastery 5 жыл бұрын
@@blackdiz2603 thanks for asking such a great question. Mongoose belongs to the outermost circle, so it would occupy the same role as our MongoDB Driver. Meaning, we would inject a Mongoose model into our CommentsDB module and use it exclusively to interact with the database. It's very important not to confuse a Mongoose model with a business Entity. We need to make sure that business rules are as independent as possible from third-party frameworks like Mongoose. A mistake I see too often in legacy code bases is that they built their Business Objects on top of - or even inside of - some third-party framework and then after a few years their codebase becomes an unstable mess because the underlying dependencies have been deprecated but no one wants to touch them because it would risk breaking all the (often poorly or not at all documented) business logic of their app. Clean Architecture was designed specifically to avoid this situation.
@crowdozer3592
@crowdozer3592 5 жыл бұрын
Do you think the upcoming class features (public/privates, getters, setters) will change this implementation at all? in the comment entity: export default (dependencies = {}) => class Comment { constructor(data = {}) { // code to validate and store the comment data in 'this' goes here } #author; #text; #replyToId; } in a use case: // instead of const comment = makeComment(info) const comment = new Comment(info) Also as a side note, it's really hard to find examples of people working with the clean architecture, in nodeJS, using more than just one entity. It would be super helpful if, for example, you changed the comment author to an Author entity and showed how you establish and validate things like many to one relationships at the business-logic entity level.
@greddee
@greddee 5 жыл бұрын
Love this part: To the client: "I've turbocharged our microservice by using a cloud-based AI" To a fellow programmer: "It's just an API that I'm calling..."
@stangeorge6893
@stangeorge6893 4 жыл бұрын
I had to pause the video right here, so true! haha
@rorycawley
@rorycawley 2 жыл бұрын
client: Will it have AI? Me: Yes.
@jdesfon
@jdesfon 5 жыл бұрын
This is the most valuable nodejs video I’ve watched so far.
@alithejumbo
@alithejumbo 4 жыл бұрын
It is indeed one of its kind.
@RaffaCaboFrio
@RaffaCaboFrio 4 жыл бұрын
Agree
@TalYaron
@TalYaron 3 жыл бұрын
@@RaffaCaboFrioAgree!
@apderic1079
@apderic1079 3 жыл бұрын
Totally agree.
@gavinlindridge
@gavinlindridge 3 жыл бұрын
100% agree if only I'd have seen it a year ago 🤦‍♂️
@napalm_exe
@napalm_exe 4 жыл бұрын
The whole "injecting" your dependencies instead of "importing" them was pure gold. I never understood why we would need to inject a dependency until now. Subscribed.
@tea_hanks1230
@tea_hanks1230 3 жыл бұрын
I have been learning NestJS for a while, that framework highly uses this concept. You should try that out if you are a Node.js dev
@binaryum
@binaryum 2 жыл бұрын
@@tea_hanks1230 do you still use it?
@bcoz1492
@bcoz1492 2 жыл бұрын
The inject is not the important part; the adapters and interfaces are the important part. He said the outer layers should depend on the inner layers, which means the external tools and frameworks should depend on our adapters and interfaces. The make-callback.js at the end of the video is a perfect example. Also, imported/required modules can still be mocked in tests. Injection with the wrapper function is not necessary and even adds bloat.
@fikriseptriananggara5922
@fikriseptriananggara5922 2 жыл бұрын
I think it is part of SOLID principals, in the D part, dependency inversion principals. where the high level module should not depend on low level module, those two must depend on abstraction. high level module is the code that we write ourself, and low level code is the dependency such as mongoose, node-postgres, mysql that 'abstracted' as db connector
@bcoz1492
@bcoz1492 2 жыл бұрын
@@fikriseptriananggara5922 you don't need to use an explicit "inject" pattern if the module being imported provides interfaces for any external modules it uses.
@yuriihusak1959
@yuriihusak1959 5 жыл бұрын
OH, MY, GOD!!!! Friends (c) This is the ONLY ONE video which shows real ARCHITECTURE in REAL case! I have been searching a video like this one through years!!! Thanks a lot!!!
@grzegorzg944
@grzegorzg944 4 жыл бұрын
I was about to write the same thing....
@johnpaulbamberg8954
@johnpaulbamberg8954 4 жыл бұрын
@@grzegorzg944 same lol.... years I've needed this
@vikaskad5737
@vikaskad5737 4 жыл бұрын
raise your hand if you feel you are a newbie in NodeJS after watching this video, thanks buddy for such knowledgeable tutorial.
@Melvin420x12
@Melvin420x12 3 жыл бұрын
Yea 100%. I feel like when I was first introduced to NodeJS and didn't understand a single concept. How is your understanding now, 11 months later? Are you applying this architecture (honestly)? Or are you applying a different strategy? Monolith?
@no-name2031
@no-name2031 3 жыл бұрын
I think it's a little bit too late, but this is not about nodeJS, in particular this is about programming in general, these concepts could be applied within any other language, I mean, maybe just oop ones? I'm not really sure
@vikaskad5737
@vikaskad5737 3 жыл бұрын
@@Melvin420x12 I didn’t get chance to implement it as I am working on existing applications but I have kept in bucket whenever my new project will start I will be going to think on it
@avibrarbrar
@avibrarbrar 3 жыл бұрын
@@no-name2031 no you can apply these concepts to any type of programming language. Even in this video dependency inversion is achieved through functions. Whereas in pure Oop language there will be an intermediate interface.
@henrytabimagiraldo7116
@henrytabimagiraldo7116 5 жыл бұрын
Thanks for this kind of videos. Most of the content creators just stand on the basics. I appreciate your pro content.
@RaqDeku
@RaqDeku 9 ай бұрын
wow...me watching this 4 years later is the cleanest explanation of clean architecture and dependency injection I have come across. That's some solid content you've shared. Thanks mate :)
@MrToromira
@MrToromira Жыл бұрын
Hello Bill, I just wanted to thank you wholehearthly for this content. It really helped me to wrap my head around all this system design jargon and navigate through the plethora of clickbaity articles and videos. Have a great day.
@jiedy-anncanon9778
@jiedy-anncanon9778 3 жыл бұрын
This is the most helpful video I have watched about Clean Architecture. I can't count how many times I come back to watch this again and again every time I feel lost. Thanks so much!
@bmejia220
@bmejia220 2 жыл бұрын
I will be watching this several times until I understand more clearly. Great video!
@ianengelbrecht4773
@ianengelbrecht4773 2 жыл бұрын
Yes agreed, so much content that talks about clean architecture, but this actually shows it in action! And only now I’m starting to understand what it’s all about.
@huslerbling
@huslerbling 5 жыл бұрын
Absolutely gorgeous! What clear and concise explanation! Please, please keep making DDD videos like this one. I've subscribed to your content.
@MartyKane217
@MartyKane217 4 жыл бұрын
This is so great. I love seeing how you implemented the Clean Architecture in JS! Very nice work, and thanks for sharing.
@justinkim7202
@justinkim7202 5 жыл бұрын
You're doing great work man. I find a lot of the conceptual stuff without practical examples so it's left up to me to experiment and I often get things wrong, but you've got some practical code as a practical example which is immensely helpful.
@Sljux
@Sljux 5 жыл бұрын
First time a Node.js setup feels REALLY RIGHT! I love this. Especially the "mini-main" index.js files that do all the dependency injections for a small module. Great work!
@marceloprado2035
@marceloprado2035 4 жыл бұрын
Really clean and testable code. Amazing! You went straight to the point, very good content. Subscribed!
@KaizenCodes
@KaizenCodes 4 жыл бұрын
This was probably one of the best express - mongo setup I’ve ever seen. Thanks so much for sharing! Will probably have to rewatch, or clone the repo and step through a few times just solidify your implementation.
@andreadiotallevi5780
@andreadiotallevi5780 4 жыл бұрын
Amazing video! More insightful content in this 33 mins than tons of other typing tutorials out there. Thank you very much!
@EricOmanoff
@EricOmanoff 5 жыл бұрын
Sooooooooooo awesome. I'm trying to learn clean architecture and having this example in js is super helpful. Thanks for the great video.
@faeshal1074
@faeshal1074 4 жыл бұрын
More about Microservices with Nodejs . Good content . Keep it up 🔥
@exactzero
@exactzero 4 жыл бұрын
Great explanation! Not much channels out there focus on the architecture side of software development. More of these, please and thank you!
@christophermaisch
@christophermaisch 4 жыл бұрын
This is gold! So many how to's but very very few why to's! Thank you for this!
@rorycawley
@rorycawley 2 жыл бұрын
This is a wonderful explanation, I haven't seen this type of clarity with concrete examples for clean architecture with node.js anywhere else. Nice work!
@hafizumar8749
@hafizumar8749 3 жыл бұрын
These are the kind of tutorials I have been looking for years and here I have got one. Keep making these kind of videos.
@Hugo280603
@Hugo280603 4 жыл бұрын
Please, don't stop making videos. You're a really good teacher
@artem_skok
@artem_skok 4 жыл бұрын
OMG, it is the video I've been searching for several years! Thanks a lot!
@tleperou
@tleperou 2 жыл бұрын
Both of your technical and teaching skills are remarkable. The best illustration of Clean architecture I've could find so far. Thanks sharing!
@3ombieautopilot
@3ombieautopilot 4 жыл бұрын
Amazing! This video has really made me to reiterate a lot of my design principles. Thank you
@dream_emulator
@dream_emulator 5 жыл бұрын
This is incredible 👌 Whole new way of thinking (for me) 🤓
@trancaohuy
@trancaohuy 4 жыл бұрын
Wonderful setup. One of the best I've seen. Well done!!!
@AndreyLLIaBepMa
@AndreyLLIaBepMa 4 жыл бұрын
Magnificent explanation supported by neat and potentially powerful app example! Thank you very much!
@tashima42
@tashima42 3 жыл бұрын
I had to watch probably too many times, but thank you. This is the best programming video I have ever watched.
@carlos_random_
@carlos_random_ 5 жыл бұрын
What a valuable video, contragulations! I have been working in a node.js app using Clean Architecture lately and it is great to see alignment with your solution... but specially being able to learn new things I hadn't thought about from it too, thank you for sharing!
@chouaibbenali5201
@chouaibbenali5201 5 жыл бұрын
I've stumbled to your channel by pure luck,it's probably the best node js vid i have ever seen, you should make more videos
@LongNguyen-vt7je
@LongNguyen-vt7je 3 жыл бұрын
Thanks a lot. This is the most valuable architecture video I've ever seen.
@digicinematic
@digicinematic 4 жыл бұрын
This video is so-o good. I've watched it twice. And the second time through I kept rewinding bits to make sure I didn't miss a thing!! Well done.
@mathws1
@mathws1 4 жыл бұрын
will do it too!
@bobinvarghese7152
@bobinvarghese7152 4 жыл бұрын
Mind = Blown. For someone who thought who knows enough about structuring code and model data and apis, this is an eye opener. This is proper pro content, at times I was falling behind because there was so much things to pick up. Please keep making videos. Thanks
@R2r_1337
@R2r_1337 2 ай бұрын
Incredible! Best explanation of the Clean Architecture I've ever seen.
@asubijotaka7374
@asubijotaka7374 3 жыл бұрын
One of the best video I've seen so far, finaly understood what dependency injection was used for. Hard to understand when you didn't studied IT and you convert to fullstack dev by yourself, now it's finally clearer. Thanks a lot. Subscribed of course.
@bmejia220
@bmejia220 2 жыл бұрын
Excellent video, Bill. This content is super helpful. I can't wait to try these concepts out to build a sturdy API. Thank you!
@A5tr0101
@A5tr0101 4 жыл бұрын
This is a really way to code in node, the use case break down into services is really intuitive
@furkandemirturk3646
@furkandemirturk3646 4 жыл бұрын
Please please please keep continuing to make videos! Thank you so much. There are a few videos that help us to scale up to a high level. This is one of them that's why It is so valuable. Thank you again!
@sty521
@sty521 2 жыл бұрын
Awesome video. Finally a real-case node js implementation with clean architecture! Very informative, thanks a lot!
@SridTech
@SridTech Жыл бұрын
Liked and subscribed. This architecture is the real meaning of plug and play. I love how each and every thing can be tweaked without affecting others. Loved it.
@SilvanoJulio
@SilvanoJulio 4 жыл бұрын
This video is a great example of what a video tutorial should be related to devs. Source code and diagrams. Business explanations, and concrete implementation. Absolutely the greatest
@user-bc8up2jz4q
@user-bc8up2jz4q 4 жыл бұрын
The video is definitely a gold. Thank you very much. I may apply the idea in our project.
@abneryang2102
@abneryang2102 4 жыл бұрын
This is so great. Would love to see more content!
@rahul4239
@rahul4239 5 жыл бұрын
Super useful, thanks for taking out time to make this.
@damercy
@damercy 3 жыл бұрын
What a great explanation. Loved how you explained the concepts in about half an hour! Subscribing!
@still-dreaming
@still-dreaming 5 жыл бұрын
Thanks for posting that! I have to try it out next I built a microservice from scratch! Seems like a lot of fun!
@Oblivianos
@Oblivianos Жыл бұрын
probably the best video on Onion/Clean arch I've watched so far. Concrete examples helped so much. We have been trying to adhere to onion at work to make our lives easier down the road and I was second guessing myself sometimes. Thanks for clearing up the fog
@gersongallo6892
@gersongallo6892 4 жыл бұрын
I just founded this. Thank you very much, this is advanced but at the same time so we'll explained that is just beautiful
@claytonmarshall8564
@claytonmarshall8564 2 жыл бұрын
Thank you so much for making this! I've been reading about clean architecture and DDD for a while now and this finally made things click
@evensnoel190
@evensnoel190 3 жыл бұрын
Clear, concise and well explained! Many thanks for this great video! I was searching for this kind of content applied to JavaScript in vain until now. Subscribed
@calanside15
@calanside15 6 ай бұрын
i did find it extemely useful, thanks a million for the effort it took to compile and make this - much love
@jaychristopheranacio9941
@jaychristopheranacio9941 4 жыл бұрын
Out of the node js videos that I came across with, this is probably the best and most clean so far.
@mattisovereighteen
@mattisovereighteen 4 жыл бұрын
Great explanation! Immediately forwarded to the rest of my team
@cpclaudio.pereira
@cpclaudio.pereira 2 жыл бұрын
Really impressive how you pass the knowledge in an easy way, real and understandable. Like some guys said, everything in only one video. Thanks for sharing
@tonyr.6637
@tonyr.6637 3 жыл бұрын
@Dev Mastery Fantastic balance of principles, application, and code details. Are you still making vids? (Or are you planning to start up again?) I would love a follow-up video that goes into some more deep-dive aspects of this practice. Perhaps also a video of common “gotchas” for people trying out this architecture for the first time.
@DevTalles
@DevTalles 10 ай бұрын
Love what you did with the video man, and also a very clever way to implement the adapter pattern for the sanitize library, the only thing that I would change, is that I prefer to have individual files for all the dependencies with their adapters, instead of having just one big file with all the third party and factory functions. But this video is a must see! thank you
@miguelangelgeq9080
@miguelangelgeq9080 Жыл бұрын
Great content! I'd like to see a TypeScript project that uses this architecture to understand the use of interfaces
@igor_cojocaru
@igor_cojocaru 4 жыл бұрын
Priceless content. Thank you
@billkariri
@billkariri 4 жыл бұрын
Amazing video, I think I'm going to start practicing on the clean architecture
@kevinjmiles
@kevinjmiles 4 жыл бұрын
Great Demo! Super Great! Clean, well done and super useful!
@JoeWong81
@JoeWong81 4 жыл бұрын
Thanks for the video bro I love the walkthrough and your teaching style...I've subscribed now to your channel!
@florinmtsc
@florinmtsc 2 жыл бұрын
So simple and to the point.. Really a pleasure to follow.
@andreilazar8368
@andreilazar8368 5 жыл бұрын
Amazingly explained! I love it!
@danimydev
@danimydev 2 жыл бұрын
Seriously the best Node JS on KZbin ... Thank you sir!
@lifeoftomi_
@lifeoftomi_ 4 жыл бұрын
Hands down the best demonstration of this concept.
@amitkumaryadav793
@amitkumaryadav793 3 жыл бұрын
Awsome Microservices tutorial with clean architecture. Thanks.
@rorgonas
@rorgonas 4 жыл бұрын
This presentation gave me a very clear guideline on how to structure my current or future NodeJS - Express projects. I've found this tutorial accidentally after searching the web for something else (as usual) and I do NOT regret the 33:49 min that I spend to watch and try to understand it. I had to stop many time to get what you are saying and I saved it for later use. Great! Thx.
@exapsy
@exapsy 5 жыл бұрын
Thank you so much, it all makes so much more sense now. Clean Architecture is a difficult concept to grasp through, just because it has tricky parts such as "No inner circle depends on outer circle" and you're like: "Well, then how the hell am I going to insert a new object into the database if I cant depend on it? You explained it very well, thank you for that.
@ayub8457
@ayub8457 4 жыл бұрын
After watching this video I have only one question. Why I didn't know about your channel before? This video is a gold! Can't wait to see your other videos. Thank you very much for sharing your knowledge!
@sandeepgamot4585
@sandeepgamot4585 Жыл бұрын
This video was outstanding in terms of depth and practicality it never felt express app until towards the end of the video. Although I understood the concept of clean architecture, but it would be really helpful if you make a playlist of achieving this from scratch. That would be gold! Thanks for such content. Subscribed
@mohamedmirghani1747
@mohamedmirghani1747 3 жыл бұрын
Amazing video, you should never stop making this unique content, Thanks
@user-cw3id8jd3v
@user-cw3id8jd3v 3 жыл бұрын
It's awesome! Thanks a lot! Please keep doing similar videos.
@bibek8284
@bibek8284 2 жыл бұрын
This is one of the best tutorial I have ever watched. I hope this gets upgrade to typescript
@avibrarbrar
@avibrarbrar 3 жыл бұрын
This type of learning material helps a lot, I am practicing clean architecture and this video helped clear some of the concepts. Thanks a lot you saved me a lot of research.
@yeseulkang6646
@yeseulkang6646 3 жыл бұрын
although i got lost in express callback, was really great video. i've always wondered that from college, i've learned the use case things but never knew how to actually use them. This video helps a lot of making sense of why we should learn software architecture. Thank you for makin such a wonderful video!
@aleksandermirowsky7988
@aleksandermirowsky7988 3 жыл бұрын
This is fantastic content. Such a good explanation, everything is so clear and concise. Liked, subscribed and turned notifications on.
@wazazaby
@wazazaby 2 жыл бұрын
This is just amazing, and it even follows some functionnal programming principles... Wow
@AlphasoundSchool
@AlphasoundSchool 8 ай бұрын
I'm a beginner developer and I'm so grateful to have found this channel. PURE GOLD! Thanks for this amazing content!
@afagund
@afagund 4 жыл бұрын
Awesome content! Thank you for sharing with us!
@pradins
@pradins Жыл бұрын
thanks for this video. this is just beauty, clean and super well explained. thanks !
@felo2991
@felo2991 Жыл бұрын
This should be the best Node video in the whole internet !
@nanoentity
@nanoentity 4 жыл бұрын
this was pretty good, very nice job man
3 жыл бұрын
Damn! Amazing video! Thank you for providing this insight, I've seen things from a new perspective and they look awesome! I'm just kinda curious if the channel is still active or if we can get more content from you on another channel, site, service, whatever. Thank you again.
@aminazgol3918
@aminazgol3918 4 жыл бұрын
that was exactly what I needed. I always knew that something is wrong with my programming style
@diegofernandobarrios1138
@diegofernandobarrios1138 4 жыл бұрын
Thanks for sharing this with us! It's very useful! Thanks bro!
@gompro
@gompro 5 жыл бұрын
simple, clean and straight forward
@brunoanken3571
@brunoanken3571 4 жыл бұрын
You just made me a better developer. Thank you!
@sergeychernikov6595
@sergeychernikov6595 7 ай бұрын
Thanks a million for this video!! I've read the Clean Architecture by Robert Martin, but could not understand how to apply the provided circular diagram in practice. Frankly speaking, I understand only 20-30% of what is going on in the video because of the lack of knowledge and experience, but it fires an awesome feeling of curiosity and desire to continue enhance my skills to become more and more professional as time goes by. UPD: I'm having so much emotions and insights watching this video so that I will download this video and keep it on my external drive for future reviews!! (if this video will accidentally disappear from KZbin)🙂
@alexispell4251
@alexispell4251 3 жыл бұрын
wow... its the best structure i ever seen. Thank you for explanations!
@stilobit6856
@stilobit6856 4 жыл бұрын
wooow thats reaaaly great it can be applyied to huge large application love it!!
@professorclever6487
@professorclever6487 4 жыл бұрын
Excellent! One of very few non trivial code examples; demonstrating clean architecture and good coding style very well
@emstudios14
@emstudios14 2 жыл бұрын
This video is an artifact of knowledge. It is so enlightening.
@mohamedelidrissi2839
@mohamedelidrissi2839 4 жыл бұрын
Very well explained, I used clean architecture in Android developers but didn't know I could use it on the web too!
@marccawood
@marccawood 4 жыл бұрын
Amazingly useful and high quality video this!
@Abhishekshingane
@Abhishekshingane Жыл бұрын
Great Video! Always wanted to understand how to implement dependency injection on a practical use case.
@ajeetts8289
@ajeetts8289 Жыл бұрын
Mind Blowing! Loved it
@tomhollins9266
@tomhollins9266 3 жыл бұрын
Explained Very Clearly. Excellent job of application of theory.
Clean Architecture IS about Vertical Slicing, actually!
15:24
About Clean Code
Рет қаралды 32 М.
ОДИН ДЕНЬ ИЗ ДЕТСТВА❤️ #shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН
She ruined my dominos! 😭 Cool train tool helps me #gadget
00:40
Go Gizmo!
Рет қаралды 56 МЛН
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 83 МЛН
tRPC, gRPC, GraphQL or REST: when to use what?
10:46
Software Developer Diaries
Рет қаралды 70 М.
Microservices Crash Course & Moleculer JS Intro
38:54
Traversy Media
Рет қаралды 37 М.
Clean Architecture in TypeScript
58:19
Donny Roufs
Рет қаралды 17 М.
The Ultimate Coding Workflow
20:26
Dev Mastery
Рет қаралды 18 М.
Node.js Project Structure and Architecture Best Practices
7:38
Software Developer Diaries
Рет қаралды 22 М.
Designing a clean REST API with Node.js (Express + Mongo)
38:31
Dev Mastery
Рет қаралды 79 М.
Секретный смартфон Apple без камеры для работы на АЭС
0:22
Урна с айфонами!
0:30
По ту сторону Гугла
Рет қаралды 7 МЛН
Телефон в воде 🤯
0:28
FATA MORGANA
Рет қаралды 1,1 МЛН
Какой ПК нужен для Escape From Tarkov?
0:48
CompShop Shorts
Рет қаралды 261 М.
Мечта Каждого Геймера
0:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,7 МЛН
Cadiz smart lock official account unlocks the aesthetics of returning home
0:30
Нашел еще 70+ нововведений в iOS 18!
11:04