SlideShare a Scribd company logo
Onion Architecture
And The Blog
Making a blog (and having fun while doing it)
Who am I
Product Developer - Systems Architect - Freelancer - Development Manager
Past experience
Senior Developer for Cleverbug
Lecturer at the Digital Skills Academy
Director of Tercet, software development consultancy
Current position
Software Development Manager for OliveMedia
Barry O Sullivan
This talk
We’re going to …
● Talk about the blog and it’s features
● look at the architecture
● look at the services we used
● look at some Laravel 5.1 code
● Show you how to publish a blog post
The Blog
What do we want it to do?
What’s is its purpose?
Our goals were to
● Host content from the community
● Make it easy for the community to contribute content
● Keep it simple and clean
● Use existing tools and libraries as much as possible
● Showcase some design best practice (as we see it anyway)
● Have some fun making it
The features
So to we decided on some simple features
● Articles are displayed as a list in the blog section
● Articles can be clicked and viewed individually
● Articles have unique urls (for SEO)
● Articles are written in markdown
● Articles are part of the repo
● People can send us articles via pull request
We had a lot more features, but these were dropped, as they increased the
scope and didn’t actually add a lot of value.
The architecture
We decided to use an Onion architecture
(Also known as Ports and Adapters or *Hexagonal Architecture)
Why we choose it:
● Clean separation of concerns
● Easy to maintain
● Encourages CQRS
● Industry best practice
● It’s just really nice
* A very misleading name, programmers are the worst at naming things
The Domain
The heart of the application.
Contains anything that’s business rule related
Keep your business logic completely separated
from your storage/service/controller logic.
Doesn’t care about the technical details, contains
only what’s necessary to validate business rules.
Made up off
● ValueObjects
● Entities
● RepositoryInterfaces
The API
Entry point for the domain.
Uses the domain to perform business operations.
Acts as the interface between the “Application”
and the business logic.
Ensures that implementation details don’t bleed
out into your controllers,
eg. database logic, presentation logic
Made up off
● Commands
● Queries
The Infrastructure
Contains the technical details about specific
technologies. Eg, how data is accessed and
where data is stored
(The framework is technically infrastructure)
Three types of infrastructure
● Controllers
● Data Storage (Database/FileSystem)
● External Services (Package, API, etc. . .)
How layers interact
A key part of an onion architecture is that outer
layers can use inner layers, but inner layers
have no knowledge of outer layers.
This means that the infrastructure can see
ValueObjects, but ValueObjects have no
knowledge of the Database.
Forces you to keep things simple and to put logic
where it belongs, no bleeding of details that will
make future changes difficult.
Building the Blog
The implementation is split into 3 sections
● The domain
● The API
● The Infrastructure
○ Services
○ Storage
○ Controllers
The Blog Domain
A blog post has the following business rules
● A blog must have a title, an author, an ID and content
● Title, author and content cannot be blank
● Publish date cannot be in the future
That leaves us with the following value objects that enforce business rules
Post, ID, Title, Author, PublishDate, Content
We don’t have any other business rules for now, so we left it at that
The Blog Domain (2)
The next step is the definition of the repo, for storing and retrieving posts.
The repo is an interface, and it defines how we expect our repository to behave,
regardless of what implementation we decide to go for.
We do this because it forces us to keep it generic, clean and easy to test. It
also gives us the option of switching to another repo type (Which we will)
The interface has three methods
store(Post $post)
fetch(UUID $id)
all()
The Blog API
Next we have the API, this is the entry point for our app, and it offers all the functionality we want to
expose. It’s CQRS, which just means we have two types of operations
We offer the following command and queries
Commands
CreatePost
Queries
Post
PostList
We’re using Laravel 5.1s commands and command bus for this, as it has the IOC built in. This means
we only ever use interfaces at this level and we let laravel handle the injection of our concrete
implementations of our repository.
Infrastructure - Services
Why reinvent the wheel when someone is giving you a jet pack for free?
We used the following packages to make our job easier
Laravel 5.1 - It’s so hot right now (and it’s really powerful)
FlySystem -Generic API for multiple storage engines
CommonMark -Convert markdown into HTML, extensible
UUID - UUIDs, because they’re actually really handy
Carbon -Improved version of PHPs DateTime classes
Infrastructure - Storage
We create a concrete class that implements the PostRepo interface.
Since they’re part of the repo, they’re part of the file system.
They’re stored by ID, and are represented by two files
blog/
e09135f2-ade1-4c25-9527-7ecbdc0d7c15/
details.json (title, author, date)
markdown.md (Actual content)
When we create a post, this structure is created
When we fetch a post, it reads from the file system and parses this data,
turning it into a post object.
Infrastructure - Controllers
Controllers are our access point to the application from an external sources
In our case, HTTP controllers and Artisan commands
HTTP to access content (It’s a website)
Artisan to create posts (We are developers after all)
In the HTTP controllers, we load CommonMark and convert the content into
HTML.
This is an important, we made the decision that rendering a post and it’s format
had nothing to do with the domain.
The Code
Let’s have a look at some code
Just a quick look so you can see
what we’re talking about
Creating a post
We made this really easy.
Open up a terminal and go to the root folder
Run the following
php artisan post:make “Post title” barryosull
This will output the ID of the post, so you can go the files and edit them. Visit
the blog on your local machine and you’ll see the post.
*barryosull is my github handle, use your own
Quick additions
At the beginning we decided to use GitHub usernames in the author field.
We then saw that best practice was to have the author’s avatar beside the post.
How hard would it be to add?
Well, not hard, with a little bit of JS in the front-end, we
connected to the public Github API and fetched their avatar.
15mins work, a better experience for visitor and our contributors
Next Steps
What will we do next?
● Cache the posts in Redis (faster)
● Unit tests
● Tags for blog posts
● View posts by tag
● View posts by author
● Turn the blog into a laravel package
● Spruce up the design
● Events for broadcasting domain changes
● Projections for handling views of data
● Write more content!
We need your content
Guess what? We need you!
Want to become an active member in the community?
Want to be part of an active github project?
Want to build up your profile?
Want to mess around with Laravel 5.1?
Want to write about your experiences?
Then write a post and send it on!
Thanks for listening
Now for questions.
Ask me any question you like!
. . . except for my pin number
. . . or my password
. . . ok, please just stick to questions about the talk
Barry O Sullivan - barry@tercet.io - http://barryosullivan.me

