fe3dback / go-arch-lint

GoLang architecture linter (checker) tool. Will check all project import path and compare with arch rules defined in yml file. Useful for hexagonal / onion / ddd / mvc and other architectural patterns. Tool can by used in your CI
MIT License
208 stars 10 forks source link

JSON tags #58

Open johnfercher opened 1 week ago

johnfercher commented 1 week ago

Hello, bro. Awesome work that you did here. This is just what I was looking for.

I have a suggestion for you, when working with DDD the entities that we define have to be free of any implementation detail. So, if we have something like:

internal/core/models/entity.go

type Entity struct {
    ID string `json:"id"`
    Name string `gorm:"name"`
}

We are coupling our entities to GORM and JSON details.

I think that this lib should have a rule to that. Something as:

version: 3

components:
  consts:           { in: internal/core/consts/** }
  models:           { in: internal/core/models/** }
  ports:            { in: internal/core/ports/** }
  drivers:          { in: internal/adapters/drivers/** }
  drivens:          { in: internal/adapters/drivens/** }
  implementations:  { in: internal/kycservices } # customizable to each case
  api:              { in: cmd/api/** }

vendors:
  uuid: { in: github.com/google/uuid  }
  chi:
    in:
      - github.com/go-chi/chi/v5
      - github.com/go-chi/chi/v5/middleware

tags: # <<< ADD HERE <<<<<<<<<
  - json
  - gorm

commonComponents:
  - consts
  - models

deps:
  models:
    mayDependOn:
      - consts

  ports:
    mayDependOn:
      - consts

  drivers:
    mayDependOn:
      - ports
      - drivens
      - implementations
    mayUseTags: # <<<< ADD HERE <<<<<<<<<
      - json

  drivens:
    mayDependOn:
      - ports
    canUse:
      - uuid
    mayUseTags: # <<<< ADD HERE <<<<<<<<<
      - gorm

  implementations:
    mayDependOn:
      - ports
      - drivers
      - drivens

  api:
    mayDependOn:
      - ports
      - implementations
      - drivers
      - drivens
    canUse:
      - chi
fe3dback commented 1 week ago

Hi, good idea. I think we can disable this feature by default, and user can enable it if they want to (like vendor imports checking).

Raw config contract:

allow:
  - useAnyTags: false # default is true. User should explicitly turn off this, for checking tags.

commonTags: # this tags will be always allowed for all structs
 - json
 - yaml

# all other tags is disallowed, and we need explicitly allow them
deps:
  repositories:
    mayUseTags:
      - db     # allow db for this layer
      - gorm   # allow orm staff

I will implement this in v4 if nobody makes it before.