Layered Architecture in Domain-Driven Design

date
Jun 22, 2023
slug
layered-architecture-in-domain-driven-design
status
Published
tags
domain-driven-design
software-architecture
ddd
summary
Layered Architecture in Domain-Driven Design combines the principles of DDD with a layered architecture pattern. It organizes a software system into distinct layers, each with specific responsibilities
type
Post

Separation of concerns

Developers often find it convenient to create functions that handle multiple responsibilities, including external communication, business logic, and database interaction. This approach may lead to challenges in testing and maintaining the codebase. Functions that mix these diverse concerns become tightly coupled and difficult to isolate for testing purposes. Any changes or updates to one aspect of the function may inadvertently affect other unrelated parts, causing unintended consequences.
To build applications that handle complex tasks, developers must adopt a more modular and decoupled approach, separating concerns and delegating specific tasks to dedicated functions or modules. This is where the Layered Architect concept comes in. It allows developers to create applications with easier testing, improved code readability, and better long-term maintainability
The basic idea is to structure the application into four conceptual layers, including Presentation Layer, Business Layer, Persistence Layer, and Database Layer
 
Image from Oreilly: Layered Architect pattern
Image from Oreilly: Layered Architect pattern

Layers in DDD microservices

While implementing Domain-Driven Design (DDD), the Layered Architect pattern is commonly simplified into three logical layers: the Application Layer, the Domain Layer, and the Infrastructure Layer, although there are various variants. In this specific case, the Persistence and Database Layer, following the original concept, are merged within the Infrastructure Layer.
notion image

Domain Layer

The Domain layer represents the core concepts, business rules, and constraints that are relevant to the application's functionalities. It serves as the pure heart of business software, devoid of any technological concepts

Application Layer

The Application layer consists of modules that facilitate communication with external services or other system components, enabling access to services through components like HTTP clients/servers and gRPC handlers

Infrastructure Layer

The Infrastructure Layer encompasses repository implementations that facilitate the storage of domain entity details in a database, along with other infrastructure-related components such as loggers, cryptography utilities, search engines...etc

Implementation

This is an implementation of Domain-Driven Design (DDD) in the Go programming language. For a comprehensive understanding, please refer to upcoming articles that will provide a detailed explanation
 

DDD Resources

 

© tonybka 2023 - 2025