Onion architecture
Architectural Patterns

Meaning

A software architecture pattern where concerns are organized in concentric layers, with the core domain at the center and outer layers depending only on inner layers, promoting separation of concerns and independence of concerns.

Primary Function

Provides a structural guideline for organizing codebases so that business logic remains independent of external concerns such as UI, databases, and frameworks.

Communicative Purpose

To communicate a layered architectural approach that enforces dependency direction toward the core domain, facilitating maintainability and testability.

Pattern

Concentric layers: Infrastructure → Application Core → Domain Entities (inner) → Interfaces → Frameworks/Drivers (outer).

Core Structure

Entities → Use Cases → Interface Adapters → Frameworks & Drivers.

Função primária

Provides a structural guideline for organizing codebases so that business logic remains independent of external concerns such as UI, databases, and frameworks.

Propósito comunicativo

To communicate a layered architectural approach that enforces dependency direction toward the core domain, facilitating maintainability and testability.

Situações de gatilho

When designing a new software system or refactoring an existing one to achieve loose coupling, testability, and independence from frameworks or infrastructure concerns.

Contextos

Software architecture discussions, layered architecture discussions, domain-driven design, clean architecture conversations, enterprise application design.

Padrão

Concentric layers: Infrastructure → Application Core → Domain Entities (inner) → Interfaces → Frameworks/Drivers (outer).

Estrutura central

Entities → Use Cases → Interface Adapters → Frameworks & Drivers.

Colocados típicos

  • clean architecture
  • hexagonal architecture
  • ports and adapters
  • domain-driven design
  • separation of concerns
  • dependency inversion

Substituições comuns

  • clean architecture
  • hexagonal architecture
  • ports and adapters

Erros comuns

Allowing outer layers to reference inner layers incorrectly, leaking domain entities to outer layers, letting infrastructure concerns leak into domain layer.

Similar / contraste

Layered architecture (traditional layered), MVC, MVVM, traditional 3-layer architecture

Interferências

Confusing onion architecture with traditional layered architecture where dependencies flow inward and outward; mixing concerns across layers.

Família do chunk

  • Software architecture patterns
  • Layered architecture
  • Domain-driven design

Nuance

Emphasizes dependency rule: inner layers cannot know about outer layers; all dependencies point inward.

Efeito pragmático

Encourages teams to think about boundaries and maintainability, leading to more adaptable and testable codebases.

Dica de memória

Think of an onion: core at the center, layers wrapping outward, each depending only on the layer beneath.

Nota

Often used interchangeably with clean architecture and hexagonal architecture, though subtle differences exist.

Upgrade path

Clean architecture / Hexagonal architecture

Frequência: HighFormulaicidade: FixedTipo de construção: conceptualPrioridade de aquisição: Active recallPrioridade de output: BothTag de espaçamento: Medium-term

Log in to save chunks.