How to use feature-based folders structure instead type-based?

From my experience type-based folders structure becomes a mess for a relatively medium or big project.

I prefer to group code by “features” or domains.
So every “feature” has it’s own folder and inside the folder there are pages, components, libs etc.

How can I achieve it with redwood?

3 Likes

Hey @syabro please check out this open issue and leave a comment I think that is what you are looking for. This way we can make this a priority. I think it has been in the backlog for quite a while. Currently, I don’t think it is possible to generate components into whatever path you. Although you could generate them and move them into whatever feature folder you want. I believe you can specify a path with the scaffolds though.

1 Like

Thanks, looks like :slight_smile:

Uh, oh, @dom Looks like we might have to dust off that PR…

:joy:

2 Likes

I don’t feel like there’s really any limitation to this in Redwood… but to think of it, your router might end up being quite the stuff :-\.

At SportOffice we’ve transitioned from an exclusive service based API to a src/lib/domain/model/verb+subject structure, which promotes pure function style a lot and scales very well. We didn’t do this early on but it proves easier to migrate there than it might look. But that’s for API side, web side, which sounds like your interest here, is another story, a topic that’s also discussed within the Contributors group.

Anyway, great point @syabro and welcome to our community \o/

1 Like

Yeah there is no limitation on doing this only thin is that generators don’t let you specify a path so you end up having to move the files manually after you create them just tedius

Posting this oldie-but-goodie here just because it poped up for me today again

And here’s the GH discussion on another project where I saw it

That discussion also has some more input on the topic

@noire.munich linked to a thread in a previous post that’s locked, so not everyone can access it.

I’m lifting my two latest posts from that thread


Someone came on to Discord a while ago as a new RW user and provided some initial feedback. Getting fresh users’ perspective on things is good. Sometimes we get used to what we already have and don’t see what we could have.

Here’s his feedback that’s relevant to what we’re discussing in this thread

I think the code organization was a bit jarring to me initially.
[…]
the naming structure and organization seemed a bit off. I would love to just encapsulate all of those components into the same folder. Something like,

Pages/Essay/Index.tsx 
Pages/Essay/components/EssayCell.tsx
Pages/Essay/components/Essay.tsx

Here’s a direct link to the full thread: Discord


Let’s say you want a “Books” page. So you run yarn rw g page Books . Now, what if there was an option to specify --page Books when generating cells and components that would make those end up inside the src/pages/BooksPage/ folder? For the cell generator maybe we could even make it default to that if you have a page with the same name as the cell. So if you run yarn rw g cell Books and you already have a BooksPage then that cell will be generated in there by default.


TBH I’m actually kind of proud of myself for that last post :blush: :speak_no_evil: I think the idea still holds up.

1 Like

Loving this.