Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Structuring large code bases with small re-usab...
Search
Bastian Hofmann
April 26, 2014
Programming
400
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Structuring large code bases with small re-usable components
From JSUnconf
Bastian Hofmann
April 26, 2014
More Decks by Bastian Hofmann
See All by Bastian Hofmann
Monitoring in Kubernetes with Prometheus and Grafana
bastianhofmann
0
370
Creating a fast Kubernetes Development Workflow
bastianhofmann
0
150
Highly available cross-region deployments with Kubernetes
bastianhofmann
1
170
From source to Kubernetes in 30 minutes
bastianhofmann
0
200
Introduction to Kubernetes
bastianhofmann
1
140
CI/CD with Kubernetes
bastianhofmann
0
250
Creating a fast Kubernetes Development Workflow
bastianhofmann
1
290
Deploying your first Micro-Service application to Kubernetes
bastianhofmann
2
210
Creating a fast Kubernetes Development Workflow
bastianhofmann
0
280
Other Decks in Programming
See All in Programming
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
370
Foundation Models frameworkで画像分析
ryodeveloper
1
600
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
240
「人を評価する AI」の設計と実装
ryoyanara
0
180
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
870
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
640
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
550
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
260
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
490
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
460
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
130
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
What's in a price? How to price your products and services
michaelherold
247
13k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Believing is Seeing
oripsolob
1
180
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
170
Skip the Path - Find Your Career Trail
mkilby
1
180
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
400
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
790
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Transcript
Structuring a large code base with re-usable components @BastianHofmann
Let's talk about...
Web Application architecture
Handling large code-bases
Code and component re-use
Rapid Development
webserver HTML browser JS
webserver HTML browser JS Ajax
webserver HTML browser JS Ajax
de duplication ode duplication code duplication code duplication code duplication
code duplication code duplication code duplication code duplication code duplication code duplication code duplication code duplication code duplicatio code duplicat code duplic code dup code du code cod co co
A few words about me
None
None
None
None
None
None
None
Questions? Ask
http://speakerdeck.com/u/bastianhofmann
None
webserver loadbalancer pgsql memcached mongodb services
webserver
status quo
None
PHP
MVC
PHP templates
Duplication and only some Code re- use
We can do better
Components
None
None
None
None
None
None
None
None
Self contained
Can be addressed and rendered separately
Server JS Browser JSON HTML HTML
None
PHP controller is part of the component
JS is part of the component
CSS can be part of the component
Share code between server and client
Templates, Validation, Entities,...
It needs to be fast
PHP Controller Mustache Template JavaScript view class Widget Providing data
Handling browser events Displaying data CSS
None
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Institution Menu
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Server
Request Response Institution
LeftColumn Image Menu Server Request Response
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Institution Menu
Widget Requirement
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution
Remember: self contained
Do not fetch data directly
Sssssssllllooooowww
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Account
Account Account Account Account Publication1 Publication2 Publication3 Institution
Require stuff
http://www.infoq.com/presentations/Evolution-of-Code- Design-at-Facebook/
None
Widget Widget Widget Widget Preparer Resolver Resolver Services Connector Interfaces
Connector Implementations
Widget Widget Widget Widget Preparer Fetch Requirements Resolver Resolver Services
Connector Interfaces Connector Implementations
Widget Widget Widget Widget Preparer Resolver Resolver Services Connector Interfaces
Connector Implementations Batch requirements and pass them to resolvers
Widget Widget Widget Widget Preparer Resolver Resolver Services Connector Interfaces
Connector Implementations Call Services as effective as possible (Multi-GET,...)
Widget Widget Widget Widget Preparer Resolver Resolver Services Connector Interfaces
Connector Implementations Attach fetched data to Requirements and pass them back to the preparer
Widget Widget Widget Widget Preparer Resolver Resolver Services Connector Interfaces
Connector Implementations Distribute fetched data to the widgets that required it
public function collect() { return [ new EntityRequirement( 'account', Account::class,
['id' => $this->request->get('id')] ), ]; }
Request Cache
Multi-GET
Futures
Data dependencies within a widget
=> Callbacks
public function collect() { yield [ new EntityRequirement( 'account', Account::class,
['id' => $this->request->get('id')] ), ]; yield [ new ServiceRequirement( 'scienceDisciplines', AccountService::class, 'getScienceDisciplines', ['account' => $this->account] ) ]; }
Data dependencies between Widgets
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution
Prefills
class PublicationKeywordSearch { public $publications; public $publicationListItems = [];
public function collect() { yield [ serviceRequirement( 'publications', PublicationService::getCall()->getByKeywords( ['virology', 'cancer'], 10, 0 ) ) ]; foreach ($this->publications as $publication) { yield new WidgetRequirement( 'publicationListItems', PublicationItem::CLASS, [ 'publicationId' => $publication->getId(), 'publication' => $publication ] ); } }
class PublicationItem { public $publicationId; public $publication; public
function collect() { yield new RequestDataRequirement('publicationId'); yield [ new EntityRequirement( 'publication', Publication::class, ['id' => $this->publicationId] ) ]; } }
Whoa, this looks awfully complicated to debug
None
None
None
None
None
So that was the backend
None
Rendering
HTML
JSON
Templates
Mustache } http://mustache.github.com/
<div id="{{widgetId}}"> <h3> Publications <a href="javascript:" class="js-showAll"> ({{count}}) </a>
</h3> <ul> {{#publicationItems}} <li>{{{.}}}</li> {{/publicationItems}} </ul> {{#showLegalFooter}} {{{legalFooter}}} {{/showLegalFooter}} </div>
http://pecl.php.net/package/v8js V8js
JavaScript
WidgetViews
<div id="{{widgetId}}"> <h3> Publications <a href="javascript:" class="js-showAll"> ({{count}}) </a>
</h3> <ul> {{#publicationItems}} <li>{{{.}}}</li> {{/publicationItems}} </ul> {{#showLegalFooter}} {{{legalFooter}}} {{/showLegalFooter}} </div>
YUI.add('views.publicationList', function (Y) { Y.views.publicationList = Y.Base.create(Y.WidgetView, { events :
{ '.js-showALl' : { click : 'showALl' } }, showAll : function () { var node = this.get('container'); node.addClass('loading'); Y.loadWidget(‚/publications/all', { keywords : this.data.keywords }, function (widget) { widget.render({ replace : node }); }); } }); });
http://twitter.github.io/flight/
http://facebook.github.io/react/
http://www.youtube.com/watch?v=fqULJBBEVQE
http://www.polymer-project.org/
<polymer-element name="tk-element" attributes="owner color"> <template> <span>This is <strong>{{owner}}</strong>'s tk-element.</span> <span
id="el" style="color: {{color}}">Not ready...</span> </template> <script> Polymer('tk-element', { owner: "Bastian", color: "red", ready: function() { this.$.el.innerText = this.owner + " is ready!"; } }); </script> </polymer-element>
<!DOCTYPE html> <html> <head> <script src="bower_components/platform/platform.js"> </script> <link rel="import" href="elements/tk-element.html">
</head> <body> <tk-element color="blue"></tk-element> </body> </html>
Benefits
Enables developers to only focus on their components
Rapid prototyping
Easier Refactoring
Error Handling
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu EXCEPTION
Institution
Profile Publications Publication Publication Publication LeftColumn Image Menu Institution
Experiments (A/B Testing)
None
Caching of Components
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu <esi:include
src="..." /> Institution
Easy re-using of components
None
Load components asynchronously
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu <div
id="placeholder"></div> <script>loadWidget('/aboutMe', function(w) { w.render({ replace : '#placeholder' }); })</script> Institution
BigPipe https://www.facebook.com/note.php? note_id=389414033919
None
Profile Menu Header LeftColumn RightColumn
None
None
None
None
pushState
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution
Profile Questions Question Question Question AboutMe LeftColumn Image Menu Institution
Conclusion?
Think about your architecture
Refactor and make it better continuously
Frontend and backend are part of the same application
Don't rewrite your whole codebase in one go
http://twitter.com/BastianHofmann http://lanyrd.com/people/BastianHofmann http://speakerdeck.com/u/bastianhofmann !
[email protected]