The infrastructure layer handles the technical “how” outside an application’s core business logic: storing data, sending email, calling third-party APIs, and communicating with message queues. Keeping those details apart from business rules helps the domain stay independent of how information is stored or communicated. section 4.2.3 section 4.7.4
Think of the application layer as the coordinator and infrastructure components as specialists. A database repository and an email client can sit side by side; sending an email does not require passing through the database layer. If the specialists need to work together, the application layer coordinates them. section 4.2.3 section 4.4.1
Infrastructure can provide concrete implementations of interfaces defined by the domain or application layer. For example, the core can define an event-publisher interface while an infrastructure adapter handles the connection to a message broker. The core need not depend directly on a database context, HTTP client, or broker implementation. section 4.2.3 section 7.5.4 section 13.4.2
Place the “how” code
In a folder-based project, database code can live in repositories/widgetRepository.js and email code in lib/emailClient.js. The domain folder holds business logic, while services coordinate use cases. This separation makes the responsibilities visible without making the repository and email client depend on each other. section 4.4.1
Interfaces also support replaceability: a mock repository can be swapped for a SQL-backed implementation without the application layer needing to know the storage details. The boundary needs protection, though; shortcuts that put database or email code into core logic can blur it again. section 4.8.3 section 4.7.4
Listing 13.1 C# Architectural Boundary Enforcement using NetArchTest
[Fact]
public void DomainLayer_ShouldNot_DependOn_InfrastructureLayer()
{
// Arrange: Define the architectural assemblies
var types = Types.InAssembly(typeof(Domain.Order).Assembly);
// Act: Assert that the domain layer does not reference infrastructure
var result = types
.That()
.ResideInNamespace("ShopZilla.OrderService.Domain")
.ShouldNot()
.HaveDependencyOn("ShopZilla.OrderService.Infrastructure")
.GetResult();
// Assert: The pipeline will crash if any file violates this boundary
Assert.True(result.IsSuccessful,
"Data Isolation Error: Core Domain cannot depend on Infrastructure!");
}
[Fact]
public void Controllers_Should_Be_SuffixMatchedAndResideInPresentation()
{
var types = Types.InAssembly(
typeof(Presentation.OrderController).Assembly);
var result = types
.That()
.Inherit(typeof(BaseController))
.Should()
.HaveNameEndingWith("Controller")
.And()
.ResideInNamespace("ShopZilla.OrderService.Presentation")
.GetResult();
Assert.True(result.IsSuccessful, "Convention Error:
Presentation controllers must have a 'Controller' suffix.");
}This architectural test checks that domain types do not depend on the infrastructure namespace. Running it in a CI pipeline turns a boundary violation into a build failure. section 13.4.2
A practical check: draw the presentation, application, domain, and infrastructure layers, then place at least two components in each. For each one, ask whether it handles a business “why” or an external technical “how.” section 4.9.2


