Modular Angular architecture for maximize code-reuse, but still provide enough flexibilityHow do I overwrite an existing component in angular?Angular CLI SASS optionsHow to extend/inherit components?Cannot find name 'require' after upgrading to Angular4Angular2/4 : Override component from another module@Angular 2: Better approach Whether to create components or modulesAngular4 for both backend & frontendHow to maximize reuse across many Angular projects?Angular App inside asp.net core 2 requires node.js?Angular 6/7 multi application change directory of projects (ng g application module1)Angular Portal to include multiple angular projects and library
Which are the methodologies for interpreting Vedas?
Fixed-Do Solfege in A Major scale with accidentals
Why did Robert pick unworthy men for the White Cloaks?
What did the 8086 (and 8088) do upon encountering an illegal instruction?
Print "N NE E SE S SW W NW"
Can I attach a DC blower to intake manifold of my 150CC Yamaha FZS FI engine?
Why is it bad to use your whole foot in rock climbing
Why is isotope an issue in reading mass spectra?
What do I need to do, tax-wise, for a sudden windfall?
Are skill challenges an official option or homebrewed?
How to properly use a function under a class?
Are the guests in Westworld forbidden to tell the hosts that they are robots?
Is it advisable to add a location heads-up when a scene changes in a novel?
Can I get a photo of an Ancient Arrow?
Why would a car salesman tell me not to get my credit pulled again?
When to use и or а as “and”?
Why is my Taiyaki (Cake that looks like a fish) too hard and dry?
Does WiFi affect the quality of images downloaded from the internet?
What's the difference between DHCP and NAT? Are they mutually exclusive?
Must I use my personal social media account for work?
Why does there seem to be an extreme lack of public trashcans in Taiwan?
Why does the PoissonDistribution not plot around its mean for moderate large numbers?
What is the theme of analysis?
Should I explain the reasons for gaslighting?
Modular Angular architecture for maximize code-reuse, but still provide enough flexibility
How do I overwrite an existing component in angular?Angular CLI SASS optionsHow to extend/inherit components?Cannot find name 'require' after upgrading to Angular4Angular2/4 : Override component from another module@Angular 2: Better approach Whether to create components or modulesAngular4 for both backend & frontendHow to maximize reuse across many Angular projects?Angular App inside asp.net core 2 requires node.js?Angular 6/7 multi application change directory of projects (ng g application module1)Angular Portal to include multiple angular projects and library
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
As a development company, it is quite common that different projects require (almost) equal code. The need for a modular system becomes more and more a requirement so that I maximize code-reuse on both front-end and back-end.
What is important is that I don't want to cut on restrictions, meaning a client would almost always be able to get the features he wants. If that feature turns out to be re-usable for other business cases, I would include it in one of the "main" modules, otherwise we would (extend/override existing modules and) create a separate module.
Back-end
Now on the back-end I have solved this, and it might be worth to explain with an example.
Let's say you have a Core module, a E-Commerce module and a Marketplace module.
- All of the modules would require a Portal / back-office / admin panel.
- The e-commerce module would need to have a dedicated webshop web project.
- The marketplace module would need to have a dedicated marketplace web project.
The way I solved this, in C#, is like so:

So in above image you can see that the controllers within the modules are extensible by overriding it. All the domain and application logics are in the same fashion (not shown): most things are virtualized so I can override it if needed within one business-project. So if one business-project does not meet the requirement by using the standard 'E-Commerce' module, it could extend or create additional logic/controllers to achieve the features.
So, for the portal application, I see no issue. I can easily lazy-load (angular) modules based on settings. This can be one single web application for all business cases and don't need any special care. So although it shows two separate Portal web applications, they will end up with the same angular front-end code. They will then just be split up on different servers of course.
Front-end
But coming down to the webshop and the marketplace modules/projects:
- They might both have a complete different design.
- Both could be used by different businesses with each it's unique checkout/marketplace flow/design.
- But, loading products, showing marketplace items, register/login and payment is in terms of functionality mostly equal.
- Some components that are created in the core module and used in the portal should be also be able to be used in the webshop/marketplace app.
So..how do I get this done correctly in angular (7)? What I know up until now and worked out so far.
Similarities between business-projects
Since all back-end controllers will have their fixed routing, the http calls are equal across all projects. One project could extend a back-end controller and behave differently, but that would not change the routing. If one project requires way-off functionalities, it would most-likely also require a separate angular module/component.
Some businesses might want to show components slightly different (in the portal). This can either be achieved by having project-specific
style.lessfiles (most likely needed anyway for main layout colors) or 'override/replace' a component, as per this answer.Even though a webshop and a marketplace are completely different businesses, they do have similar functionalities like: login, payment page for invoices, showing invoice details, upload photo's, datetime pickers and country/language selector + localization.
Sometimes extra fields are required, this can be achieved in a CRM-like method by configuring this in the database and have them load into the view on separate http-calls.
Differences between business-projects
I see the differences in a few 'stages', from minor changes to big changes:
Small design changes: This would only require a small change in the overall layout, and could be achieved by changing the company-specific style.less. If that is not enough or would require to much code within the main style.less file, we would want to replace the component.less file. Example: A login page.
Big design changes: The component functionality would be the same but it would require a complete different .html for the component. Example: Account profile page.
Functional changes: The html and less file can actually be equal, but minor to major changes are required in the component functionality / behavior. Example: One might want to automatically save data, one might want to have a confirmation button.
Complete different component: Solved, see 2. in similarities.
Remaining questions
- How could I load a different style for a specific component? Similar to supplying multiple design files for mobile, tablet and desktop. But then based on an environment variable?
- How to have a complete different .html file for the same component functionality?
- Perhaps it can be useful to have the routing configuration per-company to easily switch to a custom component instead of one of the default components within one module?
- How would I structure my folders? The ASP.NET Core-way is to have the angular project within the web project, but when I want to share components across all the different web projects I don't really see how this would work. I think I do prefer to have the angular project within the web project because they integrate quite good with each other, would also avoid token-based authentication overhead when not hosting them separately.
Consideration
One way I can think of is creating your own private npm packages, create a 'core' module, 'ecommerce' module and a 'marketplace' module. And then have every actual business-project import these npm packages. For production-ready code this would work I guess, but during development I am not sure how this would work so that I don't have to publish my package every time before I can use it in the other project. For this I would still have to solve the above questions: how can I extend/override the module again after importing it. If I would be able to all have a ng build --watch on them that it would be fine, but of I guess this will probably require intensive configuration when I want to automate it in the CI/CD? Also given the fact that it needs to easily be debuggable during testing one project.
Basically I am looking for best-practices. So far solutions were hard to find since 'modules' and 'angular' go hand in hand, so most solutions just solely focus on individual modules within one project.
I have a architecture sketch in how I would structure the angular modules:

add a comment |
As a development company, it is quite common that different projects require (almost) equal code. The need for a modular system becomes more and more a requirement so that I maximize code-reuse on both front-end and back-end.
What is important is that I don't want to cut on restrictions, meaning a client would almost always be able to get the features he wants. If that feature turns out to be re-usable for other business cases, I would include it in one of the "main" modules, otherwise we would (extend/override existing modules and) create a separate module.
Back-end
Now on the back-end I have solved this, and it might be worth to explain with an example.
Let's say you have a Core module, a E-Commerce module and a Marketplace module.
- All of the modules would require a Portal / back-office / admin panel.
- The e-commerce module would need to have a dedicated webshop web project.
- The marketplace module would need to have a dedicated marketplace web project.
The way I solved this, in C#, is like so:

So in above image you can see that the controllers within the modules are extensible by overriding it. All the domain and application logics are in the same fashion (not shown): most things are virtualized so I can override it if needed within one business-project. So if one business-project does not meet the requirement by using the standard 'E-Commerce' module, it could extend or create additional logic/controllers to achieve the features.
So, for the portal application, I see no issue. I can easily lazy-load (angular) modules based on settings. This can be one single web application for all business cases and don't need any special care. So although it shows two separate Portal web applications, they will end up with the same angular front-end code. They will then just be split up on different servers of course.
Front-end
But coming down to the webshop and the marketplace modules/projects:
- They might both have a complete different design.
- Both could be used by different businesses with each it's unique checkout/marketplace flow/design.
- But, loading products, showing marketplace items, register/login and payment is in terms of functionality mostly equal.
- Some components that are created in the core module and used in the portal should be also be able to be used in the webshop/marketplace app.
So..how do I get this done correctly in angular (7)? What I know up until now and worked out so far.
Similarities between business-projects
Since all back-end controllers will have their fixed routing, the http calls are equal across all projects. One project could extend a back-end controller and behave differently, but that would not change the routing. If one project requires way-off functionalities, it would most-likely also require a separate angular module/component.
Some businesses might want to show components slightly different (in the portal). This can either be achieved by having project-specific
style.lessfiles (most likely needed anyway for main layout colors) or 'override/replace' a component, as per this answer.Even though a webshop and a marketplace are completely different businesses, they do have similar functionalities like: login, payment page for invoices, showing invoice details, upload photo's, datetime pickers and country/language selector + localization.
Sometimes extra fields are required, this can be achieved in a CRM-like method by configuring this in the database and have them load into the view on separate http-calls.
Differences between business-projects
I see the differences in a few 'stages', from minor changes to big changes:
Small design changes: This would only require a small change in the overall layout, and could be achieved by changing the company-specific style.less. If that is not enough or would require to much code within the main style.less file, we would want to replace the component.less file. Example: A login page.
Big design changes: The component functionality would be the same but it would require a complete different .html for the component. Example: Account profile page.
Functional changes: The html and less file can actually be equal, but minor to major changes are required in the component functionality / behavior. Example: One might want to automatically save data, one might want to have a confirmation button.
Complete different component: Solved, see 2. in similarities.
Remaining questions
- How could I load a different style for a specific component? Similar to supplying multiple design files for mobile, tablet and desktop. But then based on an environment variable?
- How to have a complete different .html file for the same component functionality?
- Perhaps it can be useful to have the routing configuration per-company to easily switch to a custom component instead of one of the default components within one module?
- How would I structure my folders? The ASP.NET Core-way is to have the angular project within the web project, but when I want to share components across all the different web projects I don't really see how this would work. I think I do prefer to have the angular project within the web project because they integrate quite good with each other, would also avoid token-based authentication overhead when not hosting them separately.
Consideration
One way I can think of is creating your own private npm packages, create a 'core' module, 'ecommerce' module and a 'marketplace' module. And then have every actual business-project import these npm packages. For production-ready code this would work I guess, but during development I am not sure how this would work so that I don't have to publish my package every time before I can use it in the other project. For this I would still have to solve the above questions: how can I extend/override the module again after importing it. If I would be able to all have a ng build --watch on them that it would be fine, but of I guess this will probably require intensive configuration when I want to automate it in the CI/CD? Also given the fact that it needs to easily be debuggable during testing one project.
Basically I am looking for best-practices. So far solutions were hard to find since 'modules' and 'angular' go hand in hand, so most solutions just solely focus on individual modules within one project.
I have a architecture sketch in how I would structure the angular modules:

add a comment |
As a development company, it is quite common that different projects require (almost) equal code. The need for a modular system becomes more and more a requirement so that I maximize code-reuse on both front-end and back-end.
What is important is that I don't want to cut on restrictions, meaning a client would almost always be able to get the features he wants. If that feature turns out to be re-usable for other business cases, I would include it in one of the "main" modules, otherwise we would (extend/override existing modules and) create a separate module.
Back-end
Now on the back-end I have solved this, and it might be worth to explain with an example.
Let's say you have a Core module, a E-Commerce module and a Marketplace module.
- All of the modules would require a Portal / back-office / admin panel.
- The e-commerce module would need to have a dedicated webshop web project.
- The marketplace module would need to have a dedicated marketplace web project.
The way I solved this, in C#, is like so:

