Post

I was curious about the monorepo suggestion. Are you suggesting that a React SPA, for example, should literally be a monorepo with each vertical as its own package? Could you please share an example of what that looks like in practice?

Yes, pretty much. Taking Josh's example you shared, you would have a monorepo package for base, search and users. Each having their own package.json with defined exports. It's no different to "top level folders", just that it's "top level packages"

Generally agree! `base` is the `design-system`, but why does each domain have an additional `components` folder? Like `search` could just be 3 things flat. As modules get deeper, you'll get horizontal splits within them easily and have the same drawbacks. Staying vertical within verticals is better

I've been trying to reconcile how you'd think about both file based routing and a vertical codebase. Are the routes living alongside of the vertical? Is file based routing just not a good idea and we have to go back to code based?

TanStack Router itself says "Code-based routing is not recommended for most applications. It is recommended to use File-Based Routing instead." So do we stick with file based and just treat the vertical as a package we utilize to build our routes independent of the vertical?

Based on the above: src/ โ”œโ”€โ”€ user/ โ”‚ โ”œโ”€โ”€ queries.ts โ”‚ โ”œโ”€โ”€ mutations.ts โ”‚ โ”œโ”€โ”€ component1.tsx โ”‚ โ”œโ”€โ”€ use-something.ts โ”‚ โ””โ”€โ”€ sub-domain/ โ”‚ โ””โ”€โ”€ queries.ts โ””โ”€โ”€ routes/ โ””โ”€โ”€ user <- imports from user vertical primarily + any others โ”œโ”€โ”€ user.index.ts โ””โ”€โ”€ $userId.tsx

I still have a hard time convincing people that putting `handleClick` or `handleChange` outside of JSX doesn't make the code more readable. People are so attached to dividing things in a way that is simple, instead of putting the effort into the more delicate but useful product split

Agree, the thing that's mostly stopping adoption is that getting is right is harder and you have to stop and think a bit. Also AI has learned the horizontal split and will likely default to it.

Using a ` features` dir currently which works quite well, along a components folder for more general things and legacy stuff that's not been moved over to features yet ๐Ÿ˜… But the "But What About Shared Code?" section is a good call to maybe not name it "features" at all ๐Ÿค”

Yeah "features" is pretty generic. Imo it will lead to things being put into "components" that need to be shared between two features because they aren't a feature by itself.

"components" is also generic. Everything in react is a component - from your <Button> to your <DashboardPage>. If you want this directory for your re-usable primitives like `<Card>` etc, I'd prefer `ui-patterns` or `ui-primitives`

Yea very good & true points ๐Ÿ‘Œ Currently it's fine but I'll def keep considering improving on it, for when we're probably re-structuring anyway at some point ๐Ÿค“

We talk about 'horizontal codebases' but an even nastier version imo would be the 'route tree codebases' for frontend apps: Everything is collocated with the routes, unless it isn't. Then we fallback to horizontal splitting. And then you gotta put in 10x the effort to migrate away from it and ๐Ÿซจ ugh

yes please ๐Ÿ˜„๐Ÿ‘ there are eslint plugins that can validate architectural boundaries by checking file/dir name patterns you don't have to go monorepo ๐Ÿ™‚