angularjs - architecture decisionsin a large project 

71
Architecture decisions in a large project

Upload: elad-hirsch

Post on 16-Jul-2015

388 views

Category:

Software


1 download

TRANSCRIPT

Page 1: AngularJS - Architecture decisionsin a large project 

Architecture decisions

in a large project

Page 2: AngularJS - Architecture decisionsin a large project 

Who's speaking ?

• Elad Hirsch – Team Leader @ IDI

(Java , JavaScript , DevOps , Architecture)

• Guest lecture at TheEdge & Jenkins

Conferences

• A Programming Geek

Page 3: AngularJS - Architecture decisionsin a large project 

Technology stack

Page 4: AngularJS - Architecture decisionsin a large project 

Project Bootstrap

Page 5: AngularJS - Architecture decisionsin a large project 

Project Bootstrap

Page 6: AngularJS - Architecture decisionsin a large project 

Project Bootstrap

Page 7: AngularJS - Architecture decisionsin a large project 

Project Bootstrap

Page 8: AngularJS - Architecture decisionsin a large project 

Its all about the people

Page 9: AngularJS - Architecture decisionsin a large project 

+ =

divide et impera

Page 10: AngularJS - Architecture decisionsin a large project 

Architecture Principles

How do we handle large scale JavaScript Application ?

Page 11: AngularJS - Architecture decisionsin a large project 

Bower frontend artifacts

Library

• Share API

• Bower Dependencies

Bootstrap

• Dev Bootstrap

• Karma Tests

• Watch & Recompile

Deployable

• Application Archive

• UI/E2E Tests

Page 12: AngularJS - Architecture decisionsin a large project 

Project structure

Page 13: AngularJS - Architecture decisionsin a large project 

Snapshot

Deployment

• For rapidly moving code where bug fixes and

enhancements are coming fast

• Reduce the amount of framework based

checkout and builds

• Less framework variation to maintain

Always Moving forward

Page 14: AngularJS - Architecture decisionsin a large project 

Full Build

Page 15: AngularJS - Architecture decisionsin a large project 

Private Bower

Page 16: AngularJS - Architecture decisionsin a large project 

NPM Registry

Page 17: AngularJS - Architecture decisionsin a large project 

Artifactory

Page 18: AngularJS - Architecture decisionsin a large project 

Artifactory & NPM

Page 19: AngularJS - Architecture decisionsin a large project 

• Code reuse –Separate concerns :

– UI Widget – framework team

– MD logic – applicative teams

• DOM representation :

– link / compile overhead

– Complex DOM structure /Huge DOM nesting

• Distinction between directive instances :

– Via controllers -> more $scopes

– Event-bus || $rootScopes -> complex / hard to track

Angular directives

Page 20: AngularJS - Architecture decisionsin a large project 

ES6 ClassesEnable cleaner and more readable code.

WizardEngine

MDInfra

Page 21: AngularJS - Architecture decisionsin a large project 

if both the compile and link functions

are used, link should be the

return value of compile

Page 22: AngularJS - Architecture decisionsin a large project 

Directives are Singletons

Get state via $scope

$scope

$scope

$scope

$scope

$scope

$scope

Page 23: AngularJS - Architecture decisionsin a large project 
Page 24: AngularJS - Architecture decisionsin a large project 

if both the compile and link functions

are used, link should be the

return value of compile

Page 25: AngularJS - Architecture decisionsin a large project 

ES6 Register.jsMichael bromley

Enforce the use of a compile function

isn’t necessary in some cases

Decorate the compile

method

Page 26: AngularJS - Architecture decisionsin a large project 

Easier Reusability

of Components

Separation of Concerns

Testing as a baseline

Easy mocking

Goals to achieve

Page 27: AngularJS - Architecture decisionsin a large project 

AngularJS DI ?

Applications x Modules => Scalable enough ?

Page 28: AngularJS - Architecture decisionsin a large project 

RequireJS and AMD

• Asynchronous Module loading

• Script tags -> Real module dependencies

• Modularizing / Protect module internals

• Compile code into single minified file

Page 29: AngularJS - Architecture decisionsin a large project 

RequireJS plans for AngularJS

Page 30: AngularJS - Architecture decisionsin a large project 

Inject static files

Angular $Injection

Angular Directive

Lifecycle

Angular Directive

configuration

Require angular module

Page 31: AngularJS - Architecture decisionsin a large project 

Minification safe $inject using the inline, construction way – messy !!

$inject annotation technique – still not good

Use ng-annotate RequireJS pluginRequire-inject.js

Page 32: AngularJS - Architecture decisionsin a large project 

require $inject plugin

Register Class

Require angular module

Page 33: AngularJS - Architecture decisionsin a large project 

ng-annotate plugin

Page 34: AngularJS - Architecture decisionsin a large project 

Putting It All Together

• Define your Angular components as

ES6 Classes

• Configure RequireJS DI

• Use traceur-compiler to convert to

JavaScript-of-today compiler

• Register your class to module

Register -> type (module ,name ,class)

Page 35: AngularJS - Architecture decisionsin a large project 

