Skip to content

Commit

Permalink
added some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
roblaszczak committed Apr 14, 2017
1 parent cf8b520 commit 5d1cbdb
Show file tree
Hide file tree
Showing 42 changed files with 179 additions and 83 deletions.
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Clean Architecture checker for Golang

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](https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html).

![Clean Architecture](docs/go-cleanarch.png)

## Installing

go get github.com/roblaszczak/go-cleanarch

_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:

cleanarch

To run in provided directory

cleanarch go/src/github.com/roblaszczak/awesome-cms

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

For examples please go to [examples](examples/) directory,
with contains examples of valid and invalid architectures.

For more informations about Clean Architecture please read [Uncle's Bob article](https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html)

## Running the tests

make test

## And coding style tests

make qa

## Contributing

Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags).

## Credits

Made without love by Robert Laszczak </3

## License

This project is licensed under the MIT License.
10 changes: 5 additions & 5 deletions cleanarch/cleanarch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ func TestValidator_Validate(t *testing.T) {
Path string
IsValid bool
}{
{"../tests/valid-simple", true},
{"../tests/invalid-infra-in-domain-import", false},
{"../tests/invalid-app-in-domain-import", false},
{"../tests/invalid-import-between-modules-apps", false},
{"../tests/valid-cross-module-deps", true},
{"../examples/valid-simple", true},
{"../examples/invalid-infra-in-domain-import", false},
{"../examples/invalid-app-to-domain-import", false},
{"../examples/invalid-cross-module-deps", false},
{"../examples/valid-cross-module-deps", true},
}

for _, c := range testCases {
Expand Down
Binary file added docs/go-cleanarch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/invalid-app-to-domain-import/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Invalid `app` to `domain` import

![Schema](schema.png)
7 changes: 7 additions & 0 deletions examples/invalid-app-to-domain-import/domain/product.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package domain

import "github.com/roblaszczak/go-cleanarch/examples/invalid-app-to-domain-import/app"

type Product struct {
Price app.Price
}
Binary file added examples/invalid-app-to-domain-import/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/invalid-cross-module-deps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Invalid cross modules deps

![Schema](schema.png)

In this example modules are interacting directly
(without using `interfaces` and `infrastructure` layers).
7 changes: 7 additions & 0 deletions examples/invalid-cross-module-deps/forum/user/app/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package app

import "github.com/roblaszczak/go-cleanarch/examples/invalid-cross-module-deps/forum/post/app"

type User struct {
Posts []app.Post
}
Binary file added examples/invalid-cross-module-deps/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/invalid-infra-in-domain-import/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Invalid `infrastructure` in domain `import`

![Schema](schema.png)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package domain

import "github.com/roblaszczak/go-cleanarch/tests/invalid-infra-in-domain-import/infrastructure"
import "github.com/roblaszczak/go-cleanarch/examples/invalid-infra-in-domain-import/infrastructure"

type OrderAdder struct {
// please, don't do this :(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/valid-cross-module-deps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Invalid cross module deps

![Schema](schema.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package interfaces

import "github.com/roblaszczak/go-cleanarch/examples/valid-cross-module-deps/cms/auth/usecases"

func CheckAccess(username string) bool {
return usecases.LoginAccessChecker(username)
}
5 changes: 5 additions & 0 deletions examples/valid-cross-module-deps/cms/auth/usecases/access.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package usecases

func LoginAccessChecker(username string) bool {
return username == "admin"
}
10 changes: 10 additions & 0 deletions examples/valid-cross-module-deps/cms/cms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"github.com/roblaszczak/go-cleanarch/examples/valid-cross-module-deps/cms/content/infrastructure"
"github.com/roblaszczak/go-cleanarch/examples/valid-cross-module-deps/cms/content/usecases"
)

func main() {
usecases.AddArticle{infrastructure.AuthModuleAuthChecker{}}.AddArticle("admin", "test article")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package infrastructure

import (
"github.com/roblaszczak/go-cleanarch/examples/valid-cross-module-deps/cms/auth/interfaces"
)

type AuthModuleAuthChecker struct{}

func (a AuthModuleAuthChecker) CheckAuth(username string) bool {
return interfaces.CheckAccess(username)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package usecases

import (
"fmt"
)

type AuthChecker interface {
CheckAuth(username string) bool
}

type AddArticle struct {
AuthChecker AuthChecker
}

func (c AddArticle) AddArticle(username string, title string) error {
if !c.AuthChecker.CheckAuth(username) {
return fmt.Errorf("user %s is not allowed to add article", username)
}

// todo - some article adding logic
fmt.Printf("added %s article by %s\n", title, username)

return nil
}
Binary file added examples/valid-cross-module-deps/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/valid-simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Simple valid architecture

![Schema](schema.png)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app

import "github.com/roblaszczak/go-cleanarch/tests/valid-simple/domain"
import "github.com/roblaszczak/go-cleanarch/examples/valid-simple/domain"

type Payment struct {
Amount domain.Price
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package infrastructure

import (
"fmt"
"github.com/roblaszczak/go-cleanarch/tests/valid-simple/app"
"github.com/roblaszczak/go-cleanarch/examples/valid-simple/app"
)

type MysqlPaymentsRepository struct{}
Expand Down
6 changes: 3 additions & 3 deletions tests/valid-simple/main.go → examples/valid-simple/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"github.com/roblaszczak/go-cleanarch/tests/valid-simple/app"
"github.com/roblaszczak/go-cleanarch/tests/valid-simple/domain"
"github.com/roblaszczak/go-cleanarch/tests/valid-simple/infrastructure"
"github.com/roblaszczak/go-cleanarch/examples/valid-simple/app"
"github.com/roblaszczak/go-cleanarch/examples/valid-simple/domain"
"github.com/roblaszczak/go-cleanarch/examples/valid-simple/infrastructure"
)

func main() {
Expand Down
Binary file added examples/valid-simple/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
7 changes: 0 additions & 7 deletions tests/invalid-app-in-domain-import/domain/product.go

This file was deleted.

Empty file.

This file was deleted.

1 change: 0 additions & 1 deletion tests/invalid-infra-in-domain-import/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions tests/valid-cross-module-deps/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions tests/valid-cross-module-deps/cms/auth/interfaces/access.go

This file was deleted.

5 changes: 0 additions & 5 deletions tests/valid-cross-module-deps/cms/cms.go

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions tests/valid-cross-module-deps/cms/content/domain/user.go

This file was deleted.

12 changes: 0 additions & 12 deletions tests/valid-cross-module-deps/cms/content/infrastructure/auth.go

This file was deleted.

13 changes: 0 additions & 13 deletions tests/valid-cross-module-deps/cms/content/usecases/checkaccess.go

This file was deleted.

1 change: 0 additions & 1 deletion tests/valid-simple/README.md

This file was deleted.

0 comments on commit 5d1cbdb

Please sign in to comment.