agentleFS
JoseVelazcoHJoseVelazcoH/python-skills/skills/python-design-principles/SKILL.md

python-design-principles

Skill0 starsChanged 5 months agoApache-2.0View on GitHub

Trigger: SOLID, dependency inversion, coupling, cohesion, strategy pattern, open/closed, abstractions, Protocol, ABC, class structure. Shape Python class and module design.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is 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.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Prefer small Protocol interfaces (ISP) over fat ones.

    line 24
  2. Distinctive:

    Do not add patterns the design does not yet need (YAGNI).

    line 41

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Python Design Principles

Structure-level design: how classes and modules relate: coupling/cohesion, dependency inversion, strategy, and SOLID.

Activation Contract

Apply when designing or refactoring class/module structure: a class does many jobs, high-level code instantiates concretions, a growing if/elif selects behavior, or the user asks about SOLID/coupling/abstractions. For line-level readability use python-clean-code; for system layering use architecture guidance.

Hard Rules

  • One reason to change per class (SRP). High cohesion (related behavior together), low coupling (few cross-dependencies).
  • Depend on abstractions, not concretions (DIP). Inject collaborators via the constructor; never instantiate concrete deps inside a class.
  • Open for extension, closed for modification (OCP): add behavior with a new class, not by editing an if/elif.
  • Replace branching-on-type with the Strategy pattern: interchangeable classes behind a common Protocol/ABC.
  • Prefer small Protocol interfaces (ISP) over fat ones. Subtypes must honor the parent contract (LSP): no raise NotImplementedError overrides.

Decision Gates

SymptomPrincipleFix
Class generates IDs, prices, printsSRP/cohesionSplit into focused classes
self.db = PostgresDB() inside serviceDIPInject a Protocol collaborator
if type == "credit": ... elif ...OCP/StrategyStrategy classes behind one interface
Interface with methods some impls rejectISP/LSPSplit into small Protocols
Module A imports B imports ACouplingInvert dependency via abstraction

Execution Steps

  1. Identify the principle violated from the gate table.
  2. Introduce the smallest abstraction that fixes it: a Protocol or ABC, injected.
  3. Show # Bad → # Good; verify the client now depends only on the abstraction.
  4. Do not add patterns the design does not yet need (YAGNI).
from typing import Protocol

# Bad: branch on type, closed to extension
def pay(order, kind):
    if kind == "credit": ...
    elif kind == "debit": ...

# Good: Strategy behind a Protocol (OCP + DIP)
class PaymentProcessor(Protocol):
    def pay(self, order: Order) -> None: ...

class CreditProcessor:
    def pay(self, order: Order) -> None: ...

def checkout(order: Order, processor: PaymentProcessor) -> None:
    processor.pay(order)

Output Contract

Return restructured Python where clients depend on abstractions, plus a one-line note naming each principle applied. Keep the abstraction minimal.

References

  • references/solid.md: the five SOLID principles with Python examples.
  • references/coupling-strategy.md: coupling/cohesion and the Strategy pattern.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.