as I new learner, i learned clean architecture in c#. Actually did not create many projects with c# but i understood the clean architecture thanks to the teacher. I recently started learning node.js and was about to create my own project after tutorials. The think that stopped me was actually clean architecture. As I learned it from the c# courses I felt that somethings were going wrong in the node.js tutorials, then i searched clean architecture in node.js and found your video. It is very helpful and understandable as a beginner/low-intermediate. Thank you very much!
I’ve been poking around TH-cam and the inter webs for node/typescript specific examples of clean architecture and I gotta say I think your video is the *best* at showing the principles through a legit project, with code!! I do like how you simplified the tutorial, eliminating non essentials like an orm and messaging libs. Calling “use cases” by the name “interactors” is something I have not heard before. The only thing that I felt was truly missing was the interaction with the domain layer… you did create a domain object but then ignored it for the rest of the tutorial. Since it was such a small/simple project maybe it didn’t warrant calling any domain methods though, but would have been nice to mention that. Amazing video. Subscribing now.
Hi, Thank you for this tutorial. How we can avoid dependency injection? Example: AService.ts const AA = () => { BService.BB(); } const CC = () => { // some code } BService.ts const BB = () => { AService.CC(); } Note: we don't want use methods together Only services import to together
While watching, I realized that writing clean architecture and writing TDD at the same time seems extremely laborious. In this way, it will take a really long time to release the actual product. And the payment made by the company in return for the effort is also extremely important.
normally most of the companies follow Clean Architecture and later stage cover the test cases with min 80% threshold but TDD is just to understand how things has to handle in learning stage. In real life its a bit time consuming for sure. If you learnt it you are good to go.
Thank you for writing. In javascript and typescript bind returns a new function with the bound "this". Example: in our case router.post("/products", controller.onCreateProduct.bind(controller)); Here bind method is used to ensure that the onCreateProduct function is called with a specific this context, which is the controller object in this case. The bind method creates a new function that, when called, has its this value set to the provided argument. In this example, controller.onCreateProduct.bind(controller) creates a new function where the this value inside onCreateProduct will refer to the controller object.This is commonly done in the context of setting up routes in web frameworks, where you want to ensure that the controller methods are called with the correct context. Hope it will help! Cheers!
Awesome video Jay! I have a question though, isn't it much better if interactors are place on their own classes instead of putting them into a single class?
Hey Jay, We have a system that works and looks much cleaner at 42:04. I don't quite understand the reasoning behind implementing inversify here. After all, isn't the current form of Dependency Injection? Thank you.
Hi Thanks, All the knowledge you have gain so far till 42:00 is the manual dependency injection process with transparency where we can understand how the mechanism works and you have full control on it. Now the big overheads are it's manual and you need to write lot of boiler plate codes to get the job done. So Inversify is a Dependency framework that is helping us to reduce all manual work and make sure instances are used efficiently for optimal memory usages. Here is why and which one to use: Inversify: Use it when working on larger projects, where dependency management could get complicated. It also fits well with TypeScript-heavy codebases, where decorators and metadata provide clear advantages in terms of type safety and cleaner code. Manual DI: It works well for smaller or simpler projects, where adding an entire framework for dependency injection may be overkill. It's also useful for learning or when the project does not need the complexity that a DI framework brings. Cheers!
this is the best tutorial for clean architecture using type script please can you put a video of a project with react js or next js in frontend and express js type script for backend with clean architecture
HI Jay. Are you still going to be creating the frontend for the microservices masterclass series? would be great to see even a basic design on the frontend to see how it all goes together
Will there be any videos releated to Hexagonal architecture and Onion architecture because i have some doubts releated to them. Are they same except their name.
They are not same. It is sharing common principles like separation of concerns in layers, and clean dependency pattern, Inversion of controls etc. Each architecture has it's own emphases and implementations based on use cases. Overall if you at least know one of them you are good to go. I will release some videos in future based on these concepts.
Great work Jay! What should be the industry practice using orm models like sequelize,prisma erc. or raw queries as per tutorial? And what are your thoughts about using nestjs which has already using singleton or repository pattern
Hey thanks a lot for writing! TBH there are no such silver bullet points as Industry best practices. But it's depends on your project requirements and how your team decide what to follow. I would recommend to use some ORM to save your time and complexity. Behind the scene all ORM is used raw sql only and it gives flexibility to deal with Database queries and execution using high level abstractions. You can use TypeORM or Prisma that is widely used in NodeJS ecosystem. You can use NestJS that's an wonderful framework! But not recommended for simple requirements and specially when we are not dealing with Microservice or big project requirements. But if you really want to structure project without put your hands to create structure like in our current video. You can go with NestJS. Note: We have not implemented any ORM on this Episode just for shake of time but we have already implemented ORM (Prisma) for our this series you will see very soon in coming videos. Cheers!
Yes you can. But you need to understand how it works at least while we are facing coding interviews the framework will not help to convince interviewers :)
Hi sir.. if you don't mind.. could you please make one large application or creating apid for it by this way.. including authentication dto,types and type orm with mogodb testing?❤😊🎉
Hi Jay, first of all thank you so much for share this proffessional knowledge, your channel is amazing. Sincerely the best and precise course of node that I ever had. I have a question my friend, in what layer should the repository be? I see that the product repository uses the external library "pg" and also it comunicates with Product entity. I am a little confuse about this, can you explain me? please.
You can add it in the route file example: // Authentication middleware (example) const authMiddleware = (req: Request, res: Response, next: NextFunction) => { // Placeholder for actual authentication logic with jwt const isAuthenticated = true; // Replace with real authentication check if (!isAuthenticated) { return res.status(401).json({ message: "Unauthorized" }); } next(); }; // Apply middleware to all routes router.use(loggerMiddleware); or if specific endpoint needs authentication you can use like below: router.post( "/products", authMiddleware, async (req: Request, res: Response, next: NextFunction) => { try { const { errors, input } = await RequestValidator( CreateProductRequest, req.body ); if (errors) return res.status(400).json(errors); const data = await catalogService.createProduct(input); return res.status(201).json(data); } catch (error) { next(error); } } ); Hope it will help you :) Cheers!
To write an entity validator in TypeScript while avoiding direct coupling to specific node packages, you can adopt an abstraction approach. This involves defining your own validation interfaces and using a strategy pattern to apply various validation implementations. In our case we are using AJV and typeBox with generic to disconnecting the coupling.
I'm trying to implement this architecture to one of my projects but using nodejs without the typescript thing, and the dependency injection thing of having a instace of the interactor seems not necessary, If I want to test with a mock I can override the static class instance of the methods in the interactor itself.
Hi, Thank you for writing. Here we just want to give an overview of how clean architecture works by keeping loose coupling of the layers and dependencies. It's up to you to follow the pattern or maybe you can shape it as per your application needs by revoking extra layers. You do not necessarily need to use interactors in the case of Javascript it is out of the question. In functional programming, you can get rid of it and hook up with your dedicated function to replace the functionality. You can watch our latest episodes for references. Cheers!
I like the way you explained Clean architecture well but if I may ask, aren't just adding more abstractions and spreading code across multiple folders/files?
Hi thanks a lot for your opinion! It's up to you how you organize your codes but in this project we tried to decoupled by keeping essential layers only as per the principal. If you understood the concept you can minimize your code accordingly. In this case if we not spreading the codes to layers it belongs to and not injected dependencies properly to perform the operation in the loosely couple way then it will be not meaning full to implement Clean architecture anymore. Cheers!
It's not about ended with Object Oriented Programming! It's about the removing dependencies and utilize of layered architecture that Domain and Application business logic not to tightly dependent on framework and drivers etc. If you understand the concept correctly you can utilize it on functional programming as well. We following Class pattern just to make people understand easy way. If you are following this series you will see the functional usages with clean architecture in future lactures. Cheers!
Yes, You can use NestJS that's an wonderful framework! But not recommended for all the use cases. Example some times its overkill when we have simple requirements and specially when we are not dealing with Microservice or big project requirements. But if you really want to structure project without put your hands to create structure like in our current video. You can go with NestJS. Cheers!
Thank you for writing and your opinion. We are focusing on to understand the mechanism only not the a framework. You can use NestJS if you know how it works behind the scene. Note: This tutorial series made based on viewers request how to build such system using NodeJs not NestJS.
Don't you think every Entity having it's own folder is better..... then they have their own files inside their folder.... controller, service, repository, interface e.t.c
It's up to you how you organize your files. Only matters to follow the principal and Enterprise and Application business rules should not affect when we change UI and framework along with Data Access Layer.
as I new learner, i learned clean architecture in c#. Actually did not create many projects with c# but i understood the clean architecture thanks to the teacher. I recently started learning node.js and was about to create my own project after tutorials. The think that stopped me was actually clean architecture. As I learned it from the c# courses I felt that somethings were going wrong in the node.js tutorials, then i searched clean architecture in node.js and found your video. It is very helpful and understandable as a beginner/low-intermediate. Thank you very much!
Thank you for your kind words. Stay tuned to our channel and join our discord channel for Job offer announcements and updates.
Cheers!
I was waiting for this after watching first part. Good to see some unique advance stuff on TH-cam. Good work brother ✨
I have a legacy nodejs project written 4 years. I recented update to clean articture. Thanks!
I’ve been poking around TH-cam and the inter webs for node/typescript specific examples of clean architecture and I gotta say I think your video is the *best* at showing the principles through a legit project, with code!! I do like how you simplified the tutorial, eliminating non essentials like an orm and messaging libs. Calling “use cases” by the name “interactors” is something I have not heard before. The only thing that I felt was truly missing was the interaction with the domain layer… you did create a domain object but then ignored it for the rest of the tutorial. Since it was such a small/simple project maybe it didn’t warrant calling any domain methods though, but would have been nice to mention that.
Amazing video. Subscribing now.
Thank you for your appreciation. Some time it's not easy to cover all the edge cases. But I will take a note on your suggestion.
Cheers!
How are you my friend? Happy new year in advance, I will watch this after my holiday, i know it's a goody as usual
Thanks a lot my friend! Wish you Happy new year!
Great video! Thanks so much for your efforts.
My pleasure!
Hi,
Thank you for this tutorial.
How we can avoid dependency injection?
Example:
AService.ts
const AA = () => {
BService.BB();
}
const CC = () => {
// some code
}
BService.ts
const BB = () => {
AService.CC();
}
Note: we don't want use methods together
Only services import to together
Great. Awesome
Thank you! Cheers!
While watching, I realized that writing clean architecture and writing TDD at the same time seems extremely laborious. In this way, it will take a really long time to release the actual product. And the payment made by the company in return for the effort is also extremely important.
normally most of the companies follow Clean Architecture and later stage cover the test cases with min 80% threshold but TDD is just to understand how things has to handle in learning stage. In real life its a bit time consuming for sure. If you learnt it you are good to go.
İt's very clear. Thank you Jay!
Glad it was helpful!
Great Video. Can you please explain what was the need of .bind, why the constructor was not being called properly?
Thank you for writing. In javascript and typescript bind returns a new function with the bound "this".
Example: in our case router.post("/products", controller.onCreateProduct.bind(controller));
Here bind method is used to ensure that the onCreateProduct function is called with a specific this context, which is the controller object in this case. The bind method creates a new function that, when called, has its this value set to the provided argument. In this example, controller.onCreateProduct.bind(controller) creates a new function where the this value inside onCreateProduct will refer to the controller object.This is commonly done in the context of setting up routes in web frameworks, where you want to ensure that the controller methods are called with the correct context.
Hope it will help!
Cheers!
Awesome video Jay! I have a question though, isn't it much better if interactors are place on their own classes instead of putting them into a single class?
Hey Thanks a lot for kind words. Yes you can keep it in own classes as well. There are no silver bullet rules.
Cheers!
Hey Jay,
We have a system that works and looks much cleaner at 42:04. I don't quite understand the reasoning behind implementing inversify here. After all, isn't the current form of Dependency Injection?
Thank you.
Hi Thanks,
All the knowledge you have gain so far till 42:00 is the manual dependency injection process with transparency where we can understand how the mechanism works and you have full control on it. Now the big overheads are it's manual and you need to write lot of boiler plate codes to get the job done. So Inversify is a Dependency framework that is helping us to reduce all manual work and make sure instances are used efficiently for optimal memory usages.
Here is why and which one to use:
Inversify: Use it when working on larger projects, where dependency management could get complicated. It also fits well with TypeScript-heavy codebases, where decorators and metadata provide clear advantages in terms of type safety and cleaner code.
Manual DI: It works well for smaller or simpler projects, where adding an entire framework for dependency injection may be overkill. It's also useful for learning or when the project does not need the complexity that a DI framework brings.
Cheers!
@@codewithjay Thanks Jay. You are the best!
I watch your videos and will renew my membership again soon.
Thanks great tutorial. it helped a lot
I'm glad the tutorial was helpful for you!
Cheers!
this is the best tutorial for clean architecture using type script please can you put a video of a project with react js or next js in frontend and express js type script for backend with clean architecture
Great suggestion! I will take a note!
HI Jay. Are you still going to be creating the frontend for the microservices masterclass series? would be great to see even a basic design on the frontend to see how it all goes together
Hey Thank you for writing! Certainly I will cover that in part 2. As soon as we covered this series Elastic Search Functionality.
Will there be any videos releated to Hexagonal architecture and Onion architecture because i have some doubts releated to them. Are they same except their name.
They are not same. It is sharing common principles like separation of concerns in layers, and clean dependency pattern, Inversion of controls etc. Each architecture has it's own emphases and implementations based on use cases. Overall if you at least know one of them you are good to go. I will release some videos in future based on these concepts.
Great work Jay! What should be the industry practice using orm models like sequelize,prisma erc. or raw queries as per tutorial? And what are your thoughts about using nestjs which has already using singleton or repository pattern
@Jay you response on this will be appreciated
Hey thanks a lot for writing!
TBH there are no such silver bullet points as Industry best practices. But it's depends on your project requirements and how your team decide what to follow. I would recommend to use some ORM to save your time and complexity. Behind the scene all ORM is used raw sql only and it gives flexibility to deal with Database queries and execution using high level abstractions. You can use TypeORM or Prisma that is widely used in NodeJS ecosystem. You can use NestJS that's an wonderful framework! But not recommended for simple requirements and specially when we are not dealing with Microservice or big project requirements. But if you really want to structure project without put your hands to create structure like in our current video. You can go with NestJS.
Note: We have not implemented any ORM on this Episode just for shake of time but we have already implemented ORM (Prisma) for our this series you will see very soon in coming videos.
Cheers!
please follow the answer!
Amazing video!!
There are many ways to achieve clean architecture. In my opinion, it is good to use a framework.
Yes you can. But you need to understand how it works at least while we are facing coding interviews the framework will not help to convince interviewers :)
database is not working. i created clean_architecture database and defined table but cant create or find ?
Hi sir.. if you don't mind.. could you please make one large application or creating apid for it by this way.. including authentication dto,types and type orm with mogodb testing?❤😊🎉
Hi Jay, first of all thank you so much for share this proffessional knowledge, your channel is amazing. Sincerely the best and precise course of node that I ever had.
I have a question my friend, in what layer should the repository be? I see that the product repository uses the external library "pg" and also it comunicates with Product entity. I am a little confuse about this, can you explain me? please.
If I want to add any middleware for example I have jwt and the request needs the token, where can I add the middle ware for each requesg and how ??
You can add it in the route file example:
// Authentication middleware (example)
const authMiddleware = (req: Request, res: Response, next: NextFunction) => {
// Placeholder for actual authentication logic with jwt
const isAuthenticated = true; // Replace with real authentication check
if (!isAuthenticated) {
return res.status(401).json({ message: "Unauthorized" });
}
next();
};
// Apply middleware to all routes
router.use(loggerMiddleware);
or if specific endpoint needs authentication you can use like below:
router.post(
"/products",
authMiddleware,
async (req: Request, res: Response, next: NextFunction) => {
try {
const { errors, input } = await RequestValidator(
CreateProductRequest,
req.body
);
if (errors) return res.status(400).json(errors);
const data = await catalogService.createProduct(input);
return res.status(201).json(data);
} catch (error) {
next(error);
}
}
);
Hope it will help you :)
Cheers!
How do you write the entity validator ? In that case how to avoid the couple between node packages for validation.
To write an entity validator in TypeScript while avoiding direct coupling to specific node packages, you can adopt an abstraction approach. This involves defining your own validation interfaces and using a strategy pattern to apply various validation implementations. In our case we are using AJV and typeBox with generic to disconnecting the coupling.
@@codewithjay Thank you !
Great Video
I'm trying to implement this architecture to one of my projects but using nodejs without the typescript thing, and the dependency injection thing of having a instace of the interactor seems not necessary, If I want to test with a mock I can override the static class instance of the methods in the interactor itself.
Hi, Thank you for writing. Here we just want to give an overview of how clean architecture works by keeping loose coupling of the layers and dependencies. It's up to you to follow the pattern or maybe you can shape it as per your application needs by revoking extra layers. You do not necessarily need to use interactors in the case of Javascript it is out of the question. In functional programming, you can get rid of it and hook up with your dedicated function to replace the functionality. You can watch our latest episodes for references.
Cheers!
Great content ❤
Thanks a lot man
link to the previous episode
Hey thank you so much.
Great work
Thank you so much 😀
Thanks bro ....
clean architecture is all great but why the need of dependency injection. I have never used so confused why used here ?
I like the way you explained Clean architecture well but if I may ask, aren't just adding more abstractions and spreading code across multiple folders/files?
Hi thanks a lot for your opinion!
It's up to you how you organize your codes but in this project we tried to decoupled by keeping essential layers only as per the principal. If you understood the concept you can minimize your code accordingly. In this case if we not spreading the codes to layers it belongs to and not injected dependencies properly to perform the operation in the loosely couple way then it will be not meaning full to implement Clean architecture anymore.
Cheers!
Does every refactoring on "clean architecture" have to end up writing OOP? Why didn't you stay with the functional approach?
It's not about ended with Object Oriented Programming! It's about the removing dependencies and utilize of layered architecture that Domain and Application business logic not to tightly dependent on framework and drivers etc. If you understand the concept correctly you can utilize it on functional programming as well. We following Class pattern just to make people understand easy way. If you are following this series you will see the functional usages with clean architecture in future lactures.
Cheers!
Thanks ❤
Love it
Jay , what is your opinion about nestjs
Yes, You can use NestJS that's an wonderful framework! But not recommended for all the use cases. Example some times its overkill when we have simple requirements and specially when we are not dealing with Microservice or big project requirements. But if you really want to structure project without put your hands to create structure like in our current video. You can go with NestJS.
Cheers!
Also make another video by following functional based not classed based and used orm prisma
what's ur vs code font I love it
JetBrains Mono
Sir will u apply Kafka in this project?
Yes this series is based on Kafka & Elastic Search, Prisma and Clean Architecture!
If you are going to implement this on Nodejs why not use Nestjs instead?
Thank you for writing and your opinion. We are focusing on to understand the mechanism only not the a framework. You can use NestJS if you know how it works behind the scene.
Note: This tutorial series made based on viewers request how to build such system using NodeJs not NestJS.
For those many files needed for just one entity you need to introduce a generator :)
You can use one as per your convenient.
Cheers!
What do you mean by saying "generator", could you explain it?
Something like plopjs
Don't you think every Entity having it's own folder is better..... then they have their own files inside their folder.... controller, service, repository, interface e.t.c
It's up to you how you organize your files. Only matters to follow the principal and Enterprise and Application business rules should not affect when we change UI and framework along with Data Access Layer.
"Right?" *100000
nest js