{"id":15137128,"url":"https://github.com/meysamhadeli/booking-modular-monolith","last_synced_at":"2025-05-16T12:11:53.427Z","repository":{"id":38044518,"uuid":"492487995","full_name":"meysamhadeli/booking-modular-monolith","owner":"meysamhadeli","description":"Practical Modular Monolith, built with .Net 9, DDD, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.","archived":false,"fork":false,"pushed_at":"2025-05-12T21:44:23.000Z","size":1212,"stargazers_count":334,"open_issues_count":1,"forks_count":58,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-12T22:35:50.596Z","etag":null,"topics":["aspnetcore","boilerplate","cap","clean-architecture","cqrs","ddd","docker","dotnet","dotnet-core","dotnetcore","event-driven-architecture","event-sourcing","grpc","kubernetes","messaging","modular-monolith","oauth2","opentelemetry","template","vertical-slice-architecture"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meysamhadeli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-05-15T12:59:33.000Z","updated_at":"2025-05-12T21:44:21.000Z","dependencies_parsed_at":"2023-12-19T00:39:27.680Z","dependency_job_id":"7cdfadae-7883-4a29-b7dc-f8e9920a5944","html_url":"https://github.com/meysamhadeli/booking-modular-monolith","commit_stats":{"total_commits":65,"total_committers":3,"mean_commits":"21.666666666666668","dds":"0.41538461538461535","last_synced_commit":"6145b5f2e59b70ab9413af06b4146f434f740ea0"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meysamhadeli%2Fbooking-modular-monolith","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meysamhadeli%2Fbooking-modular-monolith/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meysamhadeli%2Fbooking-modular-monolith/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meysamhadeli%2Fbooking-modular-monolith/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meysamhadeli","download_url":"https://codeload.github.com/meysamhadeli/booking-modular-monolith/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527099,"owners_count":22085919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aspnetcore","boilerplate","cap","clean-architecture","cqrs","ddd","docker","dotnet","dotnet-core","dotnetcore","event-driven-architecture","event-sourcing","grpc","kubernetes","messaging","modular-monolith","oauth2","opentelemetry","template","vertical-slice-architecture"],"created_at":"2024-09-26T07:00:22.535Z","updated_at":"2025-05-16T12:11:53.383Z","avatar_url":"https://github.com/meysamhadeli.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\" style=\"margin-bottom:20px\"\u003e\n  \u003cimg src=\"assets/logo.png\" alt=\"booking-modular-monolith\" /\u003e\n    \u003cdiv align=\"center\"\u003e\n           \u003ca href=\"https://github.com/meysamhadeli/booking-modular-monolith/actions/workflows/dotnet.yml\"\u003e\u003cimg alt=\"build-status\" src=\"https://github.com/meysamhadeli/booking-modular-monolith/actions/workflows/dotnet.yml/badge.svg?branch=main\u0026style=flat-square\"/\u003e\u003c/a\u003e\n                 \u003ca href=\"https://github.com/meysamhadeli/booking-modular-monolith/blob/main/LICENSE\"\u003e\u003cimg alt=\"build-status\"          src=\"https://img.shields.io/github/license/meysamhadeli/booking-modular-monolith?color=%234275f5\u0026style=flat-square\"/\u003e\u003c/a\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n\n\u003e 🚀 **A practical and imaginary Modular Monolith for implementing an infrastructure for up and running Modular system with the latest technology and architecture like Vertical Slice Architecture, Event Driven Architecture, CQRS, DDD, gRpc and Cap in .Net 9.**\n\n\u003e 💡 **This project is not business-oriented and most of my focus was in the thechnical part for implement a Modular system with a sample project. In this project I implemented some concept in Modular Monolith like Inmemory Broker, Tracing, Event Driven Architecture, Vertical Slice Architecture, CQRS, DDD and gRpc.**\n\n\u003ca href=\"https://gitpod.io/#https://github.com/meysamhadeli/booking-modular-monolith\"\u003e\u003cimg alt=\"Open in Gitpod\" src=\"https://gitpod.io/button/open-in-gitpod.svg\"/\u003e\u003c/a\u003e\n\n# Table of Contents\n\n- [The Goals of This Project](#the-goals-of-this-project)\n- [Plan](#plan)\n- [Technologies - Libraries](#technologies---libraries)\n- [The Domain and Bounded Context - Service Boundary](#the-domain-and-bounded-context---service-boundary)\n- [Structure of Project](#structure-of-project)\n- [Prerequisites](#prerequisites)\n- [Development Setup](#development-setup)\n  - [Dotnet Tools Packages](#dotnet-tools-packages)\n- [How to Run](#how-to-run)\n  - [Config Certificate](#config-certificate)\n  - [Docker Compose](#docker-compose)\n  - [Build](#build)\n  - [Run](#run)\n  - [Test](#test)\n- [Documentation Apis](#documentation-apis)\n- [Support](#support)\n- [Contribution](#contribution)\n\n## The Goals of This Project\n\n- :sparkle: Using `Vertical Slice Architecture` for architecture level.\n- :sparkle: Using `Domain Driven Design (DDD)` to implement all business processes in modules.\n- :sparkle: Using `InMememoryBroker` on top of `Cap` for `Event Driven Architecture` between our modules.\n- :sparkle: Using `Inbox Pattern` on top of `Cap` for ensuring message idempotency for receiver and `Exactly once Delivery`.\n- :sparkle: Using `Outbox Pattern` on top of `Cap` for ensuring no message is lost and there is at `Least One Delivery`.\n- :sparkle: Using `CQRS` implementation with `MediatR` library.\n- :sparkle: Using `Postgres` for database level in our modules.\n- :sparkle: Using `AspNetCore OpenApi` for `generating` built-in support `OpenAPI documentation` in ASP.NET Core.\n- :sparkle: Using `Unit Testing`, `Integration Testing` for testing level.\n- :sparkle: Using `Fluent Validation` and a `Validation Pipeline Behaviour` on top of `MediatR`.\n- :sparkle: Using `Docker-Compose` and `Kubernetes` for our deployment mechanism.\n- :sparkle: Using `OpenTelemetry` for distributed tracing.\n- :sparkle: Using `IdentityServer` for implementation authentication and authorization base on `OpenID-Connect` and `OAuth2`.\n\n## Plan\n\n\u003e 🌀This project is a work in progress, new features will be added over time.🌀\n\nI will try to register future goals and additions in the [Issues](https://github.com/meysamhadeli/booking-modular-monolith/issues) section of this repository.\n\nHigh-level plan is represented in the table\n\n| Feature           | Status         |\n| ----------------- | -------------- |\n| API       | Completed ✔️   |\n| Identity Module  | Completed ✔️   |\n| Flight Module    | Completed ✔️   |\n| Passenger Module | Completed ✔️   |\n| Booking Module   | Completed ✔️   |\n| Building Blocks   | Completed ✔️ |\n\n## Technologies - Libraries\n\n- ✔️ **[`.NET 9`](https://github.com/dotnet/aspnetcore)** - .NET Framework and .NET Core, including ASP.NET and ASP.NET Core.\n- ✔️ **[`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.\n- ✔️ **[`EF Core`](https://github.com/dotnet/efcore)** - Modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.\n- ✔️ **[`AspNetCore OpenApi`](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/aspnetcore-openapi?view=aspnetcore-9.0\u0026tabs=visual-studio#configure-openapi-document-generation)** - Provides built-in support for OpenAPI document generation in ASP.NET Core.\n- ✔️ **[`Cap`](https://github.com/dotnetcore/CAP)** - An EventBus with local persistent message functionality for system integration in SOA or Microservice architecture.\n- ✔️ **[`MediatR`](https://github.com/jbogard/MediatR)** - Simple, unambitious mediator implementation in .NET.\n- ✔️ **[`FluentValidation`](https://github.com/FluentValidation/FluentValidation)** - Popular .NET validation library for building strongly-typed validation rules.\n- ✔️ **[`Scalar`](https://github.com/scalar/scalar/tree/main/packages/scalar.aspnetcore)** - Scalar provides an easy way to render beautiful API references based on OpenAPI/Swagger documents.\n- ✔️ **[`Swagger UI`](https://github.com/domaindrivendev/Swashbuckle.AspNetCore)** - Swagger tools for documenting API's built on ASP.NET Core.\n- ✔️ **[`Serilog`](https://github.com/serilog/serilog)** - Simple .NET logging with fully-structured events.\n- ✔️ **[`Polly`](https://github.com/App-vNext/Polly)** - Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner.\n- ✔️ **[`Scrutor`](https://github.com/khellang/Scrutor)** - Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection.\n- ✔️ **[`Opentelemetry-dotnet`](https://github.com/open-telemetry/opentelemetry-dotnet)** - The OpenTelemetry .NET Client.\n- ✔️ **[`DuendeSoftware IdentityServer`](https://github.com/DuendeSoftware/IdentityServer)** - The most flexible and standards-compliant OpenID Connect and OAuth 2.x framework for ASP.NET Core.\n- ✔️ **[`EasyCaching`](https://github.com/dotnetcore/EasyCaching)** - Open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier.\n- ✔️ **[`Mapster`](https://github.com/MapsterMapper/Mapster)** - Convention-based object-object mapper in .NET.\n- ✔️ **[`Hellang.Middleware.ProblemDetails`](https://github.com/khellang/Middleware/tree/master/src/ProblemDetails)** - A middleware for handling exception in .Net Core.\n- ✔️ **[`IdGen`](https://github.com/RobThree/IdGen)** - Twitter Snowflake-alike ID generator for .Net.\n- ✔️ **[`MagicOnion`](https://github.com/Cysharp/MagicOnion)** - gRPC based HTTP/2 RPC Streaming Framework for .NET, .NET Core and Unity.\n\n## The Domain And Bounded Context - Service Boundary\n\n- `Identity Module`: 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.\n\n- `Flight Module`: The Flight Service is a bounded context `CRUD` service to handle flight related operations.\n\n- `Passenger Module`: The Passenger Service is a bounded context for managing passenger information, tracking activities and subscribing to get notification for out of stock products.\n\n- `Booking Module`: The Booking Service is a bounded context for managing all operation related to booking ticket.\n\n- `Api`: The Api Project use for hosting all modules in one place.\n\n\u003e Note: We don't have separated API project for each module because they are not microervice and shouldn't host separately, so for hosting all modules, we just use one Api project.\n\n![](./assets/modular-monolith-diagram.png)\n\n## Structure of Project\n\nIn 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.\n\nWe have a separate module ([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 module to validate the user, read claims and allow access to authorized/role specific endpoints.\n\nI used [MagicOnion](https://github.com/Cysharp/MagicOnion) for `sync` communication between our modules. This framework is based on `gRPC`, which is a fast and compact binary network transport for HTTP/2. However, unlike plain gRPC, it treats C# interfaces as a protocol schema, enabling seamless code sharing between C# projects without .proto (Protocol Buffers IDL).\n\nI used [In-Memory Queue](https://github.com/yang-xiaodong/Savorboard.CAP.InMemoryMessageQueue) as my MessageBroker for `async` communication between modules using the eventual consistency mechanism. Each modules uses [Cap](https://github.com/dotnetcore/CAP) to interface with [In-Memory Queue](https://github.com/yang-xiaodong/Savorboard.CAP.InMemoryMessageQueue) for easy use messaging, availability, reliability, etc.\n\nmodules 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 modules, each module does not need to know about the other module or handle errors occurred in other modules.\n\nI treat each request as a distinct use case or slice, encapsulating and grouping all concerns from front-end to back.\nWhen 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`.\n\nWith 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.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"./assets/vertical-slice-architecture.png\" /\u003e\n\u003c/div\u003e\n\nInstead 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, consisting 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.\n\nThe 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.\n\nI used CQRS to decompose my features into small parts that makes our application:\n\n- Maximize performance, scalability and simplicity.\n- Easy to maintain and add features to. Changes only affect one command or query, avoiding breaking changes or creating side effects.\n- 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.\n\nUsing the CQRS pattern, we cut each business functionality into vertical slices, for each of these slices we group classes (see [technical folders structure](http://www.kamilgrzybek.com/design/feature-folders)) 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 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.\n\n## Development Setup\n\n### Dotnet Tools Packages\nFor installing our requirement package with .NET cli tools, we need to install `dotnet tool manifest`.\n```bash\ndotnet new tool-manifest\n```\nAnd after that we can restore our dotnet tools packages with .NET cli tools from `.config` folder and `dotnet-tools.json` file.\n```\ndotnet tool restore\n```\n\n## How to Run\n\n### Config Certificate\n\nRun the following commands for [Config SSL](https://docs.microsoft.com/en-us/aspnet/core/security/docker-compose-https?view=aspnetcore-6.0) in your system\n\n```bash\ndotnet dev-certs https -ep %USERPROFILE%\\.aspnet\\https\\aspnetapp.pfx -p {password here}\ndotnet dev-certs https --trust\n```\n\n\u003e Note: for running this command in `powershell` use `$env:USERPROFILE` instead of `%USERPROFILE%`\n\n### Docker Compose\n\nWe have a separate Docker file for setting up and running the [infrastracture.yaml](./deployments/docker-compose/infrastracture.yaml) independently.\n\n```bash\ndocker-compose -f ./deployments/docker-compose/infrastracture.yaml up -d\n```\n\nTODO 👷‍♂️\nDeployment App in Docker-Compose\n\n\u003e ### Build\nTo `build` all microservices, run this command in the `root` of the project:\n```bash\ndotnet build\n```\n\n\u003e ### Run\nTo `run` each microservice, run this command in the root of the `Api` folder of each microservice where the `csproj` file is located:\n```bash\ndotnet run\n```\n\n\u003e ### Test\n\nTo `test` all microservices, run this command in the `root` of the project:\n```bash\ndotnet test\n```\n\n\u003e ### Documentation Apis\n\nEach microservice provides `API documentation` and navigate to `/swagger` for `Swagger OpenAPI` or `/scalar/v1` for `Scalar OpenAPI` to visit list of endpoints.\n\nAs 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`.\n\n# Support\n\nIf you like my work, feel free to:\n\n- ⭐ this repository. And we will be happy together :)\n\nThanks a bunch for supporting me!\n\n## Contribution\n\nThanks to all [contributors](https://github.com/meysamhadeli/booking-modular-monolith/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.\n\nPlease follow this [contribution guideline](./CONTRIBUTION.md) to submit a pull request or create the issue.\n\n## Project References \u0026 Credits\n\n- [https://github.com/jbogard/ContosoUniversityDotNetCore-Pages](https://github.com/jbogard/ContosoUniversityDotNetCore-Pages)\n- [https://github.com/kgrzybek/modular-monolith-with-ddd](https://github.com/kgrzybek/modular-monolith-with-ddd)\n- [https://github.com/oskardudycz/EventSourcing.NetCore](https://github.com/oskardudycz/EventSourcing.NetCore)\n- [https://github.com/thangchung/clean-architecture-dotnet](https://github.com/thangchung/clean-architecture-dotnet)\n- [https://github.com/jasontaylordev/CleanArchitecture](https://github.com/jasontaylordev/CleanArchitecture)\n\n## License\nThis project is made available under the MIT license. See [LICENSE](https://github.com/meysamhadeli/booking-modular-monolith/blob/main/LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeysamhadeli%2Fbooking-modular-monolith","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeysamhadeli%2Fbooking-modular-monolith","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeysamhadeli%2Fbooking-modular-monolith/lists"}