SlideShare a Scribd company logo
Modularity problems
Architecture of corporate Symfony-applications
Who I am
● Senior Software Engineer @ Upwork
● 10+ years of PHP (Pear -> ZF 1 -> Symfony 1 -> Yii 1 -> ....)
● 4+ years of Symfony 2
● Also experience in Java (Spring, GWT, ...), C# (.Net), Ruby (Rails), JS (...)
● KNU, Faculty of Cybernetics, Theory of Programming
Modularity  problems
How to perceive this speech
This speech ...
● … is not a manual
⇒ use Google please!
● … covers some problems of modularity
⇒ it doesn’t cover a lot of stuff.
● … displays some Symfony problems
⇒ but we love Symfony anyway =)
What is “framework”?
Library vs Framework
Library
useful pieces of
code in one place
Framework
set of libraries, tools
and principles of
application
development
Framework
● It is a platform
● It defines application structure
● It unites components
● It offers tools
● It describes best practices
Modules
Modules (plugins, extensions, bundles etc.) is a
way to extend a framework.
Symfony modules
Component is Symfony library.
You need Composer to use Component.
Bundle is Symfony module.
You also need Composer to use Bundle.
But you must enable Bundle in your AppKernel
How does Bundle extend our framework?
● Commands
● Controllers
● Public services
○ also tagged services (event listeners, annotation processors etc.)
● Service Container processing
○ add support of custom service tags
○ preconfigure other modules (prepend)
● Other common code and assets (careful!)
Symfony 2.x ⇒ 4.x
● Flex
○ Flex is a tool to simplify bundle installation.
● Bundle-less
○ Application is not a bundle
○ Symfony 4.x application directory structure is self-sufficient
Corporate Symfony applications
Specifics of big product companies
● A lot of developer teams
● A lot of code
● A lot of different applications may fit in one project
● “Core” team
Example structure of corporate applications
Symfony
Team 1
Application 1
Team 1 library
Team 2
Application 2Common library 1
Common library 2
Example problems
● Create a bundle to process some common incoming
HTTP headers
● Make an update of some widely used bundle and make
everyone to upgrade
● Create a bundle with common layouts/assets (careful!)
Corporate is not opensource
● We don’t try to create an universal solution
● Bundles can depend on corporate architecture
● Some corporate bundles can go opensource
Standard complications
Versioning
How could we prevent breakage of our application by our
dependencies?
APP Bundle-1
Team 1
We’ve broken
everything...
because we can!
Use semantic
versioning!
https://semver.org
Dependencies
What if one bundle depends on another?
APP Bundle-1 Bundle-3
Team 1 Team 2
Bundle-2
Please add Bundle-3
to your AppKernel
Migration
APP Bundle-1 Bundle-3
Team 1 Team 2
Bundle-2
OK! Will try to
add that to the
next sprint
We released
major version of
Bundle-3. Please
update!
Coupling and cohesion
High cohesion
= modules must have exact purpose and clear functionality
Low coupling
= modules have to be independent from others
Modularity  problems
SOLID on bundle level
S: Bundle should have single purpose
O: Bundle should provide an API and be protected from external changes
L: Bundle should be a bundle
I: Bundle should not make us use unnecessary features
D: Bundle should depend on APIs (interfaces) instead of other bundles
Solution:
create libraries for common interfaces
Depend on libraries in your bundle instead of other bundles
Interfaces rarely break
Example: PSR-3 (logging interface)
Service as a dependency
BundleX BundleY
Service-Y2
LibraryZ
InterfaceZ
Service-X1 Service-Y1
Service as a dependency - Symfony way
my_chat:
dependencies:
http_client: "my_http.client"
formatter: "html.formatter"
Pass service name to bundle configuration
Note: use “alias” feature to reference a service by a
name
Framework-agnostic code
● Your code should be independent from framework
(controllers too)
● But bundles still depend on Symfony (bundles extend
your framework)
Unusual complications
Dependency hell
● Great amount of dependencies
● Great amount of consumers of your dependency
○ Hard to ask all consumers to update ASAP
● Lack of proper versioning
○ Legacy code
● Requirement of a different major versions of the same
dependency
● Dependencies created by different teams using
different approaches
Dependency hell - Best practices
● KISS
● Work hard if you want to create a shared library
● Implement versioning ASAP
● Provide style guidelines
Listeners
● Listener priority
○ Example: what is the priority of a security listener?
○ How to ensure that your listener will be the first one?
○ Conflict of listeners order at the same priority
● Standard “kernel” events vs own dispatchers
● How to disable a listener?
○ master/slave requests
○ by condition from another listeners
● How to be sure that listener processed an event?
Listeners - Best practices
● Avoid listeners (if you can)
○ lazy initialization
○ explicit pipelines
○ before/after
● Final listeners
● Provide exact API
○ define priority value
Assets & Twig
● Assetic
○ Removed for Symfony 4
○ Webpack Encore doesn’t do the same stuff
● Twig
○ Static HTML code(templates) depends on your JS/CSS framework
○ Hard to manage SSR and CSR
○ You still need another templating engine for JS
● Asset management
○ npm vs composer
○ Is Encore useful?
Assets & Twig - Best practices
● Don’t provide assets by bundles
● Avoid using of templates by bundles
● Move common static web stuff to separate project
(under npm)
Bundle testing
How to test a bundle?
Tester Bundle
Bundle testing - Best practices
public function testMyBundle()
{
$container = $this->createContainer();
$container->registerExtension(new MyExtension());
$container->loadFromExtension('my', []);
$container->compile();
$this->assertTrue(is_a(
$container->getDefinition('my.service')->getClass(),
MyInterface::class,
true
));
}
Other funny complications with bundles
● Register a route from a bundle
● A/B testing and graceful feature delivery
● Advanced bundle configuration processing
○ Type check
○ What about compile time validation?
● Optional dependencies
● What is “bundle API”? Can we define it well?
● Common application configuration
● ...
Conclusions
So where are we now?
● Modules (bundles) is a good way to extend a framework
- Now we know how to use them well
- Now we know the difference between modules and libraries
● Complications
- We know the complications that may appear when project grows
- We will try to avoid complications on early stage
What about Symfony
● Symfony is not an ideal framework
- But still the best one (for PHP)
- It’s made by people (not gods)
- It can be improved
- Now we can see parts that can be improved
What about us?
Be smart!
Thanks!
Any questions?

