Repository and Service Interfaces in an Accouting Software in Go with Uncle Bob's Clean Architecture

I'm trying to get hands-on experience with Uncle Bob's Clean Architecture in Go, but I'm running into some issues. Also, I'm not yet familiar with all of Go's idioms. For testing purposes, I'm applying the principles in a small accounting web tool with a REST API. Of course, I have modules like User, BankAccount, Transaction, and so on. I'm structuring the layers as described in the book Clean Architecture with a Domain layer for my entities, an Application layer for use cases, an Infrastructure layer for implementations of interfaces like repositories, services, etc. and a Config layer for all the frameworks, databases and general configurations. My main confusion is about where to define interfaces for repositories and services. For example, I have an interface for UserScopeRepository that is used in most user-related use cases. The question is: should I define this repository interface inside each use case, or define it once in the user module/layer? Also, I use UserScopeRepository in the RefreshToken use case. In that case, should I define the interface again in the use case layer? The same goes for services like password hashing, JWT token generation, etc. Should I define the service interfaces inside each use case, or more generally in the application layer? Or would it make more sense to put all services in a factory and pass them around?

May 5, 2025 - 12:49
 0

I'm trying to get hands-on experience with Uncle Bob's Clean Architecture in Go, but I'm running into some issues. Also, I'm not yet familiar with all of Go's idioms.

For testing purposes, I'm applying the principles in a small accounting web tool with a REST API. Of course, I have modules like User, BankAccount, Transaction, and so on.

I'm structuring the layers as described in the book Clean Architecture with a Domain layer for my entities, an Application layer for use cases, an Infrastructure layer for implementations of interfaces like repositories, services, etc. and a Config layer for all the frameworks, databases and general configurations.

My main confusion is about where to define interfaces for repositories and services.

For example, I have an interface for UserScopeRepository that is used in most user-related use cases. The question is: should I define this repository interface inside each use case, or define it once in the user module/layer?

Also, I use UserScopeRepository in the RefreshToken use case. In that case, should I define the interface again in the use case layer?

The same goes for services like password hashing, JWT token generation, etc. Should I define the service interfaces inside each use case, or more generally in the application layer?

Or would it make more sense to put all services in a factory and pass them around?