Slide 1

Slide 1 text

From Clean Architecture 
 to Modular Patterns Saeed Masoumi

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Who Am I ?

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Architecture

Slide 6

Slide 6 text

Architecture [ahr-ki-tek-cher] (n.) the structure and design of a system or product

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

• Pumping System • Electric Power System • Sewage Treatment System • and many other components …

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Blueprint of a restaurant sewage treatment system

Slide 15

Slide 15 text

Blueprint of a restaurant sewage treatment system

Slide 16

Slide 16 text

Blueprint of a restaurant

Slide 17

Slide 17 text

Blueprint of a restaurant • The architecture of the building tells you not what it’s made of. What it tells you is intent. • The architecture would scream: Restaurant (screaming architecture)

Slide 18

Slide 18 text

Architecture

Slide 19

Slide 19 text

Architecture • Architecture is about intent

Slide 20

Slide 20 text

Architecture • Architecture is about intent • Architecture is about use-cases

Slide 21

Slide 21 text

Architecture • Architecture is about intent • Architecture is about use-cases • MVP, MVVM, RxJava, Dagger, Retrofit, … these are tools, not architecture

Slide 22

Slide 22 text

Clean Architecture

Slide 23

Slide 23 text

Clean Architecture • Core concepts been around for decades • Has coined since 2012 by Uncle Bob

Slide 24

Slide 24 text

Clean Architecture

Slide 25

Slide 25 text

Clean Architecture Entities Use Cases Controllers Gateways Presenters Android W eb UI External Interfaces DB

Slide 26

Slide 26 text

Entities Entities

Slide 27

Slide 27 text

Entities Entities

Slide 28

Slide 28 text

Entities • Application independent business rules
 (domain module) Entities

Slide 29

Slide 29 text

Entities • Application independent business rules
 (domain module) • Can be an object with methods, or it can be a set of data structures and functions Entities

Slide 30

Slide 30 text

Entities • Application independent business rules
 (domain module) • Can be an object with methods, or it can be a set of data structures and functions • Least likely to change when something external changes Entities

Slide 31

Slide 31 text

Entities • Application independent business rules
 (domain module) • Can be an object with methods, or it can be a set of data structures and functions • Least likely to change when something external changes • For a single application, these entities are the business objects Entities

Slide 32

Slide 32 text

Interactors Use Cases

Slide 33

Slide 33 text

Interactors Use Cases

Slide 34

Slide 34 text

Interactors Use Cases • Application specific Business Rules 
 (application module)

Slide 35

Slide 35 text

Interactors Use Cases • Application specific Business Rules 
 (application module) • A description of an action that a user performs 
 on a system and tells the entity what to do

Slide 36

Slide 36 text

Interactors Use Cases • Application specific Business Rules 
 (application module) • A description of an action that a user performs 
 on a system and tells the entity what to do • We don’t care about details

Slide 37

Slide 37 text

Interactors Use Cases • Application specific Business Rules 
 (application module) • A description of an action that a user performs 
 on a system and tells the entity what to do • We don’t care about details • The result can be delivered to a web page or a mobile app …

Slide 38

Slide 38 text

Interactors Use Cases • Application specific Business Rules 
 (application module) • A description of an action that a user performs 
 on a system and tells the entity what to do • We don’t care about details • The result can be delivered to a web page or a mobile app … • Similar to the command pattern

Slide 39

Slide 39 text

Interactors Use Cases

Slide 40

Slide 40 text

Interface Adapters Controllers Gateways Presenters

Slide 41

Slide 41 text

Interface Adapters Controllers Gateways Presenters

Slide 42

Slide 42 text

Interface Adapters Controllers Gateways Presenters • convert data from the format most 
 convenient for the use cases and entities,
 to the format most convenient for some
 external agency such as the Database or 
 the Web/Android …

Slide 43

Slide 43 text

Interface Adapters Controllers Gateways Presenters • convert data from the format most 
 convenient for the use cases and entities,
 to the format most convenient for some
 external agency such as the Database or 
 the Web/Android … • Entity-Boundary-Interactor Architecture

Slide 44

Slide 44 text

Interface Adapters Controllers Gateways Presenters • convert data from the format most 
 convenient for the use cases and entities,
 to the format most convenient for some
 external agency such as the Database or 
 the Web/Android … • Entity-Boundary-Interactor Architecture • Input/Output boundaries

Slide 45

Slide 45 text

Interface Adapters Controllers Gateways Presenters • convert data from the format most 
 convenient for the use cases and entities,
 to the format most convenient for some
 external agency such as the Database or 
 the Web/Android … • Entity-Boundary-Interactor Architecture • Input/Output boundaries • MV-whatever lives here

Slide 46

Slide 46 text

Frameworks & Drivers Android W eb UI External Interfaces DB

Slide 47

Slide 47 text

Frameworks & Drivers Android W eb UI External Interfaces DB

Slide 48

Slide 48 text

Frameworks & Drivers Android W eb UI External Interfaces DB • A delivery mechanism,
 Where all the details go

Slide 49

Slide 49 text

Frameworks & Drivers Android W eb UI External Interfaces DB • A delivery mechanism,
 Where all the details go • Database, the App Frameworks …

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

So what is the Clean Architecture?

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

The Dependency Rule

Slide 54

Slide 54 text

The Dependency Rule Mechanism Policies

Slide 55

Slide 55 text

The Dependency Rule

Slide 56

Slide 56 text

The Dependency Rule • Independent of frameworks

Slide 57

Slide 57 text

The Dependency Rule • Independent of frameworks • Testable

Slide 58

Slide 58 text

The Dependency Rule • Independent of frameworks • Testable • Independent of UI

Slide 59

Slide 59 text

The Dependency Rule • Independent of frameworks • Testable • Independent of UI • Independent of Database

Slide 60

Slide 60 text

The Dependency Rule • Independent of frameworks • Testable • Independent of UI • Independent of Database • Independent of any external agency

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 63

Slide 63 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 64

Slide 64 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 65

Slide 65 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 66

Slide 66 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 67

Slide 67 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 68

Slide 68 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 69

Slide 69 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 70

Slide 70 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 71

Slide 71 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 72

Slide 72 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 73

Slide 73 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 74

Slide 74 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 75

Slide 75 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 76

Slide 76 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 77

Slide 77 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 78

Slide 78 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 79

Slide 79 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 80

Slide 80 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 81

Slide 81 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 82

Slide 82 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 83

Slide 83 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 84

Slide 84 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 85

Slide 85 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 86

Slide 86 text

UseCase Presenter ViewModel View Entities Repository Repository Entities Entities DataSource DataSource Android Stuff DataSourceImpl DataSourceImpl

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

App Structure

Slide 89

Slide 89 text

App Structure MyAwesomeApp business-logic application-domain presentation data android front

Slide 90

Slide 90 text

But there is a problem here!!!

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

Challenges in Mobile App Development

Slide 93

Slide 93 text

Challenges in Mobile App Development • Most of the use-cases are just for data consuming, So mobile apps do very little than web apps.

Slide 94

Slide 94 text

Challenges in Mobile App Development • Most of the use-cases are just for data consuming, So mobile apps do very little than web apps. • Most of the time we deal with the platform issues ( memory, storage, lifecycle hell, location services, etc)

Slide 95

Slide 95 text

Challenges in Mobile App Development • Most of the use-cases are just for data consuming, So mobile apps do very little than web apps. • Most of the time we deal with the platform issues ( memory, storage, lifecycle hell, location services, etc) • Enterprise applications ( Tap30, Snapp, DigiKala … )

Slide 96

Slide 96 text

Challenges in Mobile App Development • Most of the use-cases are just for data consuming, So mobile apps do very little than web apps. • Most of the time we deal with the platform issues ( memory, storage, lifecycle hell, location services, etc) • Enterprise applications ( Tap30, Snapp, DigiKala … ) • Team growth

Slide 97

Slide 97 text

Challenges in Mobile App Development • Most of the use-cases are just for data consuming, So mobile apps do very little than web apps. • Most of the time we deal with the platform issues ( memory, storage, lifecycle hell, location services, etc) • Enterprise applications ( Tap30, Snapp, DigiKala … ) • Team growth • Large Codebase

Slide 98

Slide 98 text

Challenges in Mobile App Development • Most of the use-cases are just for data consuming, So mobile apps do very little than web apps. • Most of the time we deal with the platform issues ( memory, storage, lifecycle hell, location services, etc) • Enterprise applications ( Tap30, Snapp, DigiKala … ) • Team growth • Large Codebase • Deliver features fast without fuss

Slide 99

Slide 99 text

Challenges in Mobile App Development • Most of the use-cases are just for data consuming, So mobile apps do very little than web apps. • Most of the time we deal with the platform issues ( memory, storage, lifecycle hell, location services, etc) • Enterprise applications ( Tap30, Snapp, DigiKala … ) • Team growth • Large Codebase • Deliver features fast without fuss • Also need an architecture for Test!!

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text


 Clean Architecture could be a little bit over-engineered

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

Modular Pattern

