SlideShare a Scribd company logo
1 of 48
Building
Maintainable PHP
Applications
Managing the complexity for the long term
Who am I?
- Senior PHP Engineer (Contractor) via Adeva
- Technical Content Creator
- Mentor
- Have worked on small startups, scale-ups and huge enterprise distributed systems
- Full-stack developer turned backend software engineer
- Have worked with PHP, Laravel, Symfony, JavaScript, MySQL, Redis, ElasticSearch etc.
- Love discussing technical ideas and experimenting with them on my personal projects
- More info at DavorMinchorov.com
- #CRUDScience
It’s all about the context you are in
Developers build different types of applications and software in different contexts
- Brand Websites
- Packages / libraries
- Small bootstrapped Software As A Service Startup
- VC-funded startup
- Scale-up software
- Enterprise Software
All of these have different types of problems at the scale they are at
They all get to the unavoidable business complexity and unmaintainable code after a while
The context that I will cover will be a startup that is at least 3 years in production and beyond
Over-engineering vs Under-engineering
Over-engineered code is usually a phrase that is thrown around for code that is either:
- Simple, full of abstractions and can be changed easily or new code can be added when the
product grows over time
- badly written and completely unnecessary
On the other hand, under-engineered code is usually either:
- Written quickly and completely unmaintainable for the long run
- It requires many changes all over the place in order to add new code
Simple code in one context is complex code in another one.
Over-engineering vs Under-engineering
Over-engineering vs Under-engineering
Over-engineering vs Under-engineering
So what determines which code is over-engineered or under-engineered?
- The context which it’s written in
- The level of maintainability and the ability to change it easily when the business rules and
processes become more complex over time.
The first code example written in an a scale-up or an enterprise software is very simple and easy
to maintain.
The second code example written in a brand website, a personal website, or a throw-away
project is very simple and easy to maintain.
If the two code examples switch their contexts, they will become over-engineered and under-
engineered respectively.
Accidental vs essential complexity
As business rules and processes grow and change over time, the product becomes more
complex and this is called essential complexity. You can’t avoid it.
The first code example will be easier to maintain, change and extend simply by adding
- event listeners to react to the events that are being dispatched
- add additional business rules within the Member entity.
- configure the inversion of control container to use different implementations
You wouldn’t need to touch the class in the example.
The business has complex enough use cases which makes sense for the code to be written this
way.
This may be a very simple code for this specific context.
Accidental vs essential complexity
The second example usually makes you think that you can add additional code in the controller
making it work based on the feature requirements as they come in.
Let’s say you add code related to
- member role assignment
- if statement to check if the member is coming from an API or a web request
- Send a welcome and verification email
- sign up member to a newsletter,
- Create audit log
- And so on
This is called creating accidental complexity by not creating additional files and folders and
splitting the code.
Accidental vs essential complexity
Accidental vs essential complexity
Framework coupling vs Framework decoupling
All frameworks are opinionated general solutions which try to save us time and lower the
amount of code that we need to write and maintain
They help us focus on the main problem which is automating business processes
Developers learn to use a framework and they use it as much as possible to solve a specific
problem with a general solution
Frameworks dictate how you write and structure your code but they don’t know about your
business
This is called framework coupling - your business code depends on your framework of choice
and makes it harder to change over time
Framework coupling vs Framework decoupling
There are a few reasons why this may be bad:
- Framework and language upgrades slow down and the code becomes harder to upgrade
when the direct implementation is being used from the framework
- The risk of breaking the product because the required changes which affect the whole
product all over the place
- Moving out code into different projects will be harder when new teams are formed when
it’s time to scale
- Changing implementations will require many changes all over the place
Framework coupling vs Framework decoupling
Framework decoupling solve these problems by coding to an interface, not to an
implementation
The benefits are:
- You can start building custom components specific to the business needs
- Freedom to structure the code however you want based on the business requirements
- The framework is a tool
- It makes it easier to design and test the code
- Far fewer changes will be required during upgrades
It may take a while to get used to thinking and working this way, which may be slower due to
team inexperience
Thinking data (CRUD) vs thinking business
processes (behaviour)
Developers are taught to build projects with the CRUD mindset at the start of their careers by
many tutorials, books, academies, universities and other resources
The business processes are neglected and the first thing people build is the database schema
Whenever a business process is executed, the process does not just save data in the database
- It may validate the input values based on specific business rules and requirements
- It may talk to a 3rd party service
- It may store the data into multiple databases
- It may talk to multiple services or applications
Business people are forced to learn technical terms to communicate with developers
Thinking data (CRUD) vs thinking business
processes (behaviour)
The business use cases are usually neglected and the product is being built in a Excel like
software
it’s very technical, will eventually become complex to manage and work with such code if it’s
written with the database-first mindset which brings accidental complexity
Business people don’t care about how the product is being built, they just want fast changes and
additional features
Developers focus on the database and what columns it will have, what data types they will be
and then they start writing the code based on the data in the database.
Designing the database with best practices in mind is important but not to the business
Thinking data (CRUD) vs thinking business
processes (behaviour)
The people who use and design the business processes think about the
use cases like:
- Choose the restaurant and the food to order
- Apply coupon
- Pay for the order
- Approve Order
- Take an order to deliver
- Pick up order from restaurant
- Take order to the customer delivery destination
- Complete the order delivery
Thinking data (CRUD) vs thinking business
processes (behaviour)
Understanding the business domain is key in order to build software that the customers need
It’s easier to:
- Name files, modules, classes, variables, methods and properties
- Understand what the business people are saying and what they need
- Communicate with a ubiquitous language
- Design the business related code without any infrastructure concerns (database for example)
Behaviour driven development and domain driven design may be useful in such cases
It may be harder to switch the mindset to think and work this way, it may take years to get used to it
Thinking data (CRUD) vs thinking business
processes (behaviour)
Planning
Developers plan their code and database but they rarely plan what they need to do
There may be many ways of planning business processes but I would mention:
- Event Storming
- Event Modelling
- Event Storytelling
They are somewhat different in how they work but they have similarities that focus on the
events that happen in the product from a behaviour point of view.
The idea of these planning processes is for customers, business people and technical people to
get into a room, and discover what and how the business processes will work in order for the
technical people to build them.
Planning
Planning
Having a plan of what the business use cases and rules are makes it easier to map that plan into
code
It helps with figuring out what the modules of the application will be and how the code will be
structured
Some of those modules can be separate applications (whenever it makes sense)
Exploring the domain also helps people to get to know the business better, it brings out ideas
out of their heads
A lot of questions will be answered during these planning sessions
The goal is not to expect or chase the complexity but rather let it evolve and manage it
Planning
Planning
Code Refactoring
Code Refactoring
Code Refactoring
The primary responsibility of a controller is to take a request data, to pass that data off to some
other object to process it, and return a response
SignUpMemberController
- The route is defined using attributes
- A SignUpMember command is being dispatched via the command bus dispatcher
- A No Content response is being returned
Code refactoring
A command is an input data transfer object that the primary responsibility of the class is to
carry data
It can have getters and setters or public readonly properties which will be initialized in the
constructor on initialization.
Commands do not have any behaviour.
The command bus pattern allows you to separate your code between the layers by taking
request data in a form of a command class and passing it through a bus, handled by a command
handler class.
The command handler class handles a single use case, can be decorated and it can be queued in
the background if the processing takes a while to complete.
Code Refactoring
Code Refactoring
Code Refactoring
A value object is a class which holds a primitive value, validate their format and makes sure that
it’s consistent so that it can passed over into the other layers.
A value object can hold multiple values as well (example: Address, Money, Coordinates)
Value objects in the code example:
- ID
- First Name
- Last Name
- Email Address
- Password
Code Refactoring
Code Refactoring
Code Refactoring
Code Refactoring
Code Refactoring
Code Refactoring
Rich domain models are classes which represent business processes from the real world and
they mainly contain business rules and behaviours
Anemic domain models are usually classes which represent the business processes from the real
world but they only contain getters and setters and are not recommended.
Rich domain models can sometimes be called write models when using CQRS
Domain models live in the heart of the domain layer
Rich domain models raise events whenever something happens in the application
All events are being dispatched at once in the order they were raised at the end of the use case.
Code Refactoring
Code Refactoring
Repositories are classes or components that encapsulate the logic required to access data
sources.
data source examples:
- MySQL
- ElasticSearch
- MongoDB
- DynamoDB
- Internal microservice REST API
- A Message Broker
- File
Code Refactoring
Code Refactoring
Code Refactoring
Code Refactoring
Read models are output data transfer objects that only contain data, no behaviour
They are usually used for picking up data from different data sources
They are alternatives to arrays
They are typed and you can easily see what kind of data to expect from the output
Code Refactoring
Code Refactoring
Events are input data transfer objects which contain only data and no behaviour
They are usually named in a past tense because they represent something that has happened in
the application
The event dispatcher dispatches events and multiple event listeners can listen to a single event
and react to that event
Event listeners, similar to command handlers, can be decorated and queued for background
processing
Events can be stored into an event store when event sourcing is used
Code Refactoring
Conclusion
Today you learned something new about:
- It’s all about the context
- Over-engineering vs Under-engineering
- Accidental vs Essential complexity
- Framework coupling vs Framework decoupling
- Thinking data (CRUD) vs thinking business processes (behaviour)
- The misconceptions of object-oriented programming and design, design patterns and
principles
- Planning
- Code refactoring
Thank you!
Any questions?