More Related Content

What's hot (20)

PPT
Learning typescript
Alexandre Marreiros
 
PDF
Distributing OSGi
Bram de Kruijff
 
PDF
Power Leveling your TypeScript
Offirmo
 
PPTX
Typescript in 30mins
Udaya Kumar
 
PPTX
Typescript 101 introduction
Bob German
 
PDF
Experience protocol buffer on android
Richard Chang
 
PPT
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
Steve Reiner
 
PDF
TypeScript: Angular's Secret Weapon
Laurent Duveau
 
PPTX
Typescript ppt
akhilsreyas
 
PDF
How to Make Your Code OSGi Friendly Without Depending on OSGi - Neil Bartlett
mfrancis
 
PDF
Getting Started with TypeScript
Gil Fink
 
PPTX
Introducing type script
Remo Jansen
 
PDF
Introduction to Angular for .NET Developers
Laurent Duveau
 
PPT
TypeScript Presentation
Patrick John Pacaña
 
PPTX
Mono Repo
Zacky Pickholz
 
PPTX
Making Symfony Services async with RabbitMq (and more Symfony)
Gaetano Giunta
 
PPTX
TypeScript
Udaiappa Ramachandran
 
PDF
Introduction to Angular for .NET Developers
Laurent Duveau
 
PPT
vb script
Anand Dhana
 
