Search code examples
reactjsreact-reduxredux-sagadirectory-structure

What is the best practice to architecture (folder structure) enterprise level React web application, using redux and redux-saga as middleware?


Any changes required with my current folder structure? Is components based or atomic level based folder structure is preferred?

.
├── App.css
├── App.js
├── App.test.js
├── assests
├── components
│   └── button.js
├── constants
├── helpers
├── index.css
├── index.js
├── pages
│   ├── action.js
│   ├── homePage.js
│   ├── reducer.js
│   └── saga.js
├── routes
├── services
└── serviceWorker.js


Solution

  • Why go with Atomic design?

    1. Separation of Concerns.
    2. Component re-usability.
    3. Simplified testing.
    4. Scalability.
    5. Uniformity.
    6. Configurability.

    Atoms: Basic building blocks of matter, such as a button, input or a form label. They’re not useful on their own.

    Molecules: Grouping atoms together, such as combining a button, input and form label to build functionality.

    Organisms: Combining molecules together to form organisms that make up a distinct section of an interface (i.e. navigation bar)

    Templates: Consisting mostly of groups of organisms to form a page — where clients can see a final design in place.

    Pages: An ecosystem that views different template renders. We can create multiple ecosystems into a single environment — the application.

    Containers: A container does data fetching and then renders its corresponding sub-component

    File Structure:

    └── src
        ├── actions
        │   └── action.js
        ├── App.js
        ├── components
        │   ├── atoms
        │   │   └── index.js
        │   ├── molecules
        │   │   └── index.js
        │   ├── organisms
        │   │   └── index.js
        │   └── templates
        │       └── index.js
        ├── index.js
        ├── pages
        │   └── home
        │       └── HomeComponent.js
        │       └── HomeContainer.js
        ├── reducers
        │   └── index.js
        ├── resources
        │   └── img
        │       └── logo.svg
        ├── routes.js
        ├── sagas
        │   └── index.js
        ├── serviceWorker.js
        ├── setupTests.js
        ├── store.js
        └── tests
            └── application.spec.js