dependency

information

Usage by another

module

Page 36: AngularJS - Architecture decisionsin a large project 

What is TypeScript ?

• Open Source

• Compiles to plain JavaScript on any browser

• Syntactic sugar for JavaScript.

• Syntax is a superset of (ES5) syntax

• Primary goal is to add strict typing to

the language (while aligning with ES6)

Page 37: AngularJS - Architecture decisionsin a large project 

TypeScript & Angular 2

Page 38: AngularJS - Architecture decisionsin a large project 

Error handling

Page 39: AngularJS - Architecture decisionsin a large project 
Page 40: AngularJS - Architecture decisionsin a large project 
Page 41: AngularJS - Architecture decisionsin a large project 
Page 42: AngularJS - Architecture decisionsin a large project 
Page 43: AngularJS - Architecture decisionsin a large project 

Expressions are forgiving

Type Attribute Evaluation

Forgiving Control Flow Statements

JavaScript evaluated against the

global window

Throw ReferenceError

TypeError

Supported

AngularJS Properties Evaluated

against $scope

Encapsulate the error

null/undefined

No support

add a Decorating $interpolate

Page 44: AngularJS - Architecture decisionsin a large project 
Page 45: AngularJS - Architecture decisionsin a large project 

Angular rendering

• Page Rendering is slower since browser

needs to do the extra work of DOM

• Compatibility with older browsers is hard

to accomplish

• Search Engines Optimization (SEO)

the biggest challenge

Page 46: AngularJS - Architecture decisionsin a large project 

Angular rendering

• Page Rendering is slower since browser

needs to do the extra work of DOM

• Compatibility with older browsers is hard

to accomplish

• Search Engines Optimization (SEO)

the biggest challenge

Page 47: AngularJS - Architecture decisionsin a large project 

Server rendering

Page 48: AngularJS - Architecture decisionsin a large project 

Angular SEO

How crawler retrieve the page - http://localhost:5000/http://localhost:8081

Page 49: AngularJS - Architecture decisionsin a large project 
Page 50: AngularJS - Architecture decisionsin a large project 

A Hybrid Approach

change the business logic on the

fly without need to compile or

change java code

Page 51: AngularJS - Architecture decisionsin a large project 

Java 8 Nashorn (JSR-223)

Page 52: AngularJS - Architecture decisionsin a large project 

Import via webjar

Registers

dropbox zxcvbn globally

as it would in the browser

Run a password through

the globally zxcvbn function

Turn the return value

into a Java POJO

Page 53: AngularJS - Architecture decisionsin a large project 

NodeJS on the JVM

Page 54: AngularJS - Architecture decisionsin a large project 

Rule engine

ClientRule Engine

ServerRule Engine

Page 55: AngularJS - Architecture decisionsin a large project 

UI Decisions

Kendo UI Mobiscroll

Page 56: AngularJS - Architecture decisionsin a large project 
Page 57: AngularJS - Architecture decisionsin a large project 
Page 58: AngularJS - Architecture decisionsin a large project 
Page 59: AngularJS - Architecture decisionsin a large project 

Israeli accessibility policy

Page 60: AngularJS - Architecture decisionsin a large project 

• Slow — Anything faster than 50 ms is

imperceptible to humans and thus can

be considered as "instant"

• Limited — You can't really show more

than about 2000 pieces of information to

a human on a single page

dirty-checking is inefficient ?

Humans are

Page 61: AngularJS - Architecture decisionsin a large project 

Lazy loading experiment

Browser performance basic fact:

• User events / layout / rendering / painting

all happen in turns in a single thread

• When your code runs for too long,

user's interaction is blocked.

Page 62: AngularJS - Architecture decisionsin a large project 

dirty checkingUser event

• For Every scope.$$watchers->function return value check

against previous value

• This is called dirty checking and can be quite slow if there are

lots of objects to compare

Page 63: AngularJS - Architecture decisionsin a large project 
Page 64: AngularJS - Architecture decisionsin a large project 

The browser UI is frozen

Challenge : moving the digest cycle and

dirty checking into separate thread.

Page 66: AngularJS - Architecture decisionsin a large project 

Use Cases

• Prefetching and/or caching data for later use

• Code syntax highlighting

• Real-time text formatting (Spell checker)

• Analyzing video or audio data

• Background I/O or polling of web-services

• Process large arrays or humungous

JSON responses

Page 67: AngularJS - Architecture decisionsin a large project 

Spring & AngularJS

Page 68: AngularJS - Architecture decisionsin a large project 

Spring Boot

Spring Security

AngularJS

Bootstrap

Bower

Metrics

Java 7 or Java 8

Maven or Gradle

Authentication Type:

- Cookie-based or OAuth2

Type of Database: SQL / NoSQL

Caching: EhCache or Hazelcast

Grunt or Gulp.js

Frameworks Project Options

Technology stack

Page 70: AngularJS - Architecture decisionsin a large project 

Stay sharp - follow on twitter

Page 71: AngularJS - Architecture decisionsin a large project 

Questions ?