Skip to content

Guide · Open source

How to use domain-driven-hexagon: a guide to DDD and hexagonal architecture

Updated · written with AI from the project's own documentation and checked against our catalogue data

domain-driven-hexagon is a reference guide, written as a README, that collects recommendations on how to structure software applications. It combines ideas from Domain-Driven Design, hexagonal, clean and onion architecture, SOLID principles and design patterns. This guide explains how to read it, which parts to focus on, and how to decide what to adopt in your own project.

Domain-Driven HexagonSairyss/domain-driven-hexagon · ★ 15k · MIT

Quick start

  1. 1Clone or open the repository. Run git clone https://github.com/Sairyss/domain-driven-hexagon to read the guide locally, or open the README on GitHub.
  2. 2Read the pros and cons. Check whether a complete architecture suits your application's size and amount of business logic.
  3. 3Study the diagram and data flow. Follow how a request moves from controller to Application service, through ports, to infrastructure and back.
  4. 4Learn the Domain layer. Read the sections on entities, aggregates, value objects and domain errors to understand where business rules belong.
  5. 5Learn ports and adapters. Read the Application layer and Infrastructure layer sections to see how interfaces separate core logic from databases and external services.
  6. 6Pick what to adopt. Adopt only the building blocks that solve a real problem in your project and skip the rest.

What is domain-driven-hexagon?

domain-driven-hexagon is an open-source project by Sairyss, published under the MIT licence. It is a guide rather than a library or framework, so there is nothing to install as a dependency. Its main emphasis is to provide recommendations on how to design software applications, gathered from different sources.

Code examples use NodeJS, TypeScript, the NestJS framework and Slonik for database access. The README says the patterns are framework and language agnostic, so the technologies can be replaced with any alternative.

  • Language of examples: TypeScript on NodeJS
  • Framework in examples: NestJS
  • Database access in examples: Slonik
  • Licence: MIT

Should you use this architecture? Read the pros and cons first

The README lists pros including independence from external frameworks and databases, easier testing, built-in security principles, and the ability for different teams to work without stepping on each other's toes. It also notes that new features stay relatively small in effort as the system grows.

The cons are just as important. The README says the architecture requires a firm understanding of SOLID, Clean/Hexagonal Architecture and Domain-Driven Design. It also says the architecture is generally ill-suited to simple CRUD applications because it adds boilerplate, abstractions and up-front complexity.

  • Good fit: applications with significant business logic and a team that understands the principles
  • Poor fit: small CRUD apps with little business logic

Understand the data flow through the layers

The README's diagram shows how a request moves through the system. A request, CLI command or event is sent to a controller using a plain DTO. The controller maps it to a Command or Query object and passes it to an Application service.

The Application service runs business logic using domain services and entities or aggregates, and reaches the infrastructure layer through ports (interfaces). The infrastructure layer maps data, reads and writes the database, and uses adapters for other I/O. Results travel back up to the controller, which returns data to the user.

  • Controller: parses the DTO and maps it to a Command or Query
  • Application service: handles the Command or Query and orchestrates logic
  • Domain layer: entities, aggregates, value objects and domain services hold business rules
  • Infrastructure layer: repositories and adapters talk to databases and external services

Use the guide's building blocks selectively

The README stresses that everything is a recommendation, not a rule. Different projects can have more or fewer layers and building blocks than described. Add more if the application needs them, and skip some if it is not complex enough.

The README suggests analysing how big and complex the application will be, finding a compromise, and using only the layers and building blocks that fit. It says that in real production applications you will most likely need only a fraction of the patterns.

  • Start with the sections that match your current problem, such as Entities, Value Objects or Repositories
  • Skip patterns that over-complicate a small project

Get the guide onto your machine

The README is meant to be read online, and the project lists no prerequisites. If you want to read it locally, clone the repository with the command below. The source does not describe any other setup steps.

git clone https://github.com/Sairyss/domain-driven-hexagon

The README's own list of related work includes the author's Backend best practices repository, which covers tools and guidelines for backend development. Other projects with overlapping ideas are Clean Architecture examples by Uncle Bob and Explicit Architecture PHP by hgraca.

Choose a companion resource based on what you need: a broader backend checklist, a different language example, or more focus on the Clean Architecture approach.

  • Clean Architecture examples by Uncle Bob
  • Explicit Architecture PHP by hgraca
  • Backend best practices by Sairyss

What people use it for

  • Learning Domain-Driven Design concepts such as entities, aggregates and value objects through TypeScript examples
  • Planning the layers of a backend with significant business logic, separating controllers, application services and infrastructure
  • Reviewing an existing backend against a checklist of design practices
  • Teaching students how ports and adapters keep core logic independent of databases and frameworks

Frequently asked questions

Is domain-driven-hexagon free to use?

Yes. The project is licensed under MIT, which the repository lists. The source does not mention any paid tier.

Do I need to install domain-driven-hexagon?

No. It is a reference guide written as a README, not a library or framework. The only command in the source is git clone https://github.com/Sairyss/domain-driven-hexagon if you want to read it locally.

What are the requirements for domain-driven-hexagon?

The source lists no prerequisites. However, the README says the approach requires a firm understanding of SOLID, Clean or Hexagonal Architecture and Domain-Driven Design to use well.

Is domain-driven-hexagon only for NestJS or TypeScript?

No. The examples use NodeJS, TypeScript, NestJS and Slonik, but the README says the patterns are framework and language agnostic. It also notes that implementations in other languages will look different.

Is domain-driven-hexagon good for small CRUD apps?

The README says no. It states that this full architecture is generally ill-suited to simple CRUD applications because it adds boilerplate, abstractions and complexity. Some principles can be used in smaller apps, but only after weighing the pros and cons.

What are alternatives to domain-driven-hexagon?

The README's related projects are Clean Architecture examples by Uncle Bob, Explicit Architecture PHP by hgraca, and the author's Backend best practices repository. These cover overlapping ideas in different depth or language.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Use domain-driven-hexagon if you want worked examples of DDD and hexagonal architecture and you are building an application with substantial business logic. Skip it for small CRUD apps or if you want a runnable starter project, since the README itself says it is a guide, not a framework.

Install options & downloads