# jgmelon22/hellosqs architecture

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

- Interactive diagram: https://gitdiagram.com/jgmelon22/hellosqs
- Repository: https://github.com/jgmelon22/hellosqs

## Overview

1. **Repository shape**
   - This is a .NET solution split into a small set of clear boundaries: `AmazonSQS.Core`, `AmazonSQS.Infrastructure`, `Producer.API`, `Consumer.API`, and unit tests.
   - The design is aligned with Clean Architecture: shared domain types in Core, queue and worker logic in Infrastructure, and the executable hosts in the two API projects.

2. **Core domain layer**
   - `AmazonSQS.Core` holds the message contract and domain model used across the system.
   - It contains request/response DTOs for an `OrderCreatedEvent`, the `OrderCreatedEvent` entity itself, and mapping extensions that convert between transport shapes and domain shapes.
   - This layer has no direct SQS or hosting dependencies.

3. **Infrastructure layer**
   - `AmazonSQS.Infrastructure` contains the implementation details for talking to SQS and processing messages.
   - It defines service contracts such as `IOrderService` and `ISqsMessagePublisher`, then provides concrete implementations in `OrderService` and `SqsMessagePublisher`.
   - It also includes `SqsOptions` for configuration-driven setup, which is important because queue URL / service endpoint are not hardcoded.

4. **Producer side**
   - `Producer.API` is the ingress boundary for creating and publishing order events.
   - `OrdersController` is the public HTTP entry point; it likely accepts an order creation request, transforms it via the shared mappings, and delegates to the publishing service.
   - `GlobalExceptionHandler` centralizes API error handling, so request failures are normalized before leaving the host.

5. **Consumer side**
   - `Consumer.API` is the runtime host for the queue consumer.
   - The presence of `Program.cs` and no controller layer suggests this project is primarily a background-processing host rather than a request/response API.
   - It wires up the background service that listens to SQS and drives downstream processing.

6. **Message flow**
   - The main data flow is: HTTP request enters `Producer.API` → mapped into the shared order event model → published to SQS through `ISqsMessagePublisher`.
   - The consumer host then polls the queue via `OrderCreatedEventConsumer` → deserializes / maps the message → invokes `IOrderService` → on success the message is removed, and on failure it is left for retry by the queue.

7. **External messaging boundary**
   - Amazon SQS is the central integration point between producer and consumer.
   - During local development, ElasticMQ simulates SQS, so the architecture can be exercised without AWS infrastructure.
   - The queue endpoint is configured through app settings, making the same code runnable against local ElasticMQ or real AWS SQS.

8. **Configuration boundary**
   - The `appsettings.json` files in both hosts are part of the runtime contract, especially for AWS region, service URL, and queue URL.
   - `SqsOptions` indicates the project uses the .NET Options pattern rather than hardcoding infrastructure settings.

9. **Testing boundary**
   - Unit tests live under `tests/UnitTests/AmazonSQS.Infrastructure.UnitTests`.
   - Tests focus on infrastructure behavior, especially `OrderServiceTests`, and use NUnit plus NSubstitute to isolate dependencies.
   - This means the test suite is validating business-processing logic without requiring live SQS.

10. **Important architectural takeaway**
   - The repo is not a monolithic app; it is a producer-consumer system with two separately hosted runtimes communicating asynchronously through SQS.
   - Core owns the message shape, Infrastructure owns queue/processing mechanics, and the two API projects are the composition roots that wire everything together.

