manakuro/golang-clean-architecture

Why does user_repository have a direct dependency on gorm.DB?

AkashKarnatak opened this issue · 1 comments

In the file interface/repository/user_repository.go, struct userRepository has a direct dependency on gorm.DB which is defined in the outer layer and hence it violates the clean architecture principle.

// interface/repository/user_repository.go
type userRepository struct {
	db *gorm.DB
}

Thanks for your question. Yes, you're right. Technically, the ORM should be defined as an adapter in order to follow the rule of specific technology separation, but if you feel that it’s too separated, then I think it’s fine to use it as is. Even if you change to another ORM in the future, then you only need to change the code in the repository at that time and you can still keep the dependencies between the usecase and the interface adapters. So, that depends on your team and projects.