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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
360
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
270
Other Decks in Programming
See All in Programming
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
130
はてなアカウント基盤 State of the Union
cockscomb
1
1.3k
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
390
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
360
霧の中の代数的エフェクト
funnyycat
1
400
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
500
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
520
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
210
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
120
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
260
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
380
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
110
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
980
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
350
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
390
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.2k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
220
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
Ruling the World: When Life Gets Gamed
codingconduct
0
280
Exploring anti-patterns in Rails
aemeredith
3
440
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
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]