More Related Content

Similar to Building Maintainable PHP Applications.pptx

Are You an Accidental or Intentional Architect?
Are You an Accidental or Intentional Architect?Are You an Accidental or Intentional Architect?
Are You an Accidental or Intentional Architect?iasaglobal
 
How to Build a Platform Team
How to Build a Platform TeamHow to Build a Platform Team
How to Build a Platform TeamVMware Tanzu
 
Software systems engineering PRINCIPLES
Software systems engineering PRINCIPLESSoftware systems engineering PRINCIPLES
Software systems engineering PRINCIPLESIvano Malavolta
 
Property dealing , A .net project
Property dealing , A .net projectProperty dealing , A .net project
Property dealing , A .net projectAnjali Kamboj
 
Sr_Dev_Ops_Engineer
Sr_Dev_Ops_EngineerSr_Dev_Ops_Engineer
Sr_Dev_Ops_EngineerErik McCarty
 
Practical_Business_Rules_Development_and_Use
Practical_Business_Rules_Development_and_UsePractical_Business_Rules_Development_and_Use
Practical_Business_Rules_Development_and_UseMichael Cook
 
Ramachandra_Reddy_Resume_2015
Ramachandra_Reddy_Resume_2015Ramachandra_Reddy_Resume_2015
Ramachandra_Reddy_Resume_2015Ramchandra Reddy
 
