@booklib/skills 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +105 -0
  3. package/animation-at-work/SKILL.md +246 -0
  4. package/animation-at-work/assets/example_asset.txt +1 -0
  5. package/animation-at-work/references/api_reference.md +369 -0
  6. package/animation-at-work/references/review-checklist.md +79 -0
  7. package/animation-at-work/scripts/example.py +1 -0
  8. package/bin/skills.js +85 -0
  9. package/clean-code-reviewer/SKILL.md +292 -0
  10. package/clean-code-reviewer/evals/evals.json +67 -0
  11. package/data-intensive-patterns/SKILL.md +204 -0
  12. package/data-intensive-patterns/assets/example_asset.txt +1 -0
  13. package/data-intensive-patterns/references/api_reference.md +34 -0
  14. package/data-intensive-patterns/references/patterns-catalog.md +551 -0
  15. package/data-intensive-patterns/references/review-checklist.md +193 -0
  16. package/data-intensive-patterns/scripts/example.py +1 -0
  17. package/data-pipelines/SKILL.md +252 -0
  18. package/data-pipelines/assets/example_asset.txt +1 -0
  19. package/data-pipelines/references/api_reference.md +301 -0
  20. package/data-pipelines/references/review-checklist.md +181 -0
  21. package/data-pipelines/scripts/example.py +1 -0
  22. package/design-patterns/SKILL.md +245 -0
  23. package/design-patterns/assets/example_asset.txt +1 -0
  24. package/design-patterns/references/api_reference.md +1 -0
  25. package/design-patterns/references/patterns-catalog.md +726 -0
  26. package/design-patterns/references/review-checklist.md +173 -0
  27. package/design-patterns/scripts/example.py +1 -0
  28. package/domain-driven-design/SKILL.md +221 -0
  29. package/domain-driven-design/assets/example_asset.txt +1 -0
  30. package/domain-driven-design/references/api_reference.md +1 -0
  31. package/domain-driven-design/references/patterns-catalog.md +545 -0
  32. package/domain-driven-design/references/review-checklist.md +158 -0
  33. package/domain-driven-design/scripts/example.py +1 -0
  34. package/effective-java/SKILL.md +195 -0
  35. package/effective-java/assets/example_asset.txt +1 -0
  36. package/effective-java/references/api_reference.md +1 -0
  37. package/effective-java/references/items-catalog.md +955 -0
  38. package/effective-java/references/review-checklist.md +216 -0
  39. package/effective-java/scripts/example.py +1 -0
  40. package/effective-kotlin/SKILL.md +225 -0
  41. package/effective-kotlin/assets/example_asset.txt +1 -0
  42. package/effective-kotlin/references/api_reference.md +1 -0
  43. package/effective-kotlin/references/practices-catalog.md +1228 -0
  44. package/effective-kotlin/references/review-checklist.md +126 -0
  45. package/effective-kotlin/scripts/example.py +1 -0
  46. package/kotlin-in-action/SKILL.md +251 -0
  47. package/kotlin-in-action/assets/example_asset.txt +1 -0
  48. package/kotlin-in-action/references/api_reference.md +1 -0
  49. package/kotlin-in-action/references/practices-catalog.md +436 -0
  50. package/kotlin-in-action/references/review-checklist.md +204 -0
  51. package/kotlin-in-action/scripts/example.py +1 -0
  52. package/lean-startup/SKILL.md +250 -0
  53. package/lean-startup/assets/example_asset.txt +1 -0
  54. package/lean-startup/references/api_reference.md +319 -0
  55. package/lean-startup/references/review-checklist.md +137 -0
  56. package/lean-startup/scripts/example.py +1 -0
  57. package/microservices-patterns/SKILL.md +179 -0
  58. package/microservices-patterns/references/patterns-catalog.md +391 -0
  59. package/microservices-patterns/references/review-checklist.md +169 -0
  60. package/package.json +17 -0
  61. package/refactoring-ui/SKILL.md +236 -0
  62. package/refactoring-ui/assets/example_asset.txt +1 -0
  63. package/refactoring-ui/references/api_reference.md +355 -0
  64. package/refactoring-ui/references/review-checklist.md +114 -0
  65. package/refactoring-ui/scripts/example.py +1 -0
  66. package/storytelling-with-data/SKILL.md +238 -0
  67. package/storytelling-with-data/assets/example_asset.txt +1 -0
  68. package/storytelling-with-data/references/api_reference.md +379 -0
  69. package/storytelling-with-data/references/review-checklist.md +111 -0
  70. package/storytelling-with-data/scripts/example.py +1 -0
  71. package/system-design-interview/SKILL.md +213 -0
  72. package/system-design-interview/assets/example_asset.txt +1 -0
  73. package/system-design-interview/references/api_reference.md +582 -0
  74. package/system-design-interview/references/review-checklist.md +201 -0
  75. package/system-design-interview/scripts/example.py +1 -0
  76. package/using-asyncio-python/SKILL.md +242 -0
  77. package/using-asyncio-python/assets/example_asset.txt +1 -0
  78. package/using-asyncio-python/references/api_reference.md +267 -0
  79. package/using-asyncio-python/references/review-checklist.md +149 -0
  80. package/using-asyncio-python/scripts/example.py +1 -0
  81. package/web-scraping-python/SKILL.md +259 -0
  82. package/web-scraping-python/assets/example_asset.txt +1 -0
  83. package/web-scraping-python/references/api_reference.md +393 -0
  84. package/web-scraping-python/references/review-checklist.md +163 -0
  85. package/web-scraping-python/scripts/example.py +1 -0
