How I structure my next.js applications

How I structure my next.js applications

Web Dev Cody

3 дня назад

13,842 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@kelvinxg6754
@kelvinxg6754 - 18.06.2024 18:29

Welcome back brother

Ответить
@Its-InderjeetSinghGill
@Its-InderjeetSinghGill - 18.06.2024 18:29

Bro you looking -10 year from your age😂

Ответить
@flnnx
@flnnx - 18.06.2024 18:44

This is how we learned to build NodeJS apps a few years ago in the bootcamp I attended. You actually made me realize how I incorporated some of it into NextJS haha.

I do the rate-limit part in the global middleware and the Auth + user Input checks within the server actions. I treat the server actions like a small middleware that checks if everything is correct before passing the data down to the business layer.

My use-cases/business layer is basically also a persistence layer, but it's actually a good idea to separate them. It seems much more maintainable and scalable for larger projects, though it might be overkill for smaller ones.. I'll definitely give it a shot and refactor some of my projects.

Ответить
@stefano8840
@stefano8840 - 18.06.2024 18:49

Did you stop using Convex?

Ответить
@jazzdestructor
@jazzdestructor - 18.06.2024 19:11

RIP the beard (though shall be missed 🧔‍♂)............... also just wanted to know if you have a common component just for a particular section of files/folders how do you handle that? add it in common components or make a common components directory for that section itself?

Ответить
@5353055
@5353055 - 18.06.2024 19:20

how about using ddd

Ответить
@parkerrex
@parkerrex - 18.06.2024 20:26

🔥

Ответить
@gamingwolf3385
@gamingwolf3385 - 18.06.2024 20:40

Hello devCody , this video really helps me
For next video , can you explain error handling with drizzle orm ?
I am using drizzle orm and postgres-js , and sometimes when i enter duplicate data on unique fields , wow new error and i don't know how to handle it

Ответить
@miGuHD
@miGuHD - 18.06.2024 20:42

Dad, why did you shave 😭

Ответить
@Danon2001
@Danon2001 - 18.06.2024 20:57

I'm wondering what about the Dependency Injection. Let's consider the simple use case of having option to connect different DBs. Let's say at the start I will need to use Drizzle, but later I need to switch to Postgress. In such a scenario, I would create a class that takes different DBs and provides simple methods for updating, querying or deleting. Then I could use that class in Persistence layer and provide another abstraction with the methods usch us updateGroupById, etc. Would that class be in the persistence layer or where would you guys put that?

Ответить
@yassinesafraoui
@yassinesafraoui - 18.06.2024 21:41

The way you write server actions is very similar to how actions/queries/mutations are written in convex, interesting 👍

Ответить
@shahzaibshahzaibkhan6480
@shahzaibshahzaibkhan6480 - 18.06.2024 21:50

This approach is great, but how the hell do you get anything done with all that mental overhead 😵?

Ответить
@yassinesafraoui
@yassinesafraoui - 18.06.2024 21:58

This is very very very helpful, thanks!

Ответить
@emmanuelezeagwula7436
@emmanuelezeagwula7436 - 18.06.2024 23:14

I never thought of using Server actions in this fashion, I always thought that it was for forms

Ответить
@JoseWaldier
@JoseWaldier - 18.06.2024 23:43

what keyboard do you use god cody?

Ответить
@JohnCanCode
@JohnCanCode - 18.06.2024 23:45

Cool vid, would like to see more on the entities and maybe services, ie would payment service be similar to db repository?

Ответить
@funkdefied1
@funkdefied1 - 19.06.2024 00:17

I’m loving Supabase right now. The business layer fits in really well with Postgres functions and edge functions.

Ответить
@michaelvik870
@michaelvik870 - 19.06.2024 00:54

this is useful stuff. Thanks for the video, cody!

Ответить
@Luisllaboj19
@Luisllaboj19 - 19.06.2024 03:13

Next.js reccomends having a data-access layer where you make the checks for accessing the data. In your way of architecting your apps I assume that's the "data-access" folder, does that include checks for auth and authorization at all? Or you're trusting the layer above it to do those checks? why if i call (by accident) one of the exported functions from the "data-access" folder directly?

Ответить
@maddada
@maddada - 19.06.2024 03:49

Really liked this. I feel Nextjs is overly complicated for the apps that I'm working on currently, so I'm sticking with bun + vite, which is very fast and stable. So hope you do some content for that too :)

Ответить
@juanofdark
@juanofdark - 19.06.2024 05:13

Hey! Nice video! Can you Tello me the name of the theme? Please!!

Ответить
@truth8690
@truth8690 - 19.06.2024 06:48

How does the architecture change when using external APIs instead of the built-in Next.js API routes?

Ответить
@ByteBound
@ByteBound - 19.06.2024 06:56

Valuable content 🙏 Thanks for sharing

Ответить
@jonasj2627
@jonasj2627 - 19.06.2024 09:09

