chingu-x / chingu-frontend

React / Apollo client for the Chingu Developer Network
10 stars 7 forks source link

codebase structure refactor #185

Open the-vampiire opened 5 years ago

the-vampiire commented 5 years ago

Goals

Guidelines

Structure

src/
  - views/
    - ViewName.jsx
    - ViewName/
  - components/
    - ViewName/
    - UI/
    - Utility/
    - Static/
  - queries/
  - mutations/
  - utils/
  - assets/
  - styles/
  - App.jsx
  - index.js

Queries and Mutations

mutation DescriptiveActionName($input_name: input_type) { mutation(input: $input) { return_field } }



### mutations
- when calling a mutation of data owned by and returning a Type always request back
  - the `id` field
  - the fields that were updated
- this will keep the cache consistent and remove the need for callback-based updates

## `views/`
- `/ViewName.jsx`
  - imports children and renders a path-associated view
- `/ViewName/`
  - `index.jsx`: same as `ViewName.jsx`
  - include non-component support files specific to the view (custom styling, assets, animations)

## `components/`
- `ViewName/`: components only used in a single View
- `Category/`: shared components under a common category
  - `UI/`: base UI components (buttons, cards)
  - `Utility/`: utility components (`<Request />`, `<Modal />`)
  - `Static/`: static homepage components
- `ComponentName/`: complex shared components not necessarily under a view or category (rare)

### component directories
- each directory should have a default export from `index.jsx`
- components should contain one SCSS file per depth of directory

### component definitions within the directories
- components should mostly remain in flat `.jsx` files
- if a component grows in complexity to require sub-components create a dir by its name to contain them
  - follows component directory guidelines
  - this new dir should now contain the SCSS styles for itself and sub-components
  - **rarely extend deeper than one sub-directory component**
the-vampiire commented 5 years ago

all newsfeed refactoring using the new structure. afterwards converting the remaining code