Clean architecture validator for go, like a The Dependency Rule and interaction between packages in your Go projects.

Overview

Clean Architecture checker for Golang

Go Report Card

go-cleanarch was created to keep Clean Architecture rules, like a The Dependency Rule and interaction between modules in your Go projects. More about Clean Architecture you can read in Uncle's Bob article.

Some benefits of using Clean Architecture:

  1. 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.
  2. Testable. The business rules can be tested without the UI, Database, Web Server, or any other external element.
  3. 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.
  4. 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.
  5. 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

Clean Architecture

Project schema requirements

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
    • frontend
      • domain
      • application
      • interfaces

Allowed LAYER_NAME:

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 informations about Clean Architecture please read Uncle's Bob article

Installing

go get -u gopkg.in/roblaszczak/go-cleanarch.v1

go-cleanarch was only tested on Linux and also should work on OS X. Probably it doesn't work well on Windows.

Running

To run in 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.

-ignore-tests

If you need to ignore *_test.go files in go-cleanarch check you can pass -ignore-tests

go-cleanarch -ignore-tests

It is useful when you have memory implementation in infrastructure layer and you need to test application service which depends of it.

-ignore-package

If for some reason you need to allow to make forbidden import, for example

github.com/roblaszczak/go-cleanarch/examples/ignore-package/app to github.com/roblaszczak/go-cleanarch/examples/ignore-package/domain.

you can use

go-cleanarch -ignore-package=github.com/roblaszczak/go-cleanarch/examples/ignore-package/app 

Layer names

The layer names can be set to a specific value with the following parameters. Each parameter stands for on layer.

go-cleanarch -domain dom -application appli -interfaces int -infrastructure outer

This would only allow the domain name to be dom, application hast to be appli, interafces must be int and infrastructure must be outer.

Running the tests

make test

And coding style tests

make qa

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Credits

Made without love by Robert Laszczak </3

License

This project is licensed under the MIT License.

Issues
  • Parameters for the layer names

    Parameters for the layer names

    I added parameters to specify the layer names via cli parameters. Another way would be to add a config file to load the layer names from but this is not yet implemented. This is a first draft of the patch.

    opened by mweb 3
  • Add

    Add "adapters" aliases for LayerInterfaces

    Hi,

    In the article The Clean Architecture the layer 3 is called "Interface Adapters". Currently go-cleanarch only supports using the term interfaces. When using Go, we found the term "interface" to be confusing and decided to use "adapters" instead to avoid any confusion. This PR adds support for the term adapters for the layer 3.

    opened by dgellow 3
  • Unable to get running

    Unable to get running

    Hello!

    I have trouble getting and building:

    go get -u gopkg.in/roblaszczak/go-cleanarch.v1
    # gopkg.in/roblaszczak/go-cleanarch.v1
    ../../../go/pkg/mod/gopkg.in/roblaszczak/[email protected]/main.go:44:37: not enough arguments in call to cleanarch.NewValidator
    	have ()
    	want (map[string]cleanarch.Layer)
    

    I tried from source, and got something compiling after adding go.mod...

    opened by tomekc 1
  • Any bigger example of Clean Architecture?

    Any bigger example of Clean Architecture?

    Hi @roblaszczak,

    Great work on the repository!

    I'm trying to get my head around clean architecture as I'm starting to design a really large application (which, I did already have quite a substantial amount done but ended up with crazy cyclic dependencies) so I'd really appreciate the help to redesign this in a cleaner, maintainable way.

    I have a lot of cross-module dependencies which, unfortunately, with such a small set of examples, I can't really work out how to get everything working together.

    Would you have any sources that would give a better example of how to structure my app?

    Thanks so much!

    opened by bt 1
  • Projects with missed layers

    Projects with missed layers

    https://github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/pull/47

    Would it be a good idea to fail go-cleanarch or just warn to log if any layer was not found in project directory?

    This behavior could be enabled with extra flag but IMO it would be better to turn this feature on by default.

    Also its hard to determine if go-cleanarch found any layer in you module. I guess it would be nice feature if go-cleanarch plot project map like this (or even more pretty one)):

    trainer Layers: application, domain, infrastructure, interfaces
    trainings Layers:application, domain, infrastructure, interfaces
    
    opened by mrsndmn 0
  • chore: replace deprecated gometalinter with golangci-lint

    chore: replace deprecated gometalinter with golangci-lint

    gometalinter is deprecated https://github.com/alecthomas/gometalinter/issues/590 so it is advised to switch to https://github.com/golangci/golangci-lint

    I've already prepared a change so I can open a PR when I get an access.

    opened by pawelmitka 0
  • Feature Request: support for go/analysis

    Feature Request: support for go/analysis

    If go/analysis was supported this could better integrate with IDEs and could be run by https://github.com/golangci/golangci-lint.

    https://disaev.me/p/writing-useful-go-analysis-linter/#using-goanalysis

    opened by bmayfi3ld 0
  •  There is no error handling in `filepath.Walk`

    There is no error handling in `filepath.Walk`

    Hi @roblaszczak

    It is a good analysis tool. And I use it.

    If the path set in the argument is wrong (no such file or directory), a runtime error will occur.

    So I think I should do error handling of no such file or directory

    Thank you.

    opened by nakamura244 2
