built to last

77
Built to Last Building scalable front-end application architectures with business logic.

Upload: dan-lynch

Post on 08-May-2015

9.790 views

Category:

Technology


0 download

DESCRIPTION

Design on a scalable, state-based, front-end application architecture to manage business logic and control flow. We'll synthesize a number of programming patterns to help you decouple not only views and data, but also navigation paradigms and transitions between states to keep your product agile and moving forward without having to refactor.

TRANSCRIPT

Page 1: Built to Last

Built to Last

Building scalable front-end application architectures with business logic.

Page 2: Built to Last

Dan LynchEngineer & Artist

questions/thoughts? @skatalynch

Page 3: Built to Last

The Web

Page 4: Built to Last

Building Things

1999, AutoCAD 10

Page 5: Built to Last

2006

SideFXcity builder interface

I like helping other people build

Page 6: Built to Last

Building things that build things

Vim3D

vim interface to building 3D

Page 7: Built to Last

famo.us

our biz dev built this app on the first famo.us framework

Page 8: Built to Last

interface for buildinginteractive textbooks

mathapedia

Page 9: Built to Last

building tools for people

Page 10: Built to Last

10

Modularity is the degree to which a system’s components may be separated and recombined. (wikipedia)

Abstraction is the process of formulating generalized ideas or concepts by extracting common qualities from specific examples (the free dictionaty)

top down

bottom up

?

Page 11: Built to Last

11

Modularity• modules• extensions

Abstraction• routing• pages• data/APIs

top down

bottom up

large-scale rapid development

Page 12: Built to Last

Why Modularity?

Page 13: Built to Last

Adding New Code

Most time you spend is maintaining code, not writing new code

Page 14: Built to Last

Intuitive

Co-workers depend on your code to make sense

Page 15: Built to Last

Extendability

If features change, it’s easy to extend or swap parts

Page 16: Built to Last

Debug/Test

It’s easy to test individual modules

Page 17: Built to Last

The Mythical Man MonthFrederick Brooks Jr.

“Men and months are interchangeable commodi-ties only when a task can be partitioned among many workers with no communication among them”

Page 18: Built to Last

Complex Communication

Page 19: Built to Last

Spaghetti Code• specific to application• not reusable• the app is the testing framework

Page 20: Built to Last

Perfectly Partitionable

Page 21: Built to Last

Modules• interdependent• little knowledge about the application• it is the sum of the modules that makes up the application

Page 22: Built to Last

Module: Each of a set of standardized parts or independent units that can be used to con-struct a more complex structure (google definition)

Page 23: Built to Last

Various Module Definitions + Terminolgies

• JS module pattern• AMD modules• Web application modules

Page 24: Built to Last

JavaScript Module Pattern

private and public encapsulation using closures

Page 25: Built to Last

AMD Modules

Page 26: Built to Last

Web Application Modules

HTML + CSS + JS

(components)

Page 27: Built to Last

Application Modules

model

view

controller

Page 28: Built to Last

Application Framework

“An Application Framework is like a playground for your code”

- Nicholas Zakas

Page 29: Built to Last

core

sandbox

module

module

module module

module

extensionextension

extensionextension

Application Framework

Page 30: Built to Last

Where to start

backbone boilerplate modular + build for production

aura modular + widgets + message passing

Page 31: Built to Last

Sandboxfacade“The programmer is most effective if shielded from, rather than exposed to the details of construction of system parts other than his own“

-Frederick Brooks Jr.

Page 32: Built to Last

core

sandbox

module

module

module module

module

extension

extension

extension

extension

each module has a sandbox

This promotes loose coupling so you can changemodules without affecting others

Page 33: Built to Last

each module has a sandbox

Page 34: Built to Last

sandbox exposes functionality

core

sandbox

module module module

Page 35: Built to Last

sandbox exposes functionality

Page 36: Built to Last

core

sandbox

module

module

module module

module

extension

extension

extension

extension

application core

Page 37: Built to Last

module registration, lifecycle,and intercommunication

Page 38: Built to Last

message passing

module life-cycle

application core is responsible for:

Page 39: Built to Last

application core - the mediator

• communication hub & centralized controller• intermediary between interdependent modules

Page 40: Built to Last

mediatormodule

module

module

application core - the mediator

modules use transitive communication through mediator

only N channels!

Page 41: Built to Last

publish

photo gallery module

Page 42: Built to Last

publish

“get-fb-photos”

Gallery Module

Page 43: Built to Last

“get-fb-photos”

mediator

Page 44: Built to Last

“get-fb-photos”

FB Integration Module

subscribe

Page 45: Built to Last

subscribe

fb integration module

Page 46: Built to Last

photo gallery module

Page 47: Built to Last

module life-cycle

Page 48: Built to Last

build for extension

Page 49: Built to Last

core

sandbox

module

module

module module

module

extension

extension

extension

extension

extending the core

Page 50: Built to Last

Where do my routes go?Where does my data live?

Where is my layout?

Page 51: Built to Last

Decouple Your Web AppNavigation URLs/routes/controllers

Data data/models/collections

Pages layouts/views/templates

Page 52: Built to Last
Page 53: Built to Last

layout extension

enable abstraction of navigation paradigms

Page 54: Built to Last

mediatormodule

router

layout

route:books

route:books

render:books

render:books

Page 55: Built to Last

controller

Page 56: Built to Last

layout

Page 57: Built to Last

module group extension

If a group of modules represents an application, what if we can manage groups to run multiple applications or portals within a single page app?

Page 58: Built to Last

module group extension

Page 59: Built to Last

route

change group

route

group?

v

yes

no

controller

Page 60: Built to Last

module group extension

Page 61: Built to Last

swap layout

change group

$.when.apply($, promises).done

afterRender()

start modules

Page 62: Built to Last

Protecting Resources/Modules

Page 63: Built to Last

middleware

typical backend

middleware can protect resources

route controller

flow

yes

no

Page 64: Built to Last

route

(typical Backbone routing with no FSM)

controller

can the front-end JS function like the backend?

Page 65: Built to Last

Finite State Machine

• events• states• transitions• actions

Page 66: Built to Last
Page 67: Built to Last

route

fail()

route

fsm

v

yes

no

controller

Backbone routing with FSM

Page 68: Built to Last

route

v

yes

yes

no no

FSM group?

fail()swap layout

start modules

enter()

resetRoutes()controller

Page 69: Built to Last
Page 70: Built to Last
Page 71: Built to Last

router extension• manage routes, delegate route callbacks to FSM

module groups extension• modify core to handle groups with async/dfd

layout extension• render views using message passing

fsm extension• manage state (group)• if routes pass, send allow controllers to callback

data extension• manage model/collection cache

Page 72: Built to Last

what we coveredhow to take core components of a

web application (routes, navigation, layouts, etc) and divy them up into

modules/extensions so that the application can grow efficiently;

without the need to refactor.

bottom up + top down!

Page 73: Built to Last

node.js end-to-end JS!backbone boilerplate great for build + gettings startedaura widgets and module lifecyclebackbone layout manager views/layoutsasync.js asyncronous flow controlgrunt.js buildrequire.js module loadingr.js optimizer

tech to use and checkout

Page 74: Built to Last

props, credit, and people to checkout

Tim Branyen Addy Osmoni

Nicholas Zakas

Page 75: Built to Last
Page 76: Built to Last
Page 77: Built to Last

@skatalynch

Thank You!