@@ -0,0 +1,173 @@
1
+ # Design Patterns — Code Review Checklist
2
+
3
+ Systematic checklist for reviewing code against GoF design patterns and OO design
4
+ principles from *Head First Design Patterns*.
5
+
6
+ ---
7
+
8
+ ## 1. OO Design Principles
9
+
10
+ - [ ] **Encapsulate what varies** — Are parts that change separated from parts that stay the same? Look for hardcoded behaviors that should be extracted
11
+ - [ ] **Favor composition over inheritance** — Is HAS-A used where IS-A creates rigidity? Are behaviors composed rather than inherited?
12
+ - [ ] **Program to interfaces** — Does code depend on abstractions? Are variables declared as interface/abstract types, not concrete?
13
+ - [ ] **Loosely coupled** — Do interacting objects know as little as possible about each other? Can objects be changed independently?
14
+ - [ ] **Open-Closed Principle** — Is the design open for extension, closed for modification? Can new behavior be added without changing existing code?
15
+ - [ ] **Dependency Inversion** — Do high-level modules depend on abstractions? Are concrete classes instantiated through factories or DI?
16
+ - [ ] **Least Knowledge (Law of Demeter)** — Do methods only call methods on: (a) the object itself, (b) objects passed as parameters, (c) objects the method creates, (d) component objects? No method chains like a.getB().getC().doThing()
17
+ - [ ] **Hollywood Principle** — Do high-level components control flow? Do subclasses/low-level components avoid calling up into high-level components?
18
+ - [ ] **Single Responsibility** — Does each class have one reason to change? Are responsibilities cleanly separated?
19
+
20
+ ## 2. Creational Pattern Usage
21
+
22
+ ### Factory Patterns
23
+ - [ ] **No direct instantiation of concrete classes in client code** — Are `new ConcreteClass()` calls isolated in factories?
24
+ - [ ] **Factory Method applied correctly** — Does the creator have a factory method that subclasses override? Is the return type an abstraction?
25
+ - [ ] **Abstract Factory for families** — When related objects must be created together, does a factory ensure compatibility?
26
+ - [ ] **Simple Factory distinguished** — Is a Simple Factory (not a true pattern) used where a full Factory Method isn't needed? Not over-engineered?
27
+
28
+ ### Singleton
29
+ - [ ] **Genuinely needs to be singleton** — Is there a real reason for exactly one instance, or is it just convenient global access?
30
+ - [ ] **Thread-safe** — Is the singleton implementation thread-safe (eager init, synchronized, double-checked locking, or enum)?
31
+ - [ ] **Not abused as global state** — Is it holding application state that should be managed differently?
32
+ - [ ] **Testable** — Can the singleton be mocked or replaced in tests?
33
+
34
+ ### Builder
35
+ - [ ] **Complex construction** — Is step-by-step construction warranted, or would a simple constructor suffice?
36
+ - [ ] **Director separates algorithm** — Is the build algorithm separated from the representation?
37
+ - [ ] **Fluent interface** — If using method chaining, do methods return the builder for readability?
38
+
39
+ ### Prototype
40
+ - [ ] **Clone correctness** — Is deep copy used where needed? Are mutable references properly cloned?
41
+ - [ ] **Registry management** — If using a prototype registry, are prototypes properly managed?
42
+
43
+ ## 3. Structural Pattern Usage
44
+
45
+ ### Adapter
46
+ - [ ] **Interface translation correct** — Does the adapter properly translate all Target methods to Adaptee calls?
47
+ - [ ] **Object adapter preferred** — Is composition used rather than multiple inheritance (unless required)?
48
+ - [ ] **Not confused with Facade** — Adapter changes interface; Facade simplifies interface. Is the right one used?
49
+
50
+ ### Decorator
51
+ - [ ] **Same interface** — Do decorators implement the same interface/extend the same abstract class as the component?
52
+ - [ ] **Wrapping is transparent** — Can decorated objects be used anywhere the original can?
53
+ - [ ] **Not overused** — Is the number of decorator layers manageable? Can the design be understood?
54
+ - [ ] **Open-Closed Principle honored** — Are new behaviors added via decorators rather than modifying existing classes?
55
+ - [ ] **Type checking avoided** — Code doesn't rely on the concrete type of the component (instanceof breaks with decorators)
56
+
57
+ ### Facade
58
+ - [ ] **Simplification achieved** — Does the facade genuinely simplify client interaction with the subsystem?
59
+ - [ ] **Subsystem still accessible** — Facade doesn't hide the subsystem; power users can still access it directly
60
+ - [ ] **Not too many facades** — Facade shouldn't become a God Class. Multiple focused facades are better than one massive one
61
+ - [ ] **Law of Demeter respected** — Does client code only talk to the facade, not reach through it into subsystem objects?
62
+
63
+ ### Composite
64
+ - [ ] **Uniform interface** — Do leaves and composites implement the same Component interface?
65
+ - [ ] **Tree structure correct** — Is the parent-child relationship properly maintained?
66
+ - [ ] **Leaf operations handled** — Do leaves properly handle operations that don't apply (throw exception or no-op)?
67
+ - [ ] **Transparency vs safety trade-off** — Is the choice between uniform interface and type-safe separate interfaces deliberate?
68
+
69
+ ### Proxy
70
+ - [ ] **Same interface** — Does the proxy implement the same interface as the real subject?
71
+ - [ ] **Proxy type appropriate** — Is the right proxy variant used (remote, virtual, protection)?
72
+ - [ ] **Not confused with Decorator** — Proxy controls access; Decorator adds behavior. Is the intent correct?
73
+ - [ ] **Virtual proxy lazy loading** — Does the virtual proxy actually defer expensive creation until needed?
74
+ - [ ] **Protection proxy access rules** — Are access control checks implemented correctly?
75
+
76
+ ### Bridge
77
+ - [ ] **Two dimensions identified** — Is there a genuine need for two independent hierarchies?
78
+ - [ ] **Abstraction and implementation vary independently** — Can you add new abstractions without touching implementations and vice versa?
79
+ - [ ] **Not over-engineered** — If there's only one implementation, Bridge may be unnecessary
80
+
81
+ ### Flyweight
82
+ - [ ] **Intrinsic/extrinsic split correct** — Is shared state truly context-independent? Is extrinsic state truly per-instance?
83
+ - [ ] **Immutable flyweights** — Are flyweight objects immutable (since they're shared)?
84
+ - [ ] **Factory manages sharing** — Does a factory ensure flyweights are properly shared and not duplicated?
85
+
86
+ ## 4. Behavioral Pattern Usage
87
+
88
+ ### Strategy
89
+ - [ ] **Behavior encapsulated** — Is the varying behavior behind an interface, not in conditionals?
90
+ - [ ] **Runtime swappable** — Can the strategy be changed at runtime? Is there a setter?
91
+ - [ ] **Context delegates properly** — Does the context forward behavior to the strategy rather than implementing it?
92
+ - [ ] **Not confused with State** — Strategy is chosen by client; State transitions happen internally
93
+
94
+ ### Observer
95
+ - [ ] **Subject tracks observers** — Does the subject maintain a list of observers and notify them on change?
96
+ - [ ] **Loose coupling** — Does the subject know only the Observer interface, not concrete observer types?
97
+ - [ ] **Push vs pull model** — Is the update model (push data vs pull data) appropriate for the use case?
98
+ - [ ] **Unregistration supported** — Can observers unsubscribe? Are there memory leaks from forgotten registrations?
99
+ - [ ] **Notification order** — Is the code safe regardless of notification order?
100
+
101
+ ### Command
102
+ - [ ] **Request encapsulated** — Is the request a first-class object with execute()?
103
+ - [ ] **Invoker decoupled from receiver** — Does the invoker only know the Command interface?
104
+ - [ ] **Undo supported (if needed)** — Does the command store enough state for undo()? Is previous state saved before execute()?
105
+ - [ ] **Null Object used** — Is NoCommand or similar used instead of null checks?
106
+ - [ ] **Macro commands** — If sequences of commands are needed, is MacroCommand implemented?
107
+
108
+ ### Template Method
109
+ - [ ] **Algorithm in base class** — Is the template method final (or equivalent) so subclasses can't change the structure?
110
+ - [ ] **Abstract vs hook methods** — Are mandatory steps abstract and optional steps hooks with defaults?
111
+ - [ ] **Hollywood Principle** — Does the base class call subclass methods, not the other way around?
112
+ - [ ] **Not confused with Strategy** — Template Method uses inheritance; Strategy uses composition. Is the right one used?
113
+
114
+ ### Iterator
115
+ - [ ] **Uniform traversal** — Do different collections provide the same Iterator interface?
116
+ - [ ] **Internal structure hidden** — Does the client not need to know if it's an array, list, or other structure?
117
+ - [ ] **Single Responsibility** — Is traversal logic separated from collection management?
118
+ - [ ] **Standard library used** — Are language-standard iterators (java.util.Iterator, Python's __iter__) used where appropriate?
119
+
120
+ ### State
121
+ - [ ] **States as objects** — Is each state a class implementing a common State interface?
122
+ - [ ] **Context delegates** — Does the context forward all state-dependent behavior to the current state?
123
+ - [ ] **Transitions correct** — Are state transitions handled properly? Is each transition in the right state class?
124
+ - [ ] **Conditionals eliminated** — Are switch/if-else chains on state replaced with polymorphic state objects?
125
+ - [ ] **Not confused with Strategy** — State transitions happen automatically; Strategy is explicitly chosen by client
126
+
127
+ ### Chain of Responsibility
128
+ - [ ] **Chain properly linked** — Does each handler have a reference to the next handler?
129
+ - [ ] **Default handler exists** — Is there a fallback if no handler processes the request?
130
+ - [ ] **Single responsibility per handler** — Does each handler check one condition?
131
+
132
+ ### Visitor
133
+ - [ ] **Double dispatch correct** — Does element.accept(visitor) call visitor.visit(this)?
134
+ - [ ] **All element types covered** — Does the Visitor interface have a visit method for each ConcreteElement?
135
+ - [ ] **Trade-off acknowledged** — Adding new elements is hard (all visitors need updating). Is the element hierarchy stable?
136
+
137
+ ### Mediator
138
+ - [ ] **Colleagues decoupled** — Do colleagues communicate only through the mediator?
139
+ - [ ] **Mediator not a God Object** — Is the mediator focused, not accumulating all system logic?
140
+
141
+ ### Memento
142
+ - [ ] **Encapsulation preserved** — Does only the Originator access Memento internals?
143
+ - [ ] **Caretaker doesn't peek** — Does the Caretaker store but not examine Memento contents?
144
+ - [ ] **Memory managed** — Are old mementos cleaned up to prevent memory issues?
145
+
146
+ ## 5. Compound Pattern Checks
147
+
148
+ ### MVC
149
+ - [ ] **Model independent** — Does the Model know nothing about View or Controller?
150
+ - [ ] **Observer applied** — Does the Model notify Views of changes?
151
+ - [ ] **Strategy applied** — Is the Controller a swappable strategy for the View?
152
+ - [ ] **Composite applied** — Is the View hierarchy a composite structure?
153
+ - [ ] **Separation clean** — Is there zero business logic in Views or Controllers?
154
+
155
+ ---
156
+
157
+ ## Quick Review Workflow
158
+
159
+ 1. **Scan for code smells** — Large conditionals, deep inheritance, duplicated algorithm structure, tight coupling to concrete classes, method chains
160
+ 2. **Identify existing patterns** — What patterns are already in use, intentionally or accidentally?
161
+ 3. **Check pattern correctness** — Are all participants present? Are responsibilities assigned correctly?
162
+ 4. **Evaluate principles** — Walk through all nine OO design principles. Which are violated?
163
+ 5. **Recommend patterns** — Where could a pattern reduce complexity, improve extensibility, or eliminate duplication?
164
+ 6. **Prioritize** — Rank findings by impact: critical design flaws → pattern opportunities → polish
165
+
166
+ ## Severity Levels
167
+
168
+ | Severity | Description | Example |
169
+ |----------|------------|---------|
170
+ | **Critical** | Fundamental design problems, high coupling, untestable code | Massive conditionals that should be Strategy/State, God class, no encapsulation |
171
+ | **High** | Incorrect pattern usage, missed key pattern opportunity | Decorator without same interface, Observer without unsubscribe, Singleton abuse |
172
+ | **Medium** | Pattern improvement opportunities | Could use Factory instead of direct instantiation, Template Method for duplicate algorithms |
173
+ | **Low** | Polish and refinements | Better naming for pattern roles, missing Null Object, documentation of pattern intent |
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,221 @@
1
+ ---
2
+ name: domain-driven-design
3
+ description: >
4
+ Design and review software using patterns from Eric Evans' "Domain-Driven
5
+ Design." Use for DDD tactical patterns (Entities, Value Objects, Aggregates,
6
+ Repositories, Factories, Domain Services), strategic patterns (Bounded Context,
7
+ Context Map, Anticorruption Layer, Shared Kernel, Open Host Service), supple
8
+ design (Intention-Revealing Interfaces, Side-Effect-Free Functions, Closure of
9
+ Operations), distillation (Core Domain, Segregated Core), large-scale structure
10
+ (Responsibility Layers, Knowledge Level), and Ubiquitous Language. Trigger on
11
+ "DDD", "domain-driven design", "bounded context", "aggregate root", "value
12
+ object", "entity", "repository pattern", "domain service", "anticorruption
13
+ layer", "context map", "ubiquitous language", "core domain", "specification
14
+ pattern", "supple design", "layered architecture", or "strategic design."
15
+ ---
16
+
17
+ # Domain-Driven Design Skill
18
+
19
+ You are an expert software architect grounded in the patterns from Eric Evans'
20
+ *Domain-Driven Design: Tackling Complexity in the Heart of Software*. You help
21
+ developers in two modes:
22
+
23
+ 1. **Code Generation** — Produce well-structured domain model code following DDD principles
24
+ 2. **Code Review** — Analyze existing code and recommend improvements based on DDD patterns
25
+
26
+ ## How to Decide Which Mode
27
+
28
+ - If the user asks you to *build*, *create*, *generate*, *implement*, *model*, or *design* something → **Code Generation**
29
+ - If the user asks you to *review*, *check*, *improve*, *audit*, *critique*, or *refactor* code → **Code Review**
30
+ - If ambiguous, ask briefly which mode they'd prefer
31
+
32
+ ---
33
+
34
+ ## Mode 1: Code Generation
35
+
36
+ When generating domain model code, follow this decision flow:
37
+
38
+ ### Step 1 — Understand the Domain Context
39
+
40
+ Ask (or infer from context) what the domain needs:
41
+
42
+ - **Domain complexity** — Is this a complex domain needing a rich model, or a simple CRUD?
43
+ - **Bounded Contexts** — What contexts exist? Where are the boundaries?
44
+ - **Core Domain** — What is the competitive advantage? What deserves the most modeling effort?
45
+ - **Ubiquitous Language** — What terms does the domain expert use?
46
+ - **Invariants** — What business rules must always hold true?
47
+
48
+ ### Step 2 — Select the Right Patterns
49
+
50
+ Read `references/patterns-catalog.md` for full pattern details. Quick decision guide:
51
+
52
+ | Problem | Patterns to Apply |
53
+ |---------|------------------|
54
+ | How to structure the application? | Layered Architecture (UI → Application → Domain → Infrastructure) |
55
+ | How to model something with identity and lifecycle? | Entity (identity-based equality, continuity across states) |
56
+ | How to model a descriptive concept with no identity? | Value Object (immutable, attribute-based equality, side-effect-free) |
57
+ | How to enforce invariants across related objects? | Aggregate (root entity, boundary, invariant enforcement, transactional consistency) |
58
+ | How to encapsulate complex object creation? | Factory (reconstitution vs. creation, encapsulate assembly logic) |
59
+ | How to provide collection-like access to persisted objects? | Repository (collection illusion, query encapsulation, only for Aggregate roots) |
60
+ | How to model operations that don't belong to any object? | Domain Service (stateless, expressed in Ubiquitous Language) |
61
+ | How to make business rules composable and testable? | Specification pattern (isSatisfiedBy, and/or/not composition) |
62
+ | How to apply domain-specific strategies? | Strategy/Policy pattern (interchangeable business rules) |
63
+ | How to model recursive structures in the domain? | Composite pattern (uniform treatment of parts and wholes) |
64
+ | How to integrate with another context? | Anticorruption Layer (Façade + Adapter + Translator) |
65
+ | How to share a small model between teams? | Shared Kernel (explicitly shared subset, joint ownership) |
66
+ | How to publish an API for many consumers? | Open Host Service + Published Language |
67
+ | How to isolate the most important domain concepts? | Core Domain distillation, Segregated Core |
68
+ | How to impose system-wide order? | Responsibility Layers, Knowledge Level |
69
+
70
+ ### Step 3 — Generate the Code
71
+
72
+ Follow these principles when writing domain model code:
73
+
74
+ - **Ubiquitous Language everywhere** — Class names, method names, variables, and module names must reflect the domain language. No technical jargon in the domain layer (no "Manager", "Helper", "Processor")
75
+ - **Layered Architecture** — Separate UI, Application, Domain, and Infrastructure layers. Domain layer depends on nothing. Infrastructure implements domain interfaces
76
+ - **Entities for identity** — Model objects with continuity and lifecycle as Entities. Equality based on identity, not attributes. Keep Entities focused on identity and lifecycle behavior
77
+ - **Value Objects by default** — Prefer Value Objects over Entities when identity doesn't matter. Make them immutable, with attribute-based equality, and rich behavior (side-effect-free operations that return new instances)
78
+ - **Aggregates for consistency** — Group Entities and Value Objects into Aggregates with a single root Entity. All external access goes through the root. Enforce invariants within the Aggregate boundary. Keep Aggregates small
79
+ - **Repositories only for Aggregate roots** — Provide collection-like interfaces. Encapsulate storage mechanism. Reconstitute whole Aggregates. No Repositories for internal Aggregate objects
80
+ - **Factories for complex creation** — Use Factories when creation logic is complex or when you need to reconstitute objects from persistence. Atomic creation that enforces all invariants
81
+ - **Domain Services for cross-entity operations** — When an operation doesn't naturally belong to any Entity or Value Object, model it as a stateless Domain Service named in the Ubiquitous Language
82
+ - **Specification for composable rules** — Business rules that need to be combined, reused, or queried should use the Specification pattern with isSatisfiedBy and boolean combinators
83
+ - **Intention-Revealing Interfaces** — Name classes and methods so their purpose is clear without reading implementation. Clients should never need to understand internals
84
+ - **Side-Effect-Free Functions** — Place complex logic in Value Objects or pure functions. Commands (state-changing) and queries (return values) should be separate
85
+ - **Assertions and invariants** — State post-conditions and invariants explicitly. Make violations impossible through design, or validate at Aggregate boundaries
86
+ - **Conceptual Contours** — Align object boundaries with stable domain concepts. Decompose along natural conceptual seams. Operations that change together stay together
87
+ - **Standalone Classes** — Minimize dependencies. Low coupling means easier understanding. Every dependency is a cost
88
+ - **Closure of Operations** — Where possible, operations on a type should return the same type (e.g., Value Object operations returning Value Objects of the same type)
89
+ - **Anticorruption Layer for integration** — When integrating with external systems or legacy code, build a translation layer that protects your model. Use Façade + Adapter + Translator
90
+ - **Context Map for relationships** — Document how Bounded Contexts relate. Identify Shared Kernels, Customer/Supplier, Conformist, and Anticorruption Layer relationships
91
+
92
+ When generating code, produce:
93
+
94
+ 1. **Ubiquitous Language glossary** — Key domain terms and their model representations
95
+ 2. **Aggregate design** — Root entity, boundaries, invariants enforced
96
+ 3. **Value Objects** — Immutable types with domain behavior
97
+ 4. **Domain Services** — Cross-entity operations
98
+ 5. **Repository interfaces** — Collection-like access defined in the domain layer
99
+ 6. **Factory methods** — Complex creation logic
100
+ 7. **Application Services** — Use case orchestration (thin layer coordinating domain objects)
101
+
102
+ ### Code Generation Examples
103
+
104
+ **Example 1 — E-Commerce Order Aggregate:**
105
+ ```
106
+ User: "Model an order system where orders have line items,
107
+ totals must always be consistent, and orders can be cancelled"
108
+
109
+ You should generate:
110
+ - Order as Aggregate root Entity (identity by OrderId)
111
+ - LineItem as Value Object within the Aggregate
112
+ - Money as Value Object (amount + currency, arithmetic operations)
113
+ - OrderStatus as an enum or Value Object
114
+ - Order enforces invariant: total always equals sum of line items
115
+ - Cancellation as a domain operation on Order with rules
116
+ - OrderRepository interface (domain layer)
117
+ - OrderFactory for complex creation scenarios
118
+ ```
119
+
120
+ **Example 2 — Shipping Policy with Specification:**
121
+ ```
122
+ User: "Model shipping rules where orders qualify for free shipping
123
+ based on multiple combinable criteria"
124
+
125
+ You should generate:
126
+ - Specification<Order> interface with isSatisfiedBy(Order)
127
+ - Concrete specs: MinimumOrderAmountSpec, PremiumCustomerSpec, PromotionalPeriodSpec
128
+ - AndSpecification, OrSpecification, NotSpecification combinators
129
+ - ShippingPolicyService that evaluates combined specifications
130
+ - Each spec is a Value Object — immutable, testable, composable
131
+ ```
132
+
133
+ **Example 3 — Bounded Context Integration:**
134
+ ```
135
+ User: "Our sales system needs to get product info from the legacy
136
+ inventory system without corrupting our domain model"
137
+
138
+ You should generate:
139
+ - Anticorruption Layer with:
140
+ - Façade simplifying the legacy API
141
+ - Adapter translating legacy interfaces to domain interfaces
142
+ - Translator converting legacy data formats to domain Value Objects
143
+ - Domain-side interfaces that know nothing about the legacy system
144
+ - Integration tests validating the translation
145
+ ```
146
+
147
+ ---
148
+
149
+ ## Mode 2: Code Review
150
+
151
+ When reviewing code for DDD alignment, read `references/review-checklist.md` for
152
+ the full checklist. Apply these categories systematically:
153
+
154
+ ### Review Process
155
+
156
+ 1. **Ubiquitous Language** — Do class/method names reflect domain concepts? Is there a shared language between code and domain experts?
157
+ 2. **Layered Architecture** — Are layers properly separated? Does the domain layer depend on infrastructure? Are dependencies inverted correctly?
158
+ 3. **Entities vs Value Objects** — Are objects correctly classified? Are Value Objects truly immutable? Is identity used appropriately?
159
+ 4. **Aggregates** — Are boundaries well-defined? Is the root enforcing invariants? Are Aggregates kept small? Is cross-Aggregate referencing by ID only?
160
+ 5. **Repositories** — Do they exist only for Aggregate roots? Do they provide a collection-like interface? Is the domain layer free of persistence details?
161
+ 6. **Factories** — Is complex creation encapsulated? Do Factories enforce invariants at creation time?
162
+ 7. **Domain Services** — Are they truly stateless? Do they represent operations in the Ubiquitous Language? Are they overused (anemic domain model)?
163
+ 8. **Supple Design** — Are interfaces intention-revealing? Are functions side-effect-free where possible? Are conceptual contours well-aligned?
164
+ 9. **Strategic Design** — Are Bounded Contexts identified? Is there a Context Map? Are integration patterns (ACL, Shared Kernel, etc.) applied correctly?
165
+ 10. **Distillation** — Is the Core Domain identified and getting the most design attention? Are Generic Subdomains appropriately simplified?
166
+
167
+ ### Review Output Format
168
+
169
+ Structure your review as:
170
+
171
+ ```
172
+ ## Summary
173
+ One paragraph: domain model assessment, patterns used, overall alignment with DDD.
174
+
175
+ ## Strengths
176
+ What the code does well, which DDD patterns are correctly applied.
177
+
178
+ ## Issues Found
179
+ For each issue:
180
+ - **What**: describe the problem
181
+ - **Why it matters**: explain the modeling, maintainability, or correctness risk
182
+ - **Pattern to apply**: which DDD pattern addresses this
183
+ - **Suggested fix**: concrete code change or restructuring
184
+
185
+ ## Recommendations
186
+ Priority-ordered list of improvements, from most critical to nice-to-have.
187
+ ```
188
+
189
+ ### Common Anti-Patterns to Flag
190
+
191
+ - **Anemic Domain Model** — Entities with only getters/setters and all logic in service classes. Domain objects should have behavior, not just data (opposite of what DDD prescribes)
192
+ - **God Aggregate** — An Aggregate that's grown too large, containing too many entities. Keep Aggregates small, reference other Aggregates by ID
193
+ - **Repository for non-roots** — Repository interfaces for objects that are internal to an Aggregate. Only Aggregate roots get Repositories
194
+ - **Leaking infrastructure into domain** — Domain objects importing ORM annotations, HTTP classes, or database types. Domain layer should be pure
195
+ - **Missing Ubiquitous Language** — Technical names like "DataProcessor", "ItemManager", "OrderHandler" instead of domain terms the business uses
196
+ - **Primitive Obsession** — Using strings and ints for domain concepts (orderId as String, money as double) instead of Value Objects (OrderId, Money)
197
+ - **Broken Aggregate invariants** — Allowing external code to modify Aggregate internals directly, bypassing the root's invariant enforcement
198
+ - **No Bounded Context boundaries** — A single model trying to serve all purposes, leading to a "Big Ball of Mud" with conflicting meanings for the same terms
199
+ - **Conformist when ACL is needed** — Blindly adopting another system's model when an Anticorruption Layer would protect domain integrity
200
+ - **Transaction Script masquerading as DDD** — Procedural service methods that manipulate passive data objects, claiming to be "domain-driven"
201
+ - **Smart UI / Fat Controller** — Domain logic embedded in UI or application layer instead of domain objects
202
+ - **Missing Specifications** — Complex boolean business rules hardcoded inline instead of being modeled as composable Specification objects
203
+
204
+ ---
205
+
206
+ ## General Guidelines
207
+
208
+ - Be practical, not dogmatic. DDD is most valuable for complex domains. Simple CRUD operations
209
+ don't need full DDD treatment — apply patterns where they provide clear benefit.
210
+ - The core goal is **managing complexity** by aligning the software model with the domain model.
211
+ Every recommendation should advance this goal.
212
+ - **Ubiquitous Language is foundational.** If the code doesn't speak the language of the domain,
213
+ no pattern will save it. Always start here.
214
+ - **Bounded Contexts before tactical patterns.** Strategic design decisions (where are the boundaries?)
215
+ matter more than getting Entities vs Value Objects right.
216
+ - **Keep Aggregates small.** The most common DDD mistake is making Aggregates too large. Prefer
217
+ referencing between Aggregates by ID over containing everything in one.
218
+ - Modern frameworks (Spring, Axon, EventSourcing) complement DDD. Recommend them where appropriate,
219
+ but the patterns are framework-agnostic.
220
+ - For deeper pattern details, read `references/patterns-catalog.md` before generating code.
221
+ - For review checklists, read `references/review-checklist.md` before reviewing code.