DEV Community

Discussion on: Better file structure in React projects

Collapse
 
raibtoffoletto profile image
Raí B. Toffoletto

I like the idea to have everything in the src folder so I know that's the code for my app. Everything else is related to the project config and compiling. I usually would use something like:
src/

  • api
  • assets
  • common (useful methods)
  • components
  • database (when used with typeorm)
  • hooks
  • reducers (with redux)
  • views
  • index.jsx (entry point)
  • settings.js
  • theme.js (in case of MaterialUI).

I like the approach of using folder structures as namespaces, using the js export to facilitate things.
But this is just a matter of preference. 😉😉

Collapse
 
victorocna profile image
Victor Ocnarescu

Cool structure. I also like to facilitate things using named js exports (in every folder). Everything except the src folder makes perfect sense to me.

Collapse
 
raibtoffoletto profile image
Raí B. Toffoletto

For the /src imagine it as the root for your code. The / is the root of your project, it's a way to separate concerns. Pretty common in other languages... loke having a Main() as an entry point of an application.

Thread Thread
 
victorocna profile image
Victor Ocnarescu

I like the idea of separation of concerns, but I regard the src folder like an API that wraps the response in a "data" object instead of responding with the actual info. I may be wrong though, I see many devs the prefer using the src folder.