I am currently working on a ColdBox application and trying to make the architecture more modular and scalable. I have gone through the official docs…, but I am curious to hear from the community: what are your best practices when it comes to structuring modules in a large ColdBox app: ??
How do you handle shared services across modules: ??
Do you prefer to keep handlers thin and move most logic to services: ??
Any tips on naming conventions or directory structures that have worked well for you; ??
Definitely prefer to keep our handlers thin and most logic to services. More than that, don’t be afraid to have more handlers. This Cruddy By Design talk is kind of the basis of how we do that and also addresses your naming conventions/directory structure questions:
As for handling services across modules, Wirebox is your friend and we document in each module what it’s dependencies are.
One area that can get tricky in a large, modular application is if you use a lot of interceptors, which all fire in a specific order. They are one of the most powerful features in Coldbox but there’s not really a clean, out of the box way to manually order them, so be mindful of that.
Very first I’ll plug https://cfcasts.com, Lots of good ColdBox content and well worth the cost if you need more than the free videos.
I have seen many new CF/ColdBox devs end up putting everything in the root ColdBox app. The more they become familiar with ColdBox they tend to put more into modules. I also know some devs that put everything in modules.
Personally, I plan out the very base functionality into the root of my ColdBox app and then break everything else out into modules.
Are you asking about using the services between modules or defining dependencies? If you are talking about using services between modules, WireBox is your friend (well, WireBox is always your friend once you get to know it! )
var otherModuleService = getInstance("someService@otherModuleName")
If you are talking about dependencies, then you would need to define these in the module config.
Short answer, I agree with @Andrew_Kretzer Keep your handlers thin and put as much logic into services as possible. I have many handlers that return JSON that simply return the results of a service and I pass in the event, rc and prc. Something like:
Naming conventions… the eternal struggle for devs, lol. The only suggestion I have is to find balance between clear meaningful names and keeping the names short.
I don’t find that I have to worry much about directory structure with ColdBox apps. ColdBox leans very much on conventions meaning I know where my handlers, views, models, modules, etc. all go.
Look at all the sample ColdBox apps out there already. Here are a few places to start
Of course, @lmajano has MANY great examples of code to browser through. He is the creator of ColdBox after all.
Disclaimer: I am by no means a ColdBox expert. It took me many years of CF Development before I really embraced MVC framework, specifically ColdBox. I will say now that I have, I don’t like creating apps that aren’t ColdBox apps! I hope some of this helps and keep asking questions!