# heitorgiacomini/modulith architecture

> Architecture diagram of the GitHub repository heitorgiacomini/modulith, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/heitorgiacomini/modulith
- Repository: https://github.com/heitorgiacomini/modulith

## Overview

#### Purpose and Entry Points
Reference .NET 10 e-commerce modular monolith: Catalog, Basket, Ordering, and Accounts run in one ASP.NET Core API process. The API composition root is `src/Bootstrapper/Api/Program.cs`; its REST and source GraphQL schemas are consumed directly or through a Fusion gateway at `src/Bootstrapper/Gateway/Program.cs`. Angular starts at `src/web-client/src/main.ts`.

#### Host Composition and Module Boundaries
The API registers independently structured modules, each owning its endpoints, domain model, and EF Core context. Module bootstrap files are `src/Modules/Catalog/Catalog/CatalogModule.cs`, `src/Modules/Basket/Basket/BasketModule.cs`, and `src/Modules/Ordering/OrderingModule.cs`. Accounts is registered through `src/Modules/Accounts/AccountsModule.cs`. Cross-module business assembly dependencies are constrained; Basket accesses Catalog only through `src/Modules/Catalog/Catalog.Contracts/Products/Features/GetProductById/GetProductByIdQuery.cs`.

#### Request and Application Pipeline
Carter endpoint slices map REST requests to MediatR command/query handlers, e.g. `src/Modules/Catalog/Catalog/Products/Features/CreateProduct/CreateProductEndpoint.cs` and `src/Modules/Basket/Basket/Features/CheckoutBasket/CheckoutBasketHandler.cs`. Shared MediatR logging and validation execute around handlers via `src/Shared/Shared/Behaviors/LoggingBehavior.cs` and `src/Shared/Shared/Behaviors/ValidationBehavior.cs`. GraphQL source schemas are module-owned extensions: `src/Modules/Catalog/Catalog/GraphQL/CatalogGraphQLExtensions.cs`, `src/Modules/Basket/Basket/GraphQL/BasketGraphQLExtensions.cs`, and `src/Modules/Ordering/Orders/GraphQL/OrderingGraphQLExtensions.cs`.

#### Domain Modules and Persistence
Catalog owns product lifecycle and emits price-change domain/integration events (`src/Modules/Catalog/Catalog/Products/Models/Product.cs`, `src/Modules/Catalog/Catalog/Data/CatalogDbContext.cs`). Basket owns carts, validates products synchronously through Catalog contracts, and uses repository/cache abstraction (`src/Modules/Basket/Data/Repository/CachedBasketRepository.cs`, `src/Modules/Basket/Data/BasketDbContext.cs`). Ordering consumes checkout events to create orders (`src/Modules/Ordering/Orders/EventHandlers/BasketCheckoutIntegrationEventHandler.cs`, `src/Modules/Ordering/Data/OrderingDbContext.cs`). Accounts owns customer profile, addresses, and saved payment methods behind authenticated REST (`src/Modules/Accounts/Accounts/Features/AccountEndpoints.cs`, `src/Modules/Accounts/Data/AccountsDbContext.cs`).

#### Events, Reliability, and Consistency
EF Core interceptors audit entities and dispatch domain events in-process: `src/Shared/Shared/Data/Interceptors/AuditableEntityInterceptor.cs` and `src/Shared/Shared/Data/Interceptors/DispatchDomainEventsInterceptor.cs`. Catalog publishes price changes; Basket consumes them through `src/Modules/Basket/Basket/EventHandlers/ProductPriceChangedIntegrationEventHandler.cs`. Basket checkout persists an outbox message transactionally, then `src/Modules/Basket/Data/Processors/OutboxProcessor.cs` publishes `src/Shared/Shared.Messaging/Events/BasketCheckoutIntegrationEvent.cs` to RabbitMQ for Ordering.

#### Edge Services, Security, and Runtime
Docker Compose defines the deployable topology in `src/docker-compose.yml` and overrides in `src/docker-compose.override.yml`: PostgreSQL, Redis, RabbitMQ, Keycloak, Seq, API, Fusion gateway/composer, and Angular. Fusion composes API-hosted Catalog/Basket/Ordering schemas; the gateway forwards authorization using `src/Bootstrapper/Gateway/AuthorizationForwardingHandler.cs` and its generated archive `src/Bootstrapper/Gateway/gateway.far`. Keycloak realm provisioning is `src/docker-config/keycloak/myrealm-realm.json`.

#### Client Boundary
Angular 21 is organized by bounded context, with routes and facades separating UI from API access. Representative boundaries are `src/web-client/src/app/contexts/catalog/catalog.routes.ts`, `src/web-client/src/app/contexts/basket/basket.facade.ts`, and `src/web-client/src/app/core/auth/auth.interceptor.ts`. It authenticates with Keycloak, sends GraphQL to Fusion for composed reads, and uses direct API REST calls where required, notably Accounts.

Main entry points: [`src/Bootstrapper/Api/Program.cs`](https://github.com/heitorgiacomini/modulith/blob/main/src/Bootstrapper/Api/Program.cs) (ASP.NET Core API), [`src/Modules/Catalog/Catalog/CatalogModule.cs`](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Catalog/Catalog/CatalogModule.cs) (Catalog), [`src/web-client/src/main.ts`](https://github.com/heitorgiacomini/modulith/blob/main/src/web-client/src/main.ts) (Angular client), [`src/Modules/Ordering/OrderingModule.cs`](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Ordering/OrderingModule.cs) (Ordering)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Clients"]
  node_angular["Angular client<br/>Angular 21<br/>[main.ts]"]
  node_auth_interceptor["Auth interceptor<br/>Angular auth"]
end

subgraph group_edge["Edge &amp; Identity"]
  node_gateway{{"Fusion gateway<br/>GraphQL gateway<br/>[Program.cs]"}}
  node_auth_forwarding["Authorization forwarding<br/>gateway handler"]
  node_keycloak{{"Keycloak<br/>identity provider<br/>[myrealm-realm.json]"}}
end

subgraph group_api["API Host &amp; Pipeline"]
  node_api_host{{"ASP.NET Core API<br/>composition root<br/>[Program.cs]"}}
  node_rest_slices["Carter endpoint slices<br/>REST endpoints"]
  node_mediatr_behaviors["MediatR behaviors<br/>application pipeline"]
  node_ef_interceptors["EF Core interceptors<br/>persistence pipeline"]
end

subgraph group_modules["Business Modules"]
  node_catalog["Catalog<br/>[CatalogModule.cs]"]
  node_basket["Basket"]
  node_ordering["Ordering<br/>[OrderingModule.cs]"]
  node_accounts["Accounts<br/>[AccountsModule.cs]"]
  node_catalog_contract["Catalog product contract<br/>cross-module query"]
end

subgraph group_infra["Data &amp; Messaging"]
  node_catalog_db[("Catalog database<br/>EF Core context")]
  node_basket_store[("Basket store and cache<br/>repository + context")]
  node_ordering_db[("Ordering database<br/>EF Core context")]
  node_accounts_db[("Accounts database<br/>EF Core context")]
  node_outbox["Basket outbox processor<br/>transactional outbox<br/>[OutboxProcessor.cs]"]
  node_rabbitmq["RabbitMQ<br/>message broker"]
end

node_angular -->|"uses"| node_auth_interceptor
node_auth_interceptor -->|"authenticates with"| node_keycloak
node_angular -->|"composed GraphQL reads"| node_gateway
node_angular -->|"direct REST, including Accounts"| node_api_host
node_gateway -->|"applies"| node_auth_forwarding
node_auth_forwarding -->|"forwards authorized GraphQL"| node_api_host
node_api_host -->|"hosts"| node_rest_slices
node_rest_slices -->|"dispatches through"| node_mediatr_behaviors
node_api_host -->|"registers REST and GraphQL"| node_catalog
node_api_host -->|"registers REST and GraphQL"| node_basket
node_api_host -->|"registers REST and GraphQL"| node_ordering
node_api_host -->|"registers authenticated REST"| node_accounts
node_catalog -->|"persists products"| node_catalog_db
node_basket -->|"persists and caches carts"| node_basket_store
node_ordering -->|"persists orders"| node_ordering_db
node_accounts -->|"persists customer data"| node_accounts_db
node_basket -->|"validates product"| node_catalog_contract
node_catalog_contract -->|"queries"| node_catalog
node_catalog -->|"domain events on save"| node_ef_interceptors
node_ef_interceptors -->|"price-change event"| node_basket
node_basket -->|"checkout transaction"| node_outbox
node_outbox -->|"publishes checkout event"| node_rabbitmq
node_rabbitmq -->|"checkout event"| node_ordering

click node_angular "https://github.com/heitorgiacomini/modulith/blob/main/src/web-client/src/main.ts"
click node_auth_interceptor "https://github.com/heitorgiacomini/modulith/blob/main/src/web-client/src/app/core/auth/auth.interceptor.ts"
click node_gateway "https://github.com/heitorgiacomini/modulith/blob/main/src/Bootstrapper/Gateway/Program.cs"
click node_auth_forwarding "https://github.com/heitorgiacomini/modulith/blob/main/src/Bootstrapper/Gateway/AuthorizationForwardingHandler.cs"
click node_keycloak "https://github.com/heitorgiacomini/modulith/blob/main/src/docker-config/keycloak/myrealm-realm.json"
click node_api_host "https://github.com/heitorgiacomini/modulith/blob/main/src/Bootstrapper/Api/Program.cs"
click node_rest_slices "https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Catalog/Catalog/Products/Features/CreateProduct/CreateProductEndpoint.cs"
click node_mediatr_behaviors "https://github.com/heitorgiacomini/modulith/blob/main/src/Shared/Shared/Behaviors/ValidationBehavior.cs"
click node_ef_interceptors "https://github.com/heitorgiacomini/modulith/blob/main/src/Shared/Shared/Data/Interceptors/DispatchDomainEventsInterceptor.cs"
click node_catalog "https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Catalog/Catalog/CatalogModule.cs"
click node_ordering "https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Ordering/OrderingModule.cs"
click node_accounts "https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Accounts/AccountsModule.cs"
click node_catalog_contract "https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Catalog/Catalog.Contracts/Products/Features/GetProductById/GetProductByIdQuery.cs"
click node_catalog_db "https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Catalog/Catalog/Data/CatalogDbContext.cs"
click node_basket_store "https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Basket/Data/Repository/CachedBasketRepository.cs"
click node_ordering_db "https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Ordering/Data/OrderingDbContext.cs"
click node_accounts_db "https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Accounts/Data/AccountsDbContext.cs"
click node_outbox "https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Basket/Data/Processors/OutboxProcessor.cs"
click node_rabbitmq "https://github.com/heitorgiacomini/modulith/blob/main/src/Shared/Shared.Messaging/Events/BasketCheckoutIntegrationEvent.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_angular,node_auth_interceptor toneBlue
class node_gateway,node_auth_forwarding,node_keycloak toneAmber
class node_api_host,node_rest_slices,node_mediatr_behaviors,node_ef_interceptors toneMint
class node_catalog,node_basket,node_ordering,node_accounts,node_catalog_contract toneRose
class node_catalog_db,node_basket_store,node_ordering_db,node_accounts_db,node_outbox,node_rabbitmq toneIndigo
```

## Components

### Clients

- [Angular client](https://github.com/heitorgiacomini/modulith/blob/main/src/web-client/src/main.ts): Angular 21 · Context routes and facades separate UI from API access. · `src/web-client/src/main.ts`
- [Auth interceptor](https://github.com/heitorgiacomini/modulith/blob/main/src/web-client/src/app/core/auth/auth.interceptor.ts): Angular auth · `src/web-client/src/app/core/auth/auth.interceptor.ts`

### Edge & Identity

- [Fusion gateway](https://github.com/heitorgiacomini/modulith/blob/main/src/Bootstrapper/Gateway/Program.cs): GraphQL gateway · Composes module source schemas for client reads. · `src/Bootstrapper/Gateway/Program.cs`
- [Authorization forwarding](https://github.com/heitorgiacomini/modulith/blob/main/src/Bootstrapper/Gateway/AuthorizationForwardingHandler.cs): gateway handler · `src/Bootstrapper/Gateway/AuthorizationForwardingHandler.cs`
- [Keycloak](https://github.com/heitorgiacomini/modulith/blob/main/src/docker-config/keycloak/myrealm-realm.json): identity provider · `src/docker-config/keycloak/myrealm-realm.json`

### API Host & Pipeline

- [ASP.NET Core API](https://github.com/heitorgiacomini/modulith/blob/main/src/Bootstrapper/Api/Program.cs): composition root · Single process hosting all modules and their REST and source GraphQL endpoints. · `src/Bootstrapper/Api/Program.cs`
- [Carter endpoint slices](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Catalog/Catalog/Products/Features/CreateProduct/CreateProductEndpoint.cs): REST endpoints · Maps HTTP requests to MediatR commands and queries. · `src/Modules/Catalog/Catalog/Products/Features/CreateProduct/CreateProductEndpoint.cs`
- [MediatR behaviors](https://github.com/heitorgiacomini/modulith/blob/main/src/Shared/Shared/Behaviors/ValidationBehavior.cs): application pipeline · Logging and validation wrap command and query handlers. · `src/Shared/Shared/Behaviors/ValidationBehavior.cs`
- [EF Core interceptors](https://github.com/heitorgiacomini/modulith/blob/main/src/Shared/Shared/Data/Interceptors/DispatchDomainEventsInterceptor.cs): persistence pipeline · Audits entities and dispatches domain events in-process. · `src/Shared/Shared/Data/Interceptors/DispatchDomainEventsInterceptor.cs`

### Business Modules

- [Catalog](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Catalog/Catalog/CatalogModule.cs): module · Owns products and price-change events. · `src/Modules/Catalog/Catalog/CatalogModule.cs`
- **Basket**: module · Owns carts, checkout, and cached basket access.
- [Ordering](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Ordering/OrderingModule.cs): module · Creates orders from checkout integration events. · `src/Modules/Ordering/OrderingModule.cs`
- [Accounts](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Accounts/AccountsModule.cs): module · Owns authenticated customer profiles, addresses, and payment methods. · `src/Modules/Accounts/AccountsModule.cs`
- [Catalog product contract](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Catalog/Catalog.Contracts/Products/Features/GetProductById/GetProductByIdQuery.cs): cross-module query · Basket synchronously validates products through this contract. · `src/Modules/Catalog/Catalog.Contracts/Products/Features/GetProductById/GetProductByIdQuery.cs`

### Data & Messaging

- [Catalog database](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Catalog/Catalog/Data/CatalogDbContext.cs): EF Core context · `src/Modules/Catalog/Catalog/Data/CatalogDbContext.cs`
- [Basket store and cache](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Basket/Data/Repository/CachedBasketRepository.cs): repository + context · `src/Modules/Basket/Data/Repository/CachedBasketRepository.cs`
- [Ordering database](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Ordering/Data/OrderingDbContext.cs): EF Core context · `src/Modules/Ordering/Data/OrderingDbContext.cs`
- [Accounts database](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Accounts/Data/AccountsDbContext.cs): EF Core context · `src/Modules/Accounts/Data/AccountsDbContext.cs`
- [Basket outbox processor](https://github.com/heitorgiacomini/modulith/blob/main/src/Modules/Basket/Data/Processors/OutboxProcessor.cs): transactional outbox · Publishes persisted checkout messages after commit. · `src/Modules/Basket/Data/Processors/OutboxProcessor.cs`
- [RabbitMQ](https://github.com/heitorgiacomini/modulith/blob/main/src/Shared/Shared.Messaging/Events/BasketCheckoutIntegrationEvent.cs): message broker · `src/Shared/Shared.Messaging/Events/BasketCheckoutIntegrationEvent.cs`

## Connections

- Angular client → Auth interceptor: uses
- Auth interceptor → Keycloak: authenticates with
- Angular client → Fusion gateway: composed GraphQL reads
- Angular client → ASP.NET Core API: direct REST, including Accounts
- Fusion gateway → Authorization forwarding: applies
- Authorization forwarding → ASP.NET Core API: forwards authorized GraphQL
- ASP.NET Core API → Carter endpoint slices: hosts
- Carter endpoint slices → MediatR behaviors: dispatches through
- ASP.NET Core API → Catalog: registers REST and GraphQL
- ASP.NET Core API → Basket: registers REST and GraphQL
- ASP.NET Core API → Ordering: registers REST and GraphQL
- ASP.NET Core API → Accounts: registers authenticated REST
- Catalog → Catalog database: persists products
- Basket → Basket store and cache: persists and caches carts
- Ordering → Ordering database: persists orders
- Accounts → Accounts database: persists customer data
- Basket → Catalog product contract: validates product
- Catalog product contract → Catalog: queries
- Catalog → EF Core interceptors: domain events on save
- EF Core interceptors → Basket: price-change event
- Basket → Basket outbox processor: checkout transaction
- Basket outbox processor → RabbitMQ: publishes checkout event
- RabbitMQ → Ordering: checkout event