Main entry points: [`src/AmazonSQS.Core/Domains/Mappings/MappingExtensions.cs`](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Core/Domains/Mappings/MappingExtensions.cs) (Mappings), [`src/AmazonSQS.Infrastructure/BackgroundServices/OrderCreatedEventConsumer.cs`](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/BackgroundServices/OrderCreatedEventConsumer.cs) (Order Consumer), [`src/Producer.API/Controllers/OrdersController.cs`](https://github.com/jgmelon22/hellosqs/blob/main/src/Producer.API/Controllers/OrdersController.cs) (OrdersController), [`src/AmazonSQS.Infrastructure/Services/OrderService.cs`](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/Services/OrderService.cs) (Order Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core"]
  node_core_event["Order Event<br/>domain entity"]
  node_core_request["Event Request<br/>dto"]
  node_core_response["Event Response<br/>dto"]
  node_mapping_extensions{{"Mappings<br/>mapping extensions"}}
end

subgraph group_infrastructure["Infrastructure"]
  node_order_consumer["Order Consumer<br/>background service"]
  node_sqs_publisher[("SQS Publisher")]
  node_order_service["Order Service<br/>[OrderService.cs]"]
  node_sqs_options["SqsOptions<br/>config model<br/>[SqsOptions.cs]"]
  node_iorder_service["IOrderService<br/>service contract<br/>[IOrderService.cs]"]
  node_isqs_publisher["ISqsMessagePublisher<br/>service contract"]
end

subgraph group_producer["Producer API"]
  node_producer_api["Producer.API<br/>host<br/>[Producer.API]"]
  node_orders_controller["OrdersController<br/>http entry"]
  node_global_exception_handler{{"Exception Handler<br/>middleware"}}
end

subgraph group_consumer["Consumer API"]
  node_consumer_api["Consumer.API<br/>host<br/>[Consumer.API]"]
  node_consumer_program["Program.cs<br/>composition root<br/>[Program.cs]"]
end

subgraph group_tests["Tests"]
  node_infra_tests["OrderServiceTests<br/>unit tests"]
end

node_producer_api -->|"hosts"| node_orders_controller
node_producer_api -->|"uses"| node_global_exception_handler
node_orders_controller -->|"maps via"| node_mapping_extensions
node_orders_controller -->|"publishes via"| node_isqs_publisher
node_mapping_extensions -->|"from"| node_core_request
node_mapping_extensions -->|"to"| node_core_event
node_mapping_extensions -->|"to"| node_core_response
node_isqs_publisher -->|"implemented by"| node_sqs_publisher
node_consumer_api -->|"starts with"| node_consumer_program
node_consumer_program -->|"registers"| node_order_consumer
node_order_consumer -->|"reads config"| node_sqs_options
node_order_consumer -->|"consumes"| node_core_event
node_order_consumer -->|"invokes"| node_iorder_service
node_iorder_service -->|"implemented by"| node_order_service
node_order_service -->|"processes"| node_core_event
node_sqs_publisher -->|"reads config"| node_sqs_options
node_infra_tests -.->|"verifies"| node_order_service

click node_producer_api "https://github.com/jgmelon22/hellosqs/blob/main/src/Producer.API"
click node_orders_controller "https://github.com/jgmelon22/hellosqs/blob/main/src/Producer.API/Controllers/OrdersController.cs"
click node_global_exception_handler "https://github.com/jgmelon22/hellosqs/blob/main/src/Producer.API/Middlewares/GlobalExceptionHandler.cs"
click node_consumer_api "https://github.com/jgmelon22/hellosqs/blob/main/src/Consumer.API"
click node_consumer_program "https://github.com/jgmelon22/hellosqs/blob/main/src/Consumer.API/Program.cs"
click node_order_consumer "https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/BackgroundServices/OrderCreatedEventConsumer.cs"
click node_sqs_publisher "https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/Services/SqsMessagePublisher.cs"
click node_order_service "https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/Services/OrderService.cs"
click node_sqs_options "https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/Configuration/SqsOptions.cs"
click node_iorder_service "https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/Interfaces/Services/IOrderService.cs"
click node_isqs_publisher "https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/Interfaces/Services/ISqsMessagePublisher.cs"
click node_core_event "https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Core/Domains/Entities/OrderCreatedEvent.cs"
click node_core_request "https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Core/Domains/DTOs/Requests/OrderCreatedEventRequest.cs"
click node_core_response "https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Core/Domains/DTOs/Responses/OrderCreatedEventResponse.cs"
click node_mapping_extensions "https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Core/Domains/Mappings/MappingExtensions.cs"
click node_infra_tests "https://github.com/jgmelon22/hellosqs/blob/main/tests/UnitTests/AmazonSQS.Infrastructure.UnitTests/Services/OrderServiceTests.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_core_event,node_core_request,node_core_response,node_mapping_extensions toneBlue
class node_order_consumer,node_sqs_publisher,node_order_service,node_sqs_options,node_iorder_service,node_isqs_publisher toneAmber
class node_producer_api,node_orders_controller,node_global_exception_handler toneMint
class node_consumer_api,node_consumer_program toneRose
class node_infra_tests toneIndigo
```

## Components

### Core

Shared message contracts and domain mapping.

- [Order Event](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Core/Domains/Entities/OrderCreatedEvent.cs): domain entity · Shared order-created event model. · `src/AmazonSQS.Core/Domains/Entities/OrderCreatedEvent.cs`
- [Event Request](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Core/Domains/DTOs/Requests/OrderCreatedEventRequest.cs): dto · Transport shape for creating an order-created event. · `src/AmazonSQS.Core/Domains/DTOs/Requests/OrderCreatedEventRequest.cs`
- [Event Response](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Core/Domains/DTOs/Responses/OrderCreatedEventResponse.cs): dto · Transport shape returned after event creation. · `src/AmazonSQS.Core/Domains/DTOs/Responses/OrderCreatedEventResponse.cs`
- [Mappings](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Core/Domains/Mappings/MappingExtensions.cs): mapping extensions · Converts between DTOs and the shared domain event. · `src/AmazonSQS.Core/Domains/Mappings/MappingExtensions.cs`

### Infrastructure

Queue integration, processing services, and background consumption.

- [Order Consumer](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/BackgroundServices/OrderCreatedEventConsumer.cs): background service · Polls SQS and dispatches incoming order events. · `src/AmazonSQS.Infrastructure/BackgroundServices/OrderCreatedEventConsumer.cs`
- [SQS Publisher](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/Services/SqsMessagePublisher.cs): service · Publishes order events to SQS. · `src/AmazonSQS.Infrastructure/Services/SqsMessagePublisher.cs`
- [Order Service](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/Services/OrderService.cs): service · Processes consumed order events. · `src/AmazonSQS.Infrastructure/Services/OrderService.cs`
- [SqsOptions](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/Configuration/SqsOptions.cs): config model · Options-backed configuration for queue and endpoint settings. · `src/AmazonSQS.Infrastructure/Configuration/SqsOptions.cs`
- [IOrderService](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/Interfaces/Services/IOrderService.cs): service contract · Abstraction for downstream order processing. · `src/AmazonSQS.Infrastructure/Interfaces/Services/IOrderService.cs`
- [ISqsMessagePublisher](https://github.com/jgmelon22/hellosqs/blob/main/src/AmazonSQS.Infrastructure/Interfaces/Services/ISqsMessagePublisher.cs): service contract · Abstraction for sending messages to SQS. · `src/AmazonSQS.Infrastructure/Interfaces/Services/ISqsMessagePublisher.cs`

### Producer API

HTTP ingress for creating and publishing order events.

- [Producer.API](https://github.com/jgmelon22/hellosqs/blob/main/src/Producer.API): host · HTTP composition root for publishing orders. · `src/Producer.API`
- [OrdersController](https://github.com/jgmelon22/hellosqs/blob/main/src/Producer.API/Controllers/OrdersController.cs): http entry · Accepts order creation requests and starts the publish flow. · `src/Producer.API/Controllers/OrdersController.cs`
- [Exception Handler](https://github.com/jgmelon22/hellosqs/blob/main/src/Producer.API/Middlewares/GlobalExceptionHandler.cs): middleware · Normalizes API errors before responses leave the host. · `src/Producer.API/Middlewares/GlobalExceptionHandler.cs`

### Consumer API

Host for queue-driven background processing.

- [Consumer.API](https://github.com/jgmelon22/hellosqs/blob/main/src/Consumer.API): host · Background-processing composition root for queue consumption. · `src/Consumer.API`
- [Program.cs](https://github.com/jgmelon22/hellosqs/blob/main/src/Consumer.API/Program.cs): composition root · Wires up the consumer host and hosted services. · `src/Consumer.API/Program.cs`

### Tests

Unit tests for infrastructure behavior.

- [OrderServiceTests](https://github.com/jgmelon22/hellosqs/blob/main/tests/UnitTests/AmazonSQS.Infrastructure.UnitTests/Services/OrderServiceTests.cs): unit tests · Validates infrastructure processing behavior without live SQS. · `tests/UnitTests/AmazonSQS.Infrastructure.UnitTests/Services/OrderServiceTests.cs`

## Connections

- Producer.API → OrdersController: hosts · Exposes the HTTP entry point for order creation.
- Producer.API → Exception Handler: uses · Registers centralized error handling.
- OrdersController → Mappings: maps via · Transforms inbound requests into shared event shapes.
- OrdersController → ISqsMessagePublisher: publishes via · Delegates outbound message delivery to the queue publisher abstraction.
- Mappings → Event Request: from · Converts request DTOs.
- Mappings → Order Event: to · Produces the shared domain event.
- Mappings → Event Response: to · Creates response DTOs from event data.
- ISqsMessagePublisher → SQS Publisher: implemented by · Concrete SQS publisher lives in infrastructure.
- Consumer.API → Program.cs: starts with · Composition root for the consumer host.
- Program.cs → Order Consumer: registers · Wires the background consumer into the host.
- Order Consumer → SqsOptions: reads config · Uses options for queue and endpoint settings.
- Order Consumer → Order Event: consumes · Deserializes the shared order event message.
- Order Consumer → IOrderService: invokes · Hands off messages for downstream processing.
- IOrderService → Order Service: implemented by · Concrete order processing service.
- Order Service → Order Event: processes · Operates on the shared event model.
- SQS Publisher → SqsOptions: reads config · Uses endpoint and queue settings from options.
- OrderServiceTests → Order Service: verifies · Exercises processing logic with substitutes.
