The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

43
The Lucid Architecture Building Scalable Applications Abed Halawi - Tech Lead at Vinelab @mulkave

Transcript of The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Page 1: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

The Lucid

Architecture Building Scalable Applications

Abed Halawi - Tech Lead at Vinelab @mulkave

Page 2: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

What is an Architecture?

Page 3: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

What is an Architecture?

Pattern of connected Structures

Page 4: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Structure & Architecture

Page 5: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016
Page 6: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Structure

Page 7: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Architecture

Page 8: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

An expression of a

What is an architecture?

viewpoint

Page 9: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Why Do We Have Them?

Page 10: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Why Do We Have Them?

Communicate Structures

Controller ✅

Model ✅

View ✅

Service ⁉

Domain ⁉

Page 11: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Why Do We Have Them?

Eradecate Homelessness of Code

0

25

50

75

100

0

25

50

75

100

v1.0 v1.2

😈👺

Page 12: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Why Do We Have Them?

Eradecate Homelessness of Code

Page 13: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Why Do We Have Them?

Illustrate Structures

Request Http Kernel

Closure

Controller

Route Process &

Respond

DDD?Technical Debt 🤑

SOA?

Page 14: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Legacy Code

Page 15: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

• No More Legacy Code

• Defines Terminology

• Comprehensive, No Limitations

• Complements Laravel’s Design

• Simple, Yet Sophisticated

• Performs at Scale

What?

How? 🤔

Page 16: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid

Page 17: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid

Page 18: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Components

Feature

Job

Service

Page 19: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Feature• As described in business, as a class name • Runs Jobs - Steps in the process of accomplishment

CreateArticleFeature

LoginUserFeature

ControllerProcess

& RespondFeature

serve

Page 20: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Feature• Controllers serve Features

Page 21: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016
Page 22: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016
Page 23: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016
Page 24: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016
Page 25: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • JobA class that does one thing; responsible for the

business logic

• CreateArticleFeature

• Validate Article Input

• Generate Slug

• Upload Files To Cdn

• Save Article

• Respond With Json

Page 26: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • JobA class that does one thing; responsible for the

business logic

• CreateArticleFeature

• ValidateArticleInputJob

• GenerateSlugJob

• UploadFilesToCdnJob

• SaveArticleJob

• RespondWithJsonJob

Page 27: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • JobA class that does one thing; responsible for the

business logic

Controller Featureserve

Validate Input

Generate Slug

Upload Files To CDN

Save Article

Respond With JSON

] Process&

] Respond

Page 28: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016
Page 29: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016
Page 30: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016
Page 31: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016
Page 32: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

132

1 2 3

Page 33: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Service

Implements Features and serves them through controllers

Website

Api

Backend

Page 34: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Service• Website • ListArticlesFeature • GetPublishedArticlesJob • RespondWithViewJob

• Api • ListArticlesFeature • GetPublishedArticlesJob • RespondWithJsonJob

• Backend • CreateArticleFeature • ValidateArticleInputJob • SaveArticleJob • RespondWithViewJob

Page 35: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Service• Website • ListArticlesFeature • GetPublishedArticlesJob • RespondWithViewJob

• Api • ListArticlesFeature • GetPublishedArticlesJob • RespondWithJsonJob

• Backend • CreateArticleFeature • ValidateArticleInputJob • SaveArticleJob • RespondWithViewJob

Page 36: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Service• Website • ListArticlesFeature • GetPublishedArticlesJob • RespondWithViewJob

• Api • ListArticlesFeature • GetPublishedArticlesJob • RespondWithJsonJob

• Backend • CreateArticleFeature • ValidateArticleInputJob • SaveArticleJob • RespondWithViewJob

Page 37: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Service

Http Kernel

WhichService?

Controller Feature

Website

Route

Controller Feature

Api

Route

Controller Feature

Backend

Route

example.com

api.example.com OR example.com/api

admin…com OR example.com/api

Domains

Page 38: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Domains

Responsible for the entities; exposing their functionalities through Jobs

Page 39: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Domains• Article

• GetPublishedArticlesJob

• SaveArticleJob

• ValidateArticleInputJob

• Cdn

• UploadFilesToCdnJob

• Http

• RespondWithJsonJob

Page 40: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Layers

Service Domain Data

F

A

T

U

R

E

E

J

O

B

M

D

E

L

O

Page 41: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Principles ✍1. Controllers serve Features

2. Avoid Cross-Domain Communication

3. Avoid Cross-Job Communication

Page 42: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Getting Started> composer create-project lucid-arch/laravel my-project

1. Init a project

> lucid make:service Api

2. Scaffold a Service

> lucid make:feature Api LoginUser

3. Generate a Feature

> lucid make:job User CheckCredentials

4. Generate a Job

Page 43: The Lucid Architecture for Building Scalable Applications at LaraconEU 2016

Lucid • Console