Can Convex be a backend itself?
- Convex functions don't run in browsers, they run on the Convex backend.
- Both web browsers and other servers (like a Next.js server) can talk to Convex, generally the WebSocket-based ConvexReactClient makes sense in browsers and the ConvexHttpClient makes sense in backend servers like Next.js server components and API routes.
- The code for a Convex backend can be placed in another package in a monorepo; I'll find a previous thread wiht this approach and link to it. The gist is that you need to export the API object so that it can be used in another package.
- The code for a Convex backend can also be placed in an entirely separate repo but if you do this it's more difficult to use the API object.
- If you're just getting started, I recommend using the same package for frontend and backend. You can keep all your convex-specific code inside the
convex/ directory so it shouldn't clutter things up to much. This code is never sent to browsers or other servers talking to Convex so there's no runtime or bundle size cost to this.