Option 1 One server process hosting the REST API and another server process supporting Angular UI
This option is the recommended option in the MicroServices architecture, where separate APIs (or a small associated API group) are launched and scaled separately, placing them in separate server processes. In such scenarios, if the Angular user interface is also associated with the REST API, this will mean that every bug fix or extension in the Angular user interface will require rebuilding and redistributing your services. And when we begin to do this, it will defeat the goal of microservices architecture.
Therefore, in such an architecture, only one Angular user interface will host one or more server instances. The Angular user interface, in turn, calls the individual APIs through the API gateway using some service discovery mechanism. However, microservice-based architecture is not trivial - it is complex with many moving parts. This level of complexity can be justified for large projects.
Option 2 One server process that hosts both the REST API and Angular UI
This parameter is the recommended option for small and medium-sized projects, where the user base is several hundred users.
In such projects, create a single repository in which the Maven project will contain two submodules: one for the REST API, and the other for the Angular interface.
Use the Maven frontend-maven-plugin plugin to create part of the user interface. This will automatically download the specified version of NodeJs and invoke the appropriate npm commands to create the Angular project. Finally, using the Maven element, copy the Angular dist folder to the static Spring Boot folder in the resources folder. (Exclude the static folder in the .gitignore file so that the Angular distribution files are not checked in the source control along with the REST API).
Now that Java build starts, it will automatically include a static folder in the fat jar, which will now serve both the API and the Angular user interface.
source share