---
url: /core/application.md
description: >-
  The application layer in Domain-Driven Design with TypeScript: command and
  query handlers that run use cases atomically and reliably.
---

# Application

The application runs the use cases: one handler per request, which calls the domain and makes the
change atomic and reliable. It lives in `application/`; the adapters of its contracts live in
`driven/`.

## Why

A controller that loads an order, checks it, saves it and sends an email mixes HTTP, rules and
storage. A second entry point, a consumer or a CLI, copies it. If the email leaves before the save
fails, the customer is told about an order that does not exist.

::: tip The fix
Each use case is one handler that only coordinates: load, call the domain, save, hand over the
events. The save and the events commit together, and the events are sent after.
:::

## How a request flows

## The building blocks

| Building block | What it is | Use it when |
| --- | --- | --- |
| [Command handlers](./command-handlers.md) | The application service of one use case that changes the system. | A request changes state: create, place, cancel. |
| [Query handlers](./query-handlers.md) | The application service of one read. | A request only reads. |
| [Event translators](./event-translators.md) | Turns domain events into integration events. | Other contexts must hear about a change. |
| [Integration events](./integration-events.md) | What other contexts receive when something happens: JSON. | You define what leaves your context. |
| [Event publishers](./event-publishers.md) | Sends integration events to the rest of the system. | You plug in a broker, or deliver in process. |
| [Unit of Work](./unit-of-work.md) | Makes a use case atomic: commit on success, roll back otherwise. | A use case writes more than once, or writes and records events. |
| [Outbox](./outbox.md) | Stores integration events with the change, then relays them, so none is lost. | Events must not be lost nor sent for a change that failed. |

## See also

* [Domain](../domain/index.md), what the handlers call
* [Strategic](../strategic/index.md), how contexts meet
* Rules: [`layers/no-outward-import`](../../rules/layers/no-outward-import.md), [`tactical/no-mixed-handler`](../../rules/tactical/no-mixed-handler.md)
