bxcodec / go-clean-arch

Go (Golang) Clean Architecture based on Reading Uncle Bob's Clean Architecture
MIT License
9.06k stars 1.19k forks source link

[enhancement] Model directory under the domain directory #47

Open aeharvlee opened 4 years ago

aeharvlee commented 4 years ago

Thanks for the great project btw. It is really nice and neat structure, and I'm really enjoying develop project with this architecture.

How would you go about putting some depth on domain directories like below? Because one domain may have so much of data types and if all that data types exists in just one file (black_ipv4.go in v3 clean-arch), it would be really hard to read the code and would be very fat.

black_ipv4
  - delivery
    - http
      - black_ipv4_handler.go
  - repository
    - black_ipv4_repo.go
  - usecase
    - black_ipv4_usecase.go
  - repository.go
  - usecase.go

domain
  - black_ipv4
    - model
      - attack_vector.go // Attack vector is a core data type indicating the type of attack the black ipv4. was attacking one of our customer's domain.
      - report.go // Report is a data type summarizing the most dangerous black ipv4 in specific period.
      - reputation.go // Reputation of black ipv4 during whole period.
  - custom_error
    - auth.go // Handles error raising during authentication process. To use this API, user must issue api key.
    - server.go // Handles error raising because of server fault which have status code 5xx mostly.

If we struct project like above example there are benefits:

  1. You can import all data types which is used in a domain with just one import sentense: import "github.com/aeharvlee/black-ip-api/black_ipv4/model
  2. You don't have to worry about one big domain file. You can freely add many data types for a domain.
  3. Readability is now good. You can read domain directory like "Oh, black_ipv4 domain have three main data types. attack_vector, report, and reputation. So if I want to add some fields on attack vector, what I do is just add some fields in attack_vector.go

Actually I used version2 features: You can see repository.go and usecase.go in black_ipv4 directory. The reason I use this v2 feature is "Repository and Usecase should use for a domain and should not use for each data types of the domain." It don't make sense use repo for attack_vector under the domain/black_ipv4/attack_vector because what we target is "domain/black_ipv4" not a piece of the domain.

If you don't understand well or need specific examples, please feel free to tell me. I will make an appropriate example on GitHub.

Edit: If you agree with me, I will edit the source code and proceed with the pull request. Thanks.

The reason I use model directory under the black_ipv4 is for using echo-swagger. echo-swagger confuses because if we don't have model directory, there are two black_ipv4 directories.