More Related Content

What's hot

Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
Giovanni Scerra ☃
 
Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...
Chris Richardson
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Nader Albert
 
Onion (clean) architecture
Onion (clean) architectureOnion (clean) architecture
Onion (clean) architecture
Business incubator Novi Sad
 
Introducing Domain Driven Design - codemash
Introducing Domain Driven Design - codemashIntroducing Domain Driven Design - codemash
Introducing Domain Driven Design - codemash
Steven Smith
 
Microservices in Practice
Microservices in PracticeMicroservices in Practice
Microservices in Practice
Kasun Indrasiri
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice Architecture
tyrantbrian
 
Getting Started on AWS - AWSome Day Dallas 2018
Getting Started on AWS - AWSome Day Dallas 2018Getting Started on AWS - AWSome Day Dallas 2018
Getting Started on AWS - AWSome Day Dallas 2018
Amazon Web Services
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
Tom Kocjan
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Ryan Riley
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principles
Sanjoy Kumar Roy
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Araf Karsh Hamid
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
John Slick
 
The Secrets of Hexagonal Architecture
The Secrets of Hexagonal ArchitectureThe Secrets of Hexagonal Architecture
The Secrets of Hexagonal Architecture
Nicolas Carlo
 
Clase 2 Modelo Entidad-Relacion (MER)
Clase 2 Modelo Entidad-Relacion (MER)Clase 2 Modelo Entidad-Relacion (MER)
Clase 2 Modelo Entidad-Relacion (MER)
José Ricardo Tillero Giménez
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
Mikalai Alimenkou
 
Vertical Slicing Architectures
Vertical Slicing ArchitecturesVertical Slicing Architectures
Vertical Slicing Architectures
Victor Rentea
 
