Building a blog with an Onion Architecture

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://barryosull.com
1 of 23

Recommended

Why Kotlin? by
Why Kotlin?Why Kotlin?
Why Kotlin?Yongqiang Li
121 views20 slides
Spring Boot Workshop - January w/ Women Who Code by
Spring Boot Workshop - January w/ Women Who CodeSpring Boot Workshop - January w/ Women Who Code
Spring Boot Workshop - January w/ Women Who CodePurnima Kamath
58 views19 slides
Zen and the Art of REST API documentation - MuCon London 2015 by
Zen and the Art of REST API documentation - MuCon London 2015Zen and the Art of REST API documentation - MuCon London 2015
Zen and the Art of REST API documentation - MuCon London 2015Steve Judd
1.4K views19 slides
Your First Scala Web Application using Play 2.1 by
Your First Scala Web Application using Play 2.1Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Matthew Barlocker
9.7K views41 slides
The Ember.js Framework - Everything You Need To Know by
The Ember.js Framework - Everything You Need To KnowThe Ember.js Framework - Everything You Need To Know
The Ember.js Framework - Everything You Need To KnowAll Things Open
1.6K views69 slides
Building Awesome APIs with Lumen by
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with LumenKit Brennan
1.3K views30 slides

More Related Content

What's hot

Building a chatbot – step by step by
Building a chatbot – step by stepBuilding a chatbot – step by step
Building a chatbot – step by stepCodeOps Technologies LLP
8.3K views108 slides
React Native Firebase Realtime Database + Authentication by
React Native Firebase Realtime Database + AuthenticationReact Native Firebase Realtime Database + Authentication
React Native Firebase Realtime Database + AuthenticationKobkrit Viriyayudhakorn
11.5K views49 slides
Laravel Webcon 2015 by
Laravel Webcon 2015Laravel Webcon 2015
Laravel Webcon 2015Tim Bracken
653 views17 slides
Codeigniter by
CodeigniterCodeigniter
CodeigniterShahRushika
31 views24 slides
[React Native Tutorial] Lecture 6: Component, Props, and Network by
[React Native Tutorial] Lecture 6: Component, Props, and Network[React Native Tutorial] Lecture 6: Component, Props, and Network
[React Native Tutorial] Lecture 6: Component, Props, and NetworkKobkrit Viriyayudhakorn
5.3K views33 slides
Os Bubna by
Os BubnaOs Bubna
Os Bubnaoscon2007
406 views33 slides

What's hot(20)

Laravel Webcon 2015 by Tim Bracken
Laravel Webcon 2015Laravel Webcon 2015
Laravel Webcon 2015
Tim Bracken653 views
[React Native Tutorial] Lecture 6: Component, Props, and Network by Kobkrit Viriyayudhakorn
[React Native Tutorial] Lecture 6: Component, Props, and Network[React Native Tutorial] Lecture 6: Component, Props, and Network
[React Native Tutorial] Lecture 6: Component, Props, and Network
Os Bubna by oscon2007
Os BubnaOs Bubna
Os Bubna
oscon2007406 views
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel by ukdpe
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnelEntity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
ukdpe1.1K views
PHP Indonesia Meetup - What's New in Yii2 and PHP5.5 by Petra Barus
PHP Indonesia Meetup - What's New in Yii2 and PHP5.5PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
Petra Barus12.3K views
Python's dynamic nature (rough slides, November 2004) by Kiran Jonnalagadda
Python's dynamic nature (rough slides, November 2004)Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)
Kiran Jonnalagadda1.1K views
Modular PHP Development using CodeIgniter Bonfire by Jeff Fox
Modular PHP Development using CodeIgniter BonfireModular PHP Development using CodeIgniter Bonfire
Modular PHP Development using CodeIgniter Bonfire
Jeff Fox22.7K views
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python by Cisco DevNet
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and PythonDEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
Cisco DevNet3.6K views
How to build a rest api by Hoang Nguyen
How to build a rest apiHow to build a rest api
How to build a rest api
Hoang Nguyen374 views
SiLCC Overview by Ushahidi
SiLCC OverviewSiLCC Overview
SiLCC Overview
Ushahidi689 views
Drupal & Summon: Keeping Article Discovery in the Library by Ken Varnum
Drupal & Summon: Keeping Article Discovery in the LibraryDrupal & Summon: Keeping Article Discovery in the Library
Drupal & Summon: Keeping Article Discovery in the Library
Ken Varnum4K views
Introduction of lambda expression and predicate builder by LearningTech
Introduction of lambda expression and predicate builderIntroduction of lambda expression and predicate builder
Introduction of lambda expression and predicate builder
LearningTech1.7K views

Similar to Building a blog with an Onion Architecture

Functional testing with behat by
Functional testing with behatFunctional testing with behat
Functional testing with behatTahmina Khatoon
306 views19 slides
Advanced web application architecture - Talk by
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - TalkMatthias Noback
686 views63 slides
Django by
DjangoDjango
DjangoNarcisse Siewe
830 views1270 slides
MuleSoft Manchester Meetup #3 slides 31st March 2020 by
MuleSoft Manchester Meetup #3 slides 31st March 2020MuleSoft Manchester Meetup #3 slides 31st March 2020
MuleSoft Manchester Meetup #3 slides 31st March 2020Ieva Navickaite
498 views42 slides
Evolutionary Design Solid by
Evolutionary Design SolidEvolutionary Design Solid
Evolutionary Design SolidXebia IT Architects
629 views40 slides
Android meetup by
Android meetupAndroid meetup
Android meetupVitali Pekelis
142 views34 slides

