64
Internal Architecting your Frontend Your mileage may vary Ruben Teijeiro @rteijeiro Senior Software Architect Tieto, CEM [email protected]

Architecting your Frontend

Embed Size (px)

Citation preview

Page 1: Architecting your Frontend

Inte

rnal

Architecting your FrontendYour mileage may vary

Ruben Teijeiro@rteijeiro

Senior Software ArchitectTieto, [email protected]

Page 2: Architecting your Frontend

Inte

rnal

Frontend(of a device or program) interface directly accessed by the user and allowing access to further devices, programs, or databases.

Page 3: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Frontend

3

http://bradfrost.com/blog/post/frontend-design

Page 4: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Frontend Design

4

http://bradfrost.com/blog/post/frontend-design

• Frontend design involves creating the HTML, CSS, and presentational JavaScript code that makes up a user interface.

• A Frontend Designer understands UX principles and best practices.

• It’s crucial to treat frontend development as a core part of the design process.

Page 5: Architecting your Frontend

© Tieto Corporation

Inte

rnal

User eXperience

5

Page 6: Architecting your Frontend

© Tieto Corporation

Inte

rnal

VR GUIs

6

Page 7: Architecting your Frontend

Inte

rnal

Frontend Frameworks

Page 8: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Frontend Frameworks

• CSS Frameworks

• JavaScript Frameworks

• Mobile Frameworks

8

Page 9: Architecting your Frontend

Inte

rnal

CSS Frameworks

Page 10: Architecting your Frontend

© Tieto Corporation

Inte

rnal

CSS Frameworks

• MaterializeCSS: http://materializecss.com

• Bootstrap: http://getbootstrap.com

• Foundation: http://foundation.zurb.com

10

Page 11: Architecting your Frontend

© Tieto Corporation

Inte

rnal

MaterializeCSS

Based on Material Design by Google

http://www.google.com/design/spec/material-design

11

Page 12: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Bootstrap

Created by Twitter

12

Page 13: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Foundation

13

Page 14: Architecting your Frontend

Inte

rnal

JavaScript Frameworks

Page 15: Architecting your Frontend

Inte

rnal

JavaScript Frameworks

Page 16: Architecting your Frontend

© Tieto Corporation

Inte

rnal

JavaScript Frameworks

• Angular: https://angularjs.org

• Ember: http://emberjs.com

• Backbone: http://backbonejs.org

• React: https://facebook.github.io/react

16

Page 17: Architecting your Frontend

© Tieto Corporation

Inte

rnal

JavaScript Frameworks

17

http://blog.bitovi.com/longevity-or-lack-thereof-in-javascript-frameworks

Page 18: Architecting your Frontend

© Tieto Corporation

Inte

rnal

JavaScript Frameworks

18

Page 19: Architecting your Frontend

Inte

rnal

Mobile Frameworks

Page 20: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Mobile Frameworks

• Ionic: http://ionicframework.com

• React Native: https://facebook.github.io/react-native

• Meteor: https://www.meteor.com

20

Page 21: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Ionic

21

Page 22: Architecting your Frontend

© Tieto Corporation

Inte

rnal

React Native

22

Page 23: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Meteor

23

Page 24: Architecting your Frontend

Inte

rnal

Frontend ArchitectureA practical case with BackboneJS

Page 25: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Frontend Architecture

• Models• Collections• Views• Events• Routers• Templates

25

Page 26: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Models

• Models are the entity of an application that store data and contain some logic around data such as validation, conversion, and data interaction.

26

Page 27: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Models

var User = Backbone.Model.extend({ defaults: { firstname: "", lastname: "", address: "", city: "", phone: "" }});

27

Page 28: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Collections

• A collection is a group of models that includes a lot of functionality as well as Underscore utility methods to help you work on multiple data models.

28

Page 29: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Collections

var Users = Backbone.Collection.extend({ model: User});

29

Page 30: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Views

• Views present an idea of organizing your Document Object Model (DOM) interface into logical blocks, and represent the model and collection data in them.

30

