Onion Architecture (Jeffrey Palermo, 2008): concentric rings with domain model at center, surrounded by domain services, application services, infrastructure outside. Dependencies only inward. Pre-cursor to Clean Architecture, sister pattern to Hexagonal.
Palermo’s Onion Architecture controls coupling: code may depend on layers closer to the center, not farther out. Domain Model combines state and behavior; repository interfaces belong in the application core while implementations and database live outside. Это подходит прежде всего long-lived systems with complex behavior, а не универсальная обязанность для каждого маленького CRUD-сайта.
| Компонент | Ответственность |
|---|---|
| Web Delivery Adapter | Переводит transport request в application command. |
| Application Service Ring | Оркестрирует use case, transaction и external ports. |
| Behavior-Rich Domain Model | Содержит state и business behavior/invariants в центре. |
| Core Repository Interface | Core-owned contract сохранения/получения domain model. |
| Core Payment Interface | Core-owned semantic contract внешнего payment operation. |
| Postgres Infrastructure Adapter | Реализует repository interface и mapping/transactions. |
| Payment Infrastructure Adapter | Реализует payment port, idempotency и status reconciliation. |
| Composition Root | Связывает concrete implementations с interfaces вне domain core. |
Delivery maps request data, application service loads state through the repository interface and asks the domain object to enforce its invariant.
Проверяемый исход: Business behavior remains in the domain center rather than becoming a procedural service-layer script.
Application code names a repository interface defined toward the center. The outside Postgres adapter translates it into SQL/transaction behavior.
Проверяемый исход: Domain and application assemblies do not import database framework types.
Application service creates a stable operation identity and invokes the payment interface. Concrete provider adapter maps provider status and timeout to semantic outcomes.
Проверяемый исход: The core never calls a concrete SDK and never treats timeout as definite failure.
Composition root injects a candidate only after repository/payment contract tests and migration/reconciliation plans pass.
Проверяемый исход: Dependency inversion enables substitution points but does not assert semantic equivalence.
Числа здесь — размерностные формулы или явно помеченные учебные inputs. Паттерн архитектуры сам по себе не задаёт SLA, throughput, latency или fault tolerance.
[CONCEPT]hexagonal-ports-adapters
Onion Architecture controls code coupling. Injection does not itself provide retries, durable state, authorization, migration compatibility, provider idempotency or availability.
Введите числа или выберите пресет