Similar to Building a blog with an Onion Architecture(20)

Advanced web application architecture - Talk by Matthias Noback
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
Matthias Noback686 views
MuleSoft Manchester Meetup #3 slides 31st March 2020 by Ieva Navickaite
MuleSoft Manchester Meetup #3 slides 31st March 2020MuleSoft Manchester Meetup #3 slides 31st March 2020
MuleSoft Manchester Meetup #3 slides 31st March 2020
Ieva Navickaite498 views
Guidelines to understand durable functions with .net core, c# and stateful se... by Concetto Labs
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 Labs31 views
Getting started contributing to Apache Spark by Holden Karau
Getting started contributing to Apache SparkGetting started contributing to Apache Spark
Getting started contributing to Apache Spark
Holden Karau178 views
Professionalizing the Front-end by Jordi Anguela
Professionalizing the Front-endProfessionalizing the Front-end
Professionalizing the Front-end
Jordi Anguela757 views
Code for Startup MVP (Ruby on Rails) Session 1 by Henry S
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 S5.9K views
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013 by Mack Hardy
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 Hardy8.1K views
Dev Ops for systems of record - Talk at Agile Australia 2015 by Mirco Hering
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 Hering969 views
Has serverless adoption hit a roadblock? by Veselin Pizurica
Has serverless adoption hit a roadblock?Has serverless adoption hit a roadblock?
Has serverless adoption hit a roadblock?
Veselin Pizurica347 views
Getting Started with Rails by Basayel Said
Getting Started with RailsGetting Started with Rails
Getting Started with Rails
Basayel Said534 views
Example Of Import Java by Melody Rios
Example Of Import JavaExample Of Import Java
Example Of Import Java
Melody Rios5 views
AngularJS 1.x - your first application (problems and solutions) by Igor Talevski
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)
Igor Talevski570 views

More from Barry O Sullivan

Value objects by
Value objectsValue objects
Value objectsBarry O Sullivan
261 views14 slides
Managing expectations by
Managing expectationsManaging expectations
Managing expectationsBarry O Sullivan
232 views23 slides
DDD: lessons learned by
DDD: lessons learnedDDD: lessons learned
DDD: lessons learnedBarry O Sullivan
570 views16 slides
Php test fest by
Php test festPhp test fest
Php test festBarry O Sullivan
1.6K views27 slides
Cleaning up your codebase with a clean architecture by
Cleaning up your codebase with a clean architectureCleaning up your codebase with a clean architecture
Cleaning up your codebase with a clean architectureBarry O Sullivan
574 views31 slides
Design patterns - The Good, the Bad, and the Anti-Pattern by
Design patterns -  The Good, the Bad, and the Anti-PatternDesign patterns -  The Good, the Bad, and the Anti-Pattern
Design patterns - The Good, the Bad, and the Anti-PatternBarry O Sullivan
1.2K views37 slides

More from Barry O Sullivan(6)

Recently uploaded

Introduction to Git Source Control by
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source ControlJohn Valentino
7 views18 slides
Quality Assurance by
Quality Assurance Quality Assurance
Quality Assurance interworksoftware2
5 views6 slides
Benefits in Software Development by
Benefits in Software DevelopmentBenefits in Software Development
Benefits in Software DevelopmentJohn Valentino
5 views15 slides
ADDO_2022_CICID_Tom_Halpin.pdf by
ADDO_2022_CICID_Tom_Halpin.pdfADDO_2022_CICID_Tom_Halpin.pdf
ADDO_2022_CICID_Tom_Halpin.pdfTomHalpin9
5 views33 slides
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation by
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook AutomationDRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook AutomationHCLSoftware
6 views8 slides
Playwright Retries by
Playwright RetriesPlaywright Retries
Playwright Retriesartembondar5
6 views1 slide

Recently uploaded(20)

Introduction to Git Source Control by John Valentino
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source Control
John Valentino7 views
ADDO_2022_CICID_Tom_Halpin.pdf by TomHalpin9
ADDO_2022_CICID_Tom_Halpin.pdfADDO_2022_CICID_Tom_Halpin.pdf
ADDO_2022_CICID_Tom_Halpin.pdf
TomHalpin95 views
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation by HCLSoftware
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook AutomationDRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation
HCLSoftware6 views
How Workforce Management Software Empowers SMEs | TraQSuite by TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuite
TraQSuite6 views
JioEngage_Presentation.pptx by admin125455
JioEngage_Presentation.pptxJioEngage_Presentation.pptx
JioEngage_Presentation.pptx
admin1254558 views
predicting-m3-devopsconMunich-2023-v2.pptx by Tier1 app
predicting-m3-devopsconMunich-2023-v2.pptxpredicting-m3-devopsconMunich-2023-v2.pptx
predicting-m3-devopsconMunich-2023-v2.pptx
Tier1 app12 views
tecnologia18.docx by nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67025 views
Quality Engineer: A Day in the Life by John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino7 views
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... by TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin96 views
Electronic AWB - Electronic Air Waybill by Freightoscope
Electronic AWB - Electronic Air Waybill Electronic AWB - Electronic Air Waybill
Electronic AWB - Electronic Air Waybill
Freightoscope 5 views
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... by NimaTorabi2
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
NimaTorabi216 views

Building a blog with an Onion Architecture

  • 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://barryosull.com