Joshowaaah!
Joshowaaah!2mo ago

Folder/File Naming/Structure Ideas

I want some ideas on how to organize a larger convex project. What file/folder naming conventions make sense? Where have people put internal mutations, queries, actions, typescript functions, http layer stuff, etc? In a way that makes sense to them, and isnt overly complicated.
5 Replies
Convex Bot
Convex Bot2mo 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!
Pierre
Pierre2mo ago
I usually do the following: convex folder => table related folder => 1 file per api function => export default Example: convex -> users -> getMe.ts -> export default query(...) I put internal function where they are called, but if they are shared a lot, I put it in a dedicated folder
erquhart
erquhart2mo ago
I typically do something like this as well, but one layer deeper, and exporting helpers instead of Convex functions. Basically forms a "db layer".
// table with simple access patterns
convex > db > users.ts

// table with complex access patterns
convex > db > users > index.ts
convex > db > users > read.ts
convex > db > users > write.ts
// table with simple access patterns
convex > db > users.ts

// table with complex access patterns
convex > db > users > index.ts
convex > db > users > read.ts
convex > db > users > write.ts
Then I organize what I call the "api layer" by feature, this is where actual product development happens and things are more fast and loose. Not many rules here.
convex > someFeature.ts
convex > someOtherFeature > whatever.ts
convex > someFeature.ts
convex > someOtherFeature > whatever.ts
For node functions where needed I make a node suffixed file.
convex > someFeature.ts
convex > someFeatureNode.ts
convex > someFeature.ts
convex > someFeatureNode.ts
Pierre
Pierre2mo ago
@erquhart curious to know, I suspect with that following layer it means your don't rely much on "triggers" which sort of magically adds extra behavior to the "write" command? If yes, is there any reason why?
erquhart
erquhart2mo ago
This: https://stack.convex.dev/triggers#consider-explicit-function-calls-instead first best practice of using triggers is don't use triggers lol

Did you find this page helpful?