J2EE Performance And Scalability Bp
J2EE Performance And Scalability BpJ2EE Performance And Scalability Bp
J2EE Performance And Scalability BpChris Adkin
 
Prodev Solutions Intro
Prodev Solutions IntroProdev Solutions Intro
Prodev Solutions IntrolarryATprodev
 
System analysis and design
System analysis and designSystem analysis and design
System analysis and designRobinsonObura
 
IBM Innovate 2013 Session: DevOps 101
IBM Innovate 2013 Session: DevOps 101IBM Innovate 2013 Session: DevOps 101
IBM Innovate 2013 Session: DevOps 101Sanjeev Sharma
 
Introduction Software and Software Engineering
Introduction Software and Software EngineeringIntroduction Software and Software Engineering
Introduction Software and Software Engineeringinfinitetechnology20
 
Introduction,Software Process Models, Project Management
Introduction,Software Process Models, Project ManagementIntroduction,Software Process Models, Project Management
Introduction,Software Process Models, Project Managementswatisinghal
 
Software Engineering Basics.pdf
Software Engineering Basics.pdfSoftware Engineering Basics.pdf
Software Engineering Basics.pdfPriyajit Sen
 
Software engineering introduction
Software engineering introductionSoftware engineering introduction
Software engineering introductionVishal Singh
 

