GO CLARCH
Go Clean Architecture Boilerplate
New to Clean Architecture? Learn Here
A familiar architecture is MVC, but MVC is not enough to be a highly agile business solution today Learn Here.
On the other hand, the fame of the existing framework becomes a kind of boundary for those who are not used to using a particular framework.
Changes to packages from third parties are also a challenge, such as changing the database from PostgreSql to Mongo.
π Contains
π° The Layer
Layer |
Directory |
Frameworks & Drivers |
/app/infra |
Interface |
/app/interfaces |
Usecases |
/app/usecases |
Entities |
/app/domain |
π§ The Questions
-
Why placing all layer to one folder (app)? Β
π₯ Bcs using this infrastructure (clean architecture), we must highlight the 4 layer in folder and ensure the concept is clean (no other file or folder).
-
Why using json validator than others for request validator? Β
π₯ Request validator have several option u can see here.
We use go-playground/validator because is very simple and clean, bcs just put in json tag, that(json tag) is familiar in go.
-
Why separate file interface, implementation in Usecase and Frameworks & Drivers layer? Β
π₯ The concept come from Bridge Design Pattern, in Usecase imagine u have 2 user (student and teacher) with same action but different behavior (bcs business rules), in Frameworks & Drivers imagine u must transition change the db from Postgres to Mongo.
β‘ Fiber Go
We use fiber for routing and more, you can change whatever you like (echo, gin, chi, etc).
Why fiber? learn here
π Air
If you familiar with nodemon in nodejs, air is exactly same. Provide hot reloading when files change with auto build.
Visit: https://github.com/cosmtrek/air for installation guide
π§ͺ Debugger
If you come from PHP maybe you use var_dump(), if u from javasript maybe u use console.log(), in GO u can use fmt.Println() or u can use logging with log.Println().
But if u don't know before, using debugger is awesome and helpful (If u use VS Code), u just go to debug and run the debugger. The config in .vscode in the project. Wanna try? Learn here
π References