So in above image you can see that the controllers within the modules are extensible by overriding it. All the domain and application logics are in the same fashion (not shown): most things are virtualized so I can override it if needed within one business-project. So if one business-project does not meet the requirement by using the standard 'E-Commerce' module, it could extend or create additional logic/controllers to achieve the features.
So, for the portal application, I see no issue. I can easily lazy-load (angular) modules based on settings. This can be one single web application for all business cases and don't need any special care. So although it shows two separate Portal web applications, they will end up with the same angular front-end code. They will then just be split up on different servers of course.
Front-end
But coming down to the webshop and the marketplace modules/projects:
- They might both have a complete different design.
- Both could be used by different businesses with each it's unique checkout/marketplace flow/design.
- But, loading products, showing marketplace items, register/login and payment is in terms of functionality mostly equal.
- Some components that are created in the core module and used in the portal should be also be able to be used in the webshop/marketplace app.
So..how do I get this done correctly in angular (7)? What I know up until now and worked out so far.
Similarities between business-projects
Since all back-end controllers will have their fixed routing, the http calls are equal across all projects. One project could extend a back-end controller and behave differently, but that would not change the routing. If one project requires way-off functionalities, it would most-likely also require a separate angular module/component.
Some businesses might want to show components slightly different (in the portal). This can either be achieved by having project-specific
style.lessfiles (most likely needed anyway for main layout colors) or 'override/replace' a component, as per this answer.Even though a webshop and a marketplace are completely different businesses, they do have similar functionalities like: login, payment page for invoices, showing invoice details, upload photo's, datetime pickers and country/language selector + localization.
Sometimes extra fields are required, this can be achieved in a CRM-like method by configuring this in the database and have them load into the view on separate http-calls.
Differences between business-projects
I see the differences in a few 'stages', from minor changes to big changes:
Small design changes: This would only require a small change in the overall layout, and could be achieved by changing the company-specific style.less. If that is not enough or would require to much code within the main style.less file, we would want to replace the component.less file. Example: A login page.
Big design changes: The component functionality would be the same but it would require a complete different .html for the component. Example: Account profile page.
Functional changes: The html and less file can actually be equal, but minor to major changes are required in the component functionality / behavior. Example: One might want to automatically save data, one might want to have a confirmation button.
Complete different component: Solved, see 2. in similarities.
Remaining questions
- How could I load a different style for a specific component? Similar to supplying multiple design files for mobile, tablet and desktop. But then based on an environment variable?
- How to have a complete different .html file for the same component functionality?
- Perhaps it can be useful to have the routing configuration per-company to easily switch to a custom component instead of one of the default components within one module?
- How would I structure my folders? The ASP.NET Core-way is to have the angular project within the web project, but when I want to share components across all the different web projects I don't really see how this would work. I think I do prefer to have the angular project within the web project because they integrate quite good with each other, would also avoid token-based authentication overhead when not hosting them separately.
Consideration
One way I can think of is creating your own private npm packages, create a 'core' module, 'ecommerce' module and a 'marketplace' module. And then have every actual business-project import these npm packages. For production-ready code this would work I guess, but during development I am not sure how this would work so that I don't have to publish my package every time before I can use it in the other project. For this I would still have to solve the above questions: how can I extend/override the module again after importing it. If I would be able to all have a ng build --watch on them that it would be fine, but of I guess this will probably require intensive configuration when I want to automate it in the CI/CD? Also given the fact that it needs to easily be debuggable during testing one project.
Basically I am looking for best-practices. So far solutions were hard to find since 'modules' and 'angular' go hand in hand, so most solutions just solely focus on individual modules within one project.
I have a architecture sketch in how I would structure the angular modules:

As a development company, it is quite common that different projects require (almost) equal code. The need for a modular system becomes more and more a requirement so that I maximize code-reuse on both front-end and back-end.
What is important is that I don't want to cut on restrictions, meaning a client would almost always be able to get the features he wants. If that feature turns out to be re-usable for other business cases, I would include it in one of the "main" modules, otherwise we would (extend/override existing modules and) create a separate module.
Back-end
Now on the back-end I have solved this, and it might be worth to explain with an example.
Let's say you have a Core module, a E-Commerce module and a Marketplace module.
- All of the modules would require a Portal / back-office / admin panel.
- The e-commerce module would need to have a dedicated webshop web project.
- The marketplace module would need to have a dedicated marketplace web project.
The way I solved this, in C#, is like so:

