Convex folder architecture
Hello, so i'm migrating my express/node server backend to a convex backed, i wanted to do my migration but still handle the same folder structure as much as possible, so basicly in my current express endpoints the flow is:
Route(GET. api/transactions..) -> controller ( this would call the services needed) -> services ( here i have a service per db collection) -> DB mongo collection.
so in services i have all the queries reads and writes for a certain collection and if in that service needs information for another collection i wouldn't call that collection directly, i would call the service that is specific to that DB collection.
also in services i would have other services for example a stripe webhook handler and that would need information form varios db collections (payments, users, suscription) so in that handler i would all the services to those db collections.
so i asked around some ai and passed the docs to those ais, some would say to have the services as internal functions and have the public functions call those, but then reading a little the doc im not sure that having nested queries was good practice in convex.
for example this would be incorrect.
// ❌ WRONG - Don't do this
export const getTransactions = query({
args: { /* validation */ },
handler: async (ctx, args) => {
// This is an anti-pattern in Convex!
return await ctx.runQuery(internal.services.transactionService.getTransactions, args);
}
});
i have it structured like this because if i want to change something to a the getstransactions services i would just change it in that services and all the other services and controller that call that service get the change with just on update.
the other ai told me to create helper functions and have all the services there. but my mayor concern is adding the queries and mutations to helpers and not getting the correct convex functionality or not the best optimised speed.
1 Reply
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!