Upgrade to Pro — share decks privately, control downloads, hide ads and more …

From Clean Architecture to Modular Patterns

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

From Clean Architecture to Modular Patterns

Avatar for Saeed Masoumi

Saeed Masoumi

March 08, 2018

More Decks by Saeed Masoumi

Other Decks in Programming

Transcript

  1. 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)
  2. Architecture • Architecture is about intent • Architecture is about

    use-cases • MVP, MVVM, RxJava, Dagger, Retrofit, … these are tools, not architecture
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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 …
  9. 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
  10. 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 …
  11. 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
  12. 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
  13. 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
  14. Frameworks & Drivers Android W eb UI External Interfaces DB

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

    • A delivery mechanism,
 Where all the details go • Database, the App Frameworks …
  16. The Dependency Rule • Independent of frameworks • Testable •

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

    Independent of UI • Independent of Database • Independent of any external agency
  18. Challenges in Mobile App Development • Most of the use-cases

    are just for data consuming, So mobile apps do very little than web apps.
  19. 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)
  20. 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 … )
  21. 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
  22. 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
  23. 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
  24. 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!!
  25. Modular Pattern • Cut the large monolith software into many

    vertical smaller monoliths (similar to microservices architecture)
  26. 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
  27. 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
  28. Independent Modules • extensible, reusable, maintainable, and adaptable. • flexible

    composite of collaborating modules • Helps on-boarding process for new developers
  29. Modern App Architecture • Again follow the dependency rule! •

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

    Break the rules based on your need • Unidirectional data flow architecture, like Flux • Easy to learn
  31. 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
  32. 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
  33. Our Main Challenges • Team growth • More features demand

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

    from business side • Large codebase • Need a platform team
  35. What we did… • Combine the idea behind Flux and

    the clean architecture principles to create a unidirectional and state-based data flow architecture
  36. 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)
  37. 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
  38. 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
  39. 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.