/Microservice.Architecture

This demo shows a working sample of microservices architecture using ASP.NET Core. It covers how to create microservices and API gateway using Ocelot, and how to deploy microservices using Docker.

Primary LanguageC#

This project was created for educational purposes and to consolidate the acquired knowledge.

Keep in mind that the implementation is ongoing and some modules may work with bugs.

About

This demo shows a working sample of microservices architecture using ASP.NET Core. It covers how to create microservices, how to create API gateways using Ocelot and how to deploy microservices using Docker containers.

Diagram

Quick Start

The fastest and easiest way to run this project is a Kubernates Cluster. You just need to install Docker Desktop and Minikube tools. Instead of building sources you can use latest version of images from public Docker Hub registry (romanbilyak). Go to the folder deploy and run run.ps1 script with specified registry parameter.

PowerShell:

.\run.ps1 -registry 'romanbilyak'

CMD:

run -registry 'romanbilyak'

Other methods of running this project are described below:

Kubernates Cluster

Prerequisites:

Go to the folder deploy and run run.ps1 or run.cmd script.

Examples

PowerShell:

.\run.ps1 -nodes 2 -cpus 4 -memory 4096 -r 'localhost:5000' -t 'v1.0' -b

CMD:

run -nodes 2 -cpus 4 -memory 4096 -r 'localhost:5000' -t 'v1.0' -b

Supported params:

Param Short Form Default Description
-nodes -n 1 Number of nodes.
-cpus -c 2 Number of CPUs allocated to Kubernetes.
-memory -m 2048 Amount of RAM to allocate to Kubernetes.
-registry -r '' Name of docker images registry.
-tag -t '' Tag of images.
-build -b false Flag to build images.

The script will:

  1. Start Kubernates Cluster localy using Minikube.

  2. Build microservices images.

  3. Push images to specified registry.

    In a case when registry is not specified images will be pushed into Docker Deamon of cluster.

    In a case when registry is set to 'localhost:5000' local registry inside cluster will be created.

  4. Deploy services to local Kubernates Cluster.

  5. Expose gateway service and start Kubernates Cluster dashboard.

Go to http://localhost to view gateway methods.

Local Docker Host

Prerequisites:

  1. Go to the folder deploy\docker-compose-infrastructure and run the following docker-compose command in CMD or PowerShell:

    docker-compose -f docker-compose.yml -f docker-compose.override.yml up
    
  2. Go to the folder deploy\docker-compose and run the following docker-compose command in CMD or PowerShell:

    docker-compose -f docker-compose.yml -f docker-compose.override.yml up
    

Visual Studio

Prerequisites:

Set gateway and microservices as startup projects. Your can also run the docker-compose-infrastructure project instead of installing and configuring infrastructure services by yourself.

Applications & Microservices

Visual Studio Local Docker Host Kubernates Cluster
angular-ui localhost:7001 localhost:9001
react-ui localhost:7002 localhost:9002
gateway localhost:7100 localhost:9100 localhost
identity-server localhost:7111 localhost:9111
identity-service localhost:7201 localhost:9201
movie-service localhost:7202 localhost:9202
review-service localhost:7203 localhost:9203
payment-service localhost:7204 localhost:9204
test-service localhost:7205 localhost:9205

Project Structure

  • applications -

  • core -

  • deploy -

  • microservices -

  • tests -

Layered Architecture

This project implements NLayer architecture and Domain Driven Design

Shared Infrastructure Layer

  • Database

    • EF Core
  • Ast.Net Core

Domain Layer

  • Entities

  • Specifications

  • Validation Rules

  • Managers

Infrastructure Layer

  • Database contexts

Application Layer

  • Application services

Web Layer

Root layer for microservice's layers

  • Controllers

  • View Models

Test Layer

  • Unit Tests

Technologies