Domain Driven Design project structure

Application

Retrieves domain entities that have been persisted, performs actions on them, and persists the changes.

Handles both commands and queries.

Domain

The "pure" implementation of the domain: entities/models, exceptions, constants, etc. The domain logic should live here because you should avoid anemic domain models, but persistence is not a concern of the domain.

more info is needed

Infrastructure

Responsible for connecting the domain with the outside world:

Domain edges

How communication occurs between the domain and the rest of the world. Each of these should be their own process that runs independently.

Database migrator

The process that performs database migrations (database migrations should occur independently in pipelines).

Service

The HTTP API, receiving requests from users, other services, etc. Communicates with the domain exclusively through the Application (via queries and commands due to CQRS).

are Entity Framework contexts a sufficient repository? is having queries in the application unnecessary duplication?

Event Listener

Listens to a Message broker and updates data projections based on events dispatched from other domains.

If you also have topics for commands, they should be their own project because commands are not the same as events.

Command Listener

Listens to a Message broker and performs commands on the domain.

commands are not the same as events.

Event Dispatcher

This may be an implementation detail, but allows for separation of concerns with the other edges.

Uses the outbox pattern to produce events to a Message broker.

graph TD
Application
Domain
Infrastructure
Service
Listener[Event Listener]
Dispatcher[Event Dispatcher]
Broker[Message Broker]
Database[(database)]
HTTP[HTTP requests]

Broker--consumes events-->Listener
Dispatcher--produces events-->Broker
HTTP-->Service

subgraph domain
Service-->Application
Listener-->Application
Application-->Domain
Application--persists domain-->Infrastructure
Infrastructure-->Database
Database-->Infrastructure
Database-->Dispatcher
end