gof-design-patterns
Skill11 starsChanged 2 days agoApache-2.0View on GitHub
Chooses and implements a design pattern in Java/Spring from the symptom that justifies it. Use when the request involves a design pattern, Strategy, Factory, Decorator, Builder, Specification, "how to structure this class", a growing if/switch chain, or refactoring a class with too many responsibilities.
3 other projects use a version of this.
Adopted by
Most recently taken up by
- ice-lfernandes/claude-spring-architectword for word, first seen Nov 15, 2026
- ryanthedev/code-foundationstheir own version, first seen Oct 8, 2026
- emvnuel/skillstheir own version, first seen Dec 27, 2025
Other versions3 projects use a version of this.
Word for word · 1
- ice-lfernandes/claude-spring-architect★ 11100% same
Edited · 0
None found.
Wrote their own version · 2
- ryanthedev/code-foundations★ 389same name
- emvnuel/skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository35 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- ai-architectSkill
- arch-adoptSkill
- arch-doctorSkill
- audit-usageSkill
- cache-architectSkill
- claude-code-architect-designerSkill
- docker-architectSkill
- domain-modelingSkill
- git-publishSkill
- graphql-api-architectSkill
- harness-lessonsSkill
- http-client-architectSkill
- init-projectSkill
- jobs-architectSkill
- messaging-architectSkill
- nerviz-diagramsSkill
- new-feature-implementSkill
- new-featureSkill
- new-projectSkill
- persistence-architectSkill
- platform-upgradeSkill
- project-bootstrapSkill
- project-configSkill
- report-issueSkill
- rest-api-architectSkill
- search-architectSkill
- security-architectSkill
- sonar-lessonsSkill
- sonarqube-setupSkill
- spikeSkill
- test-architectSkill
- transport-security-setupSkill
- triage-issueSkill
- use-case-designSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 40
Look up the symptom in the table.
- Very specific: line 79
Forces in the spec: Read the lines of 00-use-case.md and of the upstream partials that this layer implements, for the forces § Catalog …
- Very specific: line 168
Does not: create rules. If a new limit has to always hold, it goes to rules/code-quality.md, not here.
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
GoF Design Patterns
Why this is a skill and not a rule
A pattern is not a rule. A rule says always; a pattern says when. That's why this is
a skill and not rules/ — it only costs context when invoked. Form 2 (manual invocation)
and not Form 1, because a catalog the model reaches on its own turns into a pattern applied
without the symptom that justifies it, which is what the entry rule below exists to stop.
Entry rule: no pattern without a symptom observed in the code, or a force the approved
spec already names. Applying a pattern preemptively is overengineering — a Factory for
two lines, a Strategy for a single if, an interface with one implementation that will
never have a second. A force named in the spec is not preemption: variants or rules the
spec enumerates, a cross-cutting concern it applies over several implementations,
construction it constrains with invariants, a predicate it uses both to decide and to
query — code written from that spec would show the symptom on its first version, and
choosing the pattern before writing it is how that first version is never written badly.
The "When not" column binds either way. If you can point neither to the file and line
that hurts nor to the spec line that names the force, the answer is "apply no pattern at
all".
Pinned to opus: choosing a pattern against a growing chain is judgment, and the pin only raises the model for the rest of the turn (@.claude/decisions/0081-skill-model-required-per-class.md).
Procedure
- Name the symptom in the actual code (
file:line), or the force in the approved spec (its path and the line that names it) — never in the abstract. - Look up the symptom in the table. No matching row, stop — write simple code.
- Confirm the pattern doesn't collide with the active blueprint's
packages.map. - Generate from the exemplar in
templates/, with the names from@.claude/rules/naming.md. Size limits:@.claude/rules/code-quality.md. The exemplars write each constructor out, since the wiring between participants is what they show; the generated class follows@.claude/rules/lombok.md§ Generated boilerplate, outside the domain. - Record it in an ADR if the pattern changes the shape of an entire module.
Catalog
| Symptom in code | Pattern | When not |
switch/if-else over a type or enum, repeated in ≥ 2 places, growing with each new rule | Strategy | Two stable branches that have never grown · the branch needs nothing outside the value — a method of the enum or sealed type · a closed set one layer branches on once — a switch expression there; both per @.claude/rules/code-quality.md § Branching on a closed set |
| Construction with invariants, many steps, or possible invalid combinations | Static factory (of, from) | A record with validation in the compact constructor is already enough |
| ≥ 4 optional constructor parameters | Builder | Record + with*; Lombok @Builder on a domain object hides invariants |
| Cross-cutting behavior (retry, audit) repeated across implementations | Decorator | A Spring aspect already exists (@Transactional, @Retryable) that does the same thing — or the behavior is a cache, whose decorator shape @.claude/rules/caching.md owns |
| Business predicate duplicated between service and query | Specification | Predicate used only once |
| Output adapter with multiple technologies (JPA + external REST) behind the same port | Adapter (already the blueprint) | A single technology — the port is enough |
| Aggregate that emits ≥ 2 events consumed by several modules | Domain Events | A single consumer in the same module — direct call |
This table is the enforceable subset: seven rows, each with a symptom threshold and a
"when not" column. For a symptom that doesn't match any row above,
references/pattern-catalog.md covers the full GoF catalog — every pattern on
https://refactoring.guru/design-patterns/java, each with a shape reference in
templates/ and this repo's verdict on the ones that don't (forbidden, or already
covered by the language/framework). It's triage, not a second menu: the entry rule below
still gates every row in it the same way it gates the seven here — an exemplar existing
is not permission to apply it without a real symptom.
Design-time use
A pattern creates classes and interfaces, so when it is chosen decides whether the approved
spec shows the code's real shape. Chosen by the executor after approval, it never does. So
every design skill of the /new-feature pipeline runs this check for its own layer,
before writing its partial, and records the answer there — the layer that owns the classes
owns the pattern that shapes them. This section is read, never invoked: a design run cannot
reach a build-class skill, and it needs no writer here.
- Forces in the spec. Read the lines of
00-use-case.mdand of the upstream partials that this layer implements, for the forces § Catalog lists: variants or rules the spec enumerates, a cross-cutting concern over several implementations, construction with invariants, a predicate used both to decide and to query. - Symptoms on disk. The layer's existing code, already surveyed by the skill's own
survey step: a discriminating type another case already switched on, adapters or
listeners repeating the same skeleton with one step different. The class this case adds
would be the next copy — that is the symptom, cited by
file:line. - Match against § Catalog, then
references/pattern-catalog.mdfor what no row covers. The "When not" column binds exactly as it does for code. No match, or "When not" applies: the answer isnone, and that answer is written. Write the
## Design patternssection of the partial — always present, one row per pattern:Force or symptom Pattern Classes and interfaces it creates "When not" checked spec line ( 00-use-case.md§ 5, row 2) orfile:linethe row's pattern names per @.claude/rules/naming.mdwhy it does not apply none — no force in the spec, no symptom on diskwhen empty; absence is notnone. The classes a row creates also go into the partial's own components or adapter table, so the approved spec lists every class the executor will write.- Existing code the pattern reshapes — the other listeners, the earlier adapters — is a
change to code an approved case produced: a row in the partial's
## Impact on approved use cases, never an edit of that case's spec.
"Might have more variants later" is not a force. The row needs a spec line or a file:line,
or it is not written.
Forbidden in this repository
- Singleton — the Spring container already gives singleton scope; the manual version
with
staticprevents testing and hides global state. - Service Locator /
ApplicationContext.getBean— violates the composition set in@.claude/rules/architecture-ddd.md. Implsuffix, always —@.claude/rules/naming.md: the name says the role, not that it's an implementation of something.- Pattern name standing in for a role name that exists (
OrderStrategyinstead ofDiscountPolicy,OrderDecoratorinstead of naming what it actually adds) — same rule, and the two curated exemplars (Strategy.java.example,Decorator.java.example) deliberately avoid the pattern name for exactly this reason. Not forbidden when the pattern name is the established Java role vocabulary with no better alternative —Adapter,Repository,Builder,Factoryare accepted the same way@.claude/rules/naming.md's own convention table already accepts<Resource>RepositoryAdapter. The test: is there a business-meaningful name this class could have instead? If yes, use it. If the honest answer is "no, this is just the JDK-idiomatic word for this role," the pattern name stays.
Contract
Class: build — the territory is skill_classes.build's override for this skill in
@.claude/schemas/extensions.json: the src/ tree, nothing else. It sits in build rather
than with the design skills because it materializes Java code, and ArchHook.java guard
therefore also makes it unreachable from inside a design run.
Reads .claude/rules/code-quality.md, .claude/rules/naming.md,
.claude/rules/architecture-ddd.md, the active blueprint's packages.map, and
references/pattern-catalog.md when the symptom doesn't match any row of the curated
table above.
Writes domain and application code in the generated project. Doesn't touch the
inbound REST adapter — the package the blueprint's packages.map assigns to that role,
whether adapter.in.rest or infrastructure.rest — which is rest-api-architect's
territory.
Three uses, one writer each. Design time — the pipeline's design skills read § Design-time
use and write the decision into their own partial; this skill writes nothing and is not
invoked (@.claude/decisions/0089-design-patterns-decided-at-design-time.md). Standalone — a human runs
/gof-design-patterns against real code with an observed symptom; this skill is the sole
writer for that turn, as above. Injected — in a generated project, ArchHook.java context
subagent runs at SubagentStart and hands the sections listed in subagent_context of
@.claude/schemas/extensions.json (this file's ## Why this is a skill and not a rule,
## Catalog and ## Forbidden in this repository) to every agent whose agent_classes
entry declares pattern_catalog: true, before its first turn. The agent implements the
patterns the spec already decided, and applies a row on its own only for a symptom already
on disk, never as a separate invocation. In that mode this skill
writes nothing itself: the agent remains the sole owner of src/** (invariant 2), and the
catalog is reference material, the same role templates/*.example plays for the other
four pipeline skills. Renaming one of those three headings empties the injection —
ArchHook.java schema fails on it by name.
@.claude/decisions/0077-pattern-catalog-injected-at-subagent-start.md, which supersedes
0025: a skill with disable-model-invocation: true cannot be preloaded through an agent's
skills: field, so the catalog 0025 described never arrived.
Doesn't collide with the design skills (domain-modeling, persistence-architect,
rest-api-architect, messaging-architect, jobs-architect, cache-architect). They own the pattern decision
for a use case being designed, each for its own layer, through § Design-time use; this skill
owns the catalog and, invoked standalone, refactors code that already exists and already
hurts, from a concrete file:line, outside any feature run.
Does not create rules. If a new limit has to always hold, it goes to
rules/code-quality.md, not here.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