So in above image you can see that the controllers within the modules are extensible by overriding it. All the domain and application logics are in the same fashion (not shown): most things are virtualized so I can override it if needed within one business-project. So if one business-project does not meet the requirement by using the standard 'E-Commerce' module, it could extend or create additional logic/controllers to achieve the features.
So, for the portal application, I see no issue. I can easily lazy-load (angular) modules based on settings. This can be one single web application for all business cases and don't need any special care. So although it shows two separate Portal web applications, they will end up with the same angular front-end code. They will then just be split up on different servers of course.
Front-end
But coming down to the webshop and the marketplace modules/projects:
- They might both have a complete different design.
- Both could be used by different businesses with each it's unique checkout/marketplace flow/design.
- But, loading products, showing marketplace items, register/login and payment is in terms of functionality mostly equal.
- Some components that are created in the core module and used in the portal should be also be able to be used in the webshop/marketplace app.
So..how do I get this done correctly in angular (7)? What I know up until now and worked out so far.
Similarities between business-projects
Since all back-end controllers will have their fixed routing, the http calls are equal across all projects. One project could extend a back-end controller and behave differently, but that would not change the routing. If one project requires way-off functionalities, it would most-likely also require a separate angular module/component.
Some businesses might want to show components slightly different (in the portal). This can either be achieved by having project-specific
style.lessfiles (most likely needed anyway for main layout colors) or 'override/replace' a component, as per this answer.Even though a webshop and a marketplace are completely different businesses, they do have similar functionalities like: login, payment page for invoices, showing invoice details, upload photo's, datetime pickers and country/language selector + localization.
Sometimes extra fields are required, this can be achieved in a CRM-like method by configuring this in the database and have them load into the view on separate http-calls.
Differences between business-projects
I see the differences in a few 'stages', from minor changes to big changes:
Small design changes: This would only require a small change in the overall layout, and could be achieved by changing the company-specific style.less. If that is not enough or would require to much code within the main style.less file, we would want to replace the component.less file. Example: A login page.
Big design changes: The component functionality would be the same but it would require a complete different .html for the component. Example: Account profile page.
Functional changes: The html and less file can actually be equal, but minor to major changes are required in the component functionality / behavior. Example: One might want to automatically save data, one might want to have a confirmation button.
Complete different component: Solved, see 2. in similarities.
Remaining questions
- How could I load a different style for a specific component? Similar to supplying multiple design files for mobile, tablet and desktop. But then based on an environment variable?
- How to have a complete different .html file for the same component functionality?
- Perhaps it can be useful to have the routing configuration per-company to easily switch to a custom component instead of one of the default components within one module?
- How would I structure my folders? The ASP.NET Core-way is to have the angular project within the web project, but when I want to share components across all the different web projects I don't really see how this would work. I think I do prefer to have the angular project within the web project because they integrate quite good with each other, would also avoid token-based authentication overhead when not hosting them separately.
Consideration
One way I can think of is creating your own private npm packages, create a 'core' module, 'ecommerce' module and a 'marketplace' module. And then have every actual business-project import these npm packages. For production-ready code this would work I guess, but during development I am not sure how this would work so that I don't have to publish my package every time before I can use it in the other project. For this I would still have to solve the above questions: how can I extend/override the module again after importing it. If I would be able to all have a ng build --watch on them that it would be fine, but of I guess this will probably require intensive configuration when I want to automate it in the CI/CD? Also given the fact that it needs to easily be debuggable during testing one project.
Basically I am looking for best-practices. So far solutions were hard to find since 'modules' and 'angular' go hand in hand, so most solutions just solely focus on individual modules within one project.
I have a architecture sketch in how I would structure the angular modules:

asked Mar 24 at 23:36
CularBytesCularBytes
4,78124069
4,78124069
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329617%2fmodular-angular-architecture-for-maximize-code-reuse-but-still-provide-enough-f%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329617%2fmodular-angular-architecture-for-maximize-code-reuse-but-still-provide-enough-f%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown