1
my doubt is not related to codes properly, but on how to better organize the project files.
I know that this is a question that has neither the right answer nor the best answer. But as I am developing a project now where I am facing several areas and functions, I would like to know from you what tips or guidelines you can give to improve this organization and not get lost among so many files in the future.
Currently I own an organization in this style:
-js //Arquivos Js necessários para rodar o app
--angular.min.js
--angular-animate.min.js
--angular-local-storage.min.js
--angular-touch.min.js
--oc-lazyload.min.js
--ui-router.min.js
-App //escrito por eu mesmo
--controller - todos os controllers
--directives - todos os directives
--factory - todas as factorys
--app.js - configurações principais (router, filter, config)
-Lib //modulo de terceiros
--ngMask.min.js
--ngTooltip.min.js
--ngMap.min.js
-- [..etc..]
However, after a few lessons I learned more about modularizing the code and also managed to do the lazyload
of files. That is, much of the code I own, I will be able to segment according to the area. For example:
Currently my webApp
has 3 distinct areas:
- User: anyone who registers on the site;
- Moderators/Attendants: people who attend, check, mess with some restricted areas of the company;
- Administrators: Control flow of sales, reports, etc.
For this I’m thinking of using the lazyload
, to improve the safety and speed of webApp
, since I will only load the module that is really necessary for that particular view
. But that’s when it gets complicated.
In a quick structural sketch that I drew up, this is the structure that I got:
-App //escrito por eu mesmo
--Controller
---ctrl-admin.js
---ctrl-empresa.js
---ctrl-comum.js
--Directive
---dire-admin.js
---dire-empresa.js
---dire-comum.js
--Factory
---fact-admin.js
---fact-empresa.js
---fact-comum.js
--Config
---config.js
--app.js //config da rota, autenticação, etc.
-Lib
--main //Arquivos Js necessários para rodar o app
---angular.min.js
---angular-animate.min.js
---angular-local-storage.min.js
---angular-touch.min.js
---oc-lazyload.min.js
---ui-router.min.js
--modulos //lib de terceiros, secundárias (tooltip, ngImago, etc.)
---main //principais - comum a todos - (escritas por eu mesmo)
----ngLogin.min.js //processa login
----ngCart.min.js //carrinho de compras
----ngAlert.min.js //notificação de pedidos, mensagens, novo ticket, etc.
---sec //secundarias - modular - (de terceiros)
----ngMap.js - somente carrega em view X
----ngMask.js - somente carrega em view Y
----ngTooltip.js - somente carrega em view Y, view Z
[.. etc ..]
As you can see, this structure starts to get a little 'messy' and it takes a lot of care as I can start to lose myself, especially as some of these files (or large majority) will need to go through a concat
/uglify
.
And it needs to be separated because, for example, the files ctrl-admin
, dire-admin
and fact-admin
, will only be loaded in views regarding administrators (controlled by ocLazyLoad
).
Would you have any suggestions? Best Practice
? Suggestion or some guide I can study and improve this structure?
Cool! After I asked, I did another search and found this: https://github.com/mgechev/angularjs-style-guide I noticed that many projects have been using the view organization structure, where each view (e.g., clients) has its files. client.ctrl.js, client.fact.js (or concatenated). What do you think of this structure? In this case, it would be even better to create micro modules for each view, if you follow this line?
– celsomtrindade
I don’t particularly like it much, because then you remove the possibility of re-use of the view ("although this is rarely possible in the separation by modules"), but it is really of opinion, I believe that the most important thing is to define a clear form of organization, where it is easy to navigate to fix a problem, and it can be easily changed later.
– Ricardo Rodrigues de Faria
Yes, for this particular project there will be no view sharing, but I intend to set up a standard flow for future projects. About Bower, I already used, but I didn’t like the fact of downloading all the lib, polluting the files a lot. Unless I’ve used it wrong, since I’ve never really focused on it either. Any guidance on using Bower? I have also used npm, but with the same 'poréns'. Perhaps if it were possible to take only the distribution files.
– celsomtrindade
Downloading everything is no problem, the important thing is to generate a build only with what you need, there are many tasks of Grunt that compile only the necessary.
– Ricardo Rodrigues de Faria
Yes, Grunt I already have familiarity. I use it for several tasks. js, Sass, css, etc.. Do you know enough about Angularjs? Would you mind contacting us for a few thoughts?
– celsomtrindade
If it is a problem that you can not detail here by stack, you can send me in email [email protected], but if they are doubts that you can clearly expose, it is important to leave so that we can contribute to the community.
– Ricardo Rodrigues de Faria
Now that I stopped to read the links you sent. Just for the record, they are excellent!!! It was very helpful! Thanks @Ricardo Rodrigues de Fari
– celsomtrindade
Nothing expensive, anything we are available.
– Ricardo Rodrigues de Faria