# Design Patterns

Agents should invoke this skill when choosing patterns, designing...

- Repository: https://github.com/waybarrios/opencode-power-pack (549 stars)
- Category: Design
- License: MIT (modified; see UPSTREAMS.json)
- Last updated: 2026-10-28
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add waybarrios/opencode-power-pack --skill design-patterns -g -a claude-code -y`
Codex: `npx skills add waybarrios/opencode-power-pack --skill design-patterns -g -a codex -y`
Cursor: `npx skills add waybarrios/opencode-power-pack --skill design-patterns -g -a cursor -y`
Gemini CLI: `npx skills add waybarrios/opencode-power-pack --skill design-patterns -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add waybarrios/opencode-power-pack`

## Description

Agents should invoke this skill when choosing patterns, designing traits/interfaces/components, deciding abstraction boundaries, evaluating dependency injection/callbacks, or comparing implementation approaches in Rust, TypeScript/React, or Django/Python.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Design Patterns

Pattern recommendations tailored to common tech stacks. Every pattern recommendation includes when to use it, when to avoid it, and the trade-offs.

## Quick Start

### Choose a Pattern

1. **Identify the problem:** What design challenge are you solving?
2. **Consider the context:** What language? What scale? How often will this change?
3. **Evaluate options:** 2-3 candidate patterns with trade-offs
4. **Recommend:** The best fit for *this specific context* (not the "best pattern in general")

**The golden rule:** Patterns are tools, not goals. Use the simplest pattern that solves the problem. If no pattern fits, a plain function or struct is fine.

---

## Rust Patterns

### Newtype Pattern

Wrap a primitive to add type safety and domain meaning.

```rust
struct UserId(u64);
struct OrderId(u64);

// Now the compiler prevents mixing up UserId and OrderId
fn get_order(user: UserId, order: OrderId) -> Order { ... }
```

**When to use:** When two values have the same underlying type but different meanings.
**When to skip:** One-off uses where a type alias suffices.

### Builder Pattern

Construct complex objects step by step.

```rust
let config = ServerConfig::builder()
    .host("localhost")
    .port(8080)
    .max_connections(100)
    .build()?;
```

**When to use:** Structs with many optional fields, complex construction logic.
**When to skip:** Structs with 1-3 required fields, just use `new()`.

### Typestate Pattern

Encode state transitions in the type system so invalid states are unrepresentable.

```rust
struct Connection<S: State> { /* ... */ state: PhantomData<S> }
struct Disconnected;
struct Connected;
struct Authenticated;

The rest: https://github.com/waybarrios/opencode-power-pack/blob/HEAD/skills/design-patterns/SKILL.md
