E1: Clean Architecture in Next.js

Поделиться
HTML-код
  • Опубликовано: 22 ноя 2024

Комментарии • 125

  • @nikolovlazar
    @nikolovlazar  2 месяца назад +2

    This live stream series is A LOT, so I distilled everything we learned + built a proper demo app that's open source into a 53 minute tutorial: ruclips.net/video/jJVAla0dWJo/видео.html

  • @matyascsoti4400
    @matyascsoti4400 4 месяца назад +26

    My dude, i am a self taught junior developer and whilst i can write clean code, after 2 years now i realized how our apps we / i am working on have 0 architecture, 0 high level thought, and they are a complete mess on this level and the problems they bring. And it seems my peers are absolutely oblivious to this as they did not signal this and also we never had an 'architectural discussion' ( if that is even something happening at other places :D ), and as such i have no direct peer to learn from. So these kind of videos are gems inside the superficial hello world application videos most of youtube is filled with.

  • @nikolovlazar
    @nikolovlazar  4 месяца назад +15

    Woah this series took off! I'm happy you all like it! Hope you enjoy this series, and don't forget to subscribe to get notified when I post more content! Thank you all 💖

    • @NaniwaRocky
      @NaniwaRocky 4 месяца назад

      I was looking for a nextjs clean architecture in-depth setup, i really appreciate this series I will check it out thanks to youtube algo. A small suggestion would be adding chapters to your live streams after they're done. Thanks a bunch!

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      @@NaniwaRocky Thanks for the suggestion, and I'm glad you liked it! I'll look into adding chapters, but nevertheless, there's going to be a proper RUclips course on how to achieve this, and it won't be HOURS of content 😅

  • @ahmedjaber8595
    @ahmedjaber8595 4 месяца назад +45

    From web dev cody ✌️

  • @gadgetboyplaysmc
    @gadgetboyplaysmc 4 месяца назад +10

    No one usually talks about this. Thanks man! I don't use Next anymore, but love learning architecture and DDD in general.

    • @dragosbur
      @dragosbur 4 месяца назад

      What do you use? 😎

  • @tconroy
    @tconroy 3 месяца назад +1

    Just so you know for the future: when passing arguments to constructors in TS, you can automatically assign them to properties on the class with a syntax like `constructor(private id: string) {}` -- that way you don't have to repeat both the property definition and the assignment.

    • @nikolovlazar
      @nikolovlazar  3 месяца назад

      Oh I did actually type them like that. A person in the chat reminded me. Thanks for the suggestion!

  • @kristian970
    @kristian970 2 месяца назад +1

    Thank you for that stream!

  • @BibhuBal
    @BibhuBal 2 месяца назад

    Your are just Professor Dumbledor form Harry Porter . Deep , Clean and Clear

  • @FuzzyAnkles
    @FuzzyAnkles 4 месяца назад +3

    Thats pretty cool video. Would be nice to have github repo to check how things are built. That would help a lot.

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +4

      Thanks! I'll publish a demo project that implements everything we'd go through in this stream, plus a more polished proper RUclips tutorial that's shorter than the live streams 😁

  • @kiransilwal
    @kiransilwal 2 месяца назад

    1:35:48 Effect looks good. Is it just like Promise from fp-ts? I found that way of error handling easy and light weight.

    • @nikolovlazar
      @nikolovlazar  2 месяца назад

      It does look like it has a bit of learning curve, but I do think it's a really cool library!

  • @freshu2334
    @freshu2334 4 месяца назад +2

    Great stuff, would be awesome to have a demo repository with this architecture approach example :)

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +4

      There will be. As soon as I'm done figuring things out (this stream is me figuring things out) I plan on recording a proper RUclips tutorial that's shorter than the live streams and also publish a demo repository as well!

  • @RockCYP
    @RockCYP 4 месяца назад +3

    Just started watching this, great topic to dive into btw. Just wanted to say I am not a huge fan of not using a test database because the mock data can become stale, where as a test database should always be 1:1 with the dev schema at least. Would love some opinions though.

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      This would be an interesting problem to figure out. Curious to hear how would you set up testing with a database. What I'm thinking of is spinning up a docker compose config that sets up a pre-seeded db alongside the tests service and tear it down once the testing is done. I'm not 100% sure how would I set up the tearing down trigger though, but it could be cool to play around with that. How would you set this up?

    • @chenrvn
      @chenrvn 4 месяца назад +1

      ​@@nikolovlazarsound interesting.
      I think there is several level of testing abstraction and it might suitable for kinda mock e2e test.
      I belive that maintainability for the test is very important

  • @ynspc
    @ynspc 3 месяца назад

    That keyboard loved it. :D

  • @anuragraou
    @anuragraou 4 месяца назад +1

    Very cool video. I had a doubt, you talk about the persistence layer taking a input and giving an output without authorization, Can a user just bypass the Bussiness Layer and directly call the persistence layer because I can track the requests using the networks tab in developer options?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      A user can't bypass the business layer because the only touch point with the backend is the route handler (or server action). A developer can bypass the business layer and directly use the persistence APIs, but there's nothing you can do to prevent that (maybe you could with a monorepo and a good dependency config).

  • @ProgrammingwithUmair321
    @ProgrammingwithUmair321 4 месяца назад +2

    Great session man. I like your keyboard setup too 🔥😃

  • @gamingwolf3385
    @gamingwolf3385 4 месяца назад +4

    Bro , you are amazing keep going , this series is what we really need , javascript ecosystem is not clean hhh or we don't know how to organize things , not like c# devs

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      Thank you! Let's change that! 😁

    • @gamingwolf3385
      @gamingwolf3385 4 месяца назад

      Bro i start learning c# , can you suggest some resources ? In a clean architecture way ​@@nikolovlazar

    • @gamingwolf3385
      @gamingwolf3385 4 месяца назад

      Bro , can you explain clean architecture in c# , i started learning c# , its a beautiful language
      Thank you 😁

  • @jeffedmo2218
    @jeffedmo2218 4 месяца назад +1

    Absoluetly love this. Thank you. Any chance of getting a neovim / tmux / terminal setup video?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +3

      I did start to put together some content on Neovim. It will be fun creating a video on my neovim setup and workflow.

  • @nitindevatraj
    @nitindevatraj 3 месяца назад

    We need more stuff like this, ❤

  • @kiransilwal
    @kiransilwal 2 месяца назад

    My only question is on generating nanoid. In the repository layer we are tightly coupling our persistence/data layers with a package. Please correct me if I am wrong, wouldn’t it be better if we pass that package through the constructor as a service so that it is not tightly coupled to the library?

    • @nikolovlazar
      @nikolovlazar  2 месяца назад

      It’s perfectly fine that the repository implements specific libraries. Nanoid could additionally be isolated in its own service, but I deemed it might be an overkill for this scenario.

  • @Luisllaboj19
    @Luisllaboj19 4 месяца назад +3

    Hi, for the error handling do you usually throw errors in every layer? Where do you catch them, do you wrap the top level layer in try{}catch{} block or do you let nextjs take care of rendering the error page fallback?
    Error handling seems so subjective :C
    Great video btw it's so nice to see other people struggling in live session coding because all tutorias make it look like it's clean and perfect all the time lol

    • @rithalius8219
      @rithalius8219 4 месяца назад +1

      I would like to have the answer of this question. I am also having trouble handling errors. Did you find the optimum solution to this or close to optimum?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +2

      We’ll try to figure that out in the next stream (today!). I’m going to be setting up Sentry in this project, so every non-catched (and even some catched ones) will end up being sent to Sentry. When it comes to handling them, I found that services should throw, but actions should return objects so the UI can provide feedback to the user.

    • @Luisllaboj19
      @Luisllaboj19 4 месяца назад

      @@nikolovlazar Yes, and I assume that the persistance/db layer throws errors under the supabase api when anything out of the normal happens. Also makes sense actions return an object, and in that case, do you make sure every time you return the same shape of object like follwing a contract with discriminate unions or something of the style? Thank you, looking forward the next stream! This has been very insightful!

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      @@Luisllaboj19 Yep! The "zsa" package allows us to define the output just as like we define the input. I do have an example for this that I will showcase at the very beginning of the stream today.

  • @jss_developer
    @jss_developer 3 месяца назад

    I definitely see the value in this, but for my new MVP this might be an overkill atm, but once its launched and others start working with me then this would make absolute sense, less files edited, more concise folder structures. this makes sense actually. Ill need to take some time to organize it like this.

    • @nikolovlazar
      @nikolovlazar  3 месяца назад

      I also think that's the way to go. If you're starting a new project from zero, don't pay too much attention to this until you reach MVP state, or have validated the idea. Once things get serious, or other people join the project, it's definitely a good idea to establish either CA or a similar architecture so everyone's "talking" the same language. Even code reviews are faster when everyone writes code in a common predictable way. Not to mention, but debugging is faster as well. You'll know where you need to look at.

  • @bwest-dev6241
    @bwest-dev6241 2 месяца назад

    Hi, thanks for the great tutorial and series. Really enjoying it. Small problem I had watching was would have been nice if it was from scratch so we (i could code along) as you explained things. like the structure, creating of some of those files, but I still enjoyed it. h

    • @nikolovlazar
      @nikolovlazar  2 месяца назад

      Glad you enjoyed it! I do have a more concentrated tutorial that you can check out here: ruclips.net/video/jJVAla0dWJo/видео.html this one too doesn’t cover starting from scratch, but it’s showcasing clean architecture on top of a smaller GitHub project.

  • @piyushacharya7696
    @piyushacharya7696 4 месяца назад +1

    Hey man, how did you achieve such smooth scrolling in your Neovim? Is it because of the Kitty terminal? Please share.

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      It's probably the quick repeat effect: github.com/nikolovlazar/dotfiles/blob/main/.zshrc#L52-L55

    • @piyushacharya7696
      @piyushacharya7696 4 месяца назад +1

      @@nikolovlazar Wowww! Thank you so much. You don't know how much I love this change. I did change it through the system settings, though.

  • @jiachen1078
    @jiachen1078 2 месяца назад

    thank you!

  • @Deus-lo-Vuilt
    @Deus-lo-Vuilt 4 месяца назад

    I came to review concepts, hopefully later we can see a complete auth system with the backend and frontend to see the entire flow with architecture, how to handle everything with jwt and so on.

    • @nikolovlazar
      @nikolovlazar  3 месяца назад +2

      Yes the course that I plan to release will use either next-auth or lucia, not Supabase.

    • @Deus-lo-Vuilt
      @Deus-lo-Vuilt 3 месяца назад +1

      @@nikolovlazar thanks

  • @김인욱-u5q
    @김인욱-u5q 2 месяца назад

    Could you please let me know why you are calling const supabase = createClient() for each function?

    • @nikolovlazar
      @nikolovlazar  2 месяца назад

      I had to because creating it once in the constructor didn't take into consideration the session for each request. Maybe there is a way to only "refresh" or "reload" the session from the request, I just didn't look into it. But that's the reason.

  • @jonasj2627
    @jonasj2627 4 месяца назад

    What do you think about using row level security?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      I like the concept, but I still don't understand them fully. I need to spend some more time playing around with RLS. Any tips? 😁

  • @SajidAliSoftwareEngineer
    @SajidAliSoftwareEngineer 4 месяца назад +2

    niece session. you nicely teach.

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      Thank you Sajid! Glad you liked it!

  • @Mari_Selalu_Berbuat_Kebaikan
    @Mari_Selalu_Berbuat_Kebaikan 4 месяца назад +2

    Let's always do alot of good

  • @SajidAliSoftwareEngineer
    @SajidAliSoftwareEngineer 4 месяца назад +3

    what settings you are using for neovim can you please share your neovim config

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      Of course! Here's my dotfiles repo: github.com/nikolovlazar/dotfiles

  • @hello19286
    @hello19286 4 месяца назад

    I might have missed it in the video, but how do you plan on setting up/instantiating your services in page.tsx files and any other location that is not a server action? I did something similar to this on a vite-react project where I created a provider and had a hook that returned my services, but that's not really an option in server components.

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      We’re yet need to think about this.

  • @w3mw
    @w3mw 4 месяца назад

    What keyboard are you using? :D
    Will you create a video about neovim how to install it and with your config? :D

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      It's the ZSA Voyager. It has been requested previously, so I might end up making a video on how I achieved this setup and what goes into it.

  • @ray941644
    @ray941644 4 месяца назад +2

    Subbed!! Came here from WDC 😊

  • @chenrvn
    @chenrvn 4 месяца назад

    @nikolovlazar it will be very intersting to implement the Hexagonal (Ports and Adapters) architecture on Next.js :)
    do you maybe have a plan to do that?
    Thanks, Men!
    appreciate your excellent work!!

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      Thanks! I don't have plans to do that, but it would be interesting. I was planning on doing this CA series and then move on to deploying the newly refactored Next.js app on Hetzner with Docker, and the whole setup with CI/CD, creating Docker images etc...

    • @chenrvn
      @chenrvn 4 месяца назад

      BTW where do you put hooks in which layers?

  • @KrishnaList
    @KrishnaList Месяц назад

    Also make projects using DDD CQRS Event driven architecture

    • @nikolovlazar
      @nikolovlazar  Месяц назад

      Exploring DDD on this channel would be cool. Thanks for the feedback!

  • @Deus-lo-Vuilt
    @Deus-lo-Vuilt 4 месяца назад

    Thanks :3

  • @SajidAliSoftwareEngineer
    @SajidAliSoftwareEngineer 4 месяца назад +1

    I also like I prefix for interface. basically I am dotnet software engineer.

  • @JPORTES
    @JPORTES 4 месяца назад

    Hello! I LOVED YOUR KEYBOARD! what is the model?

  • @Tapadar.Monsur
    @Tapadar.Monsur 4 месяца назад +1

    Lazar, what code editor and theme are you using??

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      It’s Neovim, running within Kitty! Check out my config:
      github.com/nikolovlazar/dotfiles

    • @rahulprasad3575
      @rahulprasad3575 4 месяца назад

      @@nikolovlazar how can i apply the same theme as yours from the dot files?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      @@rahulprasad3575 It's a combination of Kitty config and Neovim config. Kitty's theme defines the background and everything outside of Neovim. Neovim only defines the syntax highlight colors, the contrast, etc...
      Kitty theme config: github.com/nikolovlazar/dotfiles/blob/main/.config/kitty/cyberdream.conf (mind the background - it's in the repo)
      Neovim theme config:
      github.com/nikolovlazar/dotfiles/blob/main/.config/nvim/lua/plugins/colorscheme.lua

  • @SajidAliSoftwareEngineer
    @SajidAliSoftwareEngineer 4 месяца назад +2

    where I can find your code repository

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +2

      This project is still close-sourced, but I do plan on making a proper, a more polished RUclips video with a demo project where I go through the same refactoring steps that I'll do in this series. That demo project will be minimal and contain only the relevant parts for the lesson, so it's going to be much cleaner and easier to understand. I'll post the video with the project on my channel, so keep an eye on it! 😁

    • @ftacapa
      @ftacapa 4 месяца назад

      @@nikolovlazar I'm waiting for that tutorial, I would love to learn how to implement this clean architecture with server actions in next js, great content ✨

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      Thanks 🙏

  • @HadesGodAum
    @HadesGodAum 4 месяца назад

    What is the book that you open along with?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      Oh those are just my notes for the stream 😅 it's a plain notebook

  • @kesar
    @kesar 4 месяца назад

    is there any gh repo w the final code?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      No repo yet. This series is me figuring stuff out together with y'all, but I do plan on releasing a more polished, proper RUclips tutorial that's not N-hours long and that uses a demo project created specifically for it. That demo project will be open source.

  • @tharindudarshana6480
    @tharindudarshana6480 4 месяца назад +2

    No relying on underlying implementation is called abstraction - ruclips.net/video/BaUsKK6AX5Q/видео.html - its a fundamental concept in Software engineering. To make a more sense, your car is a better example, you don't need to know anything about how it works just to drive and use it for your needs 🤫

  • @okkashaally2115
    @okkashaally2115 3 месяца назад

    Please create your development environment setup series

    • @nikolovlazar
      @nikolovlazar  3 месяца назад

      My Neovim setup? A few more folks have requested it as well, so I’ll definitely record a video on it!

    • @okkashaally2115
      @okkashaally2115 3 месяца назад

      @@nikolovlazar yes for sure, and some more NextJS software tutorials right now you just have one the card, but we'd love a software as this one from scratch.

    • @nikolovlazar
      @nikolovlazar  3 месяца назад

      Not sure if you've seen it, but I published a video on my dev environment setup a couple of days ago: ruclips.net/video/G7-qUMKSH_Y/видео.html

  • @okkashaally2115
    @okkashaally2115 3 месяца назад +1

    Please create you development environment setup series

    • @nikolovlazar
      @nikolovlazar  3 месяца назад

      Will do! A number of people have already requested that. I'll definitely publish a video on my dev environment. Keep an eye on my channel for it!

  • @devflo
    @devflo 4 месяца назад +1

    Also from web dev cody

  • @sebastianflajszer6969
    @sebastianflajszer6969 4 месяца назад +1

    I am just watching this moment 1:25:48 , so maybe you've changed it later, but with typescript you can create a constructor like this
    constructor(private test: number) {}
    and it will automatically create a private property and assign the value to it :)

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      Oh nice! Thanks for the tip, Sebastian!

  • @ogbillity
    @ogbillity 4 месяца назад +1

    Thank you so much. Can you share the source code.

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      You're welcome! This project will most likely remain close sourced, but I'll be creating a different one (much simpler one) after this streaming series to showcase the architecture. I also plan on publishing a proper, more polished RUclips video on this topic that will use the demo project, so make sure to keep an eye on my channel!

    • @NickHamilton88
      @NickHamilton88 4 месяца назад +1

      @@nikolovlazarnice that would be helpful

  • @SrdjanRakic-y8u
    @SrdjanRakic-y8u 24 дня назад

    Hey man are you from balkan originally? :D

    • @nikolovlazar
      @nikolovlazar  24 дня назад

      Hey Srdjane! Yes I am 😁 I’m from Macedonia, but moved to Canada last year.

    • @SrdjanRakic-y8u
      @SrdjanRakic-y8u 23 дня назад

      @@nikolovlazar Very nice, also very nice videos and content! Did you find a job and company helped you move?

    • @nikolovlazar
      @nikolovlazar  23 дня назад

      Thanks! Yeah Sentry took care of my move.

  • @iykazorji8171
    @iykazorji8171 4 месяца назад

    What keyboards are those?!

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      It’s the ZSA Voyager!

    • @iykazorji8171
      @iykazorji8171 4 месяца назад

      @@nikolovlazar Oh it's the same I have just looked curved in the video!

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      @@iykazorji8171 I've attached a couple of phone holders below it so I can bring it to a 30 degree angle 😁 Here's how it looks like: www.reddit.com/r/zsaVoyager/comments/1dmrl4d/comment/l9xvmx1/

    • @iykazorji8171
      @iykazorji8171 4 месяца назад

      @@nikolovlazar Ah, thanks! Gonna try this out!

  • @repinor
    @repinor 4 месяца назад +1

    Min 3:16.. There are very important concepts that you are just misunderstanding. Layers is a different pattern. Just check!. Maybe DDD theory would help you understand much better the graphic that depicts Clear Architecture.Actually, the architecture you depicted is Classic Layers.

    • @chenrvn
      @chenrvn 4 месяца назад

      @@repinor I understand your point but keep in mind that you can look any archetcture such: Hexegonial, clean, onion as some layering archetcture.
      In general the most important thing is the separation and dependency.

    • @repinor
      @repinor 4 месяца назад

      @@chenrvn Indeed,, I agree that you should use design principles independly of what architecture style you use, however the approach it’s being explained here is conceptually wrong. You can not think DB and Web and Devices are in the same layer, even they could be “outside” they have complete level of visibility. Hexagonal Architecture and clean Architecture in my opinion are like a kind of composable architecture in which there are levels of privacy and visibility that plays a very clear role along the solution. My point is, you should use design principles like SOLID, DRY, KISS, YAGNI, OO principles, etc, but you can not confuse design principles with architectural styles. In my opinion the way Clean Architecture is approached here is being confused with Layers.

    • @repinor
      @repinor 4 месяца назад +1

      @@chenrvnBut, what is wrong with Layers? 1. Promotes Database Driven Design. 2. Hides use cases. 3.Makes parallel work difficult, 4. Grows hard to Test and I’d say that it’s prone to shortcuts. In the long run, it will happen, because, you know the speed of the business.

    • @chenrvn
      @chenrvn 4 месяца назад +1

      @@repinor it's a great concepts.
      I just say that you can think of clean architcture also as a "layer" archetcture. It depend how you determine it.
      All what you mention above is an excellent and proved concepts :-)

  • @gadgetboyplaysmc
    @gadgetboyplaysmc 4 месяца назад

    My toxic trait is thinking I could recreate your theme on Neovim lmao. It looks really fukin good but I remember spending weeks on mine and still turning out crap and made me 10x less productive.

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      Go steal it! github.com/nikolovlazar/dotfiles

  • @Cyber_Lanka
    @Cyber_Lanka 4 месяца назад +1

    Nice video. But this is over complicated for most projects

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +2

      You definitely shouldn't do this for every project, but as your project grows into complexity you'll find yourself needing to implement something like this.

  • @HarisMladenov-il7pf
    @HarisMladenov-il7pf 4 месяца назад

    Are you Bulgarian?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      Nope, close 😁 I’m Macedonian. Pozdrav neighbour! 🙌