rtk-ai avatar

Design Patterns

This is a focused collection of Rust patterns for RTK's CLI filter architecture. It covers seven patterns with real examples: Newtype for type safety (preventing token count mixups), Builder for complex configs, State Machine for parsing multi-section output like pytest results, and others. The guide includes an honest anti-patterns section that pushes back against over-engineering, like adding async traits for "future-proofing" in a deliberately single-threaded tool. The pattern selection table is genuinely useful for deciding when to use what. Use this when you're adding a new filter module or refactoring existing ones and want to avoid both primitive obsession and unnecessary abstraction.

skills.sh installs
1.9K
GitHub stars
86K
last updated
Aug 21, 2026

Install

$ npx -y skills add rtk-ai/rtk --skill design-patterns --agent claude-code

Installs into .claude/skills of the current project.

Files

RTK Rust Design Patterns

Patterns that apply to RTK's filter module architecture. Focused on CLI tool patterns, not web/service patterns.

Pattern 1: Newtype (Type Safety)

Use when: wrapping primitive types to prevent misuse (command names, paths, token counts).

// Without Newtype — easy to mix up
fn track(input_tokens: usize, output_tokens: usize) { ... }
track(output_tokens, input_tokens);  // Silent bug!

// With Newtype — compile error on swap
pub struct InputTokens(pub usize);
pub struct OutputTokens(pub usize);
fn track(input: InputTokens, output: OutputTokens) { ... }
track(OutputTokens(100), InputTokens(400));  // Compile error ✅
// Practical RTK example: command name validation
pub struct CommandName(String);
impl CommandName {
    pub fn new(s: &str) -> Result<Self> {
        if s.contains(';') || s.contains('|') || s.contains('`') {
            anyhow::bail!("Invalid command name: shell metacharacters");
        }
        Ok(Self(s.to_string()))
    }
    pub fn as_str(&self) -> &str { &self.0 }
}

Pattern 2: Builder (Complex Configuration)

Use when: a struct has 4+ optional fields, many with defaults.

Sponsors

Details

Repository
github.com/rtk-ai/rtk
Categories
Code Review & Quality, Rust, Design & UI/UX, CLI & Terminal
First seen
Jun 3, 2026

More from rtk-ai/rtk

All 7
1freestylefly avatarxiaohongshu-cover-generatorfreestylefly/xiaohongshu-skillsGenerate Xiaohongshu (小红书) style cover images based on user topics. Use when the user wants to create a social media cover image in Xiaohongshu style, or mentio1.9Kskills.sh installs
2tanweai avatarp7tanweai/puaP7 Senior Engineer mode — solution-driven execution under P8 supervision. Use when user says 'P7模式', '方案驱动', or when spawned as sub-task executor by P8. Produce1.8Kskills.sh installs
3trailofbits avatarvulnerability-triage-brocardstrailofbits/skillsThis skill should be used when the user asks to "triage a vulnerability report", "assess a CVE", "evaluate a bug bounty submission", "decide if a finding is val1.8Kskills.sh installs
4ar9av avatarwiki-dedupar9av/obsidian-wikiScan the Obsidian wiki for page-level identity collisions — different pages covering the same concept under different names (e.g. "RSC" vs "React Server Compone1.8Kskills.sh installs
5b-mendoza avatarvalidate-implementation-planb-mendoza/agent-skillsAudits an implementation plan for requirements traceability, avoidable complexity, risky assumptions, and evidence gaps. Use when reviewing an AI-generated or h1.8Kskills.sh installs
6refoundai avatarbuilding-with-llmsrefoundai/lenny-skillsHelp users build effective AI applications. Use when someone is building with LLMs, writing prompts, designing AI features, implementing RAG, creating agents, r1.7Kskills.sh installs