What are Microservices | Microservices Architecture Training | Microservices ...
What are Microservices | Microservices Architecture Training | Microservices ...What are Microservices | Microservices Architecture Training | Microservices ...
What are Microservices | Microservices Architecture Training | Microservices ...
Edureka!
 
What is difference between dbms and rdbms
What is difference between dbms and rdbmsWhat is difference between dbms and rdbms
What is difference between dbms and rdbms
Afrasiyab Haider
 
Clean architecture
Clean architectureClean architecture
Clean architecture
.NET Crowd
 

What's hot (20)

Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Onion (clean) architecture
Onion (clean) architectureOnion (clean) architecture
Onion (clean) architecture
 
Introducing Domain Driven Design - codemash
Introducing Domain Driven Design - codemashIntroducing Domain Driven Design - codemash
Introducing Domain Driven Design - codemash
 
Microservices in Practice
Microservices in PracticeMicroservices in Practice
Microservices in Practice
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice Architecture
 
Getting Started on AWS - AWSome Day Dallas 2018
Getting Started on AWS - AWSome Day Dallas 2018Getting Started on AWS - AWSome Day Dallas 2018
Getting Started on AWS - AWSome Day Dallas 2018
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principles
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
 
The Secrets of Hexagonal Architecture
The Secrets of Hexagonal ArchitectureThe Secrets of Hexagonal Architecture
The Secrets of Hexagonal Architecture
 
Clase 2 Modelo Entidad-Relacion (MER)
Clase 2 Modelo Entidad-Relacion (MER)Clase 2 Modelo Entidad-Relacion (MER)
Clase 2 Modelo Entidad-Relacion (MER)
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
 
Vertical Slicing Architectures
Vertical Slicing ArchitecturesVertical Slicing Architectures
Vertical Slicing Architectures
 
What are Microservices | Microservices Architecture Training | Microservices ...
What are Microservices | Microservices Architecture Training | Microservices ...What are Microservices | Microservices Architecture Training | Microservices ...
What are Microservices | Microservices Architecture Training | Microservices ...
 
What is difference between dbms and rdbms
What is difference between dbms and rdbmsWhat is difference between dbms and rdbms
What is difference between dbms and rdbms
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 

Similar to Onion Architecture and the Blog

Functional testing with behat
Functional testing with behatFunctional testing with behat
Functional testing with behat
Tahmina Khatoon
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
Matthias Noback
 
Django
DjangoDjango
MuleSoft Manchester Meetup #3 slides 31st March 2020
MuleSoft Manchester Meetup #3 slides 31st March 2020MuleSoft Manchester Meetup #3 slides 31st March 2020
MuleSoft Manchester Meetup #3 slides 31st March 2020
Ieva Navickaite
 
Evolutionary Design Solid
Evolutionary Design SolidEvolutionary Design Solid
Evolutionary Design Solid
Xebia IT Architects
 
Android meetup
Android meetupAndroid meetup
Android meetup
Vitali Pekelis
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
fantabulous2024
 
Spring boot
Spring bootSpring boot
Microsoft SharePoint in the Workplace
Microsoft SharePoint in the WorkplaceMicrosoft SharePoint in the Workplace
Microsoft SharePoint in the Workplace
CTE Solutions Inc.
 
Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...
Concetto Labs
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introduction
Commit University
 
Java part 3
Java part  3Java part  3
Getting started contributing to Apache Spark
Getting started contributing to Apache SparkGetting started contributing to Apache Spark
Getting started contributing to Apache Spark
Holden Karau
 
Professionalizing the Front-end
Professionalizing the Front-endProfessionalizing the Front-end
Professionalizing the Front-end
Jordi Anguela
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
Henry S
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Mack Hardy
 
Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015
Mirco Hering
 
Has serverless adoption hit a roadblock?
Has serverless adoption hit a roadblock?Has serverless adoption hit a roadblock?
Has serverless adoption hit a roadblock?
Veselin Pizurica
 
Getting Started with Rails
Getting Started with RailsGetting Started with Rails
Getting Started with Rails
Basayel Said
 
Example Of Import Java
Example Of Import JavaExample Of Import Java
Example Of Import Java
Melody Rios
 

