Organizing app code (Architecture)


#1

Hi everybody, I’d like to know which way do you organize your code to be scalable and better to maintain with Ionic Framework, I look at internet and there are many approaches, the one I like most was the organization by features, but for Ionic which way do you organize? I just want to get some opinions of what way do you organize and why do you use this way.


#2

Organization of code is really all a personal preference, and there is not right or wrong to do it. For me, I use the default set up when you make a project on the CLI. That is, I have one file for my controllers, one for any services, one for directives, and one for my config & state setup.


#3

thanks @mhartington, it’s good to have other’s opinions. But with this approach is easy to scale or maintain? Cause your code became bigger and bigger you will have a big file with a lot of controllers did you get to this point with any of your projects?


#4

You can organize your code module wise. For example, in the www folder put a app folder for your application code. libs folder for putting ionic and other 3rd part API's. Inside the app folder there can be a index file at root. Then separate folders for each module (like login etc. ). You should write separate controllers, services , partials for each module. You can also create a commons folder for your global services, directives etc.


#5

It’s worked for me so far, plus I comment my code very well. I hate having to go through 4-5 controller files to find on thing. This way, I know that all my controllers exist in in file and a simple look-up will find me what I need