Boilerplate of the GoLang project with microservices architecture

Read more about the boilerplate on the GitHub repository https://github.com/begmaroman/go-micro-boilerplate

NOTE 1: If something is not fully clear, feel free to create an issue in GitHub or add a comment here. Let’s create an excellent boilerplate together!

I’ve created the example of the GoLang project based on the microservices architecture. This is a simple project that provides CRUD operations related to the user entity.

There are two microservices, one web service that exposes REST API, and the second one is the RPC microservice that implements functionality to work with users. Once a user sends an HTTP request to the web service, it handles the incoming request, prepares data and calls the RPC service through RPC request.

Technologies

NATS is used as a discovery service, message broker service, and transport.

All services are dockerized and can be adjusted by docker-compose configuration. Check Dockerfiles and docker-compose.yaml file in the root of the project.

Use Go modules to manage the dependencies of the project.

Structure of services

This section describes and explains the architecture of microservices both web and RPC.

There are two microservices in this project:

  • rest-api-svc is the web service that exposes REST API endpoints. It allows users to do something with the data, e.g. user entity.
  • account-svc is the RPC microservice that provides some business logic related to users. It exposes the API to do CRUD operations.

RPC service:

There are 3 layers:

  • The transport layer represents the API of the service. It can be implemented using HTTP, RPC, WS, etc. This layer prepares and passes data to pass to the service layer. No business logic inside of this layer.
  • The domain/business layer represents the business/domain logic of the service. This layer doesn’t care about transport and must not depend on it. All business logic must be implemented in this layer.
  • The store layer represents the behavior of the data store. It can be implemented using PostgreSQL, MongoDB, etc. databases, this is the internal implementation. Only the store layer knows about the kind of database inside. Data just come from the outside of this layer. No business logic inside of this layer.

The most important thing about clean architecture is to make interfaces through each layer. Don’t build dependencies on implementations, use interfaces instead. Each of these layers has its own interface that describes the behavior of it.

Web service:

We use Swagger to describe REST API of the project.

Read more about the boilerplate on the GitHub repository https://github.com/begmaroman/go-micro-boilerplate

Senior Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store