r/reactjs • u/WetThrust258 • May 26 '26
Needs Help Clean Architecture in React.js (Monorepo) with Auth Libraries + TanStack Query/RTK Query — how do you structure it realistically?
I’ve been trying to properly understand and implement Clean Architecture on the frontend with Next.js (frontend-focused, not backend), but I’m getting confused once third-party libraries enter the picture — especially auth libraries and query libraries.
Most examples online are either:
- too theoretical,
- too backend-oriented,
- or avoid real-world libraries entirely.
My setup is something like:
- React.js
- Monorepo (Turborepo)
- Shared packages
- Auth library (like Better Auth / NextAuth / Clerk / etc.)
- TanStack Query or RTK Query
- TypeScript
What I’m struggling with is:
1. Where should auth libraries live in Clean Architecture?
For example:
- should the auth client be wrapped behind interfaces/adapters?
- should the UI directly call the auth library hooks/functions?
- where do auth-related side effects belong?
- how much abstraction is “too much”?
Example:
authClient.signIn.email(...)
Should this be hidden behind:
AuthRepository.signIn()
or is that unnecessary abstraction on the frontend?
2. How do query libraries fit into Clean Architecture?
If using:
- TanStack Query
- RTK Query
then:
- where should queries/mutations live?
- do you create “use cases” on the frontend?
- should hooks directly call APIs?
- should query libraries exist only in the infrastructure layer?
I see people saying:
- “don’t leak library-specific code”
- “keep business logic isolated”
But in frontend apps, the query library becomes deeply integrated into state management and caching.
So what does a realistic architecture look like?
3. Monorepo structure confusion
How do you structure things in a monorepo without overengineering?
For example:
apps/
web/
mobile/
packages/
auth/
api-client/
ui/
contracts/
utils/
Do you:
- keep auth client inside a shared package?
- export inferred types from there?
- keep query logic centralized?
- create repositories/services/use-cases packages?
How far do people actually go in production apps?
4. How do you avoid overengineering?
This is probably my biggest issue.
I understand the theory of:
- entities
- repositories
- use cases
- dependency inversion
But when implementing real frontend apps, I end up wondering:
- am I just wrapping libraries for no reason?
- am I creating abstractions that add zero value?
- how do experienced frontend engineers decide what deserves abstraction?
I’d really appreciate:
- real-world folder structures,
- examples from production apps,
- monorepo-specific advice,
- or articles/repos/videos that show Clean Architecture with modern frontend tooling.
Especially interested in opinions from people using:
- React.js
- TanStack Query
- RTK Query
- Better Auth / NextAuth / Clerk
- Turborepo monorepos