liveBook · Manning

Infrastructure layer

As explained in Grokking Software Architecture

The architectural layer that implements external technical concerns such as persistence, messaging, and third-party communication.

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

How Grokking Software Architecture covers it

How deep it goes
Explains responsibilities, component placement, interface-based replacement, and automated boundary checks.
Examples
Uses a database repository, email client, event publisher, and architectural boundary test as concrete examples.
What you can do after
Evaluate component placement and enforce domain isolation with NetArchTest.
How it connects
Connects layered architecture with separation of concerns, dependency inversion, domain isolation, and event-driven architecture.

Also explained in

Compare how 3 books explain infrastructure layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.