Note
The project is still a work in progress, and there are many features that are not yet implemented.
Also please note that the gRPC clients are not using any credentials. This is not secure, and should not be used in production.
Please feel free to contribute to the project.
This is a template for gRPC modular monoliths in Go. It is designed to be a starting point for a new project, with all the boilerplate code already set up.
We'll use gRPC as the communication protocol between the different modules, and we'll use the protoc
compiler to generate the necessary code.
The project is divided into directories:
modules
: This directory contains the different modules of the application. Each module is a self-contained package that contains its own gRPC service implementation. Each module is basically a domain. It contains:- Controllers (gRPC Layer)
- Application (Service Layer)
- Exceptions (Per module exceptions)
- Models (Domain Layer)
- Repositories (Data Layer)
- Views (gRPC Layer)
proto
: This directory contains the.proto
files that define the gRPC services and messages. They are separated into different folders for each module.common
,config
,db
,logger
: These directories contain the common code that is used by all the modules. They are not specific to any module, and are used to provide common functionality to all the modules.
github.com/golang/protobuf
: This package is used to define the.proto
files and generate the gRPC code.google.golang.org/grpc
: This package is used to create the gRPC server and client.github.com/jinzhu/gorm
: This package is used to interact with the database.github.com/sirupsen/logrus
: This package is used for logging.github.com/spf13/viper
: This package is used for configuration management.github.com/uber-go/fx
: This package is used for dependency injection.github.com/go-playground/validator
: This package is used for input validation.
- Clone the repository
- Run
go mod tidy
to install the dependencies - Run
make proto
to generate the gRPC code - Run
make run
to start the server Runmake test
to run the tests
- Modular Monolith: The project is divided into different modules, each of which is a self-contained package. This makes it easy to reason about the code, and makes it easy to scale the project.
- gRPC: The communication between the different modules is done using gRPC. This makes it easy to define the service and messages, and the code is generated automatically.
- Dependency Injection: We use the
uber-go/fx
package for dependency injection. This makes it easy to manage the dependencies between the different modules. - Configuration Management: We use the
spf13/viper
package for configuration management. This makes it easy to manage the configuration of the application. - Logging: We use the
sirupsen/logrus
package for logging. This makes it easy to log the different events in the application. - Database: We use the
jinzhu/gorm
package to interact with the database. This makes it easy to interact with the database, and provides a lot of functionality out of the box. - Input Validation: We use the
go-playground/validator
package for input validation. This makes it easy to validate the input to the different services. - We provide injectable clients for the different modules, so that they can communicate with each other.
- We also provide a
config.yaml
file to manage the configuration of the application including the gRPC server port and the database connection string.
- Add more error handling
- Add more tests
- Add more documentation