Layout

The kratos-layout is used by command kratos new for new project creation. The directory structures and tool chains are included in this layout project. Which help you be more efficient in developing. This project could also considered as the best practice of building microservices with Go and Kratos.

kratos ddd

To create a new project:

  1. kratos new <project-name>

The following directory structures will be generated.

  1. .
  2. ├── go.mod
  3. ├── go.sum
  4. ├── LICENSE
  5. ├── README.md
  6. ├── api // Includes .proto API files and the .go files which generated from them.
  7. └── helloworld
  8. ├── errors
  9. ├── helloworld.pb.go
  10. ├── helloworld.proto
  11. └── helloworld_errors.pb.go
  12. └── v1
  13. ├── greeter.pb.go
  14. ├── greeter.proto
  15. ├── greeter_grpc.pb.go
  16. └── greeter_http.pb.go
  17. ├── cmd // The entry point of the kratos app
  18. └── server
  19. ├── main.go
  20. ├── wire.go // wire library is for dependency injection
  21. └── wire_gen.go
  22. ├── configs // The configuration files for local development.
  23. └── config.yaml
  24. └── internal // All the codes which are private. Business logics are often exist in there, under "internal" directory for preventing from unwilling import.
  25. ├── conf // The structure for configuration parsing, generated from .proto file
  26. ├── conf.pb.go
  27. └── conf.proto
  28. ├── data // For accessing data sources. This layer is mainly used as the encapsulation of databases, caches etc. The implementation of repo interface which defined in biz layer should be placed here. In order to distinguish from DAO (data access object), the data layer stress on business. Its responsibility is to transform PO to DTO. We dropped the infra layer of DDD.
  29. ├── README.md
  30. ├── data.go
  31. └── greeter.go
  32. ├── biz // The layer for composing business logics. It is similar to the domain layer in DDD. The interface of repo are defined in there, following the Dependence Inversion Principle.
  33. ├── README.md
  34. ├── biz.go
  35. └── greeter.go
  36. ├──service // The service layer which implements API definition. It is similar to the application layer in DDD. The transformations of DTO to DO and the composing of biz are processed in this layer. We should avoid to write complex business logics here.
  37. ├── README.md
  38. ├── greeter.go
  39. └── service.go
  40. └── server // The creation of http and grpc instance
  41. ├── grpc.go
  42. ├── http.go
  43. └── server.go