Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active September 7, 2022 07:36
Show Gist options
  • Save ryanflorence/110d4538bf98694538de to your computer and use it in GitHub Desktop.
Save ryanflorence/110d4538bf98694538de to your computer and use it in GitHub Desktop.
.
├── actions
├── stores
├── views
│   ├── Anonymous
│   │   ├── __tests__
│   │   ├── views
│   │   │   ├── Home
│   │   │   │   ├── __tests__
│   │   │   │   └── Handler.js
│   │   │   └── Login
│   │   │   ├── __tests__
│   │   │   └── Handler.js
│   │   └── Handler.js
│   └── SignedIn
│   ├── __tests__
│   ├── lib
│   │   └── components
│   │   ├── __tests__
│   │   └── Avatar.js
│   ├── views
│   │   ├── Courses
│   │   │   ├── __tests__
│   │   │   ├── views
│   │   │   │   ├── Assignments
│   │   │   │   │   ├── __tests__
│   │   │   │   │   └── Handler.js
│   │   │   │   ├── Default
│   │   │   │   │   ├── __tests__
│   │   │   │   │   └── Handler.js
│   │   │   │   ├── Grades
│   │   │   │   │   ├── __tests__
│   │   │   │   │   └── Handler.js
│   │   │   │   └── Users
│   │   │   │   ├── __tests__
│   │   │   │   └── Handler.js
│   │   │   └── Handler.js
│   │   └── Dashboard
│   │   ├── __tests__
│   │   ├── components
│   │   │   ├── __tests__
│   │   │   ├── Stream.js
│   │   │   ├── StreamItem.js
│   │   │   ├── TodoItem.js
│   │   │   └── TodoList.js
│   │   └── Handler.js
│   └── Handler.js
└── main.js
@irvinebroque
Copy link

This is rad.

I've also been splitting up views and components that render differently based on device type into separate entry points:

    ├── views
    │   ├── Navigation
    │   │   ├── __tests__
    │   │   ├── components
    │   │   │   ├── mobile.js
    │   │   │   ├── desktop.js
    │   │   │   │   ├── __tests__
    │   │   └── Handler.js

This makes it much easier to generate separate bundles for desktop vs mobile, and a lot more clarity within views (fewer ternary and if else statements based on environment -- just put them in Handler.js). Handler ends up behaving more like a controller -- it fetches data, checks permissions, etc., while the components handle the UI rendering.

I've found this really helps when views start growing past a few hundred lines of code, which happens fast when you write css in js.

@mrtnbroder
Copy link

Why don't you put the styles in a seperate file then @irvinebroque?
Also it's bad practice to separate desktop and mobile stuff. Better find a responsive solution.

No hating here, just a friendly tipp :)

@lesterzone
Copy link

What about structure by feature, LIFT principle:

.
├── app.js
├── categories
│   ├── categoryActions.js
│   ├── categoryStore.js
│   ├── categoryUtils.js
│   └── components
│       ├── form.js
│       └── list.js
├── core
│   └── dispatcher.js
├── router.js
├── routes.js

No more than 3 levels

@srph
Copy link

srph commented Apr 13, 2015

├── app
  ├── lib
  ├── components
  ├── handlers
    ├── home/
      ├── components/
        ├── ...
      ├── HomeView.jsx
      ├── styles.less
    ├── about
    ├── login
    ├── logout
  ├── index.js
  ├── routes.js
├── core
  ├── actions
  ├── stores
  ├── utils
  ├── config.js
├── dashboard
├── public
├── style

the app directory is basically similar to the dashboard directory. We're currently implementing this structure (having the app and dashboard in the same repo), and them have separate builds for them 😄

@samuelazran
Copy link

+1 to @kentcdodds

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