Similar to Building Maintainable PHP Applications.pptx (20)

Are You an Accidental or Intentional Architect?
Are You an Accidental or Intentional Architect?Are You an Accidental or Intentional Architect?
Are You an Accidental or Intentional Architect?
 
How to Build a Platform Team
How to Build a Platform TeamHow to Build a Platform Team
How to Build a Platform Team
 
Software systems engineering PRINCIPLES
Software systems engineering PRINCIPLESSoftware systems engineering PRINCIPLES
Software systems engineering PRINCIPLES
 
Property dealing , A .net project
Property dealing , A .net projectProperty dealing , A .net project
Property dealing , A .net project
 
Writing srs
Writing srsWriting srs
Writing srs
 
Sr_Dev_Ops_Engineer
Sr_Dev_Ops_EngineerSr_Dev_Ops_Engineer
Sr_Dev_Ops_Engineer
 
Practical_Business_Rules_Development_and_Use
Practical_Business_Rules_Development_and_UsePractical_Business_Rules_Development_and_Use
Practical_Business_Rules_Development_and_Use
 
Ramachandra_Reddy_Resume_2015
Ramachandra_Reddy_Resume_2015Ramachandra_Reddy_Resume_2015
Ramachandra_Reddy_Resume_2015
 
Software process model
Software process modelSoftware process model
Software process model
 
L02 Architecture
L02 ArchitectureL02 Architecture
L02 Architecture
 
J2EE Performance And Scalability Bp
J2EE Performance And Scalability BpJ2EE Performance And Scalability Bp
J2EE Performance And Scalability Bp
 
Day1
Day1Day1
Day1
 
Prodev Solutions Intro
Prodev Solutions IntroProdev Solutions Intro
Prodev Solutions Intro
 
System analysis and design
System analysis and designSystem analysis and design
System analysis and design
 
IBM Innovate 2013 Session: DevOps 101
IBM Innovate 2013 Session: DevOps 101IBM Innovate 2013 Session: DevOps 101
IBM Innovate 2013 Session: DevOps 101
 
Introduction Software and Software Engineering
Introduction Software and Software EngineeringIntroduction Software and Software Engineering
Introduction Software and Software Engineering
 
Architecture
ArchitectureArchitecture
Architecture
 
Introduction,Software Process Models, Project Management
Introduction,Software Process Models, Project ManagementIntroduction,Software Process Models, Project Management
Introduction,Software Process Models, Project Management
 
Software Engineering Basics.pdf
Software Engineering Basics.pdfSoftware Engineering Basics.pdf
Software Engineering Basics.pdf
 
Software engineering introduction
Software engineering introductionSoftware engineering introduction
Software engineering introduction
 

Recently uploaded

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 

Recently uploaded (20)

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 

