# kgrzybek/modular-monolith-with-ddd architecture

> Architecture diagram of the GitHub repository kgrzybek/modular-monolith-with-ddd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kgrzybek/modular-monolith-with-ddd
- Repository: https://github.com/kgrzybek/modular-monolith-with-ddd
- Video tour (about a minute): https://gitdiagram.com/kgrzybek/modular-monolith-with-ddd/video

## Overview

#### Purpose and Runtime Entry Points
This is a .NET 8 modular monolith implementing a Meetup-like meeting-groups domain with DDD, CQRS, asynchronous module integration, and event sourcing for Payments. The executable HTTP host is the ASP.NET Core REST API at `src/API/CompanyName.MyMeetings.API/Program.cs` and `src/API/CompanyName.MyMeetings.API/Startup.cs`. Docker starts the API, SQL Server, and database migrator through `docker-compose.yml`.

#### API Host and Boundary
The API is deliberately thin: controllers authenticate/authorize, map HTTP requests to module commands/queries, and return responses. It initializes module composition roots rather than containing business logic. Cross-cutting request concerns include correlation IDs, permission authorization, Swagger, and problem-details validation responses.
- `src/API/CompanyName.MyMeetings.API/Startup.cs`
- `src/API/CompanyName.MyMeetings.API/Configuration/Authorization/HasPermissionAuthorizationHandler.cs`
- `src/API/CompanyName.MyMeetings.API/Modules/Meetings/Meetings/MeetingsController.cs`

#### Bounded-Context Modules
Six isolated modules own their domain, application contracts, infrastructure, and database schema: Meetings (groups, meetings, attendance/comments), Administration (proposal approval), Payments (subscriptions and fees), Registrations (registration confirmation), and UserAccess (identity/authentication); API delegates through their public module interfaces. Each module has an independent Autofac composition root and exposes only contracts/integration-event assemblies.
- `src/Modules/Meetings/Infrastructure/MeetingsModule.cs`
- `src/Modules/Administration/Infrastructure/AdministrationModule.cs`
- `src/Modules/Payments/Infrastructure/PaymentsModule.cs`

#### CQRS and Rich Write Models
Commands traverse MediatR handlers, validation/logging/unit-of-work decorators, repositories, and DDD aggregates that enforce business rules and emit domain events. Reads bypass aggregates, using Dapper/SQL against module-owned views. This is the principal write/read boundary.
- `src/Modules/Meetings/Application/Meetings/CreateMeeting/CreateMeetingCommandHandler.cs`
- `src/Modules/Meetings/Domain/Meetings/Meeting.cs`
- `src/Modules/Meetings/Application/MeetingGroups/GetAllMeetingGroups/GetAllMeetingGroupsQueryHandler.cs`

#### Asynchronous Integration and Background Processing
Modules do not make direct calls to each other. They publish typed integration events through the in-memory event bus; each module persists outgoing messages in an outbox and consumes incoming messages through an inbox for at-least-once delivery/processing. Quartz jobs drive inbox, outbox, and internal-command processing, creating eventual-consistency boundaries.
- `src/BuildingBlocks/Infrastructure/EventBus/InMemoryEventBus.cs`
- `src/Modules/Meetings/Infrastructure/Configuration/Processing/Outbox/ProcessOutboxJob.cs`
- `src/Modules/Registrations/IntegrationEvents/NewUserRegisteredIntegrationEvent.cs`

#### Identity, Authorization, and Email
UserAccess hosts IdentityServer-based OAuth2 password-grant authentication and JWT issuance. API authorization checks granular permissions rather than roles directly. Modules use a shared email abstraction; concrete delivery is infrastructure-owned.
- `src/Modules/UserAccess/Infrastructure/IdentityServer/ResourceOwnerPasswordValidator.cs`
- `src/API/CompanyName.MyMeetings.API/Configuration/Authorization/AuthorizationChecker.cs`
- `src/BuildingBlocks/Infrastructure/Emails/EmailSender.cs`

#### Persistence and Event Sourcing
MS SQL Server is divided into schemas per module, with EF Core repositories for conventional write models and SQL views for reads. Payments differs materially: aggregates are restored/appended through SQL Stream Store, then projectors maintain read tables from event streams and checkpoints.
- `src/Database/CompanyName.MyMeetings.Database/Structure/meetings`
- `src/Modules/Payments/Infrastructure/AggregateStore/SqlStreamAggregateStore.cs`
- `src/Modules/Payments/Infrastructure/AggregateStore/SubscriptionsManager.cs`