Slide 104

Slide 104 text

Modular Pattern • Cut the large monolith software into many vertical smaller monoliths (similar to microservices architecture)

Slide 105

Slide 105 text

Modular Pattern • Cut the large monolith software into many vertical smaller monoliths (similar to microservices architecture) • Each team only needs to focus on the module that they work

Slide 106

Slide 106 text

Modular Pattern • Cut the large monolith software into many vertical smaller monoliths (similar to microservices architecture) • Each team only needs to focus on the module that they work • Organize your code as it grows

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

Independent Modules

Slide 109

Slide 109 text

Independent Modules • extensible, reusable, maintainable, and adaptable.

Slide 110

Slide 110 text

Independent Modules • extensible, reusable, maintainable, and adaptable. • flexible composite of collaborating modules

Slide 111

Slide 111 text

Independent Modules • extensible, reusable, maintainable, and adaptable. • flexible composite of collaborating modules • Helps on-boarding process for new developers

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

So let’s combine them

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

Modern App Architecture

Slide 116

Slide 116 text

Modern App Architecture • Again follow the dependency rule!

Slide 117

Slide 117 text

Modern App Architecture • Again follow the dependency rule! • Break the rules based on your need

Slide 118

Slide 118 text

Modern App Architecture • Again follow the dependency rule! • Break the rules based on your need • Unidirectional data flow architecture, like Flux

Slide 119

Slide 119 text

Modern App Architecture • Again follow the dependency rule! • Break the rules based on your need • Unidirectional data flow architecture, like Flux • Easy to learn

Slide 120

Slide 120 text

Modern App Architecture • Again follow the dependency rule! • Break the rules based on your need • Unidirectional data flow architecture, like Flux • Easy to learn • Testable

Slide 121

Slide 121 text

Modern App Architecture • Again follow the dependency rule! • Break the rules based on your need • Unidirectional data flow architecture, like Flux • Easy to learn • Testable • Use BoundedContext Pattern

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

How did we scale our app in Tap30?

Slide 124

Slide 124 text

No content

Slide 125

Slide 125 text

Our Main Challenges

Slide 126

Slide 126 text

Our Main Challenges • Team growth

Slide 127

Slide 127 text

Our Main Challenges • Team growth • More features demand from business side

Slide 128

Slide 128 text

Our Main Challenges • Team growth • More features demand from business side • Large codebase

Slide 129

Slide 129 text

Our Main Challenges • Team growth • More features demand from business side • Large codebase • Need a platform team

Slide 130

Slide 130 text

No content

Slide 131

Slide 131 text

What we did…

Slide 132

Slide 132 text

What we did… • Combine the idea behind Flux and the clean architecture principles to create a unidirectional and state-based data flow architecture

Slide 133

Slide 133 text

What we did… • Combine the idea behind Flux and the clean architecture principles to create a unidirectional and state-based data flow architecture • Convert our driver & frameworks layer to a single independent modules (e.g. location, persistence, etc)

Slide 134

Slide 134 text

What we did… • Combine the idea behind Flux and the clean architecture principles to create a unidirectional and state-based data flow architecture • Convert our driver & frameworks layer to a single independent modules (e.g. location, persistence, etc) • Increase the level of abstraction

Slide 135

Slide 135 text

What we did… • Combine the idea behind Flux and the clean architecture principles to create a unidirectional and state-based data flow architecture • Convert our driver & frameworks layer to a single independent modules (e.g. location, persistence, etc) • Increase the level of abstraction • Use BoundedContext pattern

Slide 136

Slide 136 text

No content

Slide 137

Slide 137 text

Applying BoundedContext Pattern

Slide 138

Slide 138 text

PreRequestContext

Slide 139

Slide 139 text

PreRequestContext

Slide 140

Slide 140 text

PaymentContext

Slide 141

Slide 141 text

PaymentContext

Slide 142

Slide 142 text

No content

Slide 143

Slide 143 text

Shared Architecture and Business Logic PreRideContext RideContext PaymentContext UserManagementContext Platform/SDK Modules Test Platform Twister

Slide 144

Slide 144 text

No content

Slide 145

Slide 145 text

How does it work?

Slide 146

Slide 146 text

How does it work? • Shared Architecture contains our internal libraries, architecture, etc. • Each BoundedContext is a mini-app and contains all layers from presentation to data • Each Platform module binds to a BoundedContext and add extra functionality • Test platform helps us to test specific/whole parts of the app • Twister is an app bootstrap and binds all needed modules to create our Passenger/Driver apps.

Slide 147

Slide 147 text

Thanks