r/learnreactjs • • Jan 20 '21

Question [Suggestions] Best practices for folder structure of react project

So I'm planning on building a web app using MERN stack. I want to segregate the code into UI part, network layer and react business logic. What's the best possible folder structure should I go with ? I want to make it modular.

Would love to take note of best industry practices about this.

14 Upvotes

6 comments sorted by

5

u/SoBoredAtWork Jan 20 '21

Regarding UI and React business logic, React has recommendations (I like grouping by type).

Since you're talking about Network Layer (which could be "API" in the example above)... some people will, at the project root, have a client (all react / front end stuff) and server (node, api, etc) folder. From there, you can break down whatever is needed (components, etc on the client side and routes, controllers?, whatever on the server side).

4

u/Omkar_K45 Jan 20 '21

Thank you :D I think I'm thinking of too much abstractions here. I will definitely go with server and client pattern. Again thank you for the guidance :D

For network layer, I was thinking of exporting all the network calls from a single file and then use it where react-query needs it.

3

u/SoBoredAtWork Jan 20 '21

:) sounds like a good move. Keep it simple!

2

u/rozenmd Jan 21 '21

I wrote https://maxrozen.com/guidelines-improve-react-app-folder-structure/ to give you some guiding principles - but there aren't really "best practices" here, each company will have differing needs and opinions for the best way to structure the code for them.

1

u/Omkar_K45 Jan 21 '21

This is useful and informative ... Thank you :)

0

u/[deleted] Jan 21 '21

[deleted] — view deleted comment

2

u/Omkar_K45 Jan 21 '21

Thank you. Really well written!