PDF
Introduction to TypeScript by Winston Levi
Winston Levi
 
Learning typescript
Alexandre Marreiros
 
Distributing OSGi
Bram de Kruijff
 
Power Leveling your TypeScript
Offirmo
 
Typescript in 30mins
Udaya Kumar
 
Typescript 101 introduction
Bob German
 
Experience protocol buffer on android
Richard Chang
 
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
Steve Reiner
 
TypeScript: Angular's Secret Weapon
Laurent Duveau
 
Typescript ppt
akhilsreyas
 
How to Make Your Code OSGi Friendly Without Depending on OSGi - Neil Bartlett
mfrancis
 
Getting Started with TypeScript
Gil Fink
 
Introducing type script
Remo Jansen
 
Introduction to Angular for .NET Developers
Laurent Duveau
 
TypeScript Presentation
Patrick John Pacaña
 
Mono Repo
Zacky Pickholz
 
Making Symfony Services async with RabbitMq (and more Symfony)
Gaetano Giunta
 
Introduction to Angular for .NET Developers
Laurent Duveau
 
vb script
Anand Dhana
 
Introduction to TypeScript by Winston Levi
Winston Levi
 

Similar to Modularity problems (20)

ODP
An introduction to Symfony 2 for symfony 1 developers
Giorgio Cefaro
 
PDF
Improve your web and app development with the Symfony3 framework.
Polcode
 
PDF
Which Tools Are The Best For Symfony Projects_.pdf
Moon Technolabs Pvt. Ltd.
 
PDF
Symfony 4: A new way to develop applications #ipc19
Antonio Peric-Mazar
 
PDF
Which Tools Are The Best For Symfony Projects_.pdf
Moon Technolabs Pvt. Ltd.
 
PDF
Symfony - Introduction
Piers Warmers
 
PDF
Symfony and eZ Publish
Jérôme Vieilledent
 
PDF
Symony2 A Next Generation PHP Framework
Ryan Weaver
 
PDF
Symfony 4: A new way to develop applications #phpsrb
Antonio Peric-Mazar
 
PDF
The Naked Bundle - Tryout
Matthias Noback
 
PDF
Symfony4: A new way to develop applications | Antonio Peric | CODEiD
CODEiD PHP Community
 
PDF
The Naked Bundle - Symfony Usergroup Belgium
Matthias Noback
 
PDF
Symfony2 San Francisco Meetup 2009
Fabien Potencier
 
PDF
Symfony War Stories
Jakub Zalas
 
PDF
Symfony4 - Deep dive
Salma Ghareeb
 
PDF
Symfony4 - A new way of developing web applications
Antonio Peric-Mazar
 
PDF
Introduction to symfony2
Pablo Godel
 
PDF
Writing extensible applications
Andrew Yatsenko
 
PDF
Introducing symfony
Wildan Maulana
 
An introduction to Symfony 2 for symfony 1 developers
Giorgio Cefaro
 
Improve your web and app development with the Symfony3 framework.
Polcode
 
Which Tools Are The Best For Symfony Projects_.pdf
Moon Technolabs Pvt. Ltd.
 
Symfony 4: A new way to develop applications #ipc19
Antonio Peric-Mazar
 
Which Tools Are The Best For Symfony Projects_.pdf
Moon Technolabs Pvt. Ltd.
 
Symfony - Introduction
Piers Warmers
 
Symfony and eZ Publish
Jérôme Vieilledent
 
Symony2 A Next Generation PHP Framework
Ryan Weaver
 
Symfony 4: A new way to develop applications #phpsrb
Antonio Peric-Mazar
 
The Naked Bundle - Tryout
Matthias Noback
 
Symfony4: A new way to develop applications | Antonio Peric | CODEiD
CODEiD PHP Community
 
The Naked Bundle - Symfony Usergroup Belgium
Matthias Noback
 
Symfony2 San Francisco Meetup 2009
Fabien Potencier
 
