Clean architecture with nodeJs express : practical example in node.js

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 พ.ย. 2024

ความคิดเห็น • 81

  • @kemalsogut9342
    @kemalsogut9342 10 หลายเดือนก่อน +4

    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!

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน +1

      Thank you for your kind words. Stay tuned to our channel and join our discord channel for Job offer announcements and updates.
      Cheers!

  • @shravan2891
    @shravan2891 10 หลายเดือนก่อน +4

    I was waiting for this after watching first part. Good to see some unique advance stuff on TH-cam. Good work brother ✨

  • @techpassion5680
    @techpassion5680 2 หลายเดือนก่อน

    I have a legacy nodejs project written 4 years. I recented update to clean articture. Thanks!

  • @ShaunEk1
    @ShaunEk1 5 หลายเดือนก่อน

    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.

    • @codewithjay
      @codewithjay  5 หลายเดือนก่อน

      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!

  • @abayomioloyinde
    @abayomioloyinde 10 หลายเดือนก่อน

    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

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน

      Thanks a lot my friend! Wish you Happy new year!

  • @BarakAlmog
    @BarakAlmog 8 หลายเดือนก่อน

    Great video! Thanks so much for your efforts.

    • @codewithjay
      @codewithjay  8 หลายเดือนก่อน +1

      My pleasure!

  • @hfmohammad
    @hfmohammad 9 หลายเดือนก่อน

    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

  • @morkhoudia9
    @morkhoudia9 2 วันที่ผ่านมา

    Great. Awesome

    • @codewithjay
      @codewithjay  17 ชั่วโมงที่ผ่านมา

      Thank you! Cheers!

  • @cKc1.6
    @cKc1.6 หลายเดือนก่อน

    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.

    • @codewithjay
      @codewithjay  หลายเดือนก่อน +2

      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.

  • @abdullahsevmez42
    @abdullahsevmez42 10 หลายเดือนก่อน

    İt's very clear. Thank you Jay!

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน

      Glad it was helpful!

  • @akashdanva
    @akashdanva 9 หลายเดือนก่อน

    Great Video. Can you please explain what was the need of .bind, why the constructor was not being called properly?

    • @codewithjay
      @codewithjay  9 หลายเดือนก่อน +1

      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!

  • @lawliet.fortyfour
    @lawliet.fortyfour 5 วันที่ผ่านมา

    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?

    • @codewithjay
      @codewithjay  17 ชั่วโมงที่ผ่านมา

      Hey Thanks a lot for kind words. Yes you can keep it in own classes as well. There are no silver bullet rules.
      Cheers!

  • @cKc1.6
    @cKc1.6 หลายเดือนก่อน

    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.

    • @codewithjay
      @codewithjay  หลายเดือนก่อน +1

      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!

    • @cKc1.6
      @cKc1.6 หลายเดือนก่อน

      @@codewithjay Thanks Jay. You are the best!
      I watch your videos and will renew my membership again soon.

  • @zuenirclaudio4941
    @zuenirclaudio4941 4 หลายเดือนก่อน

    Thanks great tutorial. it helped a lot

    • @codewithjay
      @codewithjay  4 หลายเดือนก่อน

      I'm glad the tutorial was helpful for you!
      Cheers!

  • @marwanassou4016
    @marwanassou4016 22 วันที่ผ่านมา

    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

    • @codewithjay
      @codewithjay  17 ชั่วโมงที่ผ่านมา

      Great suggestion! I will take a note!

  • @Riflijones01
    @Riflijones01 10 หลายเดือนก่อน +1

    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

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน +1

      Hey Thank you for writing! Certainly I will cover that in part 2. As soon as we covered this series Elastic Search Functionality.

  • @mohit84604
    @mohit84604 10 หลายเดือนก่อน +1

    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.

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน

      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.

  • @kranthikumarvitta
    @kranthikumarvitta 10 หลายเดือนก่อน +1

    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

    • @abayomioloyinde
      @abayomioloyinde 10 หลายเดือนก่อน

      @Jay you response on this will be appreciated

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน +2

      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!

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน +1

      please follow the answer!

  • @sebastianlpoliak
    @sebastianlpoliak 7 หลายเดือนก่อน

    Amazing video!!

  • @codingroom1230
    @codingroom1230 8 หลายเดือนก่อน

    There are many ways to achieve clean architecture. In my opinion, it is good to use a framework.

    • @codewithjay
      @codewithjay  8 หลายเดือนก่อน

      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 :)

  • @sharaths2294
    @sharaths2294 3 หลายเดือนก่อน

    database is not working. i created clean_architecture database and defined table but cant create or find ?

  • @viralmoney8619
    @viralmoney8619 2 หลายเดือนก่อน +1

    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?❤😊🎉

  • @devPloy
    @devPloy 7 หลายเดือนก่อน

    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.

  • @eR1cK92
    @eR1cK92 5 หลายเดือนก่อน

    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 ??

    • @codewithjay
      @codewithjay  5 หลายเดือนก่อน

      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!

  • @ishanbhawantha
    @ishanbhawantha 4 หลายเดือนก่อน

    How do you write the entity validator ? In that case how to avoid the couple between node packages for validation.

    • @codewithjay
      @codewithjay  4 หลายเดือนก่อน +1

      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.

    • @ishanbhawantha
      @ishanbhawantha 4 หลายเดือนก่อน

      @@codewithjay Thank you !

  • @_NguyenTuanAnh-nr4ee
    @_NguyenTuanAnh-nr4ee 9 หลายเดือนก่อน

    Great Video

  • @erickweil4580
    @erickweil4580 5 หลายเดือนก่อน

    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.

    • @codewithjay
      @codewithjay  5 หลายเดือนก่อน

      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!

  • @aabhishakemishra
    @aabhishakemishra 10 หลายเดือนก่อน

    Great content ❤

  • @mohamadyousef2129
    @mohamadyousef2129 8 หลายเดือนก่อน

    Thanks a lot man

  • @adeniyitaofik3832
    @adeniyitaofik3832 7 หลายเดือนก่อน

    link to the previous episode

  • @marcelee124
    @marcelee124 7 หลายเดือนก่อน

    Hey thank you so much.

  • @VerdijtHanati
    @VerdijtHanati 10 หลายเดือนก่อน

    Great work

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน

      Thank you so much 😀

  • @thebeginner613
    @thebeginner613 5 หลายเดือนก่อน

    Thanks bro ....

  • @sharaths2294
    @sharaths2294 3 หลายเดือนก่อน

    clean architecture is all great but why the need of dependency injection. I have never used so confused why used here ?

  • @bollo_omar
    @bollo_omar 10 หลายเดือนก่อน

    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?

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน +1

      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!

  • @coder_one
    @coder_one 9 หลายเดือนก่อน

    Does every refactoring on "clean architecture" have to end up writing OOP? Why didn't you stay with the functional approach?

    • @codewithjay
      @codewithjay  9 หลายเดือนก่อน +1

      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!

  • @ericsiddiq7634
    @ericsiddiq7634 10 หลายเดือนก่อน

    Thanks ❤

  • @shravanology
    @shravanology 10 หลายเดือนก่อน

    Love it

  • @pranav7478
    @pranav7478 10 หลายเดือนก่อน

    Jay , what is your opinion about nestjs

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน +1

      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!

  • @technoinfoworldwide2329
    @technoinfoworldwide2329 10 หลายเดือนก่อน +1

    Also make another video by following functional based not classed based and used orm prisma

  • @awesomeguy6427
    @awesomeguy6427 10 หลายเดือนก่อน

    what's ur vs code font I love it

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน

      JetBrains Mono

  • @aabhishakemishra
    @aabhishakemishra 10 หลายเดือนก่อน

    Sir will u apply Kafka in this project?

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน +1

      Yes this series is based on Kafka & Elastic Search, Prisma and Clean Architecture!

  • @chess4964
    @chess4964 5 หลายเดือนก่อน

    If you are going to implement this on Nodejs why not use Nestjs instead?

    • @codewithjay
      @codewithjay  5 หลายเดือนก่อน

      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.

  • @vyteniskuciauskas
    @vyteniskuciauskas 7 หลายเดือนก่อน

    For those many files needed for just one entity you need to introduce a generator :)

    • @codewithjay
      @codewithjay  7 หลายเดือนก่อน

      You can use one as per your convenient.
      Cheers!

    • @cKc1.6
      @cKc1.6 หลายเดือนก่อน

      What do you mean by saying "generator", could you explain it?

    • @vyteniskuciauskas
      @vyteniskuciauskas หลายเดือนก่อน

      Something like plopjs

  • @NathanielBabalola
    @NathanielBabalola 10 หลายเดือนก่อน +1

    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

    • @codewithjay
      @codewithjay  10 หลายเดือนก่อน +2

      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.

  • @khaledmansour59
    @khaledmansour59 2 หลายเดือนก่อน

    "Right?" *100000

  • @ArnabDas-q9f
    @ArnabDas-q9f หลายเดือนก่อน +1

    nest js