Confused about working with supabase in a monorepo (Expo + Next js)
I’m setting up a monorepo with this structure:
.
└── my-app
├── apps
│ ├── web # Next.js (frontend + API routes with tRPC, SSR)
│ ├── native # Expo (mobile client)
│ └── server? # maybe separate, but ideally API lives in web
├── packages
│ ├── db # drizzle + supabase client setup, or just supabase client
│ ├── api # tRPC routers / business logic
│ ├── ui # shared components
│ └── utils # misc helpers
Goals:
• Leverage SSR, streaming, server actions, etc. in Next.js.
• Keep type-safety end-to-end (tRPC). or generate types using the cli
• Use Supabase for DB + auth.
What I’m confused about:
• Should web + expo both call Supabase client directly (with RLS + policies)?
• Or should I wrap all Supabase access behind Next.js API routes (tRPC) so expo only talks to the API?
• If I do wrap, should packages/db hold raw queries and packages/api wrap them for tRPC?
• Supabase client has slight differences between web & expo (auth/session/storage). What’s the cleanest way to abstract that?
• Will wrapping everything in API routes make me lose some SSR/Next.js optimizations?
My current thought:
• packages/db = drizzle schema + supabase utils
• packages/api = tRPC routers, import from db
• apps/web = can sometimes use supabase client directly for SSR (auth/session), but also expose API routes
• apps/native = only talks to API routes
But I’m not sure if this is best practice or overengineering.
8 Replies
Hey! I’ve worked on similar monorepos with Next.js, Expo, Supabase, and tRPC. I can help streamline your setup so web handles SSR efficiently while Expo communicates safely through your API, and we can abstract the Supabase differences between web and mobile.
Are you prioritizing SSR performance on web or a single source of truth for all Supabase access? @sam
Probably would like to have both, my app is e-commerce + social media (so I need that speed, but also minimise code duplication)
I can help you balance SSR speed for web and minimal code duplication for mobile. Expo will talk through the API, web can access Supabase directly where needed, and shared logic will live in your packages for type-safe, maintainable code.
@sam
cool, do you have any sample project I can look at @Lordvickthor 👑
Yes I will send you some of my past work samples
Give me some moments @sam
@sam
Be very careful being contacted by people you don't know. @Lordvickthor 👑 has been here 1 day and seems like providing AI bot answers and if they are DM'ing people soliciting work or worse asking for access that is an issue.
Wrong Sam 🙂
yes, I was a bit suspicious (too eager to help). Anyway, anyone got resources for that?