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
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
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
130
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
860
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
4.4k
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
170
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.5k
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.8k
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
140
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
2.7k
5分で問診!Composer セキュリティ健康診断
codmoninc
0
330
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
2
540
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
210
Featured
See All Featured
Skip the Path - Find Your Career Trail
mkilby
1
170
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
220
BBQ
matthewcrist
89
10k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
350
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
490
Game over? The fight for quality and originality in the time of robots
wayneb77
1
220
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
900
Discover your Explorer Soul
emna__ayadi
2
1.2k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
190
30 Presentation Tips
portentint
PRO
1
350
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]