Best practices for code organization

Hi, I’m currently working with a Rest layer to interact with a Vue FrontEnd, and was wondering what would be the right way to separate my service code from the business code, for instance, I don’t want to have DB queries and other business operations inside the rest controllers, and I guess the best place for them should be on the extra’s core/controllers file, but not sure what should be the proper structure and what MODX classes I should be extending/using


The base class MODX\Revolution\Rest\modRestController itself queries the DB. So it only makes sense, that your derived classes query the database as well.

If you want your rest controller files in a different folder, then change the “basePath” parameter, when you create the MODX\Revolution\Rest\modRestService object in your index.php file.

Thanks!, I was thinking about the MVC model, where my view is the actual REST service, and the controllers would be somewhere else, but what you say makes perfect sense, MODX rest controllers themselves are designed to query the DB directly, Now Im facing a paths issue, Im in the process of creating PHPUnit test cases for some controller methods, I added a composer file along the rest folder of the assets file, but it fails to locate the model files contained inside MODX core folder or the extras core folder, yet they would work normally when called from POSTMAN, what would be the right setup to have unit test against the REST layer?