sequence

This paper mainly studies the DDD project structure of Golang

interfaces

food-app-server/interfaces

interfaces git:(master) tree
.
|____fileupload
| |____fileformat.go
| |____fileupload.go
|____food_handler.go
|____food_handler_test.go
|____handler_setup_test.go
|____login_handler.go
|____login_handler_test.go
|____middleware
| |____middleware.go
|____user_handler.go
|____user_handler_test.go
Copy the code

For example, the interfaces layer defines the methods associated with the input layer. In this example, gin provides HTTP interfaces. The handler layer calls the Application layer using some of the HTTP interfaces provided by GIN

application

food-app-server/application

application git:(master) tree
.
|____food_app.go
|____food_app_test.go
|____user_app.go
|____user_app_test.go
Copy the code

The application layer mainly calls the Domain layer and infrastructure layer to implement functions

domain

food-app-server/domain

domain git:(master) tree
.
|____entity
| |____food.go
| |____user.go
|____repository
| |____food_repository.go
| |____user_repository.go
Copy the code

The Domain layer defines entity and Repository interfaces. Entity contains some domain logic

infrastructure

food-app-server/infrastructure

infrastructure git:(master) tree
.
|____auth
| |____auth.go
| |____redisdb.go
| |____token.go
|____persistence
| |____db.go
| |____food_repository.go
| |____food_repository_test.go
| |____setup_test.go
| |____user_repository.go
| |____user_repository_test.go
|____security
| |____password.go
Copy the code

The Infrastructure layer provides an implementation of the Repository interface for the Domain layer, as well as other basic components for use by the Application layer or interfaces layer

summary

DDD consists of interfaces, Application, Domain, and Infrastructure. The Domain layer does not depend on other layers. It defines the Repository interface, which is implemented by the Infrastructure layer. The Application layer calls the Domain and infrastructure layer. Interfaces typically invoke the Application layer or infrastructure layer.

doc

  • food-app-server