My team and I are about to revamp the frontend of a large CakePHP 2 application. Our main aim, apart from giving it a fresh look, is to create more reusable SCSS/Javascript code, establish a logical structure in our frontend code as well as the third-party assets we utilize.
Currently, our CSS modifications are haphazardly added to one file without considering reusability or structure. Similarly, most of our Javascript is embedded within views, lacking organization and reusability.
We do have some functions that are shared across multiple views, but they are all consolidated into one file. Here lies the problem of scalability and maintainability.
Question
So, my question is, what would be an effective structure or architecture for managing Javascript and CSS/SCSS in a CakePHP application? Where should one start?
My ideas
Currently, we do not utilize tools like CSS preprocessors or frontend package managers such as Bower. Implementing a CSS preprocessor like SCSS and exploring the use of Bower for managing third-party assets are on our agenda.
Regarding Javascript, automatically loading a Javascript file based on the CakePHP Controller and action name could help introduce some structure. But how should the code within these files be structured? Should we consider extending a 'master' Javascript object with ready-to-use functions? And for common scripts used across pages, should we opt for separate functions or consolidate them into one reusable object?
Found resources:
How to structure Javascript architecture to complement a PHP MVC web app? => No definitive answer applicable to our scenario was found here.
https://www.sitepoint.com/architecture-in-sass/ => Provided valuable insights on organizing SASS.
JS MV* Frameworks like https://angularjs.org/ => Due to the size of our existing application, adopting a JS MVC framework like AngularJS seems daunting with our current constraints. Further research may be necessary, as these frameworks appear intricate for our project.