Symfony War Stories
Jakub Zalas
 
Symfony4 - Deep dive
Salma Ghareeb
 
Symfony4 - A new way of developing web applications
Antonio Peric-Mazar
 
Introduction to symfony2
Pablo Godel
 
Writing extensible applications
Andrew Yatsenko
 
Introducing symfony
Wildan Maulana
 
Ad

More from Юлия Коваленко (7)

PDF
Архитектура фронтенда и дизайн-системы
Юлия Коваленко
 
PDF
Symfony 2018 slides
Юлия Коваленко
 
PPTX
Filesystem abstractions and msg queue sergeev - symfony camp 2018
Юлия Коваленко
 
PDF
20181023 progressive web_apps_are_here_sfcampua
Юлия Коваленко
 
PDF
Contract testing symfony camp 2018
Юлия Коваленко
 
PDF
Database types-1 (1)
Юлия Коваленко
 
Архитектура фронтенда и дизайн-системы
Юлия Коваленко
 
Symfony 2018 slides
Юлия Коваленко
 
Filesystem abstractions and msg queue sergeev - symfony camp 2018
Юлия Коваленко
 
20181023 progressive web_apps_are_here_sfcampua
Юлия Коваленко
 
Contract testing symfony camp 2018
Юлия Коваленко
 
Database types-1 (1)
Юлия Коваленко
 
Ad

Recently uploaded (20)

PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
July Patch Tuesday
Ivanti
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 

