3

I want to write news website where user will be accessed only after login. I can write everything in app.module but want to have nice architecture and I need an advice.

Should I create another module for account? Should I create another module for articles?

So I'll have

app.module

articles.module

account.module

Is this good practice?

I should pass session id on every request after log in. Would be that better?

app.module // + account folder where will be desired components/services articles.module

Community
  • 1
  • 1
gsiradze
  • 4,583
  • 15
  • 64
  • 111
  • @Kinduser Your comment is completely wrong. You don't NEED to create more than one module for the entire application – Fredrik Lundin Feb 10 '17 at 11:19
  • @FredrikLundin You don't need to create more than one module, but if you create different module for each different functionality, it will be good practice. In my opinion, for this application account module has different functionality while articles or app module has it's own different functionality. Even more, app module should be root module.Correct me, if I am wrong – David Maisuradze Feb 10 '17 at 11:26
  • @DatoMaisuradze Definitely agree, I was just replying to Kindusers comment saying "You need one module for each component, that's just how angular works". I see that comment is deleted now, so my reply to that doesn't really make sense ;) – Fredrik Lundin Feb 10 '17 at 11:33
  • @FredrikLundin No worries, got it, I saw that comment too :) – David Maisuradze Feb 10 '17 at 12:01

2 Answers2

2

If the framework let you to do something, it doesn't mean that is good.

Just separate your code into logical parts and create modules for those parts. If you have an admin part, you can write AdminModule. One module also for User part, but if the articles is only a component under the UserModule, you don't need to create a module for him too. Also you can load the independent modules lazily, which will increase you app's performance.

So I think if you have many components under a one logic and that works separately, you need to put them into one module

Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112
2

According to Angular2 official guide (https://angular.io/docs/ts/latest/guide/ngmodule.html), module is used to organize an application into cohesive blocks of functionality. It's a best practice to create a module ArticlesModules that hold all functionalities concerning articles and AccountsModule for all account functionalities. These modules are called feature modules. Features modules are used as clear boundaries between functionalities and features in the application.

Faly
  • 13,291
  • 2
  • 19
  • 37