go-cleanarch was created to keep Clean Architecture rules, like a The Dependency Rule and interaction between modules in your Go projects. For more information you should read our article about Clean Architecture.
Some benefits of using Clean Architecture:
- Independent of Frameworks. The architecture does not depend on the existence of some library of feature laden software. This allows you to use such frameworks as tools, rather than having to cram your system into their limited constraints.
- Testable. The business rules can be tested without the UI, Database, Web Server, or any other external element.
- Independent of UI. The UI can change easily, without changing the rest of the system. A Web UI could be replaced with a console UI, for example, without changing the business rules.
- Independent of Database. You can swap out Oracle or SQL Server, for Mongo, BigTable, CouchDB, or something else. Your business rules are not bound to the database.
- Independent of any external agency. In fact your business rules simply don’t know anything at all about the outside world.
Source: The Clean Architecture
go-cleanarch assumes this files structure:
[GOPATH]/[PACKAGE_NAME]/[LAYER_NAME]
or
[GOPATH]/[PACKAGE_NAME]/[MODULE_NAME]/[LAYER_NAME]
For example
- go/src/github.com/roblaszczak/awesome-app
- auth
- domain
- application
- interfaces
- content
- domain
- submodule1
- submodule2
- etc.
- application
- interfaces
- domain
- frontend
- domain
- application
- interfaces
- auth
The default layer names are as followed. It is possible to set different names by command line parameters see -domain/-application/-interfaces/-infrastructure bellow.
var LayersAliases = map[string]Layer{
// Domain
"domain": LayerDomain,
"entities": LayerDomain,
// Application
"app": LayerApplication,
"application": LayerApplication,
"usecases": LayerApplication,
"usecase": LayerApplication,
"use_cases": LayerApplication,
// Interfaces
"interfaces": LayerInterfaces,
"interface": LayerInterfaces,
"adapters": LayerInterfaces,
"adapter": LayerInterfaces,
// Infrastructure
"infrastructure": LayerInfrastructure,
"infra": LayerInfrastructure,
}
For examples please go to examples directory, with contains examples of valid and invalid architectures.
For more information you should read our article about Clean Architecture.
go install github.com/roblaszczak/go-cleanarch@latest
go-cleanarch was only tested on Linux and also should work on OS X. Probably it doesn't work well on Windows.
To run in the current directory:
go-cleanarch
To run in provided directory
go-cleanarch go/src/github.com/roblaszczak/awesome-cms
Process will exit with code 1
if architecture is not valid, otherwise it will exit with 0
.