Application 2022-09-04

Static Analysis of Clean Architecture Layers in Go

Enforce clean architecture layer dependencies in Go using go-cleanarch for static analysis and architecture validation.

Read in: ja
Static Analysis of Clean Architecture Layers in Go

Overview

A note on how to perform static analysis of Clean Architecture layers in Go.

Using go-cleanarch

While I could have created a custom static analysis tool, I found an easy-to-use tool and decided to try it out.

roblaszczak/go-cleanarch

I introduced it to my custom CMS, gobel-api. cf. PR

Install it with go install github.com/roblaszczak/go-cleanarch@latest.

Since the layer naming differs from the default, run the check with options. go-cleanarch -application usecase

If there is a violation of layer dependencies, the check will catch it and result in an error.

If an error occurs, you'll be told, Uncle Bob is not happy.

Thoughts

I plan to create my own tool eventually, but for now, I want to rely on this tool.

I believe that static analysis tools like this should be introduced early to maintain the design and structure of applications.

Since Go makes it easy to implement static analysis tools, it seems beneficial to actively create such tools if you want to maintain the structure of specific layers, not limited to Clean Architecture.

Tags: Golang Clean Architecture
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles