python-design-patterns

Applies Python design principles like SRP, composition, and dependency injection to structure maintainable code.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill python-design-patterns-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-design-patterns
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/python-design-patterns
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill python-design-patterns-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python codebases often grow into tangled God classes, monolithic functions, and tightly coupled layers that are hard to test and modify. This Skill provides concrete design patterns and refactoring guidance to keep Python code simple, modular, and testable. ## Core Features & Use Cases - Fundamental Design Principles: Apply KISS, Single Responsibility, Separation of Concerns, and composition over inheritance with before-and-after code examples. - Layered Architecture Guidance: Structure code into API, service, and repository layers with correct dependency direction. - Testability Through Dependency Injection: Inject repositories, caches, and loggers via constructors using Protocol-based interfaces for easy fakes in tests. - Use Case: When reviewing a pull request where a handler mixes HTTP parsing, SQL queries, and business rules, use this Skill to split it into a handler, service, and repository with clear responsibilities. ## Quick Start Ask the AI to refactor a large Python class or function using the design patterns in this skill, separating concerns into focused layers.

Frequently Asked Questions about python-design-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor a God class in Python?

Apply the Single Responsibility Principle by listing every reason the class could change, then split concerns from different domains into separate classes. Use constructor dependency injection so each new class receives only the collaborators it needs.

When should I use composition instead of inheritance in Python?

Prefer composition when behavior can be built by combining objects rather than extending classes. Composition makes dependencies explicit, simplifies testing with fakes, and avoids rigid hierarchies that break when base classes change.

How do I structure a Python project into layers?

Organize code into API handlers, a service layer for business logic, and a repository layer for data access. Dependencies must point downward only: handlers import services, services import repositories, never the reverse.

When should I avoid creating an abstraction in Python?

Follow the rule of three: wait until three similar instances exist before abstracting. Premature abstraction often produces the wrong interface, while modest duplication is cheaper to maintain than a leaky shared abstraction.

Why does dependency injection produce constructors with too many parameters?

Constructors with seven or more parameters signal the class has too many responsibilities, not that injection is wrong. Split the class into smaller units first, and each resulting constructor naturally becomes smaller.