adam
adam4mo ago

Organising Convex files with folders

I'd like to organise my Convex functions by moving, for example, convex/orders.ts to convex/(orders)/orders.ts. The parenthesised folder (orders) is ignored by Convex's API generation (which is what I want), ensuring that api.orders.getById (used in my frontend, react-native app) remains unchanged and non-breaking. Is this an officially supported file organisation pattern in Convex, and is there documentation for it? I want to ensure this behaviour won't change in a future update, which could break my client's API.
12 Replies
Convex Bot
Convex Bot4mo 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!
jamwt
jamwt4mo ago
hmm good question. maybe @ballingt knows? the bundling stuff is pretty tricky and mysterious
adam
adamOP4mo ago
Would you know how this works @ballingt ?
ballingt
ballingt4mo ago
@adam I am surprised that works! Really, it collapses it like some routing frameworks do? I don't see how that would work from the code.
adam
adamOP4mo ago
Ok, so not really a feature by design then? Given it works like this and it is useful, could it become an explicit feature of Convex api routes?
RJ
RJ4mo ago
Sorry for the digressive question @adam, but how do you find this useful in practice? Just curious as it's not clear to me from your example
ballingt
ballingt4mo ago
@adam I'd love clarification here too, I can't get this to work Ah rereading, I think you're saying this this is something you'd like, but not something that works today? This is a reasonable feature, lots of approaches to customizing api routes that would be nice.
adam
adamOP4mo ago
Hrm it seems this was working but no longer works. Unless I did something silly on my side like not starting the Convex dev server or something but I was sure it was working. To clarify the idea: // Current └── packages └── backend └── convex └── orders.ts // Desired └── apps └── backend └── convex └── (orders) ├── helpers.ts ├── orders.test.ts └── orders.ts This would re-organise my files when orders.ts gets too big, while keeping the frontend API route of api.orders.getById unchanged. This Convex error is now raised:
400 Bad Request: InvalidConfig: (orders)/orders.js is not a valid path to a Convex module. Path component (orders) can only contain alphanumeric characters, underscores, or periods.
400 Bad Request: InvalidConfig: (orders)/orders.js is not a valid path to a Convex module. Path component (orders) can only contain alphanumeric characters, underscores, or periods.
RJ
RJ4mo ago
Ah I understand now, thanks!
Jamal
Jamal3mo ago
I also think this feature would be useful
Mordsith
Mordsith3mo ago
I believe this feature could introduce unnecessary complexity and make it harder to read and follow function definitions. It’s also prone to misuse by developers, especially since there’s no limit to how deeply parentheses can be nested. This could make the code more difficult to reason about; similar to the challenges we’ve faced with routing in Next.js’s app directory.
Jamal
Jamal3mo ago
thats a fair point as well. I like the idea of being able to configure more things with convex using the convex.json

Did you find this page helpful?