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

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there welcome to my Channel today in this video we will implement the clean architecture in the practical way by keeping eye on the principles if you haven't watched the previous episode I'm highly encouraging you please to go ahead and watch the previous episode to understand the flow of the clean architecture and what problem it is solving in Practical all right so let's put our hands on the coding part so here you can see in the controller everything is tied up together right so one thing is missing right here so what exactly can you guess it I think if you go to this diagram here you can see in the innermost Circle which is called Enterprise business rule the entities that is exactly missing right here so in our application the main te like main Enterprise business rule is our product right which is we haven't added anywhere we are directly entering or directly we are just creating the product to the database and we are not we are not doing anything else right so that thing is missing let's try to create that one let's go ahead and create a directory here that is called entity all the entities we are going to keep inside this entities directory so here we are going to create one more more pile that is called a product right TS perfect so here inside the product let's try to add some code quickly so we have created one class that is called Product right so this is our entity where we'll be having our name description price stock and Etc the main source of the business will be product based on the product we'll be going to perform some kind of operations on it right so where maybe seller can seller can sell the product and buyer can buy the product or something like that way all right so let's keep it very simple and you can add as many as like you know the the functionalities right here in the class also so where maybe we can validate the product maybe uh name should have to be present description has to be present price should not supposed to be less than one or something like that and stock should not supposed to be have to be minus or something like that all those validation we can put it right here in in in this class right then while we are going to create the product by by using that specific product instance then we can validate everything right here so all this rules we can addit right there right perfect then let's move forward and where we can Implement all this product can you see like in this diagram we need to have a kind of use case which is going to expose or which is going to deal with that specific business rule where we'll be writing some kind of the uh business logic right here where application business rules will be there how we can operate that product or how we can patch the product create the product all this like the core core rules you know the Core Business exactly it's going to depends on that one only right so let's try to create that the use cases so what will be the use case use case we will be create only to handle the business logic nothing else right in order to do that let's try to create One Directory here right so that is going to be like interface interfaces right and here inside the interface directory let's try to create one pile i i product i product interactor Dots here inside this i product interactor let's try to add some code right which is going to be like export interface i product interactor let's try to add this unknown word to our workspace this is going to be like add yes this is cool now uh now here we are going to add some method which is going to help us to perform our business logic right so first of all this is going to be like create product create create product it will accept any kind of input here this is going to be like input input can be anything like maybe you can mark it as a kind of unknown also if you're not sure about what kind of input it will be but in in this case like we are not focusing on the types safety at this moment maybe in future we can just focus on the type safety by assigning some kind of dto also here right but let's try to Market as a kind of any at this moment right then one more F we are going to add that is called update stock update stock will will received two parameters one will be the ID and that is going to be the number and the second one will be our our stock this is also going to be number right then third one will be our get product get products here we need to give a range this is will be our limit limit maybe number and upset also will be number right so these are the fs going to help us to perform our business logic right so now let's go ahead here uh inside this Source directory we are going to create one more directory that is called uh interactors right interactors inside this interactor let's try to create one more pile that that is called Product interactor because this is only interface right TS and let's try to add some code here export class uh product interactor and here this is going to be like implement we need to implement that interface also which is we have created i product product interactor interface right so it is complaining because we have not implemented the interface methods right which is we have declared in i product interactor so let's try to add that thing right let's quick piix Implement right so these are the functions we need to implement right now our this layer is ready now let's work on the third layer that is the green one where we can say presenter controller or Gateway whatever we can name it right but this layer can be consist of maybe one or more than one or two classes or maybe maybe more than that also right but how we can how we can design that in that case our presenter will be a combination of our controller and routes also so let's try to do that so in that case what we can do I'm going to rename this controller the product controller is a kind of X product controller so we don't want to delete the whole quotes from here right so we are going to create one pile here this is going to be like product controller not yes right let's try to add some code quickly in order to fulfill our product controller right now let's add some code here in the product controller in order to handle our HTTP Communications right right let's try to move it up right so create get and update right so these are the functions right so let's go ahead here in the in the routes so here inside the routes right let's try to rename that specific pile rather than having Index right this is going to be like our product roads right so here inside the product roads we are going to delete all these things from here because we are not going to use all these things at all right so let's try to uh try to create one instance of the controller con new product product controller right so our product controll is created let's use that product controller right here on create product right then controller on on get products then controller on update stock so this is perfect now now our pipeline is clear while it comes to any kind of request right here then it will go to routers all right let's try to rename this router as a kind of product router right and if it will go to the product router right then certain end points will be handed over to certain functionality from this controller right in the controller but here in the product controller how we will serve the request right so to serve the request we need to hook up our our business logic layer right which is we have this one this one the user use case now you can see like our controller is pushing some kind of the input to the use case right then interactor is taking care of that specific input and process some kind of the business logic and giving some kind of output right there Then presenter is taking that output and giving back to the UI so this is the thing exactly it's happening so how we can do that here inside the product controller let's declare a variable which is going to hold our product interactor instance right let's declare that variable using the private access modifier private the interactor will be a kind of instance of our i product interactor right I product interactor so but how we can assign this we need to assign some right so how we can do that we need to add one Constructor here Constructor and inside this Constructor let's say uh interactor interactor will be i product interactor right and here this do interactor will be interactor right this interactor variable we going to be pass on the time of initialization of this uh product controller and we'll be assigned into our private variable this one here now we have added our interactor which is going to help us to our handle our business logic right so let's try to add some code here in this all the all the functions right but what we can do we can go to our X product controller right so let's try to grab all these things from here right copy all the string right from our create product and let's go to product controller on the create product this one so what we can do let's try to add one TR cat here right and inside this error let's say we can say next right we can put it to error because we don't want to handle the errors right here so if if we pound some error right here while we are performing our uh our business logic all right at that time we will be simply saying like hey hey please handle the all the error in this handle level right so we'll just simply passing that specific error to the to the next iteration or next execution which is going to help us to handle right here right but anyway this is this is we are not going to handle it at this moment so let's go ahead and add some code right here in the triat so technically this is not required right so let's try to add remove this line here body is needed because we need to pass that specific things to our uh our business logic so in this case what we are going to do let's say cons data will be our await and in this case our interactor going to take care like this interactor this is going to like this interactor create product and inside the create product we need to add our body all right so this body will be going going here right so body right and we're going to remove all these things from here right and until this one also this is also not required let's try to make it as a kind of comment at this moment and and here inside this 200 let's try to remove all these things and make sure you're returning the data so right now you can see like we are pretty must remove everything right so we have handed over that specific business logic uh responsibility to our interactor which is going to help us to create the product and once everything is done then we'll be it will give some data in back right and that data we'll just providing to our our next iteration in terms of to the client right so this is the same way we are we're going to handle rest of all also so let's go to uh get products also right so here here also we can just like grab this piece of code from here copy this one go to product controller and Here Also let's say try and here next error error and here also we can just put it that that thing right here but in this case what we are going to do let's say the similar way the similar way we we did right here I use con data will be our we and this interactor do get products right so here we need to provide the limit as well as so how we can do that so let's try to grab that the offset and limit now you can fairly assign that specific data like limit and offset so limit and offset perfect now this data we are going to return it from there right so now our controller is decoupled totally right so it is just like handing over all these things to our business logic layer right and use Cas layer and it is going to take care all the business rules right there in the get product or maybe the create product Etc so let's try to handle the last one also the update stock so again go here right let's grab all these things from here right copy and go to the Pro Controller add it right here again the tri catch right next next will be ER and here we can just put inside here this DB connection is not required these are the two things are required this is fine and we can we can just remove all these things let's try to comment it out at this this moment and right here const this is going to be like our data a wait the similar way this do interactor do update stock up that stock and then here there are two parameters are needed one is called ID this is already we are grabbing it here ID and second one will be our our body right so this body will be having our uh yeah this is a kind of number right so what we need to do we need to par our ENT I in right perfect now uh request body we can have this stock right this stock we can say stock right this stock we can just pass it right here then this data we are going to return it here as well as so can you see now now our controller is pretty clean right so here in the controller now you can see we have committed out couple of things like this one right or as an example this one so these are the third party staff or maybe external Library stuff we are not going to handle in the controller because controller and routes this is mean to be only for handling the HTTP request and response so all the validations all the uh if anything need to check right before signing to the business logic those are the things those are the operations only we will be performing right here in the controller and routes now let's move forward to One Step harder right so here in the interactor right so as you can see our this layer is ready this layer is ready and this layer also it's ready right and um the the framework layer exactly we have already been added here in the express right so it seems like our layers are ready but one thing is missing right here so what exactly missing it is if you go here in the interface you can see like this interactor right product interactor we need to add the business logic right to add the business logic what kind of what kind of operations we are going to do we are going to create the product right once you're going to create the product that product will be stored somewhere in the database as an example so what principal says principal says like independent of the Frameworks and independent of the database as well as right so in this case we should have to have the flexibility at any point of time while we are performing certain operation then we should supposed to able to swap the database as well as so let's try to do that right in that case what we are going to do we are going to create one more interface for that right so let's try to create one interface this is going to be like I product Repository repository. TS right I product repository interface we are going to add some code quickly perfect so our repository is ready so we have couple of FS here this is going to be like create update and find right so while we are creating a product we need to have a kind of input some of the input which can have like uh some name or maybe product description so in this case we are using the the product class right and promise also while we are creating that product it should have to return the product as well as right in the similar case for our update it is accepting the the ID and the stock and returning the product and final so the similar we are accepting two parameters limit and offset and it is returning kind of bunch of the product as a kind of form of array right so let's try to implement this I repository to our actual class right so in that case let's try to create one more directory uh inside source this is going to be our repository repositories and inside this repositories let's try to create file this is called like um product repository TS right so let's try to add some code quickly this is going to be like export class perfect so now our repository is ready let's try to implement this repository in our interactor let's go to product interactor here we are going to create one private varable just like we did in our our product controller right the similar way private this is going to be like repository will be our i product repository yeah this one and let's try to create one Constructor Constructor also will be having repository will be i product repository which is we will accept from outside and let's try to assign that specific parameter to our private variable right this um repository will be repository perfect so now now our our problem is solved right so while we are just creating our product then let's return this one this is going to be like async because we need to perform the database operation as synchronously right and here also right this is going to be like this do Repository then the create this is going to be like our input input right then update stock also this similar let's like add this one here this is will be our update update will be our ID and stock right and here also will be this is need to delete here also will be our right and this is going to be like great product repository fine right where we will pass our limit limit or offset perfect so now our interactor is ready right so while we'll be calling our controller then controller will call our uh interactor to create the product then this specific interactor will will call our repository and can you see like where while we are we're clicking on this create product and is going to this one only interactor only not to that specific interactor class right why because while we are creating the instance of that specific things you know that the the the interactor we don't care about like what kind of class it is it it may have real implementation or it may have a mock implementation we don't care only we care about like that specific class whatever we are going to use right here in the controller all right as a kind of instance that has to be Implement all those methods of the i product interactor all this pons if we can see like all these pons are implemented then we are fine right because the expectation will be while we are going to create the interactor that specific interactor has to create the product it may be from from this class or maybe some mock class or whatever it is let's go to the repository the product repository because so far we have implemented everything right in the in the repository level we have not done anything here right so now let's go to the product repository so let's try to create couple of things right here so first of all let's try to create one private variable private uh client and client will be a kind of pool that is that is it is already been declared right here in the DB connection can you see like this is a kind of pool right client as a kind of pool so this is what exactly needed right here in the database also here right so this pool what we are going to do uh we will say uh Constructor Constructor and here while our Constructor will going to be uh called at that time we will say this do client will be will be PG client right now let's try to add all this database query right here all right where we are going to create update and fine right so all those things we need to add it so let's go here in the X product controller right so here let's try to grab all these things all this query data from here copy it and add it right here right uh definitely we need to mark it as a kind of s sync and uh this one is not DB connection this is going to like this do client query right now this is our client query and this is not the body exactly this is going to be like data which is called Data data. name or maybe we can directly deconstruct all these things here this is called as an example uh name name and this will be our description description and price and stock perfect so these are the things we can just keep it from here to here stock stock right and once we are we are receiving the response then let's make sure we're returning it right return product dot rows zero right the the first one then the similar way we can do for our rest of all also right let's go ahead and copy all these things from here and let's grab it here this one is the G product right so pint here now Mark it Mark it as a sync I think and return products dot do rows right because it's not giving the auto complete here this is not DB connection this is going to be like our client now this autocomplete going to work I think yes this is cool but here we need to add offset right this limit and offset we need to add so first of all offset will be will be dollar one then limit will be dollar two so this two parameter we need to provide it the second parameter will be an array that is called um offset offset and limit perfect now our second query also ready now let's go ahead and grab the update one right so let's grab this one and copy and add it right here let's put it here and again we need to market the kind of a sync a sync and this is not DB connection this is going to be like client and this is exactly we need to provide it just like our first one is stock that is we are grabbing it from here second one will be our ID right and we need to return this one also this is called Product product. rows right zero now our repository is completely ready so we have created our client and we are performing all the queries according accordingly so now let's go here in the export control let's drop this one Del it perfect let's have a review exactly whole pipeline if anything is left right there so here in the express app we are calling the router so here it is giving error right so because we have not clearly created that specific things from here right while the the product interactor we are not created and we are not passing it here right that is we need to do and uh if you go here right this create product then it is this is calling like create product interactor right if you go to this product interactor here in product interactor here also one thing is missing that is called repository so here exactly this dependency injection it comes to the picture right which is going to help us to provide all this or inject all those dependencies whatever uh dependencies are needed to in order to perform that sting operation now here let's try to create all this dependencies so first of all the repository new product repository right then uh secondly uh we need to create our our interactor interactor will be new new um product interactor right and this new product interactor will be will be needed like uh some input that that has to be like I product repository so as you can see our repository if you go to repository it is already implemented i product repository interface so in this case if you go here right then if we assign this one it has to be uh perfectly kind of work right so let's try to pass this one repository perfect so it is saying like this as well like uh the repository is is also a kind of i product repository interface right then interactor so here in the product controller it is it is needed i product interactor right so in this case this interactor also the product interactor also it is implemented that uh I product interactor interface right so in this case it should have to work correctly right let's try to pass this one also interactor so now let's go ahead and try to spin our application right so I'm going here YN Dave our server is listening to Port 9,000 so in this case uh let's open that HTTP request. HTTP file right let's try to call this uh get products and can you see it is giving the error right it is as expected so if you go and see the console it is saying like the cannot read property of undefined interactor so why exactly this interactor is undefined because I'm going to close everything here right if you go to Route here so here in the router while we are calling this get products endpoint then it is reaching out to this get product functions from controller right so while it is reaching to this get products function right here and it is trying to reach to our interactor as well as so because so here in the Constructor is not getting called properly that's why the interactor is undefined right so to do that right what we need to do let's go ahead here we need to bind that specific controller with this funion right so let's try to add bind here bind our controller controller right the similar thing we are going to do with the other functions as well as so here right after that bind controller and here also bind controller perfect so now let's try to spin This Server once more let's go to request. HTTP here what we are going to do we are going to call that get product request send a request now can you see you can get whole bunch of products right even if you try to update this stock Also let's say I just want to make it 100 then if you call this one now this product is going to be 100 right perfect so now one more thing we need to test it out like this create product so let's try to send a request to the create product right send request it is giving error right so why exactly this it is giving error so it says like null value column description because here we are here our request is different and maybe we are accepting some kind of inputs are different right so let's try to check it out so here in the repository now we can see in the create product we are having a kind of different name which is called description right so if you go to interactor product interactor here and create product we are simply just passing that input right then input where exactly this is coming from this is coming from controller if you go to controller and controller you can see like we have a plan body right we have not done anything like uh the validation or maybe certain Keys all the stuff we have not done here right so in that case we are not going to add more code to add the validation logic right here and let's go to straightforward here in the sttp request let's put instead of the desk it'll be description right now it should have to work let's try to spin server once more and send a request now it is perfectly working now everything is working well so can you see like couple of things we have commented out the sending email and notify to the promotion service right so these are the two things are not belongs here in the product controller these are the two things what we can do we can add to our our interactor right in order to do that what we need to do we need to create a couple of more interfaces let's go ahead and create interfaces right here right so first one will be our IM mailer right IM mailer TS right so here let's try to add some code and here send email will be two will be string and product will be unknown product will be unknown right and this is going to be like Pro or maybe we can just leave it as it is all right something going to be returned from here right then one more interface we are going to create that is called uh message broker I TS so in this case in this case let's say export export interface imss broker this is going to be like capitalized right and here also we will say notify to promotion service let's say right this is going to be like product unknown right it will return something let's say so now our these two interfaces are ready so while we are going to be here in the product interactor here uh inside this Constructor we can just like add couple of more variables priv uh private variables let's try to add all those things right so private private mailer mailer will be I mailer I IM maer right so this is we need to import Quick Fix right IM mailer and uh one more thing we need to do like private uh private broker maybe broker will be I miss broker so these are the two things also we need to uh receive from the Constructor all right so let's try to do that so in this case mailer will be let's try to copy this these things from here right then then broker also we need to copy from here perfect then let's try to add this one this mailer it will be mailer and this broker will be broker right so now now we can fairly call all these things like while we are going to uh create our products where we can perform this operations let's say here and inside this create product let's say we are we going to receive the uh response from the product this is called cons data will be this repository. data then maybe we can we can do some check here just like um if the data doesn't like this thr some kind of error otherwise await this mailer send email to someone at. let's say right then data we are going to pass it from here then return the data from here right this this is going to be like a wait all right so while we're going to create the product then we will some do do some do some check six and after that uh send the email then return the data so this is going to happen from here now the similar thing for our update stock as well as so let's say uh cons data will be a wait all right and in this case let's say a wait a wait to this is going to be like uh I think I think this is going to be like from here right so we want to the product is created then we need to notify to our this one um wait wait this broker notify to the service going to be like data right the new new while we'll be going to create a new product then we will notify to the promotion service going to say like hey a new product is arrived here right so and so while we are going to update the stock then we are going to say to the owner like our stock has been updated right other return the data so now can you see these are these are the external libraries which is we are using right here right so we don't care about like what kind of mailer it is and what kind of message broker it is only thing we are care about like the mailer has to able to send the email right where we will be putting like this is two right where we will put like two to end product information similar thing about the message broker also we don't care about what kind of message broker we are going to implement in future let's say only only we we are care about this message broker has to notify to the promotion service right and while we are creating that message broker right that message broker has to implement this specific interface so this is how exactly it's not tightly coupled with with this uh interactor right it is only accepting the the interfaces like as an example for the repository as well as we don't care about the actual implementation of the repository it may be BR SQL it may be Oracle or it may be MySQL we don't care only we are care about that specific repository which is we are going to implement it may be mock or it may be static data or it may be connecting with the database only need to implement this specific interface so this is how it going to be work right now let's try to do that uh we are going to implement that specific uh the external libraries Also let's try to create One Directory here right new directory external libraries libraries so here we are going to create one uh pile that is called our mailer mailer do TS and one is called Mrs broker. TS right so here let's try to add some code quickly so this is our mailer class right which is going to implement the IM mailer right as a kind of interface and it is sending the email so here you can implement the S grid implementation as an example right send grid implementation right here inside the send email you can Implement your prate library to send the email right the similar thing for our message broker Also let's say export right calling Mrs broker so here you can implement what were your preate library so here as I said in the interactor it doesn't care about what kind of Library you are being used as a kind of external Library outside world it is only care about like while we are calling this broker it has to send that specific notify promotion service right so while we're calling that mailer it has to send the email so this is how it's going to work right so here on the route we have an issue right so what exactly the issue it is so because this interactor exactly it's expecting couple of more parameters Also let's try to create all this depend is here so cons mailer will be new new mailer right that is we have just created uh by here in external Library package this one right and you can see this implementing IM mailer so and I product and our product interactor exactly it's needed imer interface and IM Miss broker interface so in that case this is going to work and let's try to create one broker also new um Mrs broker right now we can Implement prob this one let's say this is going to be like mailer and Brooker Brooker Perfect all right so let's try to call our HTTP call from here right let's go ahead and click on the get get product yeah it is is working correctly let's open the console and here we are going to update the stock right let's try to update the stock this is going to be like 50 and and send a request can you see sending email is going getting call even if we supposed to create the product also it is going to be called can you see it's calling message broker this is how it is working all right so this is really cool right so now let's come to the testing part so I'm not going to write any kind of test cases but I'm going to explain how exactly this whole thing is going to work as it said in the clean architecture principle each and every layer has to be uh testable even it may be repository it may be maybe entity or it may be anything right so in that case how we can test it out you can see while our use case layers are created you know then only we can pass it all this type of the interfaces right the product repository or maybe mailer or maybe message broker so here you can you can directly instantiate that specific class to your test file right and you can pass any type of the D Mo repository right here to test it out your your whole layer so you no need to climb right here in the the controller in order to uh test that specific business logic only thing we need to test it out while we creating the the product then it has to respond to that specific response just like providing some kind of the product expectation and Etc that specific things already we have been covered in our previous episode in the tdd uh test demand development using the NOS also and we have tested each and every layer right there right now you can see with the help of the clean architecture we have achieved a lot of flexibility we can we can any at any time we can replace this Express framework with with something else at any time we can change our database to something else at anytime we can change our external libraries also we decide something else right so one last thing we can do it right here these are the things we have created manually right so we can use some kind of library to use a good quality of inversion of control and dependency injection Etc so let's try to do that so in that case what we are going to do we're going to uh use some kind of library that is called yarn at reple metadata and inv verify and in inv verify right perfect so now let's try to implement that so first thing we need to do let's go to here in index. tsp here right here on the top of the file we'll try to import import um reflect refle metadata we don't need anything from here this is called like import only yeah this is perfect now let's go here in the routes right here inside the routes product routes and we are going to get rid of all these things from here right and and these are the things also we are going to get read right so let's try to keep it like this way what we are going to do we are going to create one container cons container will be our new new container this will become from invers ify right in the container we need to bind our all the services all the interfaces right so in that case let's go ahead here create a directory here right let's try to create a directory that is called utils utils and inside utils I'm going to create one pile that is called uh index.ts right one more file let's try to create that is called cons. TS or maybe app cons all the constant we can keep it right here right the TS and let's try to export this one export start from App const here inside the appc const we are going to add a couple of things right so so here inside the app constant right let's try to add something this is going to like export con and and you might have thinking like why exactly these things are needed right so these things are needed in order to uh bind our dependency with the container right and we are using symbol for symbol for will be return a kind of symbol object from a global symbol registry right matching by given key if pound otherwise it will return kind of new symbol for this key right so this is how the symbol for is going to work so let's try to remove all these things because these are these are not make sense for us only we need just like the key and value right and now let's go here in the product routes here we need to bind all the dependencies with the container all right so let's try to bind that one container right bind right so bind what exactly it's needed it is needed some kind of the identifier those identifier already we have been added right here can see as a key value right so let's try to get all those things but before that we need to pass kind of type also because we are only interested in the interfaces not the instance directly that the specific class right so in that case let's say I product a repository and here we can say interface type right so what type of interface it is like product repository and two to whom exactly because this interface is perfectly fine but but to whom because we have just created that repository from that specific interface right so this things exactly we need to bind it right here to two right so in that case let's say product repository repository class now our container will be bind certain interface with our certain class right here right now let's go ahead and Implement rest of all right one last thing we need to do that is we need to bind with our controller as well as so let's bind that one container bind so in this case interface type interface type will be our controller product controller and two like um product controller right so now everything is binded so we have bind our controller also but here it is showing the error right because this controller it's it's it says like controller not pound so in that case what we need to do we need to grab our controller instance also right how we can grab it let's try to grab it from our container const controller will be container doget and interface type here we need to say like a product controller but can you see like this is unknown right because it's not going to be comply it doesn't have this methods how we can we can get that specific type by passing that specific type interface right here right that is going to be like say product controller right so now everything is everything is working as expected right so now everything is cool so we have replac our manual uh the dependency injection with invers ify you can go ahead and check it out the invers ify documentation and to how exactly we can achieve all these dependency injections right but one more thing we are we are missing right here that is we need to take care first of all um in order to work with this dependency we need to mark all the classes uh which is going to be like inject table all right so uh let's try to mark this repository one first all right we is call uh inject table right but it is complaining right why because we need to enable something in our TS config file Also let's go here and and you can say um experimental decorator experimental decorator let's try to enable this one right now perfect let's try to save it and you can see like this error has gone right the similar way whatever we are going to use as a kind of dependency injection all those class we need to mark it as a kind of uh inject table all right that is we need to do so let's go ahead here in in the interactor also product interactor also here also we need to make it as a kind of inject table right perfect now in the external libraries also we need to mark it a kind of inject table here as well as inject table right and this is the thing we need to do in Miss Mrs broker as well as right let's try to import it cool now we have marked all the dependencies as an inject table right now still couple of things we need to take care the first thing is if you go here in the the Repository right we can see like our Constructor is using some kind of library that is perfectly fine but for uh interactor if you can see in the product interactor these are the things we are we are manually passing right so this is not going to be work like this right so how how we can replace all this things so those are the things exactly it's going to work just like we have added couple of identifier right here in app constant so with the help of this one we can we can refactor this this piece of code right so let's try to do that so before this one we can say like Ina Ina Ina and here we need to Define like what type of repository it is right let's say interface type this is going to be like our product repository right this is product repository repository is i product repository and here also we need to do the same right so let's try to copy this one with the this is going to be like a mailer mail and this is going to be like broker Mage broker perfect so now this is perfect right so let's try to check it out where what are the other places are there I think in the controller right the controller also we are receiving this product interactor so this is also we need to mark it something like this way so here let's try to import this one verify and here also we need to mark it injectable and in inject table right and this is going to be like this is also we need to import right let's try to import and here this is going to be like our uh product interactor cool now I think everything is cool so let's try to spin our application uh we will check it out like whether uh everything is going well or not right but before that let's try to remove all this commanded out code so at least we should have to be clean let's try to uh run the application yarn Dave perfect so now it is running correctly right so let's try to hit our end points going to close all let's go here in the request. HTTP let's try to get the data wow cool perfectly able to get the data right even we can update the stock as well as it is working and we can able to create the product as well as so now I hope you got a clear understanding of how this clean architecture is working and what is the beauty of the clean architecture I hope you have enjoyed this video tutorial if you like it please hit the like button and if you have not subscribed to my channel subscribe it right now because I'm going to put a lot of useful tutorial in coming days and in the next episode we are going to work on our pisma integration so in this clean architecture we have just achieved whatever we are just try to ACH through out of our pipeline right you can see like know these are the pipelines we have covered and we are hoping for like within shortly we will be able to cover it off rest of all the pending episodes as well as right all right then see you in another episode bye-bye
Info
Channel: Code with Jay
Views: 10,165
Rating: undefined out of 5
Keywords: how to use clean architecture, what is clean architecture, how clean architecture works, clean architecture practical, solid principal in nodejs, clean code in node.js, how to write clean code in node.js, how to write clean code?, node.js clean code example, clean code using node.js, clean architecture project example, clean architecture example, hexagone architecture in node.js, onion architecture in node.js, understand clean architecture, Clean architecture with nodeJs express
Id: nPsLL2OYJ-4
Channel Id: undefined
Length: 51min 27sec (3087 seconds)
Published: Sat Dec 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.