Blog by a Web Designing Company in Hyderabad, India

Web Designing and Development company in Hyderabad, India

Angular JS Documentation & Architecture

Spring MVC & Angular Js Coneptulisation

Spring MVC and AngularJs together make for a really productive and appealing frontend development stack for building form-intensive web applications.

In this blog post we will see how a form-intensive web app can be built using these technologies, and compare such approach with other available options. A fully functional and secured sample Spring MVC / AngularJs web app can be found in this github repository.

We will go over the following topics:

  • The architecture of a Spring MVC + Angular single page app
  • How to structure a web UI using Angular
  • Which Javascript / CSS libraries complement well Angular?
  • How to build a REST API backend with Spring MVC
  • Securing a REST API using Spring Security
  • How does this compare with other approaches that use a full Java-based approach?

The architecture of a Spring MVC + Angular single page web app

-intensive enterprise class applications are ideally suited for being built as single page web apps. The main idea compared to other more traditional server-side architectures is to build the server as a set of stateless reusable REST services, and from an MVC perspective to take the controller out of the backend and move it into the browser:

AngularJs Spring MVC architecture

The client is MVC-capable and contains all the presentation logic which is separated in a view layer, a controller layer and a frontend services layer. After the initial application startup, only JSON data goes over the wire between client and server.

How is backend Built?

The backend of an enterprise frontend application can be built in a very natural and web-like way as a REST API. The same technology can be used to provide web services to third-party applications - obviating in many cases the need for a separate SOAP web services stack.

From a DDD perspective, the domain model remains on the backend, at the service and persistence layer level. Over the wire only DTOs go by, but not the domain model.

How to structure frontend of web app using Angular JS

The frontend should be built around a view-specific model (which is not the domain model), and should only handle presentation logic, but no business logic. These are the three layers of the frontend:

The View Layer

The view layer is composed of Html templates, CSS, and any Angular directives representing the different UI components. This is an example of a simple view for a login form:

Log In

New user?

 

The Controller Layer

The controller layer is made of Angular controllers that glue the data retrieved from the backend and the view together. The controller initializes the view model and defines how the view should react to model changes and vice-versa:

  
angular.module('loginApp', ['common',  'editableTableWidgets'])  
    .controller('LoginCtrl', function ($scope, LoginService) {

        $scope.onLogin = function () {
            console.log('Attempting login with username ' + $scope.vm.username + ' and password ' + $scope.vm.password);

            if ($scope.form.$invalid) {
                return;
            }

            LoginService.login($scope.vm.userName, $scope.vm.password);

        };

    });

One of the main responsibilities of the controller is to perform frontend validations. Any validations done on the frontend are for user convenience only - for example they are useful to immediately inform the user that a field is required.

Any frontend validations need to be repeated in the backend at the service layer level due to security reasons, as the frontend validations can be easily bypassed.

Vivid Design Consultants

Source: Blog.Angular.University.