Hey, does anyone have experience using this architecture with Supabase? I'm not sure how to use proper types. I just don't understand how Supabase wants us to create types.

I also have a question about joins. Should I create data access functions like getApplicationsWithProfile, or should I call two functions when I need an application and a profile separately?

Ответить
@yanzhang3462
@yanzhang3462 - 19.06.2024 11:11

老师 很牛逼

Ответить
@omomer3506
@omomer3506 - 19.06.2024 11:39

Is there a way to download all your knowledge, asking for a friend.... that friend is me... i am that friend

I once had to replace my firebase with cloudinary cuz it was freaking slow, and was glad i abstracted, cuz all i had to fo was a few tweaks and write the query once

Ответить
@kamranaslam4230
@kamranaslam4230 - 19.06.2024 11:56

Your work is exceptional. I am inspired by your videos and the fresh insights I gain from them. It makes me wonder if there's something new I may have overlooked. It would be great if you start adding unit tests as well. Keep up the great work.

Ответить
@georgemwaniki
@georgemwaniki - 19.06.2024 11:59

We need more videos like this, coding tutorials are everywhere but no one is teaching architecture specific to a framework, i usually struggle to decide what goes where, great video

Ответить
@ShivGamer
@ShivGamer - 19.06.2024 12:11

Amazing Video 😊

Ответить
@raphauy
@raphauy - 19.06.2024 16:24

Hi, I use a very similar structure, except for some projects that I want to advance quickly, I unify the business layer with the persistence layer, but the separation of the view/controller layer is always there, it is super important. I communicate them with DAO objects.

Ответить
@guy-dk9cy
@guy-dk9cy - 19.06.2024 16:45

Amazing!!
can you add a second part to the video how you decide what files should have try, catch ? what files shouldn't have it and just throw errors ?
how toast work with actions ? and maybe a user auth with custom jwt and not using clerk ?
also, how can we use webhooks with this architecture? and 3rd party integrations.

Ответить
@dcmbassi
@dcmbassi - 19.06.2024 19:06

Colocation makes the most sense. I don't know why I didn't think to apply this to server actions. Great video.

Ответить
@zindev
@zindev - 19.06.2024 22:07

zsa > next-safe-actions?

Ответить
@ahmedbg91
@ahmedbg91 - 19.06.2024 22:32

Hey there, great video! Glad to see that we have a very similar approach. I've been trying to figure out myself when fetching data in server components. I've been checking if the user is authenticated before fetching, but here's what I'm thinking: if the page is protected and the user has to be authenticated for the page and the component to render, the fetch call will never be made by an unauthenticated user, right? So, it's automatically protected. But i still do it anyway.

Ответить
@congminhluu5068
@congminhluu5068 - 19.06.2024 23:11

While yes we needed to make abstractions where needed and it's important to have a clear architecture your team can get behind, make it where it makes sense and don't base it solely on Clean Code.

That is a 2008 book with a lot of outdated practice.

Search for qntm clean on google

Ответить
@nasko235679
@nasko235679 - 19.06.2024 23:50

I have a question regarding server actions. So as far as I understand it you're using server actions mostly for writing to the database (which is logical since they are all POST requests). What I don't understand is how do I handle errors if the post request fails and doesn't get pushed to the database. Even in your demonstration where you get the post and you await for it to be published there was no form of error handling (as far as I could tell). Also I had a project where I lazily used server actions for everything (including fetching stuff from db) and while it was working there's gotta be some negative consequences right? The way you do it by fetching directly in the server components seems better and is the right way AFAIK.

Ответить
@codinginflow
@codinginflow - 20.06.2024 13:20

Is it possible to teach yourself Clean Architecture? I remember trying to read the book and everything went straight over my head lol.

Ответить
@LeviCrider
@LeviCrider - 20.06.2024 15:27

What kind of keyboard you rocking? Sounds immaculate.

Ответить
@sylarfx
@sylarfx - 21.06.2024 02:28

the problem with architectures is that people tend to fall into mental masturbation about it and overcomplicate things into hard to maintain state

Ответить
@JoshuaMcQueen
@JoshuaMcQueen - 21.06.2024 07:10

What about the loading state? How do you handle that?

Ответить
@lucahoffmann8695
@lucahoffmann8695 - 22.06.2024 00:27

the keyboard click sounds are just horrendous 😵‍💫

Ответить
@RiteshNEVERUNIFORM
@RiteshNEVERUNIFORM - 22.06.2024 11:55

Which theme is that

Ответить
@kryttee
@kryttee - 22.06.2024 12:32

Would love to see github repo of this, it's hard for me to comprehend the structure just by looking at the video

Ответить
@Alex.Shalda
@Alex.Shalda - 22.06.2024 14:14

awesome

Ответить
@LofiChillOut
@LofiChillOut - 22.06.2024 23:02

Great stuff. Can you link to the safe server action package

Ответить
@DatoDaraselia
@DatoDaraselia - 25.06.2024 02:21

Thanks Cody! This is so useful!

Ответить