Hey everyone! I'm diving into RPC with ORPC in Next.js, and I'm a bit unsure about the best way to structure my directories. I found that I needed to integrate Next Auth through the API directory, but it feels awkward to mix RPC with traditional API routes. Is there a better approach, or is it okay to keep them together? I'd love to hear your thoughts!
2 Answers
It's actually really common to mix RPC and traditional API routes in Next.js projects! The key is to treat them as separate concerns. For NextAuth, using the API directory makes sense since it deals with standard HTTP callbacks and redirects. Generally, it's a good idea to utilize RPC for your app's logic where you're in control of both ends and stick to REST endpoints for things like third-party integrations or auth flows that expect standard HTTP. The separation might feel a bit strange at first, but it helps maintain a clean architecture for your RPC layer!
Totally get that! What do you think is a traditional API route?
Don't worry too much about the directory structure; it shouldn’t limit how you organize your code. RPC is still an API after all, so ask yourself what's really bothering you about mixing them.

I had the same concerns, but once I read a detailed explanation, it clicked for me!