Releases(v1.2.1)
Owner
Robert Laszczak
Robert Laszczak
Find outdated golang packages

This project is not supported anymore Go-outdated is minimalistic library that helps to find outdated packages hosted on github.com in your golang pro

null 42 Jul 23, 2022
A Go linter to check that errors from external packages are wrapped

Wrapcheck A simple Go linter to check that errors from external packages are wrapped during return to help identify the error source during debugging.

Tom Arrell 158 Aug 8, 2022
depth is tool to retrieve and visualize Go source code dependency trees.

depth is tool to retrieve and visualize Go source code dependency trees. Install Download the appropriate binary for your platform from the Rele

Kyle Banks 773 Aug 7, 2022
A reference for the Go community that covers the fundamentals of writing clean code and discusses concrete refactoring examples specific to Go.

A reference for the Go community that covers the fundamentals of writing clean code and discusses concrete refactoring examples specific to Go.

Lasse Martin Jakobsen 2.2k Aug 8, 2022
PlantUML Class Diagram Generator for golang projects

GoPlantUML PlantUML Class Diagram Generator for golang projects. Generates class diagram text compatible with plantuml with the information of all str

Javier Feliu 1k Aug 9, 2022
Manage your repository's TODOs, tickets and checklists as config in your codebase.

tickgit ??️ tickgit is a tool to help you manage latent work in a codebase. Use the tickgit command to view pending tasks, progress reports, completio

Augmentable 278 Jul 30, 2022
My toy gin-like webframe

gan-webframe My toy gin-like webframe gan named after my favourite cartoon character Stan in South Park! Usage: func main() { r := gan.Default() //

null 0 Nov 21, 2021
Tool to populate your code with traceable and secure error codes

Essential part of any project, especially customer facing is proper and secure error handling. When error happens and customer reports it, it would be nice to know the context of the error and where it exactly occured.

vs 52 Apr 1, 2022
This static analysis tool works to ensure your program's data flow does not spill beyond its banks.

Go Flow Levee This static analysis tool works to ensure your program's data flow does not spill beyond its banks. An input program's data flow is expl

Google 166 Aug 8, 2022
A report card for your Go application

Go Report Card A web application that generates a report on the quality of an open source go project. It uses several measures, including gofmt, go ve

GoJP 1.7k Aug 4, 2022
πŸ”’πŸŒ Security scanner for your Terraform code

????tfsec uses static analysis of your terraform templates to spot potential security issues.

tfsec 4.9k Aug 5, 2022
Know when GC runs from inside your golang code

gcnotifier gcnotifier provides a way to receive notifications after every run of the garbage collector (GC). Knowing when GC runs is useful to instruc

Carlo Alberto Ferraris 168 Jun 10, 2022
dont-interface calculates how many interface{} are declared or used in your project?

dont-interface calculates how many interface{} are declared or used in your project?

Ray Eldath 17 Jun 9, 2022
Drone Plugin for detecting credentials or other sensitive data in your repository

A plugin to detect hard-coded secrets and sensitive data in your source code files. Building Build the plugin binary: scripts/build.sh Build the plug

Drone by Harness 1 Apr 21, 2022
Detect non-inclusive language in your source code.

Detect non-inclusive language in your source code. I stay woke - Erykah Badu Creating an inclusive work environment is imperative to a healthy, suppor

woke 337 Aug 9, 2022
Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go

Sloc Cloc and Code (scc) A tool similar to cloc, sloccount and tokei. For counting physical the lines of code, blank lines, comment lines, and physica

Ben Boyter 3.7k Aug 10, 2022
Jenkins tracer is used to record all the Jenkins job environment variables and metrics, and send them to Elasticsearch

Jenkins Tracer Jenkins tracer is used to record all the jenkins job variables like record the build duration, build variables, repository metadata, et

Misbahul Ardani 3 Apr 22, 2021
πŸ”₯ ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint

revive Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. Revive provides a framework for developme

Minko Gechev 3.6k Aug 7, 2022