Claude Cursor GitHub Copilot Skill

architecture-patterns

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 tactic

LLM Mart · 0 points · 0 views 0 listing impressions 0 install-command copies
Download sebastiendegodez-skraft-plugin-plugins_skraft-framework_skills_architecture-patterns-c6117c6.zip · 13 KB

Install

skills CLI npx skills add https://github.com/SebastienDegodez/skraft-plugin/tree/main/plugins/skraft-framework/skills/architecture-patterns
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install sebastiendegodez-skraft-plugin@llmmart
Git git clone https://github.com/SebastienDegodez/skraft-plugin.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole sebastiendegodez/skraft-plugin collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

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.

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.

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.

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 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 once Event Sourcing is chosen: lifecycle, store, projections, snapshots, sagas, upcasting, concurrency, outbox, reservation.

Selecting a pattern

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: read when reviewing an existing design for misplaced logic, leaking abstractions or over-engineering.

Files (skraft-plugin)
  • references
    • anti-patterns.md 2 KB
      Loading…
    • cqrs.md 2.7 KB
      Loading…
    • ddd-strategic.md 2.9 KB
      Loading…
    • ddd-tactical.md 2.5 KB
      Loading…
    • event-modeling.md 2.5 KB
      Loading…
    • event-sourcing.md 3.4 KB
      Loading…
    • pattern-selection-matrix.md 2.3 KB
      Loading…
  • SKILL.md 8.5 KB
    ---
    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.
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.