2 min readCalm pace · scan the outline anytime

Where does this code go?

Quick placement reference for Modular Hexagonal DDD — Core paths by scenario.

Where does this code go?

Use this table when you are unsure which folder owns a change. Paths below are Core roles; host folder names vary by adapter — see Adapters. For fair multi-host examples of persistence / composition / UI / async, open those concept pages (they list every documented host, not one favorite).

ScenarioCore location
Database schema / migrationsModule Infrastructure/Persistence/…
Application input DTOApplication/DTO/{Capability}/
Intra-module Domain DTODomain/DTO/
Pure business rules (Entities)Domain/Entities/
Persistence / I/O contractsDomain/Ports/{Capability}/
Process orchestrationApplication/UseCases/{Capability}/
Persistence adapterInfrastructure/Persistence/…
External / peer integrationInfrastructure/ExternalServices/ (ACL adapters, HTTP clients)
Tech adapter used by one moduleThat module’s Infrastructure (+ local port if needed)
Same tech port used by ≥2 modulesPromote to Shared kernel
Cross-module data needed nowConsumer local port + ACL adapter → thin peer *ModuleInterface
Cross-module side effect laterPublisher Domain Event → consumer translation listener → inbound Use Case
Multi-step cross-module flowOrchestration Use Case or Infra process manager (ACL + Events only)
Cross-context report / listOwned projection or ACL read — not ORM join across modules
Processed eventId storeConsumer Infrastructure
Cross-module business types in SharedForbidden — use ACL / Events

Decision shortcuts

QuestionAnswer
Is it a business invariant?Domain Entity / Domain service
Is it orchestration of a user intention?First-level *UseCase
Does it talk to DB / HTTP / peer?Port in Domain, adapter in Infrastructure
Does UI need to call it?Only first-level Use Cases
Do two modules need the same tech helper?Promote to Shared
Do two modules need the same business concept?ACL or Events — never Shared

Design test

If the peer module is deleted and replaced by HTTP, does Application/Domain still compile?

If you are placing a use statement and the test would fail, you are in the wrong layer — see Anti-patterns and the Decision tree.

Modular Hexagonal Domain-Driven Design
Core 1.0.0-draft