# codelytv/inbox_outbox_pattern-course architecture

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

- Interactive diagram: https://gitdiagram.com/codelytv/inbox_outbox_pattern-course
- Repository: https://github.com/codelytv/inbox_outbox_pattern-course

## Overview

1. This repo is a set of two closely related sample applications: `01-outbox` and `02-inbox`. Each contains a full Next.js + TypeScript codebase that demonstrates event-driven modular monolith style design, with the difference being how domain events are propagated and processed.

2. The main runtime is a Next.js app. Its only HTTP-facing API shown in the tree is under `src/app/api/mooc/...`, which exposes course and user endpoints. These route handlers are the presentation boundary; they call application services in the `src/contexts/...` tree rather than business logic directly.

3. The domain is split into bounded contexts:
   - `mooc` for courses and users
   - `shop` for products, product reviews, and shop users
   - `retention` for email and user-retention projections
   - `shared` for reusable primitives, event abstractions, and infrastructure helpers  
   Each context follows the same layered structure: `domain` entities/value objects, `application` use cases, and `infrastructure` adapters.

4. Persistence is PostgreSQL, with schema setup scripts in `databases/` and shared DB plumbing in `src/contexts/shared/infrastructure/postgres`. Repositories are implemented per aggregate/context, for example `PostgresUserRepository`, `PostgresCourseRepository`, `PostgresShopUserRepository`, and `PostgresProductReviewRepository`. The repo also uses separate schemas such as `public`, `mooc`, `shop`, and `retention` to isolate context data.

5. The shared layer provides the architectural backbone: base domain classes, identifiers/value objects, a clock, UUID generation, event interfaces, event serialization/deserialization, HTTP error wrappers, and dependency injection configuration (`diod.config.ts`). This is what keeps the feature contexts decoupled from framework and transport concerns.

6. The central business event is user registration. `mooc/users/application/registrar/UserRegistrar` creates and persists a `User` aggregate, which emits `UserRegisteredDomainEvent`. That event becomes the integration point for other contexts rather than direct cross-context calls.

7. In the outbox variant, events are first written durably to Postgres via `PostgresOutboxEventBus` and later published to RabbitMQ by a separate script (`publish-outbox-to-rabbitmq.ts`). This creates a clear boundary between transactional state changes and external message delivery. The `retention/email` context also has an outbox-backed email sender in the later outbox example (`PostgresOutboxEmailSender`).

8. RabbitMQ is the asynchronous integration bus between contexts. The repo includes scripts to configure RabbitMQ and to consume messages. Subscribers such as `SendWelcomeEmailOnUserRegistered` and `RegisterShopUserOnUserRegistered` react to `UserRegisteredDomainEvent` and update their own local models or trigger side effects.

9. The retention context shows two kinds of downstream reactions:
   - email handling in `retention/email`, which builds and sends a `WelcomeEmail`
   - user projection/update handling in `retention/retention-user`, which updates a local retention model  
   In the inbox variant, `retention/total-registered-users` adds a durable counter projection, illustrating consumer-side processing of possibly duplicated events.

10. The shop context is another independent consumer of the user event stream. `shop/shop-user` mirrors registered users into a shop-specific read model, while `shop/products` and `shop/product-reviews` are standard CRUD/search subdomains backed by Postgres. This makes the repo a good example of multiple bounded contexts sharing only events and contracts, not tables.

11. The project also includes operational and developer tooling that matters to the architecture: `compose.yml` for local infrastructure, `Makefile` for common tasks, GitHub Actions CI, HTTP request samples in `etc/request`, and scripts for seeding courses, stress-testing user creation, and debugging message consumption. These scripts are part of the delivery/verification flow, not core business logic.

12. Tests mirror the production structure almost one-to-one: there are unit tests for domain and application services, repository tests for Postgres adapters, and API tests for the Next.js routes. That mirrors the intended dependency direction: presentation and infrastructure are thin wrappers around application and domain layers.

13. If you draw the architecture, the important flows are: HTTP request → route handler → use case → repository/domain event → outbox or event bus → RabbitMQ → downstream subscriber → local context repository or external side effect. The key boundary is that each bounded context owns its own data and reacts to events instead of calling into other contexts directly.

