Skip to content

Instantly share code, notes, and snippets.

@amcdnl
Last active March 3, 2021 18:10
Show Gist options
  • Save amcdnl/cc8dc3fbb5ccb90be78d1c46cd518f08 to your computer and use it in GitHub Desktop.
Save amcdnl/cc8dc3fbb5ccb90be78d1c46cd518f08 to your computer and use it in GitHub Desktop.

Example Structure

/
    /scripts
    /src
        /assets
            /css
            /font
            /img
            /svg
        /core
            /graphql
                apollo.tsx
                state.tsx
            /themes
                dark.tsx
                light.tsx
            /tests
            /services
            /store
            /data
        /shared
            /utils
            /components
                /charts
                /Button
        /App
            /Navbar
                /Profile
                /Search
                index.tsx
                NavBar.tsx
                NavBar.scss
                NavBar.test.tsx
            /Dashboard
                /ActivityFeed
                    index.tsx
                    ActivityFeed.tsx
                    ActivityFeed.scss
                    ActivityFeed.test.tsx
                index.tsx
                Dashboard.tsx
                Dashboard.scss
                Dashboard.test.tsx
            App.tsx
            App.scss
            AppRoutes.tsx
        index.tsx
        index.html

Breakdown

Application features are grouped by feature type implementing a SRP pattern for all components and functions.

  • scripts/ - Any scripts (js/sh/etc) that are specific to the application build or deployment.
  • src/assets - Static assets such as images, svgs, css, fonts. No javascript should be here.
  • src/core - Global state, services and configuration specific to the application itself.
  • src/shared - Components and functions that are not coupled to the application itself. Nothing in this folder should reference anything outside of shared.
  • src/shared/components - DRY components
  • src/shared/utils - Misc utils.
  • src/App - The application itself that is glueing all the components together. This should not have any startup code/etc.
  • src/App/* - Stateful components that make up specific features of the application. These should not reference any other stateful components outside of their folder. Any component that is specific to this feature should be nested within this feature folder.
  • src/index.tsx - The bootstrapping of the app component.

Conventions

  • Each function should have a single class (export ideally)
  • Barrels should be used to export the consumable functions of the feature/function. Avoid broad sweeping exports for tree shaking reasons.
  • File names should be named the same as their exports.
  • Try to make components DRY where possible with state being passed down. This will make testing easier.

References

@josh-williams
Copy link

"Each function should have a single class (export ideally)"
You mean "each file"?

@josh-williams
Copy link

DRY in programming usually means "Don't repeat yourself". I would just say "Try to keep GraphQL operations out of components where possible with state being passed down from a parent container".

@pzipoy
Copy link

pzipoy commented Aug 23, 2018

src/shared/utils - Misc utils.

This seems like a catch-all directory. I would be interested to know what we specifically expect this folder to contain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment