Figloalds
Figloalds5w ago

How do you guys scaffold your Convex backend projects?

Hi I'm working on a new project using Convex and I'm struggling a little bit with code organization now that I'm having more and more things added, but there's still time to organize I found myself with these 3 categories of things that are not great to have all on the same files: - Internal helper functions that are snippets of queries or mutations, to be reused in queries, mutations, internal queries, internal mutations - internal queries and internal mutations, in these I don't validate user role/credential anything, because I'm assuming the public action/mutation/query that is calling them already handled it - queries, mutations and actions, in these I expect them to be correctly validated So if I have a large "someModel.ts" file with all of these 3 intermingled I will struggle to organize that and to have the correct mindset that would allow me to guarantee that the public apis are running their proper validation, and I'll also run into naming conflicts because I may need a "getById" that is validated for the frontend to use, but I may also need a "getByIdInternal" for internal methods to use and then I may need to wrap that getByIdInternal function in a internalQuery so that I can do it from an action; How do you guys organize your code?
6 Replies
Convex Bot
Convex Bot5w ago
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!
erquhart
erquhart5w ago
I shared some of my approach here, there's relevant discussion above and below too: https://discord.com/channels/1019350475847499849/1019350478817079338/1393251680618942585
mistakenCynic
mistakenCynic5w ago
Personally I saw someone doing something similar to this on Github and it's helped me stay organized a ton:
- convex
- convex.config.ts
- [table name]
- private.ts (internal.a.private.x)
- public.ts (api.a.public.x)
- helpers.ts (TS functions)
- actions.ts (internal, node)
- schema.ts (table schema, types)
- convex
- convex.config.ts
- [table name]
- private.ts (internal.a.private.x)
- public.ts (api.a.public.x)
- helpers.ts (TS functions)
- actions.ts (internal, node)
- schema.ts (table schema, types)
It really helps with a ton of tables or where you need duplicate internal and public queries/mutations.
erquhart
erquhart5w ago
I tried something like that early on. The challenge when your project gets bigger is feature development gets a bit tangled with the details of which table(s) the feature is touching.
AutumnLight
AutumnLight5w ago
im doing something similar, i just called mine feature/ and then i have featurename.schema.ts and functions.ts
Figloalds
FigloaldsOP5w ago
I like that a lot actually, tyvm

Did you find this page helpful?