Building Maintainable PHP Applications.pptx

  • 2. Who am I? - Senior PHP Engineer (Contractor) via Adeva - Technical Content Creator - Mentor - Have worked on small startups, scale-ups and huge enterprise distributed systems - Full-stack developer turned backend software engineer - Have worked with PHP, Laravel, Symfony, JavaScript, MySQL, Redis, ElasticSearch etc. - Love discussing technical ideas and experimenting with them on my personal projects - More info at DavorMinchorov.com - #CRUDScience
  • 3. It’s all about the context you are in Developers build different types of applications and software in different contexts - Brand Websites - Packages / libraries - Small bootstrapped Software As A Service Startup - VC-funded startup - Scale-up software - Enterprise Software All of these have different types of problems at the scale they are at They all get to the unavoidable business complexity and unmaintainable code after a while The context that I will cover will be a startup that is at least 3 years in production and beyond
  • 4. Over-engineering vs Under-engineering Over-engineered code is usually a phrase that is thrown around for code that is either: - Simple, full of abstractions and can be changed easily or new code can be added when the product grows over time - badly written and completely unnecessary On the other hand, under-engineered code is usually either: - Written quickly and completely unmaintainable for the long run - It requires many changes all over the place in order to add new code Simple code in one context is complex code in another one.
  • 7. Over-engineering vs Under-engineering So what determines which code is over-engineered or under-engineered? - The context which it’s written in - The level of maintainability and the ability to change it easily when the business rules and processes become more complex over time. The first code example written in an a scale-up or an enterprise software is very simple and easy to maintain. The second code example written in a brand website, a personal website, or a throw-away project is very simple and easy to maintain. If the two code examples switch their contexts, they will become over-engineered and under- engineered respectively.
  • 8. Accidental vs essential complexity As business rules and processes grow and change over time, the product becomes more complex and this is called essential complexity. You can’t avoid it. The first code example will be easier to maintain, change and extend simply by adding - event listeners to react to the events that are being dispatched - add additional business rules within the Member entity. - configure the inversion of control container to use different implementations You wouldn’t need to touch the class in the example. The business has complex enough use cases which makes sense for the code to be written this way. This may be a very simple code for this specific context.
  • 9. Accidental vs essential complexity The second example usually makes you think that you can add additional code in the controller making it work based on the feature requirements as they come in. Let’s say you add code related to - member role assignment - if statement to check if the member is coming from an API or a web request - Send a welcome and verification email - sign up member to a newsletter, - Create audit log - And so on This is called creating accidental complexity by not creating additional files and folders and splitting the code.
  • 12. Framework coupling vs Framework decoupling All frameworks are opinionated general solutions which try to save us time and lower the amount of code that we need to write and maintain They help us focus on the main problem which is automating business processes Developers learn to use a framework and they use it as much as possible to solve a specific problem with a general solution Frameworks dictate how you write and structure your code but they don’t know about your business This is called framework coupling - your business code depends on your framework of choice and makes it harder to change over time
  • 13. Framework coupling vs Framework decoupling There are a few reasons why this may be bad: - Framework and language upgrades slow down and the code becomes harder to upgrade when the direct implementation is being used from the framework - The risk of breaking the product because the required changes which affect the whole product all over the place - Moving out code into different projects will be harder when new teams are formed when it’s time to scale - Changing implementations will require many changes all over the place
  • 14. Framework coupling vs Framework decoupling Framework decoupling solve these problems by coding to an interface, not to an implementation The benefits are: - You can start building custom components specific to the business needs - Freedom to structure the code however you want based on the business requirements - The framework is a tool - It makes it easier to design and test the code - Far fewer changes will be required during upgrades It may take a while to get used to thinking and working this way, which may be slower due to team inexperience
  • 15. Thinking data (CRUD) vs thinking business processes (behaviour) Developers are taught to build projects with the CRUD mindset at the start of their careers by many tutorials, books, academies, universities and other resources The business processes are neglected and the first thing people build is the database schema Whenever a business process is executed, the process does not just save data in the database - It may validate the input values based on specific business rules and requirements - It may talk to a 3rd party service - It may store the data into multiple databases - It may talk to multiple services or applications Business people are forced to learn technical terms to communicate with developers
  • 16. Thinking data (CRUD) vs thinking business processes (behaviour) The business use cases are usually neglected and the product is being built in a Excel like software it’s very technical, will eventually become complex to manage and work with such code if it’s written with the database-first mindset which brings accidental complexity Business people don’t care about how the product is being built, they just want fast changes and additional features Developers focus on the database and what columns it will have, what data types they will be and then they start writing the code based on the data in the database. Designing the database with best practices in mind is important but not to the business
  • 17. Thinking data (CRUD) vs thinking business processes (behaviour) The people who use and design the business processes think about the use cases like: - Choose the restaurant and the food to order - Apply coupon - Pay for the order - Approve Order - Take an order to deliver - Pick up order from restaurant - Take order to the customer delivery destination - Complete the order delivery
  • 18. Thinking data (CRUD) vs thinking business processes (behaviour) Understanding the business domain is key in order to build software that the customers need It’s easier to: - Name files, modules, classes, variables, methods and properties - Understand what the business people are saying and what they need - Communicate with a ubiquitous language - Design the business related code without any infrastructure concerns (database for example) Behaviour driven development and domain driven design may be useful in such cases It may be harder to switch the mindset to think and work this way, it may take years to get used to it
  • 19. Thinking data (CRUD) vs thinking business processes (behaviour)
  • 20. Planning Developers plan their code and database but they rarely plan what they need to do There may be many ways of planning business processes but I would mention: - Event Storming - Event Modelling - Event Storytelling They are somewhat different in how they work but they have similarities that focus on the events that happen in the product from a behaviour point of view. The idea of these planning processes is for customers, business people and technical people to get into a room, and discover what and how the business processes will work in order for the technical people to build them.
  • 22. Planning Having a plan of what the business use cases and rules are makes it easier to map that plan into code It helps with figuring out what the modules of the application will be and how the code will be structured Some of those modules can be separate applications (whenever it makes sense) Exploring the domain also helps people to get to know the business better, it brings out ideas out of their heads A lot of questions will be answered during these planning sessions The goal is not to expect or chase the complexity but rather let it evolve and manage it
  • 27. Code Refactoring The primary responsibility of a controller is to take a request data, to pass that data off to some other object to process it, and return a response SignUpMemberController - The route is defined using attributes - A SignUpMember command is being dispatched via the command bus dispatcher - A No Content response is being returned
  • 28. Code refactoring A command is an input data transfer object that the primary responsibility of the class is to carry data It can have getters and setters or public readonly properties which will be initialized in the constructor on initialization. Commands do not have any behaviour. The command bus pattern allows you to separate your code between the layers by taking request data in a form of a command class and passing it through a bus, handled by a command handler class. The command handler class handles a single use case, can be decorated and it can be queued in the background if the processing takes a while to complete.
  • 31. Code Refactoring A value object is a class which holds a primitive value, validate their format and makes sure that it’s consistent so that it can passed over into the other layers. A value object can hold multiple values as well (example: Address, Money, Coordinates) Value objects in the code example: - ID - First Name - Last Name - Email Address - Password
  • 37. Code Refactoring Rich domain models are classes which represent business processes from the real world and they mainly contain business rules and behaviours Anemic domain models are usually classes which represent the business processes from the real world but they only contain getters and setters and are not recommended. Rich domain models can sometimes be called write models when using CQRS Domain models live in the heart of the domain layer Rich domain models raise events whenever something happens in the application All events are being dispatched at once in the order they were raised at the end of the use case.
  • 39. Code Refactoring Repositories are classes or components that encapsulate the logic required to access data sources. data source examples: - MySQL - ElasticSearch - MongoDB - DynamoDB - Internal microservice REST API - A Message Broker - File
  • 43. Code Refactoring Read models are output data transfer objects that only contain data, no behaviour They are usually used for picking up data from different data sources They are alternatives to arrays They are typed and you can easily see what kind of data to expect from the output
  • 45. Code Refactoring Events are input data transfer objects which contain only data and no behaviour They are usually named in a past tense because they represent something that has happened in the application The event dispatcher dispatches events and multiple event listeners can listen to a single event and react to that event Event listeners, similar to command handlers, can be decorated and queued for background processing Events can be stored into an event store when event sourcing is used
  • 47. Conclusion Today you learned something new about: - It’s all about the context - Over-engineering vs Under-engineering - Accidental vs Essential complexity - Framework coupling vs Framework decoupling - Thinking data (CRUD) vs thinking business processes (behaviour) - The misconceptions of object-oriented programming and design, design patterns and principles - Planning - Code refactoring