• Stars
    star
    256
  • Rank 159,219 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created over 2 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Practical microservices based on different software architecture and technologies like Golang, CQRS, Vertical Slice Architecture, Docker, RabbitMQ, OpenTelemetry and Postgresql.

CI Go Version

Shop Golang Microservices

The main idea of creating this project is implementing an infrastructure for up and running distributed system with the latest technology and architecture like Vertical Slice Architecture, OpenTelemetry, RabbitMq in Golang, and we will not deal mainly with business. ๐Ÿš€

Open in Gitpod

The Goals of This Project

  • โ‡๏ธ Using Vertical Slice Architecture for architecture level.
  • โ‡๏ธ Using Rabbitmq for Event Driven Architecture between our microservices with streadway/amqp library.
  • โ‡๏ธ Using gRPC for internal communication between our microservices with grpc/grpc-go library.
  • โ‡๏ธ Using CQRS implementation with mehdihadeli/Go-MediatR library.
  • โ‡๏ธ Using Postgres for database in our microservices with go-gorm/gorm library.
  • โ‡๏ธ Using go-playground/validator for validating input data in the REST calls.
  • โ‡๏ธ Using OpenTelemetry for distributed tracing with open-telemetry/opentelemetry-go library.
  • โ‡๏ธ Using OAuth2 for implementation authentication and authorization with go-oauth2/oauth2 library.
  • โ‡๏ธ Using Echo framework for RESTFul api.
  • โ‡๏ธ Using Swagger with swaggo/swag library for api documentation.
  • โ‡๏ธ Using uber-go/fx library for dependency injection.
  • โ‡๏ธ Using Viper for configuration management.
  • โ‡๏ธ Using logrus as a structured logger.
  • โ‡๏ธ Using Unit Testing,Integration Testing and End To End Testing for testing level.
  • โ‡๏ธ Using Docker-Compose for our deployment mechanism.

Plan

๐ŸŒ€This project is a work in progress, new features will be added over time.๐ŸŒ€

I will try to register future goals and additions in the Issues section of this repository.

Technologies - Libraries

  • โœ”๏ธ labstack/echo - High performance, minimalist Go web framework
  • โœ”๏ธ go-gorm/gorm - The fantastic ORM library for Go, aims to be developer friendly
  • โœ”๏ธ sirupsen/logrus - Logrus is a structured logger for Go
  • โœ”๏ธ streadway/amqp - Go RabbitMQ Client Library
  • โœ”๏ธ spf13/viper - Go configuration with fangs
  • โœ”๏ธ swaggo/echo-swagger - Echo middleware to automatically generate RESTful API documentation
  • โœ”๏ธ mehdihadeli/Go-MediatR - This package is a Mediator Pattern implementation in Go
  • โœ”๏ธ go-playground/validator - Implements value validations for structs and individual fields based on tags
  • โœ”๏ธ open-telemetry/opentelemetry-go - Implementation of OpenTelemetry in Go for distributed-tracing
  • โœ”๏ธ meysamhadeli/problem-details - Error Handler for mapping our error to standardized error payload to client
  • โœ”๏ธ go-resty/resty - Simple HTTP and REST client library for Go (inspired by Ruby rest-client)
  • โœ”๏ธ grpc/grpc-go - The Go language implementation of gRPC. HTTP/2 based RPC
  • โœ”๏ธ go-oauth2/oauth2 - An open protocol to allow secure authorization in a simple and standard method
  • โœ”๏ธ stretchr/testify - A toolkit with common assertions and mocks that plays nicely with the standard library
  • โœ”๏ธ uber-go/fx - Fx is a dependency injection system for Go
  • โœ”๏ธ cenkalti/backoff - This is a Go port of the exponential backoff algorithm
  • โœ”๏ธ stretchr/testify - A toolkit with common assertions and mocks that plays nicely with the standard library
  • โœ”๏ธ testcontainers/testcontainers-go - it's a package to create and clean up container for automated integration/smoke tests
  • โœ”๏ธ avast/retry-go - Simple golang library for retry mechanism
  • โœ”๏ธ ahmetb/go-linq - .NET LINQ capabilities in Go

The Domain And Bounded Context - Service Boundary

Structure of Project

In this project I used vertical slice architecture and feature folder structure to structure my files.

I used RabbitMQ as my MessageBroker for async communication between microservices using the eventual consistency mechanism.

Microservices are event based which means they can publish and/or subscribe to any events occurring in the setup. By using this approach for communicating between services, each microservice does not need to know about the other services or handle errors occurred in other microservices.

I treat each request as a distinct use case or slice, encapsulating and grouping all concerns from front-end to back. When adding or changing a feature in an application in n-tire architecture, we are typically touching many "layers" in an application. We are changing the user interface, adding fields to models, modifying validation, and so on. Instead of coupling across a layer, we couple vertically along a slice. We minimize coupling between slices, and maximize coupling in a slice.

