Grouping by feature #1286
Replies: 1 comment 10 replies
-
yay our first discussion! I have wanted to use this feature more, so thank you for creating this! First off, I totally agree, I think there can be a lot of room for improvement and I generally agree with what you're laying out here. I would be super open to trying out organization by feature, rather than by type or kind of technology/pattern used, with two requests: I think we should keep Additionally, it's very rare that an atom or bit of state is used in only one feature, they are often used between features and referenced in many ways due to the derived nature of our application state. I would hate to have some state here and some state in different folders due to the feature they are semi-related to. If you are okay with these two requests, I would love to move towards this way of organizing the project! |
Beta Was this translation helpful? Give feedback.
-
Forward: Sorry for the essay. I'm debugging the transaction signing flow and feeling the pain of all the code I need to reference being spread out in various unrelated folders. This topic's come up a few times, so writing my thoughts while they're fresh.
Currently we group by technology in many places. Hooks are grouped by the fact they're hooks. Components are all grouped together unless they're the upper page route etc (regardless of whether they're global or only used for a single feature)
I'd like to put forward a case why this isn't optimal, and why grouping by feature is a much more developer-friendly, thoughtful way to go about organising a scalable codebase.
Starting with components. Consider the extension popup when you create a transaction request. The components that create most of this are in two places:
src/pages/transaction
src/components/transactions
Many of the transaction components in
src/components
are only used in the context ofsrc/pages/transaction
.Similarly with our hooks. We have a
src/common/hooks/transaction
folder. There are hooks in here only used as part of this transaction flow.What if, instead, we organise by the features we're building, rather than the what elements of the React toolbox it is we're using to build them?
Here are some reasons against grouping by technology:
src/models/transactions.ts
src/controllers/transactions.ts
src/views/transactions.ts
src/transactions/transaction.model.ts
src/transactions/transaction.controller.ts
src/transactions/transaction.views.ts
components
folder to me is "all components that are shared across the app". Right now we use it as both feature components and shared components. That's helpful information that cannot be inferred by the directory structures.Suggestion
I'd reserve the
src/common
andsrc/component
folders only for reusable hooks/components/etc across the app. Within the context of a shared folder, they may be organised by technology, or sub-feature, whatever works.Everything else relates to a feature such as: transaction signing, the settings dropdown, sending an asset flow etc are put into a
features
folder. If you're not working on tx signing, you can safely ignore everything in that folder. That's a huge win for me. I find myself really unproductive in this repo because there's too much going on. I have to constantly search the entire codebase to figured out "where is x used", which oftentimes I should be able to infer from the directory structure.Personally I'd have a much easier time working with the wallet if we followed a structure like this. Interested to hear your thoughts @aulneau @fbwoolf
Beta Was this translation helpful? Give feedback.
All reactions