Different project structures when building an Angular App with separated Spring Backend











up vote
0
down vote

favorite












I want to build a web page where I separate Database, Backend and Frontend and make then communicate via REST. I got quite confused about how to structure the project(s). As I read, there are the following approaches:




  1. Make different projects: one for the frontend (let's say Angular) and one for the Backend (Spring) including the database connection. These are completely separated from each other and different IDE's might be used.


  2. Build it in one big project but still use REST for communication (see picture below).



Now what I would like to know is what the difference between these two approaches is? I do not know (and do not ask) which one is the better one, but I cannot even make out reasons or effects to pick one above or below the other one.



Approach 2










share|improve this question


















  • 1




    I think the best solution is to follow the architecture of JHipster which puts both backend and frontend into one project. If you put them into two different projects, you have to take care of CORS, and also use a suited authentication mechanism like JWT or Oauth
    – zakaria amine
    Nov 11 at 12:33










  • @zakariaamine But wouldn't I always need to use suited authentication mechanisms when I seperate Frontend and Backend by REST, since I need a ways to authenticate the user access? Or did I get that wrong?
    – Rüdiger
    Nov 11 at 14:00






  • 1




    If you put them in the same project, and you serve directly your front end files by a spring Controller, then you can simply use a HTTP session, which is already provided. Otherwise, different projects requires further setup in both the front end, in which you have to handle the security and the backend to issue and verify tokens.
    – zakaria amine
    Nov 11 at 18:44










  • @zakariaamine I see that I got troubles understanding how all of that works together. But let's see if we can clarify this a little: Whenever I can simply use a HTTP session that is already provided, I do not have a "real" REST separation between frontend and backend, right? Since I could also just leave the REST-stuff.
    – Rüdiger
    Nov 11 at 20:20















up vote
0
down vote

favorite












I want to build a web page where I separate Database, Backend and Frontend and make then communicate via REST. I got quite confused about how to structure the project(s). As I read, there are the following approaches:




  1. Make different projects: one for the frontend (let's say Angular) and one for the Backend (Spring) including the database connection. These are completely separated from each other and different IDE's might be used.


  2. Build it in one big project but still use REST for communication (see picture below).



Now what I would like to know is what the difference between these two approaches is? I do not know (and do not ask) which one is the better one, but I cannot even make out reasons or effects to pick one above or below the other one.



Approach 2










share|improve this question


















  • 1




    I think the best solution is to follow the architecture of JHipster which puts both backend and frontend into one project. If you put them into two different projects, you have to take care of CORS, and also use a suited authentication mechanism like JWT or Oauth
    – zakaria amine
    Nov 11 at 12:33










  • @zakariaamine But wouldn't I always need to use suited authentication mechanisms when I seperate Frontend and Backend by REST, since I need a ways to authenticate the user access? Or did I get that wrong?
    – Rüdiger
    Nov 11 at 14:00






  • 1




    If you put them in the same project, and you serve directly your front end files by a spring Controller, then you can simply use a HTTP session, which is already provided. Otherwise, different projects requires further setup in both the front end, in which you have to handle the security and the backend to issue and verify tokens.
    – zakaria amine
    Nov 11 at 18:44










  • @zakariaamine I see that I got troubles understanding how all of that works together. But let's see if we can clarify this a little: Whenever I can simply use a HTTP session that is already provided, I do not have a "real" REST separation between frontend and backend, right? Since I could also just leave the REST-stuff.
    – Rüdiger
    Nov 11 at 20:20













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to build a web page where I separate Database, Backend and Frontend and make then communicate via REST. I got quite confused about how to structure the project(s). As I read, there are the following approaches:




  1. Make different projects: one for the frontend (let's say Angular) and one for the Backend (Spring) including the database connection. These are completely separated from each other and different IDE's might be used.


  2. Build it in one big project but still use REST for communication (see picture below).



Now what I would like to know is what the difference between these two approaches is? I do not know (and do not ask) which one is the better one, but I cannot even make out reasons or effects to pick one above or below the other one.



Approach 2










share|improve this question













I want to build a web page where I separate Database, Backend and Frontend and make then communicate via REST. I got quite confused about how to structure the project(s). As I read, there are the following approaches:




  1. Make different projects: one for the frontend (let's say Angular) and one for the Backend (Spring) including the database connection. These are completely separated from each other and different IDE's might be used.


  2. Build it in one big project but still use REST for communication (see picture below).



Now what I would like to know is what the difference between these two approaches is? I do not know (and do not ask) which one is the better one, but I cannot even make out reasons or effects to pick one above or below the other one.



Approach 2







spring angular maven spring-boot






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 11:43









Rüdiger

311217




311217








  • 1




    I think the best solution is to follow the architecture of JHipster which puts both backend and frontend into one project. If you put them into two different projects, you have to take care of CORS, and also use a suited authentication mechanism like JWT or Oauth
    – zakaria amine
    Nov 11 at 12:33










  • @zakariaamine But wouldn't I always need to use suited authentication mechanisms when I seperate Frontend and Backend by REST, since I need a ways to authenticate the user access? Or did I get that wrong?
    – Rüdiger
    Nov 11 at 14:00






  • 1




    If you put them in the same project, and you serve directly your front end files by a spring Controller, then you can simply use a HTTP session, which is already provided. Otherwise, different projects requires further setup in both the front end, in which you have to handle the security and the backend to issue and verify tokens.
    – zakaria amine
    Nov 11 at 18:44










  • @zakariaamine I see that I got troubles understanding how all of that works together. But let's see if we can clarify this a little: Whenever I can simply use a HTTP session that is already provided, I do not have a "real" REST separation between frontend and backend, right? Since I could also just leave the REST-stuff.
    – Rüdiger
    Nov 11 at 20:20














  • 1




    I think the best solution is to follow the architecture of JHipster which puts both backend and frontend into one project. If you put them into two different projects, you have to take care of CORS, and also use a suited authentication mechanism like JWT or Oauth
    – zakaria amine
    Nov 11 at 12:33










  • @zakariaamine But wouldn't I always need to use suited authentication mechanisms when I seperate Frontend and Backend by REST, since I need a ways to authenticate the user access? Or did I get that wrong?
    – Rüdiger
    Nov 11 at 14:00






  • 1




    If you put them in the same project, and you serve directly your front end files by a spring Controller, then you can simply use a HTTP session, which is already provided. Otherwise, different projects requires further setup in both the front end, in which you have to handle the security and the backend to issue and verify tokens.
    – zakaria amine
    Nov 11 at 18:44










  • @zakariaamine I see that I got troubles understanding how all of that works together. But let's see if we can clarify this a little: Whenever I can simply use a HTTP session that is already provided, I do not have a "real" REST separation between frontend and backend, right? Since I could also just leave the REST-stuff.
    – Rüdiger
    Nov 11 at 20:20








1




1




I think the best solution is to follow the architecture of JHipster which puts both backend and frontend into one project. If you put them into two different projects, you have to take care of CORS, and also use a suited authentication mechanism like JWT or Oauth
– zakaria amine
Nov 11 at 12:33




I think the best solution is to follow the architecture of JHipster which puts both backend and frontend into one project. If you put them into two different projects, you have to take care of CORS, and also use a suited authentication mechanism like JWT or Oauth
– zakaria amine
Nov 11 at 12:33












@zakariaamine But wouldn't I always need to use suited authentication mechanisms when I seperate Frontend and Backend by REST, since I need a ways to authenticate the user access? Or did I get that wrong?
– Rüdiger
Nov 11 at 14:00




@zakariaamine But wouldn't I always need to use suited authentication mechanisms when I seperate Frontend and Backend by REST, since I need a ways to authenticate the user access? Or did I get that wrong?
– Rüdiger
Nov 11 at 14:00




1




1




If you put them in the same project, and you serve directly your front end files by a spring Controller, then you can simply use a HTTP session, which is already provided. Otherwise, different projects requires further setup in both the front end, in which you have to handle the security and the backend to issue and verify tokens.
– zakaria amine
Nov 11 at 18:44




If you put them in the same project, and you serve directly your front end files by a spring Controller, then you can simply use a HTTP session, which is already provided. Otherwise, different projects requires further setup in both the front end, in which you have to handle the security and the backend to issue and verify tokens.
– zakaria amine
Nov 11 at 18:44












@zakariaamine I see that I got troubles understanding how all of that works together. But let's see if we can clarify this a little: Whenever I can simply use a HTTP session that is already provided, I do not have a "real" REST separation between frontend and backend, right? Since I could also just leave the REST-stuff.
– Rüdiger
Nov 11 at 20:20




@zakariaamine I see that I got troubles understanding how all of that works together. But let's see if we can clarify this a little: Whenever I can simply use a HTTP session that is already provided, I do not have a "real" REST separation between frontend and backend, right? Since I could also just leave the REST-stuff.
– Rüdiger
Nov 11 at 20:20












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










This is really question about personal preference, but you have them be in completely different projects and at the same time you can put your JS bundles (from ng build) inside of the resources/static folder (of the Spring app) and it'll work perfectly, assuming you want to run them on the same server.



You can set a proxy config to make it easier like:



{
"/api": {
"target": "http://localhost:8080",
"secure": false
}
}


This way whenever you do a rest call with something like Angulars HttpClient, as long as you put /api in front of the url it'll call your spring backend.



Example:



  public fetchResource(id: number): Observable<Resource> {
return this.http.get(`/api/resources/${id}`);
}


I prefer to have my client and api in different projects.



Whenever you want to add the JS bundles to your resources/static folder, you can just create an NPM script to do it for you in package.json.






share|improve this answer





















  • Thanks! I got two points on that: 1. The first thing you mentioned (moving the JS-bundles) is only necessary when I deploy it as one single application but build it as two before? 2. If you do not use that way, you are having two applications deployed on your tomcat (or whatever server u might use) and they function as two different applications, right? But I struggle to understand WHY someone would use it one way or the other. Sure everyone has his preferences, but each of these solutions has to come with some "pro's and con's"
    – Rüdiger
    Nov 11 at 20:27








  • 1




    I worded myself incorrectly. You're going to want to run ng build --prod when you're ready to deploy regardless of whether or not you're running it on the same server as your Spring Boot app. When you're still in dev, you don't need to move any JS bundles to resources/static (again, if you choose to run it on the same server). Can if you want, but don't need to. 2: You could host your angular app on GH pages and your API on heroku. It'll work fine. And the last point is really just for convenience. Look into the front-end-maven-plugin
    – abrandell
    Nov 11 at 21:32











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',
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248390%2fdifferent-project-structures-when-building-an-angular-app-with-separated-spring%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










This is really question about personal preference, but you have them be in completely different projects and at the same time you can put your JS bundles (from ng build) inside of the resources/static folder (of the Spring app) and it'll work perfectly, assuming you want to run them on the same server.



You can set a proxy config to make it easier like:



{
"/api": {
"target": "http://localhost:8080",
"secure": false
}
}


This way whenever you do a rest call with something like Angulars HttpClient, as long as you put /api in front of the url it'll call your spring backend.



Example:



  public fetchResource(id: number): Observable<Resource> {
return this.http.get(`/api/resources/${id}`);
}


I prefer to have my client and api in different projects.



Whenever you want to add the JS bundles to your resources/static folder, you can just create an NPM script to do it for you in package.json.






share|improve this answer





















  • Thanks! I got two points on that: 1. The first thing you mentioned (moving the JS-bundles) is only necessary when I deploy it as one single application but build it as two before? 2. If you do not use that way, you are having two applications deployed on your tomcat (or whatever server u might use) and they function as two different applications, right? But I struggle to understand WHY someone would use it one way or the other. Sure everyone has his preferences, but each of these solutions has to come with some "pro's and con's"
    – Rüdiger
    Nov 11 at 20:27








  • 1




    I worded myself incorrectly. You're going to want to run ng build --prod when you're ready to deploy regardless of whether or not you're running it on the same server as your Spring Boot app. When you're still in dev, you don't need to move any JS bundles to resources/static (again, if you choose to run it on the same server). Can if you want, but don't need to. 2: You could host your angular app on GH pages and your API on heroku. It'll work fine. And the last point is really just for convenience. Look into the front-end-maven-plugin
    – abrandell
    Nov 11 at 21:32















up vote
1
down vote



accepted










This is really question about personal preference, but you have them be in completely different projects and at the same time you can put your JS bundles (from ng build) inside of the resources/static folder (of the Spring app) and it'll work perfectly, assuming you want to run them on the same server.



You can set a proxy config to make it easier like:



{
"/api": {
"target": "http://localhost:8080",
"secure": false
}
}


This way whenever you do a rest call with something like Angulars HttpClient, as long as you put /api in front of the url it'll call your spring backend.



Example:



  public fetchResource(id: number): Observable<Resource> {
return this.http.get(`/api/resources/${id}`);
}


I prefer to have my client and api in different projects.



Whenever you want to add the JS bundles to your resources/static folder, you can just create an NPM script to do it for you in package.json.






share|improve this answer





















  • Thanks! I got two points on that: 1. The first thing you mentioned (moving the JS-bundles) is only necessary when I deploy it as one single application but build it as two before? 2. If you do not use that way, you are having two applications deployed on your tomcat (or whatever server u might use) and they function as two different applications, right? But I struggle to understand WHY someone would use it one way or the other. Sure everyone has his preferences, but each of these solutions has to come with some "pro's and con's"
    – Rüdiger
    Nov 11 at 20:27








  • 1




    I worded myself incorrectly. You're going to want to run ng build --prod when you're ready to deploy regardless of whether or not you're running it on the same server as your Spring Boot app. When you're still in dev, you don't need to move any JS bundles to resources/static (again, if you choose to run it on the same server). Can if you want, but don't need to. 2: You could host your angular app on GH pages and your API on heroku. It'll work fine. And the last point is really just for convenience. Look into the front-end-maven-plugin
    – abrandell
    Nov 11 at 21:32













up vote
1
down vote



accepted







up vote
1
down vote



accepted






This is really question about personal preference, but you have them be in completely different projects and at the same time you can put your JS bundles (from ng build) inside of the resources/static folder (of the Spring app) and it'll work perfectly, assuming you want to run them on the same server.



You can set a proxy config to make it easier like:



{
"/api": {
"target": "http://localhost:8080",
"secure": false
}
}


This way whenever you do a rest call with something like Angulars HttpClient, as long as you put /api in front of the url it'll call your spring backend.



Example:



  public fetchResource(id: number): Observable<Resource> {
return this.http.get(`/api/resources/${id}`);
}


I prefer to have my client and api in different projects.



Whenever you want to add the JS bundles to your resources/static folder, you can just create an NPM script to do it for you in package.json.






share|improve this answer












This is really question about personal preference, but you have them be in completely different projects and at the same time you can put your JS bundles (from ng build) inside of the resources/static folder (of the Spring app) and it'll work perfectly, assuming you want to run them on the same server.



You can set a proxy config to make it easier like:



{
"/api": {
"target": "http://localhost:8080",
"secure": false
}
}


This way whenever you do a rest call with something like Angulars HttpClient, as long as you put /api in front of the url it'll call your spring backend.



Example:



  public fetchResource(id: number): Observable<Resource> {
return this.http.get(`/api/resources/${id}`);
}


I prefer to have my client and api in different projects.



Whenever you want to add the JS bundles to your resources/static folder, you can just create an NPM script to do it for you in package.json.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 15:56









abrandell

384




384












  • Thanks! I got two points on that: 1. The first thing you mentioned (moving the JS-bundles) is only necessary when I deploy it as one single application but build it as two before? 2. If you do not use that way, you are having two applications deployed on your tomcat (or whatever server u might use) and they function as two different applications, right? But I struggle to understand WHY someone would use it one way or the other. Sure everyone has his preferences, but each of these solutions has to come with some "pro's and con's"
    – Rüdiger
    Nov 11 at 20:27








  • 1




    I worded myself incorrectly. You're going to want to run ng build --prod when you're ready to deploy regardless of whether or not you're running it on the same server as your Spring Boot app. When you're still in dev, you don't need to move any JS bundles to resources/static (again, if you choose to run it on the same server). Can if you want, but don't need to. 2: You could host your angular app on GH pages and your API on heroku. It'll work fine. And the last point is really just for convenience. Look into the front-end-maven-plugin
    – abrandell
    Nov 11 at 21:32


















  • Thanks! I got two points on that: 1. The first thing you mentioned (moving the JS-bundles) is only necessary when I deploy it as one single application but build it as two before? 2. If you do not use that way, you are having two applications deployed on your tomcat (or whatever server u might use) and they function as two different applications, right? But I struggle to understand WHY someone would use it one way or the other. Sure everyone has his preferences, but each of these solutions has to come with some "pro's and con's"
    – Rüdiger
    Nov 11 at 20:27








  • 1




    I worded myself incorrectly. You're going to want to run ng build --prod when you're ready to deploy regardless of whether or not you're running it on the same server as your Spring Boot app. When you're still in dev, you don't need to move any JS bundles to resources/static (again, if you choose to run it on the same server). Can if you want, but don't need to. 2: You could host your angular app on GH pages and your API on heroku. It'll work fine. And the last point is really just for convenience. Look into the front-end-maven-plugin
    – abrandell
    Nov 11 at 21:32
















Thanks! I got two points on that: 1. The first thing you mentioned (moving the JS-bundles) is only necessary when I deploy it as one single application but build it as two before? 2. If you do not use that way, you are having two applications deployed on your tomcat (or whatever server u might use) and they function as two different applications, right? But I struggle to understand WHY someone would use it one way or the other. Sure everyone has his preferences, but each of these solutions has to come with some "pro's and con's"
– Rüdiger
Nov 11 at 20:27






Thanks! I got two points on that: 1. The first thing you mentioned (moving the JS-bundles) is only necessary when I deploy it as one single application but build it as two before? 2. If you do not use that way, you are having two applications deployed on your tomcat (or whatever server u might use) and they function as two different applications, right? But I struggle to understand WHY someone would use it one way or the other. Sure everyone has his preferences, but each of these solutions has to come with some "pro's and con's"
– Rüdiger
Nov 11 at 20:27






1




1




I worded myself incorrectly. You're going to want to run ng build --prod when you're ready to deploy regardless of whether or not you're running it on the same server as your Spring Boot app. When you're still in dev, you don't need to move any JS bundles to resources/static (again, if you choose to run it on the same server). Can if you want, but don't need to. 2: You could host your angular app on GH pages and your API on heroku. It'll work fine. And the last point is really just for convenience. Look into the front-end-maven-plugin
– abrandell
Nov 11 at 21:32




I worded myself incorrectly. You're going to want to run ng build --prod when you're ready to deploy regardless of whether or not you're running it on the same server as your Spring Boot app. When you're still in dev, you don't need to move any JS bundles to resources/static (again, if you choose to run it on the same server). Can if you want, but don't need to. 2: You could host your angular app on GH pages and your API on heroku. It'll work fine. And the last point is really just for convenience. Look into the front-end-maven-plugin
– abrandell
Nov 11 at 21:32


















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248390%2fdifferent-project-structures-when-building-an-angular-app-with-separated-spring%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Guess what letter conforming each word

Run scheduled task as local user group (not BUILTIN)

Port of Spain