Dive to clean architecture with golang

Dive to clean architecture with golang

0c9a69560f916778b569086d792680bb?s=128

bmf_san

July 03, 2019
Tweet

Transcript

  1. Dive to clean architecture with golang @bmf_san @Makuake LT Party

    2019/07/03
  2. @bmf_san bmf-san bmf-tech.com Twitter Github Blog

  3. Golang × Clean Architecture

  4. Table of contents • What is the clean architecture? •

    Implementation of clean architecture • Conclusions
  5. 1 What is the clean architecture?

  6. Ideas for architecture of systems • Over the last several

    years… • Hexagonal Architecture (Ports and Adapters) • Onion Architecture • Screaming Architecture • DCI • BCE • etc…
  7. The separation of concerns

  8. Things that are produced by those architecture of systems is

    … • Independent of Frameworks • Testable • Independent of UI • Independent of Database • Independent of any external agency • →For eliminating dependencies and getting testability.
  9. Clean architecture

  10. Layers 4PVSDFIUUQTCMPHDMFBODPEFSDPNVODMFCPCUIFDMFBOBSDIJUFDUVSFIUNM

  11. Entities • Entities encapsulate the most important business rules •

    ex. an object with methods, a set of data structures and functions…
  12. Use Cases • Use cases contains application specific business rules

  13. Interface Adapters • Interface adapters is a set of adapters

    which convert data for entities and use cases
  14. Frameworks and Drivers • Frameworks and drivers contains frameworkss and

    tools such as the database, web framework, etc
  15. The rules of layers • Not only four layers, we

    can change numbers of layers • An inner layer can’t know about an outer layers • The dependency direction is from an outer layer to an inner layer
  16. 2 Implementation of clean architecture

  17. Repository • Github • bmf-san/go-clean-architecture-web-application- boilerplate • https://github.com/bmf-san/go-clean-architecture-web- application-boilerplate

  18. I’m waiting for your nice review.

  19. Directory structures -BZFST %JSFDUPSZ 'SBNFXPSLT
 BOE
 %SJWFST JOGSBTUSVDUVSF *OUFSGBDF JOUFSGBDFT

    6TF$BTFT VTFDBTFT &OUJUJFT EPNBJO
  20. DIP • Dependency Inversion Principle • One of the SOLID

    principles • Modules should depend on abstractions(e.g. interfaces) • Abstractions should not depend on details(e.g. concrete implementations) • For increasing loosely coupled between high level modules and low level modules • Modules will be more flexible
  21. Accept interfaces, return structs

  22. None
  23. DIP in golang

  24. Before

  25. After

  26. What changed? 42-)BOEMFS 'PP3FQPTJUPSZ #FGPSF "GUFS 42-)BOEMFS 'PP3FQPTJUPSZ 42-)BOEMFS*OUFSGBDF

  27. Example

  28. Example JOGSBTUSVDUVSFTRM)BOEMFSHP *OUFSGBDF JOUFSGBDFTTRM)BOEMFSHP JOUFSGBDFTVTFS@SFQPTJUPSZHP *OGSBTUSVDUVSF *OUFSGBDFT

  29. Code reading • See the direction of dependency NBJOHP SPVUFSHP

    VTFS@DPOUSPMMFSHP VTFS@JOUFSBDUPSHP VTFS@SFQPTJUPSZHP VTFSHP ˣ ˣ ˣ ˣ ˣ *OGSBTUSVDUVSF *OUFSGBDFT 6TF$BTFT %PNBJO
  30. 3 Conclusions

  31. Conclusions • Architect should have leadership for handling clean architecture

    • handson, study session for understanding architecture …etc • There are different ways to interpret it • To expand knowledge for it together as a team • There are various patterns for transactions • A framework is just a tool, not a way of life. • Written on the page p.197 Clean Architecture ୡਓʹֶͿιϑτ΢ΣΞͷߏ଄ͱઃܭ
  32. References - Github • Github • manuelkiessling/go-cleanarchitecture • https://github.com/manuelkiessling/go-cleanarchitecture •

    rymccue/golang-standard-lib-rest-api • https://github.com/rymccue/golang-standard-lib-rest-api • hirotakan/go-cleanarchitecture-sample • https://github.com/hirotakan/go-cleanarchitecture-sample
  33. References - Blog • Blog • The Clean Code Blog

    • https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html • Recruit Technologies - GoݴޠͱDependency Injection • https://recruit-tech.co.jp/blog/2017/12/11/go_dependency_injection/ • Clean ArchitectureͰAPI ServerΛߏஙͯ͠ΈΔ • https://qiita.com/hirotakan/items/698c1f5773a3cca6193e • ΫϦʔϯΞʔΩςΫνϟͷॻ੶ΛಡΜͩͷͰAPIαʔόΛ࣮૷ͯ͠Έͨ • https://qiita.com/yoshinori_hisakawa/items/f934178d4bd476c8da32 • Go × Clean Architectureͷαϯϓϧ࣮૷ • http://nakawatch.hatenablog.com/entry/2018/07/11/181453
  34. References - Books and Papers • Books • Clean Architecture

    ୡਓʹֶͿιϑτ΢ΣΞͷߏ଄ͱઃ ܭ • Papers • The Dependency Inversion Principle • https://web.archive.org/web/20110714224327/http:// www.objectmentor.com/resources/articles/dip.pdf
  35. Thank you !