This project is example of ToDo Service using clean design for gRPC microservices. Template for clean design you can find HERE
We have 4 main layer:
- Deliver layer
- Interactors (Use Cases)
- Repositories
- Domain
1 -> 2 -> 3 -> 4
First layer can use any other, Second layer can use only layers 3-4 and so on.
Models, UseCase behaviour (interfaces). !! NO IMPLEMENTATION !!
Layer for getting data from any source. In example you can see postgres DB and test Mock implementation.
Here we implement main logic of our service. Whole implementation depends on domain layer behaviour.
After running of UseCases we should send result back to client. Here we can implement different clients types.
For example, gRPC client, REST client, CLI client.
So this layer doesn't depend on implementation of our core (interactors) and easy for testing.
Full example with JWT Auth microservice using this clean design you can find here - https://github.com/ekprog/grpc_auth_service
protoc -I ./proto \
--go_out ./pkg/pb \
--go_opt paths=source_relative \
--go-grpc_out ./pkg/pb \
--go-grpc_opt paths=source_relative \
--grpc-gateway_out ./pkg/pb \
--grpc-gateway_opt paths=source_relative \
--openapiv2_out ./docs \
./proto/api/*.proto
protoc -I ./proto \
--go_out ./pkg/pb \
--go_opt paths=source_relative \
--go-grpc_out ./pkg/pb \
--go-grpc_opt paths=source_relative \
./proto/api/*.proto \
--experimental_allow_proto3_optional
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./server
docker build -t api_gw .
protoc -I ./proto \
--go_out ./pkg/pb \
--go_opt paths=source_relative \
./proto/events/**/*.proto
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./server
docker compose build
docker compose up
docker compose --env-file .env up