59
Using to build Front-end JavaScript Apps that Scale Fluent 2014

Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Embed Size (px)

DESCRIPTION

Developing large apps is difficult. Ensuring that code is consistent, well structured, tested and has an architecture that encourages enhancement and maintainability is essential. When it comes to building large server-focused apps the solutions to this problem have been tried and tested. But, how do you achieve this when building HTML5 single page apps? BladeRunnerJS is an open source developer toolkit and lightweight front-end framework that has helped Caplin Systems ensure that a 200k LoC JavaScript codebase hasn’t become a tangled mess of unstable spaghetti code. This codebase is packaged and delivered to customers as an SDK. Additionally customers receive a getting started application of around 50k LoC for them to build upon, and they’re expected not to turn that into a tangled … you get the idea. In this talk you’ll learn the main concepts to apply when building a front-end app that scales and how BladeRunnerJS can support the development process.

Citation preview

Page 1: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Using !

to build Front-end

JavaScript Apps that Scale !

!Fluent 2014

Page 2: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Phil @leggetter [email protected]

Caplin Systems !

!

!

@BladeRunnerJS

Page 3: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 4: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

• Toolkit written in Java: Modular + Extensible

• Our version of:

• Yeoman + Grunt + Broccoli + Browserify + App Architecture + Micro-libraries

• New concepts: Blades + Workbenches

• Not a replacement for Angular, Ember, Web Components…

Page 5: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Overview

• What is a Large Scale front-end App?

• What are the signs of scaling?

• What are the solutions? (with demos)

Page 6: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

What is a large-scale JavaScript app?

Page 7: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

–Addy Osmani, Patterns For Large-Scale JavaScript Application Architecture

In my view, large-scale JavaScript apps are non-trivial applications requiring significant

developer effort to maintain, where most heavy lifting of data manipulation and display falls to

the browser.

Page 8: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Large CodebaseMore functionality === More code

Page 9: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Caplin Trader• SDK:

• ~1,000 JavaScript files

• ~131,000 LoC

• ~131 lines per file

• ~650 test files

• ~95,000 test LoC

• Typical Apps:

• ~425 JavaScript files

• ~50,000 LoC

• ~117 lines per file

• ~200 test files

• ~21,000 test LoC

Page 10: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Complexity

Page 11: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 12: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 13: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Gmail & Caplin Trader• Large Single Page Apps (SPAs)

• Complex functionality

• Complex interactions

• User

• Technology

• Leave open all day

Page 14: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

ContributorsThe Human Factor

Page 15: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Who contributes to an app?• Front-end devs

• Back-end devs

• Designers

• QA

• Infrastructure and release engineers

• Technical authors

Page 16: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

So, how do you ensure an application is maintainable?

1. structure a massive codebase (js, css, html, i18n, images, config etc.)

2. an architecture for complex functionality and interaction (UI and other components)

3. make sure that all contributors can work in harmony

4. development must be a productive experience

5. ensure all these compliment each other

Page 17: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Signs of scaling

Page 18: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Dev Setup takes forever

Page 19: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

My App isn’t working!• Other contributors breaking functionality

• Code accessed and modified from elsewhere

• Dependency Analysis and out of order file concatenation

Page 20: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Finding assets is hard

Page 21: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

What does this code do?

• Inconsistent coding style

• Inconsistent code structure

• Side effects through unexpected overrides

Page 22: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Long App Reloads

Page 23: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Have the tests finished yet?

• Having to run all the tests

• UI-based tests: Slow & unreliable

• Continuous Integration…taking 8 hours!

Stopwatch designed by Irit Barzily from the thenounproject.com

Page 24: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Scaling Solution

Page 25: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

• Streamlined developer workflow

• Consistency

• Focus on building a single feature (in isolation)

• Scalable loosely-coupled application architecture

• Quality at its core (maintainability)

BRJS Goals

Page 26: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Developer Workflow Focus on Features

Page 27: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 28: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Building a single feature in isolation

Page 29: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Blades

Page 30: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 31: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 32: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Workbenches

Page 33: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 34: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 35: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Blade Demo

Page 36: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 37: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 38: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

• Streamlined developer workflow

• Consistency

• Focus on building a single feature (in isolation)

• Scalable loosely-coupled application architecture

• Quality at its core (maintainability)

Goals

Page 39: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Application Architecture

Page 40: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Requires an Architecture that…

• Allows complex interactions

• Support developing a feature in isolation

• Allows components to be changed without side effects

• Is to maintain: Fix / Update / Extend

Page 41: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Blades (again)

Page 42: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

MVVM

Page 43: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Services

Page 44: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

What is a service?• Use services to access shared resources

• Persistence Service

• RESTful Service

• Realtime Service

• Services registered and accessed via a ServiceRegistry

• Dynamic Service Locator1

1 http://martinfowler.com/articles/injection.html#ADynamicServiceLocator

Page 45: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Why use services?

• Blades should not directly communicate

• Functionality encapsulated behind an interface

• Loose-coupled communication

• Dependencies can be injected for different scenarios:

• Workbench / Test / App

Page 46: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Services Demo

Page 47: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 48: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

• Streamlined developer workflow

• Consistency

• Focus on building a single feature (in isolation)

• Scalable loosely-coupled application architecture

• Quality at its core (maintainability)

Goals

Page 49: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Quality

Page 50: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Winning!• Streamlined dev workflow: focus on features

• e.g. Blades & Workbenches

• Consistency: Asset structure, Coding style & structure, Architecture

• Loose coupling: MVVM, Services & Interfaces

• Facilitates testing

• Can easily swap out implementations

• MVVM: Avoid testing the DOM

Page 51: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Test Demo !

./brjs test <path_to_run_tests>

Page 52: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 53: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Biggest Win• Testing features in

isolation

• Change view model and assert against mocked Service

• Inject mock service, make calls and assert View Model

Page 54: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Page 55: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Need Proof?Our full suite Caplin Trader

testing time went from

>8 Hours

< 30 minutes

Much less for a single feature

Page 56: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

• Streamlined developer workflow

• Consistency

• Focus on building a single feature (in isolation)

• Scalable loosely-coupled application architecture

• Quality at its core (maintainability)

Goals

Page 57: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Summary• BladeRunnerJS toolkit: Streamline developer

workflow + focus on features

• Blades: Build features in isolation (grouping assets together)

• Services: loose coupled communication e.g. EventHub

• Quality: Test units (classes), features (ViewModel < - > Service) & keep DOM testing to a minimum.

Page 58: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

BRJS at Fluent• BladeRunnerJS is a new open source solution

• bladerunnerjs.org

• v0.4 released last week

• @leggetter & @patrickmyles are at Fluent today & tomorrow

• BoF session tomorrow - table #7

Page 59: Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014

Phil @leggetter [email protected]

Caplin Systems !

!

!

@BladeRunnerJS bladerunnerjs.org