Slide 1

Slide 1 text

Dive to clean architecture with golang @bmf_san @Makuake LT Party 2019/07/03

Slide 2

Slide 2 text

@bmf_san bmf-san bmf-tech.com Twitter Github Blog

Slide 3

Slide 3 text

Golang × Clean Architecture

Slide 4

Slide 4 text

Table of contents • What is the clean architecture? • Implementation of clean architecture • Conclusions

Slide 5

Slide 5 text

1 What is the clean architecture?

Slide 6

Slide 6 text

Ideas for architecture of systems • Over the last several years… • Hexagonal Architecture (Ports and Adapters) • Onion Architecture • Screaming Architecture • DCI • BCE • etc…

Slide 7

Slide 7 text

The separation of concerns

Slide 8

Slide 8 text

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.

Slide 9

Slide 9 text

Clean architecture

Slide 10

Slide 10 text

Layers 4PVSDFIUUQTCMPHDMFBODPEFSDPNVODMFCPCUIFDMFBOBSDIJUFDUVSFIUNM

Slide 11

Slide 11 text

Entities • Entities encapsulate the most important business rules • ex. an object with methods, a set of data structures and functions…

Slide 12

Slide 12 text

Use Cases • Use cases contains application specific business rules

Slide 13

Slide 13 text

Interface Adapters • Interface adapters is a set of adapters which convert data for entities and use cases

Slide 14

Slide 14 text

Frameworks and Drivers • Frameworks and drivers contains frameworkss and tools such as the database, web framework, etc

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

2 Implementation of clean architecture

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

I’m waiting for your nice review.

Slide 19

Slide 19 text

Directory structures -BZFST %JSFDUPSZ 'SBNFXPSLT
 BOE
 %SJWFST JOGSBTUSVDUVSF *OUFSGBDF JOUFSGBDFT 6TF$BTFT VTFDBTFT &OUJUJFT EPNBJO

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Accept interfaces, return structs

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

DIP in golang

Slide 24

Slide 24 text

Before

Slide 25

Slide 25 text

After

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Example

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Code reading • See the direction of dependency NBJOHP SPVUFSHP VTFS@DPOUSPMMFSHP VTFS@JOUFSBDUPSHP VTFS@SFQPTJUPSZHP VTFSHP ˣ ˣ ˣ ˣ ˣ *OGSBTUSVDUVSF *OUFSGBDFT 6TF$BTFT %PNBJO

Slide 30

Slide 30 text

3 Conclusions

Slide 31

Slide 31 text

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 ୡਓʹֶͿιϑτ΢ΣΞͷߏ଄ͱઃܭ

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Thank you !