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
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!
hmm good question. maybe @ballingt knows? the bundling stuff is pretty tricky and mysterious
Would you know how this works @ballingt ?
@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.
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?
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
@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.
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:
Ah I understand now, thanks!
I also think this feature would be useful
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.
thats a fair point as well. I like the idea of being able to configure more things with convex using the
convex.json