Slide 1

Slide 1 text

And what we can do wrong PHP Application Architecture

Slide 2

Slide 2 text

It'se Me Martin Holzhauer woodworker@twitter woodworker@github Working at Doing PHP Stuff since 2002 (PHP 4.1.2)

Slide 3

Slide 3 text

What this Talk features ● basics behind application architecture ● what i've learned in the last years ● ideas you can apply to your work ● maybe good content

Slide 4

Slide 4 text

What this Talk is NOT ● practical advice to change everything now ● the only truth ● a reason to stop think about architecture yourself ● full of fancy pictures and effects

Slide 5

Slide 5 text

Architecture The almighty Master Plan!?

Slide 6

Slide 6 text

At least we hope so. We all do Architecture !?

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Using Patterns is not having an Architecture "We do have an Architecture, our Application is MVC"

Slide 9

Slide 9 text

Using Patterns is not having an Architecture Frameworks, Programming Languages or Patterns are only the tools to implement your Architecture

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

And what is Architecture?

Slide 12

Slide 12 text

Architecture is the definition of your use cases If you want a short business punchline

Slide 13

Slide 13 text

Architecture is the definition of your business or at least what we developer think is the definition

Slide 14

Slide 14 text

Programming is Architecture When you think about your functions, classes, objects or methods you are doing Architectural decisions.

Slide 15

Slide 15 text

Find your use cases

Slide 16

Slide 16 text

Define your use cases

Slide 17

Slide 17 text

Architecture and Use cases When you look at your project: ● do you see the framework? ● do you see mvc? ● do you see web? ● do you see database?

Slide 18

Slide 18 text

Architecture and Use cases or do you see the use cases

Slide 19

Slide 19 text

Real Life vs. Programming http://en.wikipedia.org/wiki/File:Use_case_restaurant_model.svg

Slide 20

Slide 20 text

Use cases you could do UML Case diagrams but don't be silly ٩(●̮̮̃•)۶

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Use cases My opinion is that "User adds a Place" on an index card is good enough

Slide 23

Slide 23 text

Your use cases will disclose your API

Slide 24

Slide 24 text

Use case driven development ● There is NO "one Interface fits all" ● Specific methods for specific use cases ● Do not try to abstract you interface to much ● As always, you need to find good compromises

Slide 25

Slide 25 text

decouple your system from the underlying technologies Implement use cases, not technologies

Slide 26

Slide 26 text

Implement use cases and hide technologies ● Do not use ORM/ODM Entities in your public API ● Do not use Framework specific Interfaces in your public API ● Do not any external, third party stuff in YOUR public API

Slide 27

Slide 27 text

Implement use cases and hide technologies ○ selectFromDb($field, $table) Bad ○ getById($id) Good

Slide 28

Slide 28 text

Implement use cases and hide technologies ○ search('text', Search::Type_Keyword) OKisch ○ searchByKeyword('text') Better

Slide 29

Slide 29 text

Implement use cases Your models and interfaces represent your business not your database

Slide 30

Slide 30 text

The cool thing about that You can switch your framework/tools ● as in we are porting our app-frontend to Symfony2 ● we are moving to $coolNoSQLDB ● we decided to hate zend_db ● we have written a optimized service for $usecase in erlang

Slide 31

Slide 31 text

The cool thing about that You can simply write another UI ● we need a mobile site ● we want an Android/iPhone app ● we want an API

Slide 32

Slide 32 text

A good architecture will let you grow Or shrink or change

Slide 33

Slide 33 text

An Example Or better a view on a small part of your business

Slide 34

Slide 34 text

Architecture and growth An Example (Search) Iteration 1 Usage: $placeService->search('Berlin') Implementation: LIKE query

Slide 35

Slide 35 text

Architecture and growth An Example (Search) Iteration 1 Usage: $placeService->searchByCity('Berlin') Implementation: LIKE query

Slide 36

Slide 36 text

Architecture and growth An Example (Search) Iteration 2 Usage: $placeService->searchByCity('Berlin') Implementation: Fulltext index

Slide 37

Slide 37 text

Architecture and growth An Example (Search) Iteration 3 Usage: $placeService->searchByCity('Berlin') Implementation: Solr

Slide 38

Slide 38 text

Iteration 4 Usage: $placeService->searchByCity('Berlin') Implementation: Solr + Database Architecture and growth An Example (Search)

Slide 39

Slide 39 text

Architecture and growth An Example (Search) Iteration 5 Usage: $placeService->searchByCity('Berlin') Implementation: Solr + Memcache + DB

Slide 40

Slide 40 text

My Point You care about the use cases You do not give a f**k about implementation

Slide 41

Slide 41 text

More Informations www.cleancoders.com Podcast Episode 7

Slide 42

Slide 42 text

General Informations www.cleancoders.com Podcast Episode 7

Slide 43

Slide 43 text

Questions? Maybe i will have answers or can confuse you a bit more ;D

Slide 44

Slide 44 text

KTHXBYE @woodworker [email protected]