Skip to content
Back to skills

Architecture Patterns

ASecurity

Use when selecting architecture patterns for a new feature, performing Event Modeling, defining bounded contexts, choosing DDD tactical patterns, evaluating pattern fitness, or understanding how patterns compose. Covers Event Modeling methodology, DDD strategic design, DDD tactical patterns, Clean Architecture, CQRS, and Event Sourcing.

  • 16 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 26, 2026
ai-agentsgoreactapidatabase

Works with

  • api

Security analysis

A100/100

Pro scans all 9 files and shows the line behind each finding

Scanned November 26, 2026

npx -y skills add SebastienDegodez/skraft-plugin --skill architecture-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Architecture Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Architecture Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sebastiendegodez-architecture-patterns/badge)](https://www.skillsdirectory.com/skills/sebastiendegodez-architecture-patterns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: architecture-patterns
description: Use when selecting architecture patterns for a new feature, performing Event Modeling, defining bounded contexts, choosing DDD tactical patterns, evaluating pattern fitness, or understanding how patterns compose. Covers Event Modeling methodology, DDD strategic design, DDD tactical patterns, Clean Architecture, CQRS, and Event Sourcing.
---

# Architecture Patterns

Select a pattern for a problem, never by preference. Every pattern added to a design is justified
by a story or a quality-attribute requirement; "we might need it later" justifies nothing.

Patterns compose in this order, outside in: Event Modeling (what the system does) → DDD Strategic
(where the boundaries are) → DDD Tactical (the domain model) → Clean Architecture (layers) → CQRS
(commands vs queries) → Event Sourcing (only when history has value) → Sagas (cross-aggregate
workflows). CQRS and Event Sourcing are independent: CQRS without Event Sourcing is the common case.

## Event Modeling

Model behaviour as a timeline: **Command** (imperative intent, may be rejected) → **Event**
(past-tense fact, never rejected) → **Read Model** (query output shaped for one consumer, no
mutation). One command + its events + the read model that surfaces the result is a **slice**, the
minimum unit of deliverable value; each slice maps to Gherkin (Given = prior state, When =
command, Then = event and/or read model).

- Name events as business facts, never implementation steps (`SaveToDatabase`).
- Model a rejection as an event only when the business records it or reacts to it; a rejection
  that changes no state is an error result of the command.
- A trigger enters from outside: a user, another context, the clock, the application start. A
  step inside one use case is no command.
- Every command has a read model the user needed before acting.
- Model only the slices the current stories require.

Procedure, slice completeness check and examples: [references/event-modeling.md](references/event-modeling.md).

## DDD Strategic Design

- **Bounded context:** a boundary inside which every term has one meaning. Same word, different
  meaning → different contexts; also consider a boundary on different team, rate of change or
  data store. Name contexts after their language (`EligibilityContext`), never a layer.
- **Subdomain class:** Core (competitive advantage: full DDD), Supporting (necessary, not
  differentiating: standard patterns), Generic (commodity: buy or use off the shelf).
- **Ubiquitous Language:** per context; code, tests and docs use it untranslated; a concept from
  another context is translated at the boundary.

Apply these before labelling any context-map arrow:

1. **A Core downstream is never Conformist.** It gets an Anti-Corruption Layer (ideally against
   an upstream Open Host Service / Published Language). Conformist is admissible only for a
   Supporting or Generic downstream.
2. **Consuming a published contract is not Conformist.** Upstream exposing a stable public
   contract (ViewModel, event schema, DTO) and hiding its entities is Open Host Service +
   Published Language.
3. **A local copy or translation is an ACL**, however trivial the translation is today.

| Observation | Label |
|---|---|
| Downstream imports upstream domain entities, no translation | Conformist (Supporting/Generic downstream only) |
| Upstream exposes a stable public contract, hides its domain | Open Host Service + Published Language |
| Downstream translates or copies that contract into its own types | Anti-Corruption Layer |
| Downstream is Core | ACL, whatever the translation effort |

All seven context-map patterns with their risks: [references/ddd-strategic.md](references/ddd-strategic.md).

## DDD Tactical Patterns

- **Aggregate:** only for an invariant that must hold across successive or concurrent changes of
  one identity: the aggregate is that transaction boundary. One root, all access through it;
  invariants enforced atomically inside, never across aggregates; reference other aggregates by
  ID only; one repository per aggregate; prefer small (more than 3–5 child entities is a smell).
  Two entities share an aggregate only when a business invariant needs them in one transaction.
  An invariant checked once at construction goes into a self-validating value object or a
  first-class collection; a rule spanning values goes into a policy or a domain service, never
  into an anaemic aggregate. A design with no aggregate is valid when no identity changes.
- **Value object:** immutable, equal by value, self-validating; replaces primitives.
- **Domain event:** past tense (`EligibilityChecked`, not `EligibilityCheckEvent`), minimal
  immutable payload, raised by the aggregate root after the state change.
- **Repository:** one per aggregate, never for anything else; domain-named methods, returns
  aggregates, no ORM type in the interface. Interface in **Domain** when it persists an aggregate,
  in **Application** for a CRUD entity or a read model, never in Infrastructure; the contracts
  record the choice, never an ADR. A source read once (configuration, a catalog loaded at
  start) sits behind an Application loading interface, not a repository.
- **Published contract:** an interface another story, context or extension consumes carries the
  inputs and outputs that consumer needs and an evolution rule (additions only; readers ignore
  what they do not know). Build nothing for the consumer itself.
- **Domain service:** stateless logic spanning several aggregates; logic of one aggregate stays in
  it; infrastructural logic goes behind an Application interface.
- **Policy / Specification:** a named rule; a Specification is a composable predicate
  (`HasCleanRecord.And(HasMinimumExperience)`).

Rules per pattern, when not to use each, examples: [references/ddd-tactical.md](references/ddd-tactical.md).

## Clean Architecture

Layers: API (controllers, request/response models) → Infrastructure (persistence, messaging,
external APIs; implements Application interfaces) → Application (use cases, commands, queries,
Application interfaces) → Domain (aggregates, entities, value objects, events, domain services).

### Dependency Rule

Project references point inward only, one layer at a time:

- Domain → nothing
- Application → Domain
- Infrastructure → Application
- API → Infrastructure (composes use cases through it)

Types reachable through a transitive reference may be imported; never add a direct reference to
reach them.

### Feature Folders

Inside each layer, group code by feature (`Loans`, `Invoicing`), never by technical kind
(`Repositories`, `Services`). A feature's use cases import no other feature's application code;
what two features both need moves to that layer's `Shared` folder.

### Use Case Boundary

Every external request goes through a use case; a controller never touches a Domain object or a
repository. Any I/O abstraction (publisher, gateway, read store) is an Application interface,
implemented in Infrastructure, injected, and exposes no framework type (`DbContext`,
`IQueryable`).

## CQRS

Apply when read and write shapes diverge, reads dominate, or reporting needs projections; never
for CRUD with the same shapes, never "because CQRS". Commands mutate through aggregates and return
an acknowledgment or an id, never a view; queries never mutate and return a model shaped for the
consumer, never an aggregate. Default to simple CQRS (one database); separate stores only with
Event Sourcing or a measured read problem.

Read [references/cqrs.md](references/cqrs.md) when choosing between the repository and a read
store for a query, deciding who maps an aggregate to a ViewModel, or choosing a command bus or a
projection type.

## Event Sourcing

Ask: **does knowing the history of state changes provide business value?** No → do not use it.
Yes when: audit trail required, temporal queries, several diverging read models, events are the
integration API. Never for a Generic or Supporting subdomain, nor for CRUD without audit need.

Read [references/event-sourcing.md](references/event-sourcing.md) once Event Sourcing is chosen:
lifecycle, store, projections, snapshots, sagas, upcasting, concurrency, outbox, reservation.

## Selecting a pattern

[references/pattern-selection-matrix.md](references/pattern-selection-matrix.md): problem →
pattern table, pattern depth per subdomain class, combinations to avoid. Read it before adding any
pattern beyond Clean Architecture + Repository.

[references/anti-patterns.md](references/anti-patterns.md): read when reviewing an existing design
for misplaced logic, leaking abstractions or over-engineering.

Files in this skill

  • SKILL.md22.9 KB
  • references/anti-patterns.md11.4 KB
  • references/ddd-strategic.md9.6 KB
  • references/ddd-tactical.md9.9 KB
  • references/event-modeling.md8.2 KB
  • references/event-sourcing.md15.3 KB
  • references/pattern-catalog.md8.8 KB
  • references/pattern-selection-matrix.md6.2 KB
  • references/read-store-pattern.md6.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.