Modularity problems

  • 1. Modularity problems Architecture of corporate Symfony-applications
  • 2. Who I am ● Senior Software Engineer @ Upwork ● 10+ years of PHP (Pear -> ZF 1 -> Symfony 1 -> Yii 1 -> ....) ● 4+ years of Symfony 2 ● Also experience in Java (Spring, GWT, ...), C# (.Net), Ruby (Rails), JS (...) ● KNU, Faculty of Cybernetics, Theory of Programming
  • 4. How to perceive this speech This speech ... ● … is not a manual ⇒ use Google please! ● … covers some problems of modularity ⇒ it doesn’t cover a lot of stuff. ● … displays some Symfony problems ⇒ but we love Symfony anyway =)
  • 6. Library vs Framework Library useful pieces of code in one place Framework set of libraries, tools and principles of application development
  • 7. Framework ● It is a platform ● It defines application structure ● It unites components ● It offers tools ● It describes best practices
  • 8. Modules Modules (plugins, extensions, bundles etc.) is a way to extend a framework.
  • 9. Symfony modules Component is Symfony library. You need Composer to use Component. Bundle is Symfony module. You also need Composer to use Bundle. But you must enable Bundle in your AppKernel
  • 10. How does Bundle extend our framework? ● Commands ● Controllers ● Public services ○ also tagged services (event listeners, annotation processors etc.) ● Service Container processing ○ add support of custom service tags ○ preconfigure other modules (prepend) ● Other common code and assets (careful!)
  • 11. Symfony 2.x ⇒ 4.x ● Flex ○ Flex is a tool to simplify bundle installation. ● Bundle-less ○ Application is not a bundle ○ Symfony 4.x application directory structure is self-sufficient
  • 13. Specifics of big product companies ● A lot of developer teams ● A lot of code ● A lot of different applications may fit in one project ● “Core” team
  • 14. Example structure of corporate applications Symfony Team 1 Application 1 Team 1 library Team 2 Application 2Common library 1 Common library 2
  • 15. Example problems ● Create a bundle to process some common incoming HTTP headers ● Make an update of some widely used bundle and make everyone to upgrade ● Create a bundle with common layouts/assets (careful!)
  • 16. Corporate is not opensource ● We don’t try to create an universal solution ● Bundles can depend on corporate architecture ● Some corporate bundles can go opensource
  • 18. Versioning How could we prevent breakage of our application by our dependencies? APP Bundle-1 Team 1 We’ve broken everything... because we can!
  • 20. Dependencies What if one bundle depends on another? APP Bundle-1 Bundle-3 Team 1 Team 2 Bundle-2 Please add Bundle-3 to your AppKernel
  • 21. Migration APP Bundle-1 Bundle-3 Team 1 Team 2 Bundle-2 OK! Will try to add that to the next sprint We released major version of Bundle-3. Please update!
  • 22. Coupling and cohesion High cohesion = modules must have exact purpose and clear functionality Low coupling = modules have to be independent from others
  • 24. SOLID on bundle level S: Bundle should have single purpose O: Bundle should provide an API and be protected from external changes L: Bundle should be a bundle I: Bundle should not make us use unnecessary features D: Bundle should depend on APIs (interfaces) instead of other bundles
  • 25. Solution: create libraries for common interfaces Depend on libraries in your bundle instead of other bundles Interfaces rarely break Example: PSR-3 (logging interface)
  • 26. Service as a dependency BundleX BundleY Service-Y2 LibraryZ InterfaceZ Service-X1 Service-Y1
  • 27. Service as a dependency - Symfony way my_chat: dependencies: http_client: "my_http.client" formatter: "html.formatter" Pass service name to bundle configuration Note: use “alias” feature to reference a service by a name
  • 28. Framework-agnostic code ● Your code should be independent from framework (controllers too) ● But bundles still depend on Symfony (bundles extend your framework)
  • 30. Dependency hell ● Great amount of dependencies ● Great amount of consumers of your dependency ○ Hard to ask all consumers to update ASAP ● Lack of proper versioning ○ Legacy code ● Requirement of a different major versions of the same dependency ● Dependencies created by different teams using different approaches
  • 31. Dependency hell - Best practices ● KISS ● Work hard if you want to create a shared library ● Implement versioning ASAP ● Provide style guidelines
  • 32. Listeners ● Listener priority ○ Example: what is the priority of a security listener? ○ How to ensure that your listener will be the first one? ○ Conflict of listeners order at the same priority ● Standard “kernel” events vs own dispatchers ● How to disable a listener? ○ master/slave requests ○ by condition from another listeners ● How to be sure that listener processed an event?
  • 33. Listeners - Best practices ● Avoid listeners (if you can) ○ lazy initialization ○ explicit pipelines ○ before/after ● Final listeners ● Provide exact API ○ define priority value
  • 34. Assets & Twig ● Assetic ○ Removed for Symfony 4 ○ Webpack Encore doesn’t do the same stuff ● Twig ○ Static HTML code(templates) depends on your JS/CSS framework ○ Hard to manage SSR and CSR ○ You still need another templating engine for JS ● Asset management ○ npm vs composer ○ Is Encore useful?
  • 35. Assets & Twig - Best practices ● Don’t provide assets by bundles ● Avoid using of templates by bundles ● Move common static web stuff to separate project (under npm)
  • 36. Bundle testing How to test a bundle? Tester Bundle
  • 37. Bundle testing - Best practices public function testMyBundle() { $container = $this->createContainer(); $container->registerExtension(new MyExtension()); $container->loadFromExtension('my', []); $container->compile(); $this->assertTrue(is_a( $container->getDefinition('my.service')->getClass(), MyInterface::class, true )); }
  • 38. Other funny complications with bundles ● Register a route from a bundle ● A/B testing and graceful feature delivery ● Advanced bundle configuration processing ○ Type check ○ What about compile time validation? ● Optional dependencies ● What is “bundle API”? Can we define it well? ● Common application configuration ● ...
  • 40. So where are we now? ● Modules (bundles) is a good way to extend a framework - Now we know how to use them well - Now we know the difference between modules and libraries ● Complications - We know the complications that may appear when project grows - We will try to avoid complications on early stage
  • 41. What about Symfony ● Symfony is not an ideal framework - But still the best one (for PHP) - It’s made by people (not gods) - It can be improved - Now we can see parts that can be improved