Similar to Onion Architecture and the Blog (20)

Functional testing with behat
Functional testing with behatFunctional testing with behat
Functional testing with behat
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
 
Django
DjangoDjango
Django
 
MuleSoft Manchester Meetup #3 slides 31st March 2020
MuleSoft Manchester Meetup #3 slides 31st March 2020MuleSoft Manchester Meetup #3 slides 31st March 2020
MuleSoft Manchester Meetup #3 slides 31st March 2020
 
Evolutionary Design Solid
Evolutionary Design SolidEvolutionary Design Solid
Evolutionary Design Solid
 
Android meetup
Android meetupAndroid meetup
Android meetup
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
 
Spring boot
Spring bootSpring boot
Spring boot
 
Microsoft SharePoint in the Workplace
Microsoft SharePoint in the WorkplaceMicrosoft SharePoint in the Workplace
Microsoft SharePoint in the Workplace
 
Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introduction
 
Java part 3
Java part  3Java part  3
Java part 3
 
Getting started contributing to Apache Spark
Getting started contributing to Apache SparkGetting started contributing to Apache Spark
Getting started contributing to Apache Spark
 
Professionalizing the Front-end
Professionalizing the Front-endProfessionalizing the Front-end
Professionalizing the Front-end
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
 
Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015
 
Has serverless adoption hit a roadblock?
Has serverless adoption hit a roadblock?Has serverless adoption hit a roadblock?
Has serverless adoption hit a roadblock?
 
Getting Started with Rails
Getting Started with RailsGetting Started with Rails
Getting Started with Rails
 
Example Of Import Java
Example Of Import JavaExample Of Import Java
Example Of Import Java
 

Recently uploaded

The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
NishanthaBulumulla1
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 

Recently uploaded (20)

The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 

