From bddea81685d40814def9685ddd708cc8b7277ce0 Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Sun, 29 May 2022 13:23:26 +0100 Subject: [PATCH] Edit readme --- README.md | 97 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 7b2ade7..27b1e81 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg?style=flat-square)](https://opensource.org/licenses/MIT) + # Booking-Microservices-Sample -Booking Microservices is a Sample application for booking 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. +Booking Microservices is a Sample application for booking 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. - -🌀 Keep in mind this repository is work in progress and will be complete over time 🚀 +🌀 This repository is a work in progress and will be completed over time 🚀 # Table of Contents @@ -22,32 +22,33 @@ Booking Microservices is a Sample application for booking ticket. This applicati ## The Goals of This Project -- The microservices base on `Domain Driven Design (DDD)` implementation. +- Microservices based on `Domain Driven Design (DDD)` implementation. - Correct `separation of bounded contexts` for each microservice. -- Communications between bounded contexts through asynchronous `MessageBus` and `events`. +- Communication between bounded contexts through asynchronous `MessageBus` and `events`. - Simple `CQRS` implementation and event driven architecture. - Using `Best Practice` and `New Technologies` and `Design Patterns`. - Using `Docker-Compose` and `Kubernetes` for our deployment mechanism. -- Implementing various type of testing like `Unit Testing`, `Integration Testing`. +- Implementing various types of testing like `Unit Testing`, `Integration Testing`. ## Plan -> This project is in progress, New features will be added over time. -I will try to register some [Issues](https://github.com/meysamhadeli/booking-microservices-sample/issues) for my `TODO` works, just to not forget and also for tracking my works in future. +> 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](https://github.com/meysamhadeli/booking-microservices-sample/issues) section of this repository. High-level plan is represented in the table -| Feature | Status | -| ------- | ------ | -| API Gateway | Completed ✔️ | -| Identity Service | Completed ✔️ | -| Flight Service | Completed ✔️ | -| Passenger Service | Completed ✔️ | -| Booking Service | Completed ✔️ | -| Building Blocks | In Progress 👷‍♂️ | - +| Feature | Status | +| ----------------- | -------------- | +| API Gateway | Completed ✔️ | +| Identity Service | Completed ✔️ | +| Flight Service | Completed ✔️ | +| Passenger Service | Completed ✔️ | +| Booking Service | Completed ✔️ | +| Building Blocks | In Progress 👷‍♂️ | ## Technologies - Libraries + - ✔️ **[`.NET 6`](https://dotnet.microsoft.com/download)** - .NET Framework and .NET Core, including ASP.NET and ASP.NET Core - ✔️ **[`MVC Versioning API`](https://github.com/microsoft/aspnet-api-versioning)** - Set of libraries which add service API versioning to ASP.NET Web API, OData with ASP.NET Web API, and ASP.NET Core - ✔️ **[`EF Core`](https://github.com/dotnet/efcore)** - Modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations @@ -74,87 +75,87 @@ High-level plan is represented in the table ## The Domain And Bounded Context - Service Boundary -- `Identity Service`: The Identity Service is a bounded context for authenticate and authorize users through with [Identity Server](https://github.com/DuendeSoftware/IdentityServer). Also, this service is responsible for creating users and their corresponding roles and permission with using [.Net Core Identity](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity) and Jwt authentication and authorization. +- `Identity Service`: The Identity Service is a bounded context for the authentication and authorization of users using [Identity Server](https://github.com/DuendeSoftware/IdentityServer). This service is responsible for creating new users and their corresponding roles and permissions using [.Net Core Identity](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity) and Jwt authentication and authorization. -- `Flight Service`: The Flight Service is a bounded context for all operation related to flight and get available filght and seat. +- `Flight Service`: The Flight Service is a bounded context `CRUD` service to handle flight related operations. -- `Passenger Service`: The Passenger Service is a bounded context for managing our passengers information, track the activities and subscribing to get notification for out of stock products +- `Passenger Service`: The Passenger Service is a bounded context for managing passenger information, tracking activities and subscribing to get notification for out of stock products. - `Booking Service`: The Booking Service is a bounded context for managing all operation related to booking ticket. - ## Structure of Project -I used [yarp reverse proxy](https://microsoft.github.io/reverse-proxy/articles/index.html) for routes synchronous and asynchronous request to the corresponding microservice. and each microservices has own business and dependencies such as databases, files and etc. and each microservices is decuple from other microservices and develop and deploy separately. and these microservices talk to each other with synchronous call like Rest or gRpc and use RabbitMq or Kafka for asynchronous call. +In this project I used a mix of [clean architecture](https://jasontaylor.dev/clean-architecture-getting-started/), [vertical slice architecture](https://jimmybogard.com/vertical-slice-architecture/) and I used [feature folder structure](http://www.kamilgrzybek.com/design/feature-folders/) to structure my files. -We have separate microservice ([IdentityServer](https://github.com/DuendeSoftware/IdentityServer)) for authentication and authorization and each request go to API Gateway and then route to Identity microservices and after authentication and authorization back API Gateway and then route to expected microservices. +I used [yarp reverse proxy](https://microsoft.github.io/reverse-proxy/articles/index.html) to route synchronous and asynchronous requests to the corresponding microservice. Each microservices has its dependencies such as databases, files and etc. Each microservice is decoupled from other microservices and developed and deployed separately. Microservices talk to each other with Rest or gRpc for synchronous calls and use RabbitMq or Kafka for asynchronous calls. -Also here I used [RabbitMQ](https://github.com/rabbitmq) as my MessageBroker for async communication between the microservices with using eventually consistency mechanism. and top of that I use [MassTransit](https://github.com/MassTransit/MassTransit) provides many requirements in microservice projects such as messaging, availability, reliability and etc. +We have a separate microservice ([IdentityServer](https://github.com/DuendeSoftware/IdentityServer)) for authentication and authorization of each request. Once signed in users are issued a JWT token. This token is used by other microservices to validate the user, read claims and allow access to authorized/role specific endpoints. + +I used [RabbitMQ](https://github.com/rabbitmq) as my MessageBroker for async communication between microservices using the eventually consistency mechanism. Each microservice uses [MassTransit](https://github.com/MassTransit/MassTransit) to interface with [RabbitMQ](https://github.com/rabbitmq) providing, messaging, availability, reliability, etc. 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. -Also I used a [mediator pattern](https://dotnetcoretutorials.com/2019/04/30/the-mediator-pattern-in-net-core-part-1-whats-a-mediator/) with using [MediatR](https://github.com/jbogard/MediatR) library in my controllers for a clean and [thin controller](https://codeopinion.com/thin-controllers-cqrs-mediatr/), also instead of using a `application service` class because after some times our controller will depends to different services and this breaks single responsibility principle. We use mediator pattern to manage the delivery of messages to handlers. One of the advantages behind the [mediator pattern](https://lostechies.com/jimmybogard/2014/09/09/tackling-cross-cutting-concerns-with-a-mediator-pipeline/) is that it allows the application code to define a pipeline of activities for requests . For example in our controllers we create a command and send it to mediator and mediator will route our command to a specific command handler in application layer. - -To support [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle) and [Don't Repeat Yourself principles](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself), the implementation of cross-cutting concerns is done using the mediatr [pipeline behaviors](https://github.com/jbogard/MediatR/wiki/Behaviors) or creating a [mediatr decorators](https://lostechies.com/jimmybogard/2014/09/09/tackling-cross-cutting-concerns-with-a-mediator-pipeline/). - -Also in this project I used mix of [clean architecture](https://jasontaylor.dev/clean-architecture-getting-started/) and [vertical slice architecture](https://jimmybogard.com/vertical-slice-architecture/) and also I used [feature folder structure](http://www.kamilgrzybek.com/design/feature-folders/) in this project. - -Also here I used cqrs for decompose my features to very small parts that make our application - -- maximize performance, scalability and simplicity. -- adding new feature to this mechanism is very easy without any breaking change in other part of our codes. New features only add code, we're not changing shared code and worrying about side effects. -- easy to maintain and any changes only affect on one command or query and avoid any breaking changes on other parts -- it gives us better separation of concerns and cross cutting concern (with help of mediatr behavior pipelines) in our code instead of a big service class for doing a lot of things. - 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 different "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`. +When adding or changing a feature in an application in n-tire architecture, we are typically touching many different "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. ![](./assets/Vertical-Slice-Architecture.jpg) -With using CQRS pattern, we cut each business functionality into some vertical slices, and inner each of this slices we have [technical folders structure](http://www.kamilgrzybek.com/design/feature-folders) specific to that feature (command, handlers, infrastructure, repository, controllers, ...). 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 SQL 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. +Instead of grouping related action methods in one controller, as found in traditional ASP.net controllers, I used the [REPR pattern](https://deviq.com/design-patterns/repr-design-pattern). Each action gets its own small endpoint, consisiting of a route, the action, and an `IMediator` instance (see [MediatR](https://github.com/jbogard/MediatR)). The request is passed to the `IMediator` instance, routed through a [`Mediatr pipeline`](https://lostechies.com/jimmybogard/2014/09/09/tackling-cross-cutting-concerns-with-a-mediator-pipeline/) where custom [middleware](https://github.com/jbogard/MediatR/wiki/Behaviors) can log, validate and intercept requests. The request is then handled by a request specific `IRequestHandler` which performs business logic before returning the result. +The use of the [mediator pattern](https://dotnetcoretutorials.com/2019/04/30/the-mediator-pattern-in-net-core-part-1-whats-a-mediator/) in my controllers creates clean and [thin controllers](https://codeopinion.com/thin-controllers-cqrs-mediatr/). By separating action logic into individual handlers we support the [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle) and [Don't Repeat Yourself principles](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself), this is because traditional controllers tend to become bloated with large action methods and several injected `Services` only being used by a few methods. + +Also here 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](http://www.kamilgrzybek.com/design/feature-folders) specific to that feature together (command, handlers, infrastructure, repository, controllers, ...). 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 SQL 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. ## How to Run ### Config Certificate -Runt the following commands for [Config SSL](microsoft.com/en-us/aspnet/core/security/docker-compose-https?view=aspnetcore-6.0) in your system -``` bash +Run the following commands for [Config SSL](microsoft.com/en-us/aspnet/core/security/docker-compose-https?view=aspnetcore-6.0) in your system + +```bash dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p {password here} dotnet dev-certs https --trust ``` ->Note: for running this command in `powershell` use `$env:USERPROFILE` instead of `%USERPROFILE%` + +> Note: for running this command in `powershell` use `$env:USERPROFILE` instead of `%USERPROFILE%` ### Docker Compose -Run this app on docker with this [docker-compose.yaml](./deployments/docker-compose/docker-compose.yaml) file with bellow command in root of application: +Run this app in docker using the [docker-compose.yaml](./deployments/docker-compose/docker-compose.yaml) file with the below command at the root of the application: -``` bash +```bash docker-compose -f ./deployments/docker-compose/docker-compose.yaml up -d ``` ### Documentation Apis -For testing apis I used [REST Client](https://github.com/Huachao/vscode-restclient) plugin of VSCode and this file [booking.rest](./booking.rest) is in root of project. -Also after running api you have access to swagger open api for all microservices in /swagger route path. +Each microservice uses swagger open api, navigate to /swagger for a list of every endpoint. +For testing apis I used the [REST Client](https://github.com/Huachao/vscode-restclient) plugin for VSCode running this file [booking.rest](./booking.rest). # Support + If you like my work, feel free to: - ⭐ this repository. And we will be happy together :) - Thanks a bunch for supporting me! ## Contribution Contributions are always welcome! Please take a look at the [contribution guidelines](https://github.com/meysamhadeli/booking-microservices-sample/blob/master/contributing.md) pages first. -Thanks to all [contributors](https://github.com/meysamhadeli/booking-microservices-sample/graphs/contributors), you're awesome and wouldn't be possible without you! The goal is to build a categorized community-driven collection of very well-known resources. +Thanks to all [contributors](https://github.com/meysamhadeli/booking-microservices-sample/graphs/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. ## Project Refrences & Credits + - [https://github.com/jbogard/ContosoUniversityDotNetCore-Pages](https://github.com/jbogard/ContosoUniversityDotNetCore-Pages) - [https://github.com/kgrzybek/modular-monolith-with-ddd](https://github.com/kgrzybek/modular-monolith-with-ddd) - [https://github.com/oskardudycz/EventSourcing.NetCore](https://github.com/oskardudycz/EventSourcing.NetCore)