suggest-patterns

A code-review command that checks Python code against Clean Architecture, an approach that keeps web requests, business rules, and database access in separate layers.

In plain words
What is it for?
Use it to inspect every Python file and review router, business-logic, and database relationships, interfaces, cohesion, coupling, and other design principles.
Why use it?
When these layers depend on each other in the wrong direction, code becomes harder to test, replace, and maintain. The review checks whether the project’s structure and dependencies follow the intended boundaries.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/mktoronto/python-clean-architecture/suggest-patterns
Clone the repo
git clone --depth 1 https://github.com/MKToronto/python-clean-architecture
Per session 12 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 966 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00012 $0.00966
Opus 5 $0.00006 $0.00483
Sonnet 5 $0.00002 $0.00193
Haiku 4.5 $0.00001 $0.00097

Measured 2d ago against content hash 495688a78a77, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

suggest-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/suggest-patterns.md · 54 lines

How it starts

The opening of the file, as written. The whole thing — 54 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Scan the code at $ARGUMENTS (or the current working directory if no path given) and recommend which of the 25 Pythonic design patterns would improve it.

Process

  1. Read the code — Find and read ALL Python files in the target path recursively.

  2. Match code smells to patterns — Look for these specific smells:

    Code Smell Pattern Pythonic Implementation
    Long if/elif switching behavior Strategy Callable type alias, pass functions as args
    Need to create families of related objects Abstract Factory Tuples of functions + functools.partial
    Two independent hierarchies that vary Bridge Callable type alias replaces abstract reference
    Need undo/batch/queue operations Command Functions returning undo closures
    Side effects mixed with core logic Pub/Sub Dict-based subscribe(event, handler) / post_event()
    Object creation from config/JSON data Registry dict[str, Callable] mapping + **kwargs unpacking
    Same algorithm duplicated across classes Template Method Free function + Protocol parameter
    Sequential data transformations Pipeline functools.reduce for composition
    Need to react to events without coupling Callback Function passed as argument
    Reusing a function with a different interface Function Wrapper Wraps another function, translates args
    Separating configuration from usage Function Builder Higher-order function returns configured function
    Bare primitives for domain concepts (prices, emails) Value Objects Subclass built-in types with __new__ validation, or frozen dataclass
    Need audit trail, temporal queries, or event replay Event Sourcing Immutable Event[T], append-only EventStore[T], projection functions
    Read/write patterns diverge; list views compute derived fields CQRS Separate write model + read projection, projector function after writes
    Complex object with many optional parts Builder Fluent API with Self return type, .build() returns frozen product
    Multiple DB writes that must succeed or fail together Unit of Work Context manager wrapping transaction: commit on success, rollback on error
    Need exactly one instance of a shared resource Singleton Module-level instance (preferred), or metaclass with _instances dict
    Object behaves differently depending on internal state State Protocol-based state objects, context delegates to current state
    Incompatible interface from external library Adapter Protocol interface + functools.partial for single-method adaptation
    Client coupled to complex subsystem details Facade Simplified interface class, functools.partial to bind dependencies
    Transient failures in external API/DB calls Retry @retry decorator with exponential backoff, fallback strategies
    Slow startup loading unused resources Lazy Loading functools.cache, cached_property, generators, __getattr__
    Data access logic mixed into domain classes Repository Protocol interface for CRUD, concrete implementations per backend
    Sequential operations on an object are verbose Fluent Interface Methods return self for chaining, domain-specific verbs
    Need extensibility without modifying core code Plugin Architecture Config-driven creation, importlib auto-discovery, self-registering modules
  3. Report suggestions — For each match, show:

    • File and line — where the smell is
    • Code smell — what makes this a candidate
    • Pattern — which pattern applies and why
    • Before — current code snippet
    • After — refactored code using the Pythonic implementation
    • Trade-off — is the refactoring worth it here? (sometimes the simple version is fine)
  4. Prioritize — Order suggestions by impact. A pattern that simplifies 50 lines beats one that saves 3 lines. Note when the current code is simple enough that applying a pattern would be over-engineering.

Read the full file on GitHub · 54 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 54 lines · 12 tokens per session scan A 495688a78a77

Subscribe to this mod's changes

suggest-patterns is a command published in the GitHub repository MKToronto/python-clean-architecture (8 stars, last pushed 2mo ago), licensed MIT. It adds 12 tokens to every session and 966 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.