Onion Architecture and the Blog

  • 1. Onion Architecture And The Blog Making a blog (and having fun while doing it)
  • 2. Who am I Product Developer - Systems Architect - Freelancer - Development Manager Past experience Senior Developer for Cleverbug Lecturer at the Digital Skills Academy Director of Tercet, software development consultancy Current position Software Development Manager for OliveMedia Barry O Sullivan
  • 3. This talk We’re going to … ● Talk about the blog and it’s features ● look at the architecture ● look at the services we used ● look at some Laravel 5.1 code ● Show you how to publish a blog post
  • 4. The Blog What do we want it to do? What’s is its purpose? Our goals were to ● Host content from the community ● Make it easy for the community to contribute content ● Keep it simple and clean ● Use existing tools and libraries as much as possible ● Showcase some design best practice (as we see it anyway) ● Have some fun making it
  • 5. The features So to we decided on some simple features ● Articles are displayed as a list in the blog section ● Articles can be clicked and viewed individually ● Articles have unique urls (for SEO) ● Articles are written in markdown ● Articles are part of the repo ● People can send us articles via pull request We had a lot more features, but these were dropped, as they increased the scope and didn’t actually add a lot of value.
  • 6. The architecture We decided to use an Onion architecture (Also known as Ports and Adapters or *Hexagonal Architecture) Why we choose it: ● Clean separation of concerns ● Easy to maintain ● Encourages CQRS ● Industry best practice ● It’s just really nice * A very misleading name, programmers are the worst at naming things
  • 7. The Domain The heart of the application. Contains anything that’s business rule related Keep your business logic completely separated from your storage/service/controller logic. Doesn’t care about the technical details, contains only what’s necessary to validate business rules. Made up off ● ValueObjects ● Entities ● RepositoryInterfaces
  • 8. The API Entry point for the domain. Uses the domain to perform business operations. Acts as the interface between the “Application” and the business logic. Ensures that implementation details don’t bleed out into your controllers, eg. database logic, presentation logic Made up off ● Commands ● Queries
  • 9. The Infrastructure Contains the technical details about specific technologies. Eg, how data is accessed and where data is stored (The framework is technically infrastructure) Three types of infrastructure ● Controllers ● Data Storage (Database/FileSystem) ● External Services (Package, API, etc. . .)
  • 10. How layers interact A key part of an onion architecture is that outer layers can use inner layers, but inner layers have no knowledge of outer layers. This means that the infrastructure can see ValueObjects, but ValueObjects have no knowledge of the Database. Forces you to keep things simple and to put logic where it belongs, no bleeding of details that will make future changes difficult.
  • 11. Building the Blog The implementation is split into 3 sections ● The domain ● The API ● The Infrastructure ○ Services ○ Storage ○ Controllers
  • 12. The Blog Domain A blog post has the following business rules ● A blog must have a title, an author, an ID and content ● Title, author and content cannot be blank ● Publish date cannot be in the future That leaves us with the following value objects that enforce business rules Post, ID, Title, Author, PublishDate, Content We don’t have any other business rules for now, so we left it at that
  • 13. The Blog Domain (2) The next step is the definition of the repo, for storing and retrieving posts. The repo is an interface, and it defines how we expect our repository to behave, regardless of what implementation we decide to go for. We do this because it forces us to keep it generic, clean and easy to test. It also gives us the option of switching to another repo type (Which we will) The interface has three methods store(Post $post) fetch(UUID $id) all()
  • 14. The Blog API Next we have the API, this is the entry point for our app, and it offers all the functionality we want to expose. It’s CQRS, which just means we have two types of operations We offer the following command and queries Commands CreatePost Queries Post PostList We’re using Laravel 5.1s commands and command bus for this, as it has the IOC built in. This means we only ever use interfaces at this level and we let laravel handle the injection of our concrete implementations of our repository.
  • 15. Infrastructure - Services Why reinvent the wheel when someone is giving you a jet pack for free? We used the following packages to make our job easier Laravel 5.1 - It’s so hot right now (and it’s really powerful) FlySystem -Generic API for multiple storage engines CommonMark -Convert markdown into HTML, extensible UUID - UUIDs, because they’re actually really handy Carbon -Improved version of PHPs DateTime classes
  • 16. Infrastructure - Storage We create a concrete class that implements the PostRepo interface. Since they’re part of the repo, they’re part of the file system. They’re stored by ID, and are represented by two files blog/ e09135f2-ade1-4c25-9527-7ecbdc0d7c15/ details.json (title, author, date) markdown.md (Actual content) When we create a post, this structure is created When we fetch a post, it reads from the file system and parses this data, turning it into a post object.
  • 17. Infrastructure - Controllers Controllers are our access point to the application from an external sources In our case, HTTP controllers and Artisan commands HTTP to access content (It’s a website) Artisan to create posts (We are developers after all) In the HTTP controllers, we load CommonMark and convert the content into HTML. This is an important, we made the decision that rendering a post and it’s format had nothing to do with the domain.
  • 18. The Code Let’s have a look at some code Just a quick look so you can see what we’re talking about
  • 19. Creating a post We made this really easy. Open up a terminal and go to the root folder Run the following php artisan post:make “Post title” barryosull This will output the ID of the post, so you can go the files and edit them. Visit the blog on your local machine and you’ll see the post. *barryosull is my github handle, use your own
  • 20. Quick additions At the beginning we decided to use GitHub usernames in the author field. We then saw that best practice was to have the author’s avatar beside the post. How hard would it be to add? Well, not hard, with a little bit of JS in the front-end, we connected to the public Github API and fetched their avatar. 15mins work, a better experience for visitor and our contributors
  • 21. Next Steps What will we do next? ● Cache the posts in Redis (faster) ● Unit tests ● Tags for blog posts ● View posts by tag ● View posts by author ● Turn the blog into a laravel package ● Spruce up the design ● Events for broadcasting domain changes ● Projections for handling views of data ● Write more content!
  • 22. We need your content Guess what? We need you! Want to become an active member in the community? Want to be part of an active github project? Want to build up your profile? Want to mess around with Laravel 5.1? Want to write about your experiences? Then write a post and send it on!
  • 23. Thanks for listening Now for questions. Ask me any question you like! . . . except for my pin number . . . or my password . . . ok, please just stick to questions about the talk Barry O Sullivan - barry@tercet.io - http://barryosullivan.me