How jgmelon22/hellosqs works
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: MappingExtensions.cs Mappings · OrderCreatedEventConsumer.cs Order Consumer · OrdersController.cs OrdersController · OrderService.cs Order Service
Components 16
Core
Shared message contracts and domain mapping.
- Order Event · Shared order-created event model.
src/AmazonSQS.Core/Domains/Entities/OrderCreatedEvent.cs - Event Request · Transport shape for creating an order-created event.
src/AmazonSQS.Core/Domains/DTOs/Requests/OrderCreatedEventRequest.cs - Event Response · Transport shape returned after event creation.
src/AmazonSQS.Core/Domains/DTOs/Responses/OrderCreatedEventResponse.cs - Mappings · 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 · Polls SQS and dispatches incoming order events.
src/AmazonSQS.Infrastructure/BackgroundServices/OrderCreatedEventConsumer.cs - SQS Publisher · Publishes order events to SQS.
src/AmazonSQS.Infrastructure/Services/SqsMessagePublisher.cs - Order Service · Processes consumed order events.
src/AmazonSQS.Infrastructure/Services/OrderService.cs - SqsOptions · Options-backed configuration for queue and endpoint settings.
src/AmazonSQS.Infrastructure/Configuration/SqsOptions.cs - IOrderService · Abstraction for downstream order processing.
src/AmazonSQS.Infrastructure/Interfaces/Services/IOrderService.cs - ISqsMessagePublisher · 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 · HTTP composition root for publishing orders.
src/Producer.API - OrdersController · Accepts order creation requests and starts the publish flow.
src/Producer.API/Controllers/OrdersController.cs - Exception Handler · Normalizes API errors before responses leave the host.
src/Producer.API/Middlewares/GlobalExceptionHandler.cs
Consumer API
Host for queue-driven background processing.
- Consumer.API · Background-processing composition root for queue consumption.
src/Consumer.API - Program.cs · Wires up the consumer host and hosted services.
src/Consumer.API/Program.cs
Tests
Unit tests for infrastructure behavior.
- OrderServiceTests · Validates infrastructure processing behavior without live SQS.
tests/UnitTests/AmazonSQS.Infrastructure.UnitTests/Services/OrderServiceTests.cs
Connections 17
- 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.