#### Database Lifecycle and Delivery
Database structure, migrations, seeds, and a DbUp migrator are versioned in-repo. NUKE is the build entry point and orchestrates compilation, tests, SQL Server-backed integration runs, migration, and SUT preparation. Key infrastructure is .NET 8, SQL Server, Docker Compose, Autofac, EF Core, Dapper, MediatR, Quartz, Serilog, IdentityServer4, and SQL Stream Store.
- `src/Database/DatabaseMigrator/Program.cs`
- `src/Database/CompanyName.MyMeetings.Database/Scripts/Migrations`
- `build/Build.cs`

Main entry points: [`src/API/CompanyName.MyMeetings.API/Startup.cs`](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/API/CompanyName.MyMeetings.API/Startup.cs) (API startup), [`src/Database/CompanyName.MyMeetings.Database/Structure/meetings`](https://github.com/kgrzybek/modular-monolith-with-ddd/tree/master/src/Database/CompanyName.MyMeetings.Database/Structure/meetings) (SQL Server), [`src/API/CompanyName.MyMeetings.API/Modules/Meetings/Meetings/MeetingsController.cs`](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/API/CompanyName.MyMeetings.API/Modules/Meetings/Meetings/MeetingsController.cs) (Meetings controller), [`src/Modules/Meetings/Domain/Meetings/Meeting.cs`](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Meetings/Domain/Meetings/Meeting.cs) (Meeting aggregate)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API boundary"]
  node_api_host["ASP.NET Core API<br/>HTTP host<br/>[Program.cs]"]
  node_startup["API startup<br/>composition root<br/>[Startup.cs]"]
  node_meetings_controller["Meetings controller<br/>REST controller"]
  node_permission_auth["Permission authorization"]
end

subgraph group_modules["Modules and processing"]
  node_meetings_module{{"Meetings module<br/>bounded context<br/>[MeetingsModule.cs]"}}
  node_administration_module{{"Administration module<br/>bounded context"}}
  node_payments_module{{"Payments module<br/>bounded context<br/>[PaymentsModule.cs]"}}
  node_useraccess_identity["IdentityServer authentication<br/>identity provider"]
  node_command_pipeline["Command pipeline<br/>CQRS write path"]
  node_meeting_aggregate{{"Meeting aggregate<br/>DDD aggregate<br/>[Meeting.cs]"}}
  node_query_handler["Meeting groups query<br/>CQRS read path"]
  node_event_bus["In-memory event bus<br/>integration bus"]
  node_outbox_job["Outbox processor<br/>Quartz job"]
  node_registration_event["New user registered event<br/>integration event"]
  node_email_sender["Email sender<br/>shared infrastructure<br/>[EmailSender.cs]"]
end

subgraph group_data["Persistence and delivery"]
  node_sql_server[("SQL Server<br/>database<br/>[meetings]")]
  node_payment_event_store[("Payments event store<br/>event-sourced store")]
  node_payments_projector["Payments projections<br/>projection manager"]
  node_database_migrator["DbUp migrator<br/>database lifecycle<br/>[Program.cs]"]
  node_migrations["Database migrations<br/>migration scripts<br/>[Migrations]"]
  node_build["NUKE build<br/>build orchestration<br/>[Build.cs]"]
end

node_api_host -->|"initializes"| node_startup
node_startup -->|"composes"| node_meetings_module
node_startup -->|"composes"| node_administration_module
node_startup -->|"composes"| node_payments_module
node_meetings_controller -->|"authorizes with"| node_permission_auth
node_meetings_controller -->|"sends commands"| node_command_pipeline
node_meetings_controller -->|"sends queries"| node_query_handler
node_command_pipeline -->|"loads and changes"| node_meeting_aggregate
node_meeting_aggregate -->|"persists via repository"| node_sql_server
node_query_handler -->|"reads views"| node_sql_server
node_meeting_aggregate -.->|"records outgoing events"| node_outbox_job
node_outbox_job -->|"publishes"| node_event_bus
node_event_bus -->|"delivers events"| node_registration_event
node_event_bus -.->|"consumed asynchronously"| node_meetings_module
node_useraccess_identity -->|"issues JWTs for"| node_api_host
node_payments_module -->|"stores aggregates in"| node_payment_event_store
node_payment_event_store -->|"projects streams"| node_payments_projector
node_payments_projector -->|"updates read tables"| node_sql_server
node_migrations -->|"applied by"| node_database_migrator
node_database_migrator -->|"migrates"| node_sql_server
node_build -->|"orchestrates"| node_database_migrator

click node_api_host "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/API/CompanyName.MyMeetings.API/Program.cs"
click node_startup "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/API/CompanyName.MyMeetings.API/Startup.cs"
click node_meetings_controller "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/API/CompanyName.MyMeetings.API/Modules/Meetings/Meetings/MeetingsController.cs"
click node_permission_auth "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/API/CompanyName.MyMeetings.API/Configuration/Authorization/HasPermissionAuthorizationHandler.cs"
click node_meetings_module "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Meetings/Infrastructure/MeetingsModule.cs"
click node_administration_module "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Administration/Infrastructure/AdministrationModule.cs"
click node_payments_module "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Payments/Infrastructure/PaymentsModule.cs"
click node_useraccess_identity "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/UserAccess/Infrastructure/IdentityServer/ResourceOwnerPasswordValidator.cs"
click node_command_pipeline "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Meetings/Application/Meetings/CreateMeeting/CreateMeetingCommandHandler.cs"
click node_meeting_aggregate "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Meetings/Domain/Meetings/Meeting.cs"
click node_query_handler "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Meetings/Application/MeetingGroups/GetAllMeetingGroups/GetAllMeetingGroupsQueryHandler.cs"
click node_event_bus "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/BuildingBlocks/Infrastructure/EventBus/InMemoryEventBus.cs"
click node_outbox_job "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Meetings/Infrastructure/Configuration/Processing/Outbox/ProcessOutboxJob.cs"
click node_registration_event "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Registrations/IntegrationEvents/NewUserRegisteredIntegrationEvent.cs"
click node_email_sender "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/BuildingBlocks/Infrastructure/Emails/EmailSender.cs"
click node_sql_server "https://github.com/kgrzybek/modular-monolith-with-ddd/tree/master/src/Database/CompanyName.MyMeetings.Database/Structure/meetings"
click node_payment_event_store "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Payments/Infrastructure/AggregateStore/SqlStreamAggregateStore.cs"
click node_payments_projector "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Payments/Infrastructure/AggregateStore/SubscriptionsManager.cs"
click node_database_migrator "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Database/DatabaseMigrator/Program.cs"
click node_migrations "https://github.com/kgrzybek/modular-monolith-with-ddd/tree/master/src/Database/CompanyName.MyMeetings.Database/Scripts/Migrations"
click node_build "https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/build/Build.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_host,node_startup,node_meetings_controller,node_permission_auth toneBlue
class node_meetings_module,node_administration_module,node_payments_module,node_useraccess_identity,node_command_pipeline,node_meeting_aggregate,node_query_handler,node_event_bus,node_outbox_job,node_registration_event,node_email_sender toneAmber
class node_sql_server,node_payment_event_store,node_payments_projector,node_database_migrator,node_migrations,node_build toneMint
```

## Components

### API boundary

- [ASP.NET Core API](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/API/CompanyName.MyMeetings.API/Program.cs): HTTP host · Thin REST host and module composition boundary. · `src/API/CompanyName.MyMeetings.API/Program.cs`
- [API startup](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/API/CompanyName.MyMeetings.API/Startup.cs): composition root · `src/API/CompanyName.MyMeetings.API/Startup.cs`
- [Meetings controller](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/API/CompanyName.MyMeetings.API/Modules/Meetings/Meetings/MeetingsController.cs): REST controller · `src/API/CompanyName.MyMeetings.API/Modules/Meetings/Meetings/MeetingsController.cs`
- [Permission authorization](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/API/CompanyName.MyMeetings.API/Configuration/Authorization/HasPermissionAuthorizationHandler.cs): authorization · Enforces granular permissions at the API boundary. · `src/API/CompanyName.MyMeetings.API/Configuration/Authorization/HasPermissionAuthorizationHandler.cs`

### Modules and processing

- [Meetings module](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Meetings/Infrastructure/MeetingsModule.cs): bounded context · Owns meeting groups, meetings, attendance, and comments. · `src/Modules/Meetings/Infrastructure/MeetingsModule.cs`
- [Administration module](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Administration/Infrastructure/AdministrationModule.cs): bounded context · Owns proposal approval. · `src/Modules/Administration/Infrastructure/AdministrationModule.cs`
- [Payments module](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Payments/Infrastructure/PaymentsModule.cs): bounded context · Owns subscriptions and fees. · `src/Modules/Payments/Infrastructure/PaymentsModule.cs`
- [IdentityServer authentication](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/UserAccess/Infrastructure/IdentityServer/ResourceOwnerPasswordValidator.cs): identity provider · Validates password grants and issues JWTs. · `src/Modules/UserAccess/Infrastructure/IdentityServer/ResourceOwnerPasswordValidator.cs`
- [Command pipeline](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Meetings/Application/Meetings/CreateMeeting/CreateMeetingCommandHandler.cs): CQRS write path · MediatR handlers apply validation, logging, and unit-of-work decorators. · `src/Modules/Meetings/Application/Meetings/CreateMeeting/CreateMeetingCommandHandler.cs`
- [Meeting aggregate](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Meetings/Domain/Meetings/Meeting.cs): DDD aggregate · Enforces meeting business rules and raises domain events. · `src/Modules/Meetings/Domain/Meetings/Meeting.cs`
- [Meeting groups query](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Meetings/Application/MeetingGroups/GetAllMeetingGroups/GetAllMeetingGroupsQueryHandler.cs): CQRS read path · Reads module views directly with Dapper/SQL. · `src/Modules/Meetings/Application/MeetingGroups/GetAllMeetingGroups/GetAllMeetingGroupsQueryHandler.cs`
- [In-memory event bus](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/BuildingBlocks/Infrastructure/EventBus/InMemoryEventBus.cs): integration bus · Publishes typed events between isolated modules. · `src/BuildingBlocks/Infrastructure/EventBus/InMemoryEventBus.cs`
- [Outbox processor](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Meetings/Infrastructure/Configuration/Processing/Outbox/ProcessOutboxJob.cs): Quartz job · Dispatches persisted outgoing integration messages. · `src/Modules/Meetings/Infrastructure/Configuration/Processing/Outbox/ProcessOutboxJob.cs`
- [New user registered event](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Registrations/IntegrationEvents/NewUserRegisteredIntegrationEvent.cs): integration event · `src/Modules/Registrations/IntegrationEvents/NewUserRegisteredIntegrationEvent.cs`
- [Email sender](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/BuildingBlocks/Infrastructure/Emails/EmailSender.cs): shared infrastructure · Concrete delivery behind the shared email abstraction. · `src/BuildingBlocks/Infrastructure/Emails/EmailSender.cs`

### Persistence and delivery

- [SQL Server](https://github.com/kgrzybek/modular-monolith-with-ddd/tree/master/src/Database/CompanyName.MyMeetings.Database/Structure/meetings): database · Module schemas, EF write stores, and SQL read views. · `src/Database/CompanyName.MyMeetings.Database/Structure/meetings`
- [Payments event store](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Payments/Infrastructure/AggregateStore/SqlStreamAggregateStore.cs): event-sourced store · Restores and appends payment aggregate streams. · `src/Modules/Payments/Infrastructure/AggregateStore/SqlStreamAggregateStore.cs`
- [Payments projections](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Modules/Payments/Infrastructure/AggregateStore/SubscriptionsManager.cs): projection manager · Maintains payment read tables and checkpoints from streams. · `src/Modules/Payments/Infrastructure/AggregateStore/SubscriptionsManager.cs`
- [DbUp migrator](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/src/Database/DatabaseMigrator/Program.cs): database lifecycle · Applies versioned database migrations. · `src/Database/DatabaseMigrator/Program.cs`
- [Database migrations](https://github.com/kgrzybek/modular-monolith-with-ddd/tree/master/src/Database/CompanyName.MyMeetings.Database/Scripts/Migrations): migration scripts · `src/Database/CompanyName.MyMeetings.Database/Scripts/Migrations`
- [NUKE build](https://github.com/kgrzybek/modular-monolith-with-ddd/blob/master/build/Build.cs): build orchestration · Builds, tests, migrates, and prepares integration runs. · `build/Build.cs`

## Connections

- ASP.NET Core API → API startup: initializes
- API startup → Meetings module: composes
- API startup → Administration module: composes
- API startup → Payments module: composes
- Meetings controller → Permission authorization: authorizes with
- Meetings controller → Command pipeline: sends commands
- Meetings controller → Meeting groups query: sends queries
- Command pipeline → Meeting aggregate: loads and changes
- Meeting aggregate → SQL Server: persists via repository
- Meeting groups query → SQL Server: reads views
- Meeting aggregate → Outbox processor: records outgoing events
- Outbox processor → In-memory event bus: publishes
- In-memory event bus → New user registered event: delivers events
- In-memory event bus → Meetings module: consumed asynchronously
- IdentityServer authentication → ASP.NET Core API: issues JWTs for
- Payments module → Payments event store: stores aggregates in
- Payments event store → Payments projections: projects streams
- Payments projections → SQL Server: updates read tables
- Database migrations → DbUp migrator: applied by
- DbUp migrator → SQL Server: migrates
- NUKE build → DbUp migrator: orchestrates
