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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
190
Introduction to Kubernetes
bastianhofmann
1
140
CI/CD with Kubernetes
bastianhofmann
0
240
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
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.3k
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
720
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
170
Vite+ Unified Toolchain for the Web
naokihaba
0
330
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
14
5.7k
Lessons from Spec-Driven Development
simas
PRO
0
220
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
570
RTSPクライアントを自作してみた話
simotin13
0
620
Performance Engineering for Everyone
elenatanasoiu
0
190
AIで効率化できた業務・日常
ochtum
0
140
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.3k
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
190
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Claude Code のすすめ
schroneko
67
230k
Balancing Empowerment & Direction
lara
6
1.2k
Mobile First: as difficult as doing things right
swwweet
225
10k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
320
Making the Leap to Tech Lead
cromwellryan
135
9.9k
The Curse of the Amulet
leimatthew05
1
13k
How to Talk to Developers About Accessibility
jct
2
240
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
The Language of Interfaces
destraynor
162
27k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.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]