OpenCut icon indicating copy to clipboard operation
OpenCut copied to clipboard

[FEATURE] Add Bun server with API using TanStack and tRPC

Open vietnamesekid opened this issue 1 year ago • 2 comments

Problem

Currently, the project doesn’t have a dedicated state management solution or an independent API layer. This makes it harder to manage shared state and handle data fetching in a scalable, consistent way. By introducing a separate API server and integrating modern state management tools, we can keep concerns clearly separated, improve maintainability, and make it easier for contributors to build new features without tightly coupling frontend and backend logic

Solution

Adding a Bun-powered API server would bring significant benefits to the project. Bun’s modern JavaScript runtime delivers excellent speed and up-to-date tooling, which can help us achieve better performance out of the box. By using tRPC, we gain fully type-safe, end-to-end API calls without the overhead of maintaining OpenAPI or GraphQL schemas. Combined with TanStack tools like TanStack Query, this setup enables efficient data fetching and caching on the frontend. Overall, having a dedicated, modern API layer improves separation of concerns and makes the project more maintainable and scalable in the long run.

My idea is to spin up a Bun server to handle all API routes, with tRPC managing the API procedures to ensure type safety across the stack. On the frontend, we can connect to this API layer using TanStack Query (or other TanStack libraries already in use) for seamless data fetching. The implementation should be kept modular so that contributors can easily add or extend endpoints in the future without friction.

Alternative

...

Anything else?

No response

vietnamesekid avatar Jul 15 '25 06:07 vietnamesekid

this will come in neat later but we currently have one api route and soon none after we remove the waitlist so doing this later would make sense

mazeincoding avatar Jul 15 '25 11:07 mazeincoding

Another consideration is using a database with sync capabilities, something like Convex. It would reduce the efforts with dealing with routes, managing states and syncing with the db in React Layer.

Although it may require some heavy changes to how the application handles state management, in the long run, the benefits would outweigh the setup. @mazeincoding

paschaldev avatar Jul 16 '25 13:07 paschaldev