diff --git a/1-monolith-architecture-style/README.md b/1-monolith-architecture-style/README.md index 69f1778..c2d0153 100644 --- a/1-monolith-architecture-style/README.md +++ b/1-monolith-architecture-style/README.md @@ -7,6 +7,16 @@ - [Key Features](#key-features) - [When to Use](#when-to-use) - [Challenges](#challenges) +- [Monolith Architecture Design](#monolith-architecture-design) +- [Development Setup](#development-setup) + - [Dotnet Tools Packages](#dotnet-tools-packages) + - [Husky](#husky) + - [Upgrade Nuget Packages](#upgrade-nuget-packages) +- [How to Run](#how-to-run) + - [Build](#build) + - [Run](#run) + - [Test](#test) +- [Documentation Apis](#documentation-apis) ## Key Features @@ -28,3 +38,64 @@ - Limited scalability (scaling requires scaling the entire application). - Difficult to adopt new technologies incrementally. +## Monolith Architecture Design + +![](./assets/booking-monolith.png) + + +## Development Setup + +### Dotnet Tools Packages +For installing our requirement packages with .NET cli tools, we need to install `dotnet tool manifest`. +```bash +dotnet new tool-manifest +``` +And after that we can restore our dotnet tools packages with .NET cli tools from `.config` folder and `dotnet-tools.json` file. +``` +dotnet tool restore +``` + +### Husky +Here we use `husky` to handel some pre commit rules and we used `conventional commits` rules and `formatting` as pre commit rules, here in [package.json](.././package.json). of course, we can add more rules for pre commit in future. (find more about husky in the [documentation](https://typicode.github.io/husky/get-started.html)) +We need to install `husky` package for `manage` `pre commits hooks` and also I add two packages `@commitlint/cli` and `@commitlint/config-conventional` for handling conventional commits rules in [package.json](.././package.json). +Run the command bellow in the root of project to install all npm dependencies related to husky: + +```bash +npm install +``` + +> Note: In the root of project we have `.husky` folder and it has `commit-msg` file for handling conventional commits rules with provide user friendly message and `pre-commit` file that we can run our `scripts` as a `pre-commit` hooks. that here we call `format` script from [package.json](./package.json) for formatting purpose. + +### Upgrade Nuget Packages +For upgrading our nuget packages to last version, we use the great package [dotnet-outdated](https://github.com/dotnet-outdated/dotnet-outdated). +Run the command below in the root of project to upgrade all of packages to last version: +```bash +dotnet outdated -u +``` + +## How to Run + +> ### Build +To `build` monolith app, run this command in the `root` of the project: +```bash +dotnet build +``` + +> ### Run +To `run` monolith app, run this command in the root of the `Api` folder where the `csproj` file is located: +```bash +dotnet run +``` + +> ### Test + +To `test` monolith app, run this command in the `root` of the project: +```bash +dotnet test +``` + +> ### Documentation Apis + +Each microservice provides `API documentation` and navigate to `/swagger` for `Swagger OpenAPI` or `/scalar/v1` for `Scalar OpenAPI` to visit list of endpoints. + +As part of API testing, I created the [booking.rest](./booking.rest) file which can be run with the [REST Client](https://github.com/Huachao/vscode-restclient) `VSCode plugin`. diff --git a/1-monolith-architecture-style/assets/.gitkeep b/1-monolith-architecture-style/assets/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/1-monolith-architecture-style/assets/booking-monolith.drawio b/1-monolith-architecture-style/assets/booking-monolith.drawio new file mode 100644 index 0000000..d4033ca --- /dev/null +++ b/1-monolith-architecture-style/assets/booking-monolith.drawio @@ -0,0 +1,348 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/1-monolith-architecture-style/assets/booking-monolith.png b/1-monolith-architecture-style/assets/booking-monolith.png new file mode 100644 index 0000000..f090df5 Binary files /dev/null and b/1-monolith-architecture-style/assets/booking-monolith.png differ diff --git a/2-modular-monolith-architecture-style/assets/booking-modular-monolith.drawio b/2-modular-monolith-architecture-style/assets/booking-modular-monolith.drawio index fbadb1e..1cfebb4 100644 --- a/2-modular-monolith-architecture-style/assets/booking-modular-monolith.drawio +++ b/2-modular-monolith-architecture-style/assets/booking-modular-monolith.drawio @@ -1,53 +1,32 @@ - + - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -90,56 +69,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -149,18 +78,6 @@ - - - - - - - - - - - - @@ -227,61 +144,20 @@ - - - - - - - - - - - - + - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -414,16 +290,16 @@ - + - + - + - + @@ -431,22 +307,22 @@ - + - + - + - + - + - + @@ -454,7 +330,7 @@ - + @@ -462,20 +338,25 @@ - + - + - + - + + + + + + diff --git a/2-modular-monolith-architecture-style/assets/booking-modular-monolith.png b/2-modular-monolith-architecture-style/assets/booking-modular-monolith.png index 898f804..7e9a60a 100644 Binary files a/2-modular-monolith-architecture-style/assets/booking-modular-monolith.png and b/2-modular-monolith-architecture-style/assets/booking-modular-monolith.png differ diff --git a/2-modular-monolith-architecture-style/src/Modules/Booking/src/EventMapper.cs b/2-modular-monolith-architecture-style/src/Modules/Booking/src/BookingEventMapper.cs similarity index 91% rename from 2-modular-monolith-architecture-style/src/Modules/Booking/src/EventMapper.cs rename to 2-modular-monolith-architecture-style/src/Modules/Booking/src/BookingEventMapper.cs index 2996d90..ecfc0e6 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Booking/src/EventMapper.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Booking/src/BookingEventMapper.cs @@ -6,7 +6,7 @@ namespace Booking; using Booking.Features.CreatingBook.V1; -public sealed class EventMapper : IEventMapper +public sealed class BookingEventMapper : IEventMapper { public IIntegrationEvent? MapToIntegrationEvent(IDomainEvent @event) { diff --git a/2-modular-monolith-architecture-style/src/Modules/Booking/src/Extensions/Infrastructure/InfrastructureExtensions.cs b/2-modular-monolith-architecture-style/src/Modules/Booking/src/Extensions/Infrastructure/InfrastructureExtensions.cs index 3d0050d..e931b44 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Booking/src/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Booking/src/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -14,7 +14,7 @@ public static class InfrastructureExtensions { public static WebApplicationBuilder AddBookingModules(this WebApplicationBuilder builder) { - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.AddMinimalEndpoints(assemblies: typeof(BookingRoot).Assembly); builder.Services.AddValidatorsFromAssembly(typeof(BookingRoot).Assembly); builder.Services.AddCustomMapster(typeof(BookingRoot).Assembly); diff --git a/2-modular-monolith-architecture-style/src/Modules/Flight/src/Extensions/Infrastructure/InfrastructureExtensions.cs b/2-modular-monolith-architecture-style/src/Modules/Flight/src/Extensions/Infrastructure/InfrastructureExtensions.cs index dc9ab2a..e5288ea 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Flight/src/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Flight/src/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -17,7 +17,7 @@ public static class InfrastructureExtensions { public static WebApplicationBuilder AddFlightModules(this WebApplicationBuilder builder) { - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.AddMinimalEndpoints(assemblies: typeof(FlightRoot).Assembly); builder.Services.AddValidatorsFromAssembly(typeof(FlightRoot).Assembly); builder.Services.AddCustomMapster(typeof(FlightRoot).Assembly); diff --git a/3-microservices-architecture-style/src/Services/Flight/src/Flight/EventMapper.cs b/2-modular-monolith-architecture-style/src/Modules/Flight/src/FlightEventMapper.cs similarity index 97% rename from 3-microservices-architecture-style/src/Services/Flight/src/Flight/EventMapper.cs rename to 2-modular-monolith-architecture-style/src/Modules/Flight/src/FlightEventMapper.cs index 9035417..06249e0 100644 --- a/3-microservices-architecture-style/src/Services/Flight/src/Flight/EventMapper.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Flight/src/FlightEventMapper.cs @@ -14,7 +14,7 @@ using Seats.Features.CreatingSeat.V1; using Seats.Features.ReservingSeat.V1; // ref: https://www.ledjonbehluli.com/posts/domain_to_integration_event/ -public sealed class EventMapper : IEventMapper +public sealed class FlightEventMapper : IEventMapper { public IIntegrationEvent? MapToIntegrationEvent(IDomainEvent @event) { diff --git a/2-modular-monolith-architecture-style/src/Modules/Identity/src/Configurations/IdentityRoot.cs b/2-modular-monolith-architecture-style/src/Modules/Identity/src/Configurations/IdentityRoot.cs deleted file mode 100644 index 25fb8b1..0000000 --- a/2-modular-monolith-architecture-style/src/Modules/Identity/src/Configurations/IdentityRoot.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Identity.Configurations; - -public class IdentityRoot -{ -} diff --git a/2-modular-monolith-architecture-style/src/Modules/Identity/src/Extensions/Infrastructure/InfrastructureExtensions.cs b/2-modular-monolith-architecture-style/src/Modules/Identity/src/Extensions/Infrastructure/InfrastructureExtensions.cs index 3e754e5..7c5c9dd 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Identity/src/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Identity/src/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -17,7 +17,7 @@ public static class InfrastructureExtensions { public static WebApplicationBuilder AddIdentityModules(this WebApplicationBuilder builder) { - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.AddMinimalEndpoints(assemblies: typeof(IdentityRoot).Assembly); builder.Services.AddValidatorsFromAssembly(typeof(IdentityRoot).Assembly); builder.Services.AddCustomMapster(typeof(IdentityRoot).Assembly); diff --git a/3-microservices-architecture-style/src/Services/Identity/src/Identity/Configurations/EventMapper.cs b/2-modular-monolith-architecture-style/src/Modules/Identity/src/IdentityEventMapper.cs similarity index 82% rename from 3-microservices-architecture-style/src/Services/Identity/src/Identity/Configurations/EventMapper.cs rename to 2-modular-monolith-architecture-style/src/Modules/Identity/src/IdentityEventMapper.cs index 2cce314..887210d 100644 --- a/3-microservices-architecture-style/src/Services/Identity/src/Identity/Configurations/EventMapper.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Identity/src/IdentityEventMapper.cs @@ -1,9 +1,9 @@ -namespace Identity.Configurations; - using BuildingBlocks.Core; using BuildingBlocks.Core.Event; -public sealed class EventMapper : IEventMapper +namespace Identity; + +public sealed class IdentityEventMapper : IEventMapper { public IIntegrationEvent? MapToIntegrationEvent(IDomainEvent @event) { diff --git a/2-modular-monolith-architecture-style/src/Modules/Identity/src/IdentityRoot.cs b/2-modular-monolith-architecture-style/src/Modules/Identity/src/IdentityRoot.cs new file mode 100644 index 0000000..05b7694 --- /dev/null +++ b/2-modular-monolith-architecture-style/src/Modules/Identity/src/IdentityRoot.cs @@ -0,0 +1,5 @@ +namespace Identity; + +public class IdentityRoot +{ +} diff --git a/2-modular-monolith-architecture-style/src/Modules/Passenger/src/Extensions/Infrastructure/InfrastructureExtensions.cs b/2-modular-monolith-architecture-style/src/Modules/Passenger/src/Extensions/Infrastructure/InfrastructureExtensions.cs index f4ed2a4..52646b9 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Passenger/src/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Passenger/src/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -15,7 +15,7 @@ public static class InfrastructureExtensions { public static WebApplicationBuilder AddPassengerModules(this WebApplicationBuilder builder) { - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.AddMinimalEndpoints(assemblies: typeof(PassengerRoot).Assembly); builder.Services.AddValidatorsFromAssembly(typeof(PassengerRoot).Assembly); builder.Services.AddCustomMapster(typeof(PassengerRoot).Assembly); diff --git a/2-modular-monolith-architecture-style/src/Modules/Passenger/src/EventMapper.cs b/2-modular-monolith-architecture-style/src/Modules/Passenger/src/PassengerEventMapper.cs similarity index 95% rename from 2-modular-monolith-architecture-style/src/Modules/Passenger/src/EventMapper.cs rename to 2-modular-monolith-architecture-style/src/Modules/Passenger/src/PassengerEventMapper.cs index 21a700e..1deafb7 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Passenger/src/EventMapper.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Passenger/src/PassengerEventMapper.cs @@ -7,7 +7,7 @@ namespace Passenger; using Identity.Consumers.RegisteringNewUser.V1; using Passengers.Features.CompletingRegisterPassenger.V1; -public sealed class EventMapper : IEventMapper +public sealed class PassengerEventMapper : IEventMapper { public IIntegrationEvent? MapToIntegrationEvent(IDomainEvent @event) { diff --git a/3-microservices-architecture-style/src/Services/Booking/src/Booking/EventMapper.cs b/3-microservices-architecture-style/src/Services/Booking/src/Booking/BookingEventMapper.cs similarity index 91% rename from 3-microservices-architecture-style/src/Services/Booking/src/Booking/EventMapper.cs rename to 3-microservices-architecture-style/src/Services/Booking/src/Booking/BookingEventMapper.cs index 2996d90..ecfc0e6 100644 --- a/3-microservices-architecture-style/src/Services/Booking/src/Booking/EventMapper.cs +++ b/3-microservices-architecture-style/src/Services/Booking/src/Booking/BookingEventMapper.cs @@ -6,7 +6,7 @@ namespace Booking; using Booking.Features.CreatingBook.V1; -public sealed class EventMapper : IEventMapper +public sealed class BookingEventMapper : IEventMapper { public IIntegrationEvent? MapToIntegrationEvent(IDomainEvent @event) { diff --git a/3-microservices-architecture-style/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs b/3-microservices-architecture-style/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs index 62155a2..7ac8c25 100644 --- a/3-microservices-architecture-style/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/3-microservices-architecture-style/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -32,7 +32,7 @@ public static class InfrastructureExtensions var env = builder.Environment; builder.Services.AddScoped(); - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.Configure(options => diff --git a/3-microservices-architecture-style/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs b/3-microservices-architecture-style/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs index cbba0dd..efb8ec7 100644 --- a/3-microservices-architecture-style/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/3-microservices-architecture-style/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -36,7 +36,7 @@ public static class InfrastructureExtensions var env = builder.Environment; builder.Services.AddScoped(); - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.Configure(options => diff --git a/2-modular-monolith-architecture-style/src/Modules/Flight/src/EventMapper.cs b/3-microservices-architecture-style/src/Services/Flight/src/Flight/FlightEventMapper.cs similarity index 97% rename from 2-modular-monolith-architecture-style/src/Modules/Flight/src/EventMapper.cs rename to 3-microservices-architecture-style/src/Services/Flight/src/Flight/FlightEventMapper.cs index 9035417..06249e0 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Flight/src/EventMapper.cs +++ b/3-microservices-architecture-style/src/Services/Flight/src/Flight/FlightEventMapper.cs @@ -14,7 +14,7 @@ using Seats.Features.CreatingSeat.V1; using Seats.Features.ReservingSeat.V1; // ref: https://www.ledjonbehluli.com/posts/domain_to_integration_event/ -public sealed class EventMapper : IEventMapper +public sealed class FlightEventMapper : IEventMapper { public IIntegrationEvent? MapToIntegrationEvent(IDomainEvent @event) { diff --git a/3-microservices-architecture-style/src/Services/Identity/src/Identity.Api/Program.cs b/3-microservices-architecture-style/src/Services/Identity/src/Identity.Api/Program.cs index 20c7bed..7de6353 100644 --- a/3-microservices-architecture-style/src/Services/Identity/src/Identity.Api/Program.cs +++ b/3-microservices-architecture-style/src/Services/Identity/src/Identity.Api/Program.cs @@ -1,4 +1,5 @@ using BuildingBlocks.Web; +using Identity; using Identity.Configurations; using Identity.Extensions.Infrastructure; diff --git a/3-microservices-architecture-style/src/Services/Identity/src/Identity/Configurations/IdentityRoot.cs b/3-microservices-architecture-style/src/Services/Identity/src/Identity/Configurations/IdentityRoot.cs deleted file mode 100644 index 25fb8b1..0000000 --- a/3-microservices-architecture-style/src/Services/Identity/src/Identity/Configurations/IdentityRoot.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Identity.Configurations; - -public class IdentityRoot -{ -} diff --git a/3-microservices-architecture-style/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs b/3-microservices-architecture-style/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs index 727bc69..c88be99 100644 --- a/3-microservices-architecture-style/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/3-microservices-architecture-style/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -34,7 +34,7 @@ public static class InfrastructureExtensions var env = builder.Environment; builder.Services.AddScoped(); - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.Configure(options => diff --git a/2-modular-monolith-architecture-style/src/Modules/Identity/src/Configurations/EventMapper.cs b/3-microservices-architecture-style/src/Services/Identity/src/Identity/IdentityEventMapper.cs similarity index 82% rename from 2-modular-monolith-architecture-style/src/Modules/Identity/src/Configurations/EventMapper.cs rename to 3-microservices-architecture-style/src/Services/Identity/src/Identity/IdentityEventMapper.cs index 2cce314..887210d 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Identity/src/Configurations/EventMapper.cs +++ b/3-microservices-architecture-style/src/Services/Identity/src/Identity/IdentityEventMapper.cs @@ -1,9 +1,9 @@ -namespace Identity.Configurations; - using BuildingBlocks.Core; using BuildingBlocks.Core.Event; -public sealed class EventMapper : IEventMapper +namespace Identity; + +public sealed class IdentityEventMapper : IEventMapper { public IIntegrationEvent? MapToIntegrationEvent(IDomainEvent @event) { diff --git a/3-microservices-architecture-style/src/Services/Identity/src/Identity/IdentityRoot.cs b/3-microservices-architecture-style/src/Services/Identity/src/Identity/IdentityRoot.cs new file mode 100644 index 0000000..05b7694 --- /dev/null +++ b/3-microservices-architecture-style/src/Services/Identity/src/Identity/IdentityRoot.cs @@ -0,0 +1,5 @@ +namespace Identity; + +public class IdentityRoot +{ +} diff --git a/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs b/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs index 2056f39..ba27182 100644 --- a/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -34,7 +34,7 @@ public static class InfrastructureExtensions var env = builder.Environment; builder.Services.AddScoped(); - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.Configure( diff --git a/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/EventMapper.cs b/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/PassengerEventMapper.cs similarity index 95% rename from 3-microservices-architecture-style/src/Services/Passenger/src/Passenger/EventMapper.cs rename to 3-microservices-architecture-style/src/Services/Passenger/src/Passenger/PassengerEventMapper.cs index 21a700e..1deafb7 100644 --- a/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/EventMapper.cs +++ b/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/PassengerEventMapper.cs @@ -7,7 +7,7 @@ namespace Passenger; using Identity.Consumers.RegisteringNewUser.V1; using Passengers.Features.CompletingRegisterPassenger.V1; -public sealed class EventMapper : IEventMapper +public sealed class PassengerEventMapper : IEventMapper { public IIntegrationEvent? MapToIntegrationEvent(IDomainEvent @event) {