r/reactjs • u/derdak • May 24 '26
How do you structure your React side projects? Looking for something lean. Not full clean architecture, but not spaghetti either
Working on a side project and trying to find the sweet spot for code organization.
I've looked into clean architecture and it makes sense at scale, but it feels like overkill for a solo side project: too many layers, too much boilerplate, and honestly too much to maintain when you're moving fast.
At the same time, I've been burned before by projects that had zero structure and turned into a mess after a few months.
What I'm looking for:
- Minimal but intentional folder/file structure
- Easy to maintain solo
- Room to grow without having to refactor everything
- No over-engineering, but also no spaghetti code
A few things I'm wondering:
- Are any of you actually using clean architecture in React projects, and is it worth it at a small scale?
- What's your go-to folder structure for a side project you plan to maintain long-term?
- Any patterns or conventions you swear by for keeping things sane without a heavy architecture?
Not looking for the "enterprise" answer. Just what actually works for lean, maintainable React code as a solo dev.
17
u/super_pjj May 24 '26
I came across this before and I loved it : https://github.com/alan2207/bulletproof-react
9
u/JavChz May 24 '26
There are no hard rules, that's the double edge sowrd with react vs angular, you have too much freedom.
If you don't know where to start go:
components
services
state (zustad, redux, context, etc)
utils
hooks
assets
layout
That kinda takes cares of most things.
5
u/njmh May 24 '26
Side projects are a great way to practice with production grade architectures, even if it’s not necessary or overly complicates your projects.
Same reason a lot of homelabbers run full blown kubernetes clusters to run Jellyfin and pihole on their home network. It’s good practice for real devops and it jobs.
5
u/MPiccinato May 24 '26
Give https://tkdodo.eu/blog/the-vertical-codebase a read. Others have pointed this out in a way, it really helps in the long term. Nothing is more annoying than working on a feature in 6, very distant, folders over time.
5
u/Otak1790 May 24 '26
React users wrongly tend to bundle their files by types ( HoC, hooks, components... ) but this approach fails when the project grows :
This is especially important with ai, because a bad architecture will make the ai search more for information ( grepping the whole codebase multiple times to find relevant folders ) wasting tokens
Now the solution fits in one word "colocation" You put all the code that are often used together as closely as possible, there is an infinite way of implementing it but none are wrong as long as you follow the principle.
Example : My app has a user feature, I create a folder with all the user related things
Sorry for the long post, i currently have a hangover but I did my best to answer
3
u/azangru May 24 '26
What does a react codebase built upon 'clean architecture' look like?
4
u/yksvaan May 24 '26
I prefer modular architecture, easier to keep it clean and the main app acts as foundation and initializator for the modules, initializing common services, providing them to modules, calling modules to register their routes etc.
And secondly, React is an UI library, don't mix everything in it. Use it to render UI, maintain its internal state and manage user events, passing them to the actual business logic/data services. Then necessary state updates get synced back and the loop continues. Most components can be dead simple and more or less pure.
I think the modern trend of mixing way too many things in React can lead to very messy and hard to maintain codebases. Make sure network code, auth etc. goes through centralized services that provide abstracted methods, React code should never need to know where data comes from, how it's stored, what network protocol is used or any other implementation details.
1
u/Outrageous-Chip-3961 May 24 '26
Yes I have a go-to folder that i usually just fork for every project as it has a lot of linters setup and config
But for simplicity its:
assets
components
features
hooks
utils
routes
types
services
use @/ aliases
use linters
use husky
I use tanstack query/router/form/table, so add if you need (but do it in a way that you can replace it easily).
I also prefer css modules over tailwind.
1
u/GasVarGames May 24 '26
bulletproof react!!!
1
u/Cahnis May 25 '26
clean architecture in react is 🤮. That is a OOP / backend world architecture. React lives in the functional / frontend world.
Pick whatever you think makes the most sense for your current project here: https://www.robinwieruch.de/react-folder-structure/
1
u/cuong_xteam May 25 '26
My rule for solo side projects: feature folders, not type folders.
Why this works for side projects:
What I'd skip until you actually need it:
One non-obvious thing: write data fetching at the feature level (features/dashboard/api.ts), not in a global /api folder. When you eventually swap REST → tRPC → server actions, you only touch one folder.
1
u/scaleable May 26 '26
group by domain, for better navigation, easier expansion etc
this will automatically require a directory for common things
any other directory grouping that is not by domain is a thing of rookies
4
u/[deleted] May 24 '26
[removed] — view removed comment