50
Best practices FOR CREATING MODULAR WEB APPLICATIONS Iliyan Peychev HERE GmbH @ipeychev

Best practices for creating modular Web applications

Embed Size (px)

Citation preview

Page 1: Best practices for creating modular Web applications

Best practices

FOR CREATING MODULAR WEB APPLICATIONS

Iliyan Peychev HERE GmbH @ipeychev

Page 2: Best practices for creating modular Web applications

CHALLENGES

Page 3: Best practices for creating modular Web applications

CHALLENGES

handling the Events Subscribing and unsubscribing to events

Manipulating the dom Manually? Virtual DOM? Re-DOM?

UNIT TESTS Mock everything? Staying as close to the reality as possible?

maintaining the state State might be spread among different services or components

Page 4: Best practices for creating modular Web applications

CHALLENGES

OPTIMIZE APPLICATION How to achieve maximum performance? Rendering on the server too?

Integration and end2end tests How do we keep them in sync with the code?

CONTINUOUS DEPLOYMENT AND DELIVERY How easy is to make releases? How do we keep the documentation in sync?

MAKING CHANGES TO THE SYSTEM How to prevent the “Software rot”?

Page 5: Best practices for creating modular Web applications

There is no silver bulletSome of these challenges are technical, others aren’t

(Technical challenges are easier to solve)

Page 6: Best practices for creating modular Web applications

FRAMEWORKSSomeone tells you how to write an application and

gives you the tools for writing it

Page 7: Best practices for creating modular Web applications

FRAMEWORKS and

libraries 2006

2010backboneModel–view–presenter (MVP) application design paradigm

YUIPowerful and rich, deprecated now

jQueryShaped the model for writing

applications for years2006

Page 8: Best practices for creating modular Web applications

2011

2013

2010

reactRevolutionized the way Web

applications were built

emberModel–view–viewmodel (MVVM) pattern

angular 1Complete and rich, but complex and

hard for maintenance and support

FRAMEWORKS and

libraries

Page 9: Best practices for creating modular Web applications

2017

2016angular 2Complete and rich, better than

Angular1

FRAMEWORKS and

libraries?

Page 10: Best practices for creating modular Web applications

FUNDAMENTALS OF DESIGNING

YOUR APPLICATION ARCHITECTURE

COMPONENTS AND MODULES

Page 11: Best practices for creating modular Web applications

WHAT IS A MODULE?

Page 12: Best practices for creating modular Web applications

MODULE

A “module” is a piece of functionality, which could be plugged to the application, replaced if needed and possibly reused

a piece of functionality

A module consists from one or more components

One component should stay in one module

Page 13: Best practices for creating modular Web applications

LET’S TAKE A LOOK AT THE REAL WORLD

COMPONENTS AND MODULES

Page 14: Best practices for creating modular Web applications
Page 15: Best practices for creating modular Web applications

Components

Page 16: Best practices for creating modular Web applications

Modules

Page 17: Best practices for creating modular Web applications

Modules

Page 18: Best practices for creating modular Web applications
Page 19: Best practices for creating modular Web applications
Page 20: Best practices for creating modular Web applications

INTERNATIONAL SPACE STATION

Page 21: Best practices for creating modular Web applications

International space station

Page 22: Best practices for creating modular Web applications

International space station

Page 23: Best practices for creating modular Web applications

Apply the same model to your

applications

(This is where things go wrong usually)

Page 24: Best practices for creating modular Web applications

PRACTICAL GUIDELINES

Page 25: Best practices for creating modular Web applications

features as modules

Separate the features of the application in modules

One module may consist from multiple components

The feature should be tested individually

Then included to the application

Page 26: Best practices for creating modular Web applications

COMPONENTS

Prefer to create components, which only render data

Create a few components to maintain the state

They will provide data to the rendering components

When testing, mock the external dependencies

Page 27: Best practices for creating modular Web applications

Avoid framework dependencies when possible

Try to make your classes framework agnostic

Then “glue” them to you framework of choice

Page 28: Best practices for creating modular Web applications

maintaining the state

Maintaining the state properly is the key to keep the

whole application maintainable

Use Flux pattern and some implementation like

Redux, MobX, or write your own

Page 29: Best practices for creating modular Web applications

Do not follow blindly

documentation/examples

Page 30: Best practices for creating modular Web applications
Page 31: Best practices for creating modular Web applications

Test each component separately

component 1

Module 2

Component 2 Component 3

Module 1

Component 4

}}

Page 32: Best practices for creating modular Web applications

Then test the whole system

component 1

Module 2

Component 2

Component 3

Module 1

Component 4

Page 33: Best practices for creating modular Web applications

pack the module and distribute

It might be NPM

or any other

module system

Page 34: Best practices for creating modular Web applications

SHARE CODE

Design the system with the idea to share code with other people

Page 35: Best practices for creating modular Web applications

Module systems

in JavaScript world

Page 36: Best practices for creating modular Web applications

ES2015 Commonjs

module

systems

amd

Made popular by Node, in 2013 they said its dead

Standard, not implemented in the browsers yet, but used widely with transpilers

Originally split from CommonJS, the difference is the async loading

Page 37: Best practices for creating modular Web applications

ES2015

features

Re-exporting Export an imported module

cyclic dependencies better handled than in CommonJS

single default export export function circle(x, y) {}

multiple named exports export const sqrt = Math.sqrt;

Page 38: Best practices for creating modular Web applications

CREATING MODULAR Web applications IN PRACTICE

Page 39: Best practices for creating modular Web applications

Could be part of an Indoor Positioning System

Let’s create an application for

monitoring iBeacons in range

Page 40: Best practices for creating modular Web applications

PARTS OF AN indoor positioning system

Venue maps

Indoor Radio Mapping tool

Detecting and monitoring Wi-Fi and Beacons

Positioning API

Location services/ End user applications

Page 41: Best practices for creating modular Web applications

iBeacons

Location

Services

Indoor

detect send Enrich Anchor Services

Page 42: Best practices for creating modular Web applications

Monitoring beacons

1 2

3 4

5 6 1 2 3 4 5 6

Page 43: Best practices for creating modular Web applications

ArchitectureMain parts of the system

Mobile application Mobile application created with ReactNative

Web Application Web application, created with React

Storage Data storage

Server NodeJS server to serve the Web application

Page 44: Best practices for creating modular Web applications

Which parts could be reused?

Page 45: Best practices for creating modular Web applications

The Communication with the server

Isolate it in a module It could be implemented using WebSockets, WeDeploy, etc.

Location

Services

Indoor

Location

Services

Indoor

Page 46: Best practices for creating modular Web applications

Detecting the beacons on iOS and android

Isolate the logic in modules with same API and expose it to React Native

1 2

3 4

5 6

1 2

3 4

5 6

Page 47: Best practices for creating modular Web applications

rendering the beacons on the screen

Isolate the logic in a module

1 2

3 4

5 6 1 2 3 4 5 6

Page 48: Best practices for creating modular Web applications

More things to consider Make the Web

application isomorphic

Replacing the communication part on the fly

Page 49: Best practices for creating modular Web applications

DEMO

Page 50: Best practices for creating modular Web applications

Questions?

Thanks!

ipeychev

ipeychev