With this approach, each of our vertical slices can decide for itself how to best fulfill the request. New features only add code, we're not changing shared code and worrying about side effects.

Instead of grouping related action methods in one endpoint, I used the REPR pattern. Each action gets its own small endpoint, and for communication between our endpoint and handlers, I use Go-MediatR for decouple our endpoint to handlers directly, and it gives use some pipeline behavior for logging, caching, validation and... easily.

The use of the mediator pattern in my endpoints creates clean and thin endpoint. By separating action logic into individual handlers we support the Single Responsibility Principle and Don't Repeat Yourself principles, this is because traditional controllers tend to become bloated with large action methods and several injected Services only being used by a few methods.

I used CQRS to decompose my features into small parts that makes our application:

  • Maximize performance, scalability and simplicity.
  • Easy to maintain and add features to. Changes only affect one command or query, avoiding breaking changes or creating side effects.
  • It gives us better separation of concerns and cross-cutting concern (with help of mediatr behavior pipelines), instead of bloated service classes doing many things.

Using the CQRS pattern, we cut each business functionality into vertical slices, for each of these slices we group classes (see technical folders structure) specific to that feature together (command, handlers, infrastructure, repository, controllers, etc). In our CQRS pattern each command/query handler is a separate slice. This is where you can reduce coupling between layers. Each handler can be a separated code unit, even copy/pasted. Thanks to that, we can tune down the specific method to not follow general conventions (e.g. use custom postgresql query or even different storage). In a traditional layered architecture, when we change the core generic mechanism in one layer, it can impact all methods.

Support

If you like my work, feel free to:

  • โญ this repository. And we will be happy together :)

Thanks a bunch for supporting me!

Contribution

Thanks to all contributors, you're awesome and this wouldn't be possible without you! The goal is to build a categorized community-driven collection of very well-known resources.

Please follow this contribution guideline to submit a pull request or create the issue.

Project References & Credits

License

This project is made available under the MIT license. See LICENSE for details.

More Repositories

1

awesome-dotnet-tips

A curated list of awesome tips and tricks, resources, videos and articles in .net, software architecture, microservice and cloud-native.
C#
1,048
star
2

booking-microservices

Practical microservices, built with .Net 8, DDD, CQRS, Event Sourcing, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
C#
900
star
3

Airline-Microservices

Airline Microservice is a simple Airline application for online reserving flight ticket. This application based on different software architecture and technologies like .Net Core, CQRS, DDD, Vertical Slice Architecture, Docker, kubernetes, tye, masstransit, RabbitMQ, Grpc, yarp reverse proxy, Identity Server, Redis, SqlServer, Entity Framework Core, Event Sourcing and different level of testing.
C#
336
star
4

booking-modular-monolith

Practical Modular Monolith, built with .Net 8, DDD, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
C#
211
star
5

booking-microservices-expressjs

Practical microservices, built with Node.Js, CQRS, Vertical Slice Architecture, Event-Driven Architecture, Postgres, RabbitMQ, Express and the latest technologies.
TypeScript
146
star
6

booking-microservices-nestjs

Practical microservices, built with Nestjs, CQRS, Vertical Slice Architecture, Event-Driven Architecture, Postgres, RabbitMQ and the latest technologies.
TypeScript
144
star
7

problem-details

ProblemDetails is a Error Handler base on [RFC 7807] standard to map our error to standardized error payload to client.
Go
49
star
8

ecommerce-monolith

A monolith, built with .Net, DDD, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
C#
35
star
9

Chat.Application

Implementing chat application wit .net core and allows you to send/receive text messages with other users
C#
7
star
10

MicroPack

MicroPack is a framework with many capabilities for using microservices on .net core
C#
7
star
11

Spotlight-Wallpapers

Download Spotlight, Bing and Unsplash wallpapers
C#
7
star
12

meysamhadeli

6
star
13

Retail-Application

C#
4
star
14

dotnet-kit

A framework for up and running microservices in dotnet.
C#
3
star
15

MicroService-Sample

C#
3
star
16

OrdersService

C#
2
star
17

Go.Samples

Go
2
star
18

blog-samples

C#
2
star
19

IdentityServer.Sample

A Sample of Authentication & Authorization with OpenID and OAuth 2 in Identity Server
C#
2
star
20

Nanoservice

this project is a sample of using docker and kubernetes.
C#
2
star
21

Tariff-Comparison

C#
2
star
22

OrderManagement

C#
2
star
23

GarageSale

Go
1
star
24

wallstream.privacy

privacy page
1
star
25

chat-signalr-sample

A chat application base on SignalR in .net 7
C#
1
star