Main entry points: [`02-inbox/2-inbox_pattern/src/contexts/shared/infrastructure/domain-event/rabbitmq/RabbitMqEventBus.ts`](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/shared/infrastructure/domain-event/rabbitmq/RabbitMqEventBus.ts) (RabbitMQ), [`01-outbox/3-outbox_pattern/src/contexts/shop/shop-user/domain/ShopUser.ts`](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shop/shop-user/domain/ShopUser.ts) (Shop context), [`01-outbox/3-outbox_pattern/src/contexts/shared/infrastructure/domain-event/rabbitmq/RabbitMqEventBus.ts`](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shared/infrastructure/domain-event/rabbitmq/RabbitMqEventBus.ts) (RabbitMQ), [`01-outbox/3-outbox_pattern/src/app/api/mooc/courses/route.ts`](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/app/api/mooc/courses/route.ts) (MOOC API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_outbox["01-outbox"]
  node_outbox_app["Next app<br/>runtime<br/>[layout.tsx]"]
  node_outbox_mooc_api["MOOC API<br/>http routes<br/>[route.ts]"]
  node_outbox_mooc_users["User registrar<br/>application use case<br/>[UserRegistrar.ts]"]
  node_outbox_mooc_courses["Course queries<br/>application use cases<br/>[CourseSearcher.ts]"]
  node_outbox_mooc_user_domain{{"User model<br/>domain aggregate<br/>[User.ts]"}}
  node_outbox_mooc_course_domain{{"Course model<br/>domain aggregate<br/>[Course.ts]"}}
  node_outbox_shop["Shop context<br/>bounded context<br/>[ShopUser.ts]"]
  node_outbox_shop_products["Products<br/>application+domain<br/>[Product.ts]"]
  node_outbox_shop_reviews["Reviews<br/>application+domain<br/>[ProductReview.ts]"]
  node_outbox_shop_users["Shop users<br/>subscriber model"]
  node_outbox_retention["Retention context<br/>bounded context<br/>[RetentionUser.ts]"]
  node_outbox_ret_email["Welcome email<br/>subscriber"]
  node_outbox_ret_user["Retention user<br/>projection updater"]
  node_outbox_shared["Shared kernel<br/>shared platform<br/>[AggregateRoot.ts]"]
  node_outbox_eventbus[("Outbox bus<br/>infra event bus")]
  node_outbox_rabbit["RabbitMQ<br/>async bus"]
  node_outbox_postgres[("Postgres<br/>persistence")]
end

subgraph group_inbox["02-inbox"]
  node_inbox_app["Next app<br/>runtime<br/>[layout.tsx]"]
  node_inbox_mooc_api["MOOC API<br/>http routes<br/>[route.ts]"]
  node_inbox_mooc_users["User registrar<br/>application use case<br/>[UserRegistrar.ts]"]
  node_inbox_retention["Retention context<br/>bounded context<br/>[RetentionUser.ts]"]
  node_inbox_total_users{{"Total users<br/>projection"}}
  node_inbox_ret_email["Welcome email<br/>subscriber"]
  node_inbox_shop_users["Shop users<br/>subscriber model"]
  node_inbox_shared["Shared kernel<br/>shared platform<br/>[AggregateRoot.ts]"]
  node_inbox_rabbit["RabbitMQ<br/>async bus"]
  node_inbox_postgres[("Postgres<br/>persistence")]
end

node_outbox_app -->|"serves"| node_outbox_mooc_api
node_outbox_mooc_api -->|"calls"| node_outbox_mooc_users
node_outbox_mooc_api -->|"calls"| node_outbox_mooc_courses
node_outbox_mooc_users -->|"creates"| node_outbox_mooc_user_domain
node_outbox_mooc_courses -->|"reads"| node_outbox_mooc_course_domain
node_outbox_mooc_users -->|"publishes"| node_outbox_eventbus
node_outbox_eventbus -.->|"delivers"| node_outbox_rabbit
node_outbox_rabbit -->|"consumes"| node_outbox_shop_users
node_outbox_rabbit -->|"consumes"| node_outbox_ret_email
node_outbox_rabbit -->|"consumes"| node_outbox_ret_user
node_outbox_shop_users -->|"updates"| node_outbox_shop
node_outbox_ret_email -->|"uses"| node_outbox_retention
node_outbox_ret_user -->|"updates"| node_outbox_retention
node_outbox_shop -->|"contains"| node_outbox_shop_products
node_outbox_shop -->|"contains"| node_outbox_shop_reviews
node_outbox_shop -->|"contains"| node_outbox_shop_users
node_outbox_shared -->|"supports"| node_outbox_eventbus
node_outbox_shared -->|"supports"| node_outbox_postgres
node_inbox_app -->|"serves"| node_inbox_mooc_api
node_inbox_mooc_api -->|"calls"| node_inbox_mooc_users
node_inbox_mooc_users -->|"publishes"| node_inbox_rabbit
node_inbox_rabbit -->|"consumes"| node_inbox_ret_email
node_inbox_rabbit -->|"consumes"| node_inbox_shop_users
node_inbox_rabbit -->|"consumes"| node_inbox_total_users
node_inbox_ret_email -->|"uses"| node_inbox_retention
node_inbox_total_users -->|"updates"| node_inbox_retention
node_inbox_shop_users -->|"persists"| node_inbox_postgres
node_inbox_shared -->|"supports"| node_inbox_rabbit
node_inbox_shared -->|"supports"| node_inbox_postgres

click node_outbox_app "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/app/layout.tsx"
click node_outbox_mooc_api "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/app/api/mooc/courses/route.ts"
click node_outbox_mooc_users "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/mooc/users/application/registrar/UserRegistrar.ts"
click node_outbox_mooc_courses "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/mooc/courses/application/search/CourseSearcher.ts"
click node_outbox_mooc_user_domain "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/mooc/users/domain/User.ts"
click node_outbox_mooc_course_domain "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/mooc/courses/domain/Course.ts"
click node_outbox_shop "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shop/shop-user/domain/ShopUser.ts"
click node_outbox_shop_products "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shop/products/domain/Product.ts"
click node_outbox_shop_reviews "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shop/product-reviews/domain/ProductReview.ts"
click node_outbox_shop_users "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shop/shop-user/application/register-on-user-registered/RegisterShopUserOnUserRegistered.ts"
click node_outbox_retention "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/retention/retention-user/domain/RetentionUser.ts"
click node_outbox_ret_email "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/retention/email/application/send-welcome-email/SendWelcomeEmailOnUserRegistered.ts"
click node_outbox_ret_user "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/retention/retention-user/application/update-last-activity-date/UpdateLastActivityDateOnUserUpdated.ts"
click node_outbox_shared "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shared/domain/AggregateRoot.ts"
click node_outbox_eventbus "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shared/infrastructure/domain-event/PostgresOutboxEventBus.ts"
click node_outbox_rabbit "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shared/infrastructure/domain-event/rabbitmq/RabbitMqEventBus.ts"
click node_outbox_postgres "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shared/infrastructure/postgres/PostgresConnection.ts"
click node_inbox_app "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/app/layout.tsx"
click node_inbox_mooc_api "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/app/api/mooc/courses/route.ts"
click node_inbox_mooc_users "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/mooc/users/application/registrar/UserRegistrar.ts"
click node_inbox_retention "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/retention/retention-user/domain/RetentionUser.ts"
click node_inbox_total_users "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/retention/total-registered-users/application/increment/IncrementTotalRegisteredUsersOnUserRegistered.ts"
click node_inbox_ret_email "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/retention/email/application/send-welcome-email/SendWelcomeEmailOnUserRegistered.ts"
click node_inbox_shop_users "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/shop/shop-user/application/register-on-user-registered/RegisterShopUserOnUserRegistered.ts"
click node_inbox_shared "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/shared/domain/AggregateRoot.ts"
click node_inbox_rabbit "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/shared/infrastructure/domain-event/rabbitmq/RabbitMqEventBus.ts"
click node_inbox_postgres "https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/shared/infrastructure/postgres/PostgresConnection.ts"

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_outbox_app,node_outbox_mooc_api,node_outbox_mooc_users,node_outbox_mooc_courses,node_outbox_mooc_user_domain,node_outbox_mooc_course_domain,node_outbox_shop,node_outbox_shop_products,node_outbox_shop_reviews,node_outbox_shop_users,node_outbox_retention,node_outbox_ret_email,node_outbox_ret_user,node_outbox_shared,node_outbox_eventbus,node_outbox_rabbit,node_outbox_postgres toneBlue
class node_inbox_app,node_inbox_mooc_api,node_inbox_mooc_users,node_inbox_retention,node_inbox_total_users,node_inbox_ret_email,node_inbox_shop_users,node_inbox_shared,node_inbox_rabbit,node_inbox_postgres toneAmber
```

## Components

### 01-outbox

Outbox-pattern sample app

- [Next app](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/app/layout.tsx): runtime · Next.js frontend, API routes, and scripts for the outbox variant · `01-outbox/3-outbox_pattern/src/app/layout.tsx`
- [MOOC API](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/app/api/mooc/courses/route.ts): http routes · HTTP presentation boundary for mooc courses and users · `01-outbox/3-outbox_pattern/src/app/api/mooc/courses/route.ts`
- [User registrar](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/mooc/users/application/registrar/UserRegistrar.ts): application use case · Creates and persists users, emitting registration events · `01-outbox/3-outbox_pattern/src/contexts/mooc/users/application/registrar/UserRegistrar.ts`
- [Course queries](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/mooc/courses/application/search/CourseSearcher.ts): application use cases · Course search and find use cases · `01-outbox/3-outbox_pattern/src/contexts/mooc/courses/application/search/CourseSearcher.ts`
- [User model](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/mooc/users/domain/User.ts): domain aggregate · User aggregate, value objects, and UserRegistered event · `01-outbox/3-outbox_pattern/src/contexts/mooc/users/domain/User.ts`
- [Course model](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/mooc/courses/domain/Course.ts): domain aggregate · Course aggregate and repository contract · `01-outbox/3-outbox_pattern/src/contexts/mooc/courses/domain/Course.ts`
- [Shop context](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shop/shop-user/domain/ShopUser.ts): bounded context · Independent shop domain with products, reviews, and mirrored users · `01-outbox/3-outbox_pattern/src/contexts/shop/shop-user/domain/ShopUser.ts`
- [Products](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shop/products/domain/Product.ts): application+domain · Product catalog search and persistence · `01-outbox/3-outbox_pattern/src/contexts/shop/products/domain/Product.ts`
- [Reviews](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shop/product-reviews/domain/ProductReview.ts): application+domain · Product review creation and search · `01-outbox/3-outbox_pattern/src/contexts/shop/product-reviews/domain/ProductReview.ts`
- [Shop users](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shop/shop-user/application/register-on-user-registered/RegisterShopUserOnUserRegistered.ts): subscriber model · Shop-side user mirror and event-driven registration · `01-outbox/3-outbox_pattern/src/contexts/shop/shop-user/application/register-on-user-registered/RegisterShopUserOnUserRegistered.ts`
- [Retention context](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/retention/retention-user/domain/RetentionUser.ts): bounded context · Email and retention projections reacting to user events · `01-outbox/3-outbox_pattern/src/contexts/retention/retention-user/domain/RetentionUser.ts`
- [Welcome email](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/retention/email/application/send-welcome-email/SendWelcomeEmailOnUserRegistered.ts): subscriber · Builds and sends welcome email on user registration · `01-outbox/3-outbox_pattern/src/contexts/retention/email/application/send-welcome-email/SendWelcomeEmailOnUserRegistered.ts`
- [Retention user](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/retention/retention-user/application/update-last-activity-date/UpdateLastActivityDateOnUserUpdated.ts): projection updater · Updates local retention user activity data · `01-outbox/3-outbox_pattern/src/contexts/retention/retention-user/application/update-last-activity-date/UpdateLastActivityDateOnUserUpdated.ts`
- [Shared kernel](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shared/domain/AggregateRoot.ts): shared platform · Base domain types, events, HTTP helpers, DI, and Postgres plumbing · `01-outbox/3-outbox_pattern/src/contexts/shared/domain/AggregateRoot.ts`
- [Outbox bus](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shared/infrastructure/domain-event/PostgresOutboxEventBus.ts): infra event bus · Durable Postgres outbox and RabbitMQ event delivery · `01-outbox/3-outbox_pattern/src/contexts/shared/infrastructure/domain-event/PostgresOutboxEventBus.ts`
- [RabbitMQ](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shared/infrastructure/domain-event/rabbitmq/RabbitMqEventBus.ts): async bus · Cross-context integration bus used by subscribers and scripts · `01-outbox/3-outbox_pattern/src/contexts/shared/infrastructure/domain-event/rabbitmq/RabbitMqEventBus.ts`
- [Postgres](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/01-outbox/3-outbox_pattern/src/contexts/shared/infrastructure/postgres/PostgresConnection.ts): persistence · Context-isolated database schemas and repository storage · `01-outbox/3-outbox_pattern/src/contexts/shared/infrastructure/postgres/PostgresConnection.ts`

### 02-inbox

Inbox-pattern sample app

- [Next app](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/app/layout.tsx): runtime · Next.js frontend, API routes, and scripts for the inbox variant · `02-inbox/2-inbox_pattern/src/app/layout.tsx`
- [MOOC API](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/app/api/mooc/courses/route.ts): http routes · HTTP presentation boundary for mooc courses and users · `02-inbox/2-inbox_pattern/src/app/api/mooc/courses/route.ts`
- [User registrar](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/mooc/users/application/registrar/UserRegistrar.ts): application use case · Creates and persists users, emitting registration events · `02-inbox/2-inbox_pattern/src/contexts/mooc/users/application/registrar/UserRegistrar.ts`
- [Retention context](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/retention/retention-user/domain/RetentionUser.ts): bounded context · Email, retention projection, and durable consumer-side counters · `02-inbox/2-inbox_pattern/src/contexts/retention/retention-user/domain/RetentionUser.ts`
- [Total users](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/retention/total-registered-users/application/increment/IncrementTotalRegisteredUsersOnUserRegistered.ts): projection · Durable count of registered users from consumed events · `02-inbox/2-inbox_pattern/src/contexts/retention/total-registered-users/application/increment/IncrementTotalRegisteredUsersOnUserRegistered.ts`
- [Welcome email](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/retention/email/application/send-welcome-email/SendWelcomeEmailOnUserRegistered.ts): subscriber · Builds and sends welcome email on user registration · `02-inbox/2-inbox_pattern/src/contexts/retention/email/application/send-welcome-email/SendWelcomeEmailOnUserRegistered.ts`
- [Shop users](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/shop/shop-user/application/register-on-user-registered/RegisterShopUserOnUserRegistered.ts): subscriber model · Shop-side user mirror and event-driven registration · `02-inbox/2-inbox_pattern/src/contexts/shop/shop-user/application/register-on-user-registered/RegisterShopUserOnUserRegistered.ts`
- [Shared kernel](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/shared/domain/AggregateRoot.ts): shared platform · Base domain types, events, HTTP helpers, DI, and Postgres plumbing · `02-inbox/2-inbox_pattern/src/contexts/shared/domain/AggregateRoot.ts`
- [RabbitMQ](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/shared/infrastructure/domain-event/rabbitmq/RabbitMqEventBus.ts): async bus · Cross-context integration bus used by subscribers and scripts · `02-inbox/2-inbox_pattern/src/contexts/shared/infrastructure/domain-event/rabbitmq/RabbitMqEventBus.ts`
- [Postgres](https://github.com/codelytv/inbox_outbox_pattern-course/blob/main/02-inbox/2-inbox_pattern/src/contexts/shared/infrastructure/postgres/PostgresConnection.ts): persistence · Context-isolated database schemas and repository storage · `02-inbox/2-inbox_pattern/src/contexts/shared/infrastructure/postgres/PostgresConnection.ts`

## Connections

- Next app → MOOC API: serves · App exposes HTTP routes for mooc operations
- MOOC API → User registrar: calls · Route handlers delegate to user use cases
- MOOC API → Course queries: calls · Route handlers delegate to course use cases
- User registrar → User model: creates · Registrar builds aggregate and emits domain event
- Course queries → Course model: reads · Course use cases work through the course model
- User registrar → Outbox bus: publishes · Domain events are stored durably in the outbox
- Outbox bus → RabbitMQ: delivers · Separate publisher forwards outbox events to RabbitMQ
- RabbitMQ → Shop users: consumes · Shop user subscriber reacts to UserRegistered
- RabbitMQ → Welcome email: consumes · Retention email subscriber reacts to UserRegistered
- RabbitMQ → Retention user: consumes · Retention projection subscriber reacts to user updates
- Shop users → Shop context: updates · Mirrors registered users into shop-local model
- Welcome email → Retention context: uses · Email use case belongs to retention bounded context
- Retention user → Retention context: updates · Retains local activity projection
- Shop context → Products: contains · Shop product subdomain
- Shop context → Reviews: contains · Shop product review subdomain
- Shop context → Shop users: contains · Shop user mirror subdomain
- Shared kernel → Outbox bus: supports · Shared event abstractions back the outbox bus
- Shared kernel → Postgres: supports · Shared persistence helpers back repositories
- Next app → MOOC API: serves · App exposes HTTP routes for mooc operations
- MOOC API → User registrar: calls · Route handlers delegate to user use cases
- User registrar → RabbitMQ: publishes · Events go directly to RabbitMQ in inbox variant
- RabbitMQ → Welcome email: consumes · Email subscriber reacts to UserRegistered
- RabbitMQ → Shop users: consumes · Shop user subscriber reacts to UserRegistered
- RabbitMQ → Total users: consumes · Durable projection increments on UserRegistered
- Welcome email → Retention context: uses · Email use case belongs to retention bounded context
- Total users → Retention context: updates · Projection stored in retention context
- Shop users → Postgres: persists · Shop user mirror stored in local database
- Shared kernel → RabbitMQ: supports · Shared event abstractions back RabbitMQ integration
- Shared kernel → Postgres: supports · Shared persistence helpers back repositories