Page 31: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Viewsvar usersView = Backbone.View.extend({ template: _.template( usersTemplate ), events: { 'dblclick label': 'edit' }, render: function() { this.$el.html( this.template( this.model.attributes ) ); return this; }, edit: function(e) { console.log(e.target + ' was double clicked.'); }});

31

Page 32: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Events

• Events are a basic inversion of control. Instead of having one function call another by name, the second function is registered as a handler to be called when a specific event occurs.

32

Page 33: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Events

Backbone.on('event', function() { console.log('Handled Backbone event');});

Backbone.trigger('event');

// logs: Handled Backbone event

33

Page 34: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Routers

• In Backbone, routers provide a way for you to connect URLs (either hash fragments, or real) to parts of your application. Any piece of your application that you want to be bookmarkable, shareable, and back-button-able, needs a URL.

34

Page 35: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Routersvar AppRouter = Backbone.Router.extend({ routes: { "*actions": "getHome", "users": "getUsers", }, getHome: function() { console.log("You are in the homepage."); }, getUsers: function() { var users = new usersView(); users.render(); }});

35

Page 36: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Templates

• Templates are used to create the visual elements of your interface using HTML markup. They should not include the logic of your application.

36

Page 37: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Templates

<ul> <li>{{firstname}}</li> <li>{{lastname}}</li> <li>{{address}}</li> <li>{{city}}</li> <li>{{phone}}</li></ul>

37

Page 38: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Organizing your code

38

Page 39: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Organizing your code

• Separate every component in different files (models,

collections, views and routers).

• Define an entry point of the application.

• Use namespaces.

39

Page 40: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Application Directory Structure

40

.|-- assets| |-- css| |-- fonts| `-- img|-- src| |-- models| |-- views| | |-- users| | |-- products| | `-- customers| `-- collections`-- templates

Page 41: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Modular Directory Structure

41

.|-- app| |-- modules| | |-- user| | | |-- models| | | |-- views| | | |-- collections| | `-- customer| | | |-- ...| |-- utils| `-- auth.

Page 42: Architecting your Frontend

Inte

rnal

Module Bundlers

Page 43: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Module Bundlers

• Webpack: https://webpack.github.io

• Browserify: http://browserify.org

43

Page 44: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Browserify

44

Page 45: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Webpack

45

Page 46: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Webpack

46

Page 47: Architecting your Frontend

Inte

rnal

Frontend Tools

Page 48: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Package Managers

48

Page 49: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Package Managers

• npm: https://www.npmjs.com

• Bower: http://bower.io

49

Page 50: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Task Runners

50

Page 51: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Task Runners

• Grunt: http://gruntjs.com

• Gulp: http://gulpjs.com

51

Page 52: Architecting your Frontend

© Tieto Corporation

Inte

rnal

CSS Preprocessors

52

Page 53: Architecting your Frontend

© Tieto Corporation

Inte

rnal

CSS Preprocessors

• SASS: http://sass-lang.com

• LESS: http://lesscss.org

• Compass: http://compass-style.org

53

Page 54: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Template Systems

54

Page 55: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Template Systems

• Handlebars: http://handlebarsjs.com

• Mustache: https://mustache.github.io

• Underscore: http://underscorejs.org

55

Page 56: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Linting

56

Page 57: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Linting Tools

• CSSLint: http://csslint.net

• ESLint: http://eslint.org

57

Page 58: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Testing

58

Page 59: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Testing

• QUnit: https://qunitjs.com

• CasperJS: http://casperjs.org

• Jasmine: http://jasmine.github.io

• PhantomJS: http://phantomjs.org

59

Page 60: Architecting your Frontend

© Tieto Corporation

Inte

rnal

Visual Regression

60

Page 61: Architecting your Frontend

© Tieto Corporation

Inte

rnal

http://shoov.io

61

Page 62: Architecting your Frontend

Inte

rnal

WebServicesA practical case with Drupal

Page 63: Architecting your Frontend

Inte

rnal

Questions

Page 64: Architecting your Frontend

Inte

rnal

Ruben Teijeiro@rteijeiro

Senior Software ArchitectTieto, [email protected]