python-design
What it does
The skill gives design rules for Python scripts and tools. It is for developers who want code that is easy to change and easy to understand.
When to use it
- βWhen you write or change Python files, especially command-line scripts.
- βWhen you plan how to split a Python project into modules.
- βWhen you review Python code and want to spot design problems.
Skill link
https://github.com/mindfold-ai/Trellis/blob/main/.agents/skills/python-design/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βReview this Python script and tell me where its design is getting messy or hard to change.β
5 new skills a week. 1 minute to read.
How it works
The agent applies rules from a well-known software design book, such as keeping modules deep with simple interfaces, and checks for warning signs that make code hard to change.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Python Design for CLI Scripts
Design patterns and principles for writing maintainable Python CLI tools and utilities. Based on A Philosophy of Software Design (Ousterhout), adapted for scripting contexts.
When to Activate
- Writing or modifying Python files
- Planning module decomposition
- Code review of Python changes
- Refactoring scripts that feel "messy"
- Adding a new subcommand or utility function
Core Thesis
The central challenge is managing complexity, not adding features.
Complexity is anything that makes code hard to understand or modify. It has three symptoms:
- Change Amplification β A small change requires edits in many places
- Cognitive Load β You must hold too much context to make a safe change
- Unknown Unknowns β You don't know what you don't know (the most dangerous)
Complexity is incremental. It accumulates through hundreds of small decisions, not one catastrophic mistake. Therefore: sweat the small stuff.
Principle 1: Deep Modules
A module's value is the ratio of functionality hidden vs. interface exposed.
Deep module (good): Shallow module (bad):
ββββββββββββ ββββββββββββββββββββββββββββ
β simple β β complex interface β
β interfaceβ β many params, many methods β
ββββββββββββ€ ββββββββββββββββββββββββββββ€
β β β β
β rich β β thin implementation β
β impl β β β
β β ββββββββββββββββββββββββββββ
β β
ββββββββββββ
Practical test: If a caller must understand how the module works internally to use it correctly, the module is too shallow.
Example: Task Data Access
# Shallow β caller must know JSON structure, file paths, error handling
def _read_json_file(path: Path) -> dict:
with open(path, encoding="utf-8") as f:
return json.load(f)
# Every caller does this independently:
task_path = tasks_dir / name / "task.json"
data = _read_json_file(task_path)
title = data.get("title") or data.get("name", "")
status = data.get("status", "planning")
assignee = data.get("assignee", "")
# Deep β caller gets what they need, module hides JSON/path/parsing
@dataclass(frozen=True)
class TaskInfo:
name: str
title: str
status: str
assignee: str
priority: str
directory: Path
def load_task(tasks_dir: Path, name: str) -> TaskInfo | None:
"""Load task by directory name. Returns None if not found."""
...
def list_active_tasks(tasks_dir: Path) -> list[TaskInfo]:
"""List all non-archived tasks, sorted by priority."""
...
The deep version absorbs complexity: JSON parsing, field defaults, directory scanning, archive filtering. Callers just work with typed data.
Principle 2: Type-First Development
Types define contracts before implementation. This workflow catches design problems early:
- Define data shapes β dataclass or TypedDict first
- Define function signatures β parameter and return types
- Implement to satisfy types β let the type checker guide completeness
- Validate at boundaries β runtime checks only where data enters the system
Frozen Dataclasses for Internal Data
from dataclasses import dataclass
from typing import Literal
@dataclass(frozen=True)
class AgentRecord:
agent_id: str
task_name: str
worktree_path: Path
platform: Literal["Codex", "codex", "cursor"]
status: Literal["running", "done", "failed"]
branch: str
Frozen dataclasses are immutable β no accidental mutation, safe to pass around.
TypedDict for External JSON Shapes
When the data comes from a file (task.json, config.yaml, registry.json), use TypedDict to document the expected shape:
from typing import TypedDict, Required, NotRequired
class TaskData(TypedDict):
title: Required[str]
status: Required[str]
assignee: NotRequired[str]
priority: NotRequired[str]
parent: NotRequired[str]
children: NotRequired[list[str]]
This eliminates scattered .get("field", default) calls β the shape is documented once.
NewType for Domain Primitives
When two strings mean different things, make the type system enforce it:
from typing import NewType
TaskName = NewType("TaskName", str) # directory name like "03-10-v040"
BranchName = NewType("BranchName", str)
FAQ
Which problems does it look for?
It looks for changes that spread across many places, heavy mental load, and hidden surprises that make code risky to change.
Is it only for web apps?
No. The skill is written for scripts and command-line tools, so it fits those best.
Does it add new features?
No. The central idea is managing complexity rather than adding features.
Details
Original description by the author
Python design patterns for CLI scripts and utilities β type-first development, deep modules, complexity management, and red flags. Use when reading, writing, reviewing, or refactoring Python files, especially in .trellis/scripts/ or any CLI/scripting context. Also activate when planning module structure, deciding where to put new code, or doing code review.
repo: mindfold-ai/Trellis
Popularity
- GitHub stars
- 15k
- Ranking position
- #11023
- License
- AGPL-3.0
- Updated
- 9/29/2026
Comments
- β¦
More skills from this repository
first-principles-thinking
15kHelps your agent test a plan or design by breaking it into basic truths and reasoning up from them, instead of relying on habit or convention.
trellis-before-dev
15kHelps your agent read the project's coding guidelines and task notes before it starts writing code, so it follows the team's conventions.
trellis-brainstorm
15kHelps your agent clarify a new feature or unclear task by asking one useful question at a time, checking the code, and agreeing on a narrow scope.
trellis-break-loop
15kHelps your agent analyze a bug after it is fixed, find its root cause type and why earlier fixes failed, and save lessons to prevent a repeat.
Similar skills
api-connector-builder
280kHas your agent build new API connections following the existing pattern. Use when you need to add one more integration without creating a new way of doing things.
api-design
280kHelps your agent design REST APIs following best practices. It's useful for defining how APIs communicate, how errors are shown, and how to organize data.
backend-patterns
280kHelps your agent with server-side architecture patterns and database optimization. It's useful for building or reviewing code that runs on the server.