后端助手
- 作者仓库星标 0
- 作者更新于 实时读取
- 作者仓库 skills-registry
- 领域
- 通用
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 88 / 100 · 社区维护
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- Token 消耗评级
- 中等消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 底层运行要求
- Python
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 网络行为
- 仅限本地
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: django-clean-arch
description: > Use when this capability is needed. Standard Django encourages "fat models" and business logic…
category: 通用
runtime: Python
---
# django-clean-arch 输出预览
## PART A: 任务判断
- 适用问题:通用任务拆解、检查和交付。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“The Layered Structure / Domain Models (Pure Python) / Repository Interfaces (Abstract)”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于通用任务拆解、检查和交付,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“The Layered Structure / Domain Models (Pure Python) / Repository Interfaces (Abstract)”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、执行终端命令、主要在本地完成、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、执行终端命令;主要在本地完成;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文没有稳定的斜杠命令要求。安装验证后通常全局生效,直接在对话里点名这个 Skill 并描述任务即可。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、执行终端命令。
先用一个小任务确认它会围绕“The Layered Structure / Domain Models (Pure Python) / Repository Interfaces (Abstract)”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: django-clean-arch
description: > Use when this capability is needed. Standard Django encourages "fat models" and business logic…
category: 通用
source: tomevault-io/skills-registry
---
# django-clean-arch
## 什么时候使用
- 把通用方向的常用动作沉淀成 Agent 可调用的技能 适合处理通用任务拆解、检查、交付和复盘,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查、可继续迭代的步骤;通常不需要额外…
- 面向通用任务拆解、检查和交付,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「The Layered Structure / Domain Models (Pure Python) / Repository Interfaces (Abstract)」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、执行终端命令;主要在本地完成;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "django-clean-arch" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> The Layered Structure / Domain Models (Pure Python) / Repository Interfaces (Abstract)
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> Python | 读取文件、写入/修改文件、执行终端命令 | 主要在本地完成
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} django_clean_arch
Standard Django encourages "fat models" and business logic in views or model methods. Clean Architecture inverts this: Django becomes a delivery mechanism, and the core domain is framework-independent. This skill covers the patterns, file structure, and conventions for Clean Architecture in Django.
The Layered Structure
myproject/
├── domain/ # Pure Python — no Django, no DB
│ ├── models/ # Domain entities and value objects
│ │ ├── order.py
│ │ └── user.py
│ ├── repositories/ # Abstract interfaces (Protocol/ABC)
│ │ ├── order_repository.py
│ │ └── user_repository.py
│ └── exceptions.py # Domain-specific exceptions
│
├── application/ # Use cases — orchestrates domain
│ ├── use_cases/
│ │ ├── create_order.py
│ │ ├── cancel_order.py
│ │ └── get_order_summary.py
│ └── services/ # Application services (not domain services)
│ └── email_service.py # Abstract interface for sending emails
│
├── infrastructure/ # Concrete implementations of interfaces
│ ├── repositories/
│ │ ├── django_order_repository.py # Uses Django ORM
│ │ └── django_user_repository.py
│ └── services/
│ └── sendgrid_email_service.py
│
├── interfaces/ # Delivery layer — Django views, DRF serializers
│ ├── api/
│ │ ├── views.py # Thin views: parse → use case → serialize
│ │ ├── serializers.py
│ │ └── urls.py
│ └── admin/
│ └── admin.py
│
└── config/ # Django settings, dependency injection
├── settings.py
├── urls.py
└── container.py # Dependency injection wiring
Domain Models (Pure Python)
Domain models are plain Python dataclasses or classes — no Django inheritance, no ORM fields:
# domain/models/order.py
from __future__ import annotations
from dataclasses import dataclass, field
from decimal import Decimal
from datetime import datetime
from typing import Optional
from enum import Enum
class OrderStatus(str, Enum):
PENDING = "pending"
CONFIRMED = "confirmed"
SHIPPED = "shipped"
CANCELLED = "cancelled"
@dataclass
class OrderItem:
product_id: int
name: str
price: Decimal
quantity: int
@property
def subtotal(self) -> Decimal:
return self.price * self.quantity
@dataclass
class Order:
user_id: int
items: list[OrderItem]
status: OrderStatus = OrderStatus.PENDING
id: Optional[int] = None
created_at: Optional[datetime] = None
@property
def total(self) -> Decimal:
return sum(item.subtotal for item in self.items)
def cancel(self, reason: str) -> None:
if self.status == OrderStatus.SHIPPED:
raise ValueError("Cannot cancel a shipped order")
self.status = OrderStatus.CANCELLED
self._cancellation_reason = reason
Repository Interfaces (Abstract)
# domain/repositories/order_repository.py
from typing import Protocol, Optional
from myproject.domain.models.order import Order
class OrderRepository(Protocol):
def save(self, order: Order) -> Order: ...
def find_by_id(self, order_id: int) -> Optional[Order]: ...
def find_by_user(self, user_id: int) -> list[Order]: ...
def delete(self, order_id: int) -> None: ...
Use Cases
Each use case handles exactly one business operation. It receives dependencies via constructor, and exposes a single execute() method:
# application/use_cases/create_order.py
from dataclasses import dataclass
from decimal import Decimal
from typing import Optional
from myproject.domain.models.order import Order, OrderItem
from myproject.domain.repositories.order_repository import OrderRepository
from myproject.domain.repositories.product_repository import ProductRepository
from myproject.domain.exceptions import ProductNotFoundError
@dataclass
class CreateOrderInput:
user_id: int
product_ids: list[int]
coupon_code: Optional[str] = None
@dataclass
class CreateOrderOutput:
order_id: int
total: Decimal
status: str
class CreateOrderUseCase:
def __init__(
self,
order_repo: OrderRepository,
product_repo: ProductRepository,
) -> None:
self._orders = order_repo
self._products = product_repo
def execute(self, input: CreateOrderInput) -> CreateOrderOutput:
products = self._products.find_by_ids(input.product_ids)
if len(products) != len(input.product_ids):
raise ProductNotFoundError("One or more products not found")
items = [
OrderItem(
product_id=p.id,
name=p.name,
price=p.price,
quantity=1, # simplification
)
for p in products
]
order = Order(user_id=input.user_id, items=items)
saved = self._orders.save(order)
return CreateOrderOutput(
order_id=saved.id,
total=saved.total,
status=saved.status.value,
)
Django ORM Repository (Infrastructure)
# infrastructure/repositories/django_order_repository.py
from typing import Optional
from myproject.domain.models.order import Order, OrderItem, OrderStatus
from myproject.domain.repositories.order_repository import OrderRepository
from myproject.infrastructure.orm_models import OrderORM, OrderItemORM
class DjangoOrderRepository:
"""Translates between domain Order and Django ORM OrderORM."""
def save(self, order: Order) -> Order:
if order.id is None:
orm_obj = OrderORM.objects.create(
user_id=order.user_id,
status=order.status.value,
)
for item in order.items:
OrderItemORM.objects.create(
order=orm_obj,
product_id=item.product_id,
name=item.name,
price=item.price,
quantity=item.quantity,
)
else:
orm_obj = OrderORM.objects.get(id=order.id)
orm_obj.status = order.status.value
orm_obj.save()
return self._to_domain(orm_obj)
def find_by_id(self, order_id: int) -> Optional[Order]:
try:
orm_obj = OrderORM.objects.prefetch_related('items').get(id=order_id)
return self._to_domain(orm_obj)
except OrderORM.DoesNotExist:
return None
def _to_domain(self, orm_obj: OrderORM) -> Order:
return Order(
id=orm_obj.id,
user_id=orm_obj.user_id,
status=OrderStatus(orm_obj.status),
items=[
OrderItem(
product_id=item.product_id,
name=item.name,
price=item.price,
quantity=item.quantity,
)
for item in orm_obj.items.all()
],
)
Thin Views (Delivery Layer)
# interfaces/api/views.py
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from myproject.application.use_cases.create_order import CreateOrderUseCase, CreateOrderInput
from myproject.config.container import get_container
from .serializers import CreateOrderSerializer
class OrderCreateView(APIView):
def post(self, request):
# 1. Parse and validate input
serializer = CreateOrderSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
# 2. Call use case
use_case: CreateOrderUseCase = get_container().create_order_use_case
output = use_case.execute(
CreateOrderInput(
user_id=request.user.id,
product_ids=serializer.validated_data['product_ids'],
coupon_code=serializer.validated_data.get('coupon_code'),
)
)
# 3. Serialize output
return Response(
{"order_id": output.order_id, "total": str(output.total)},
status=status.HTTP_201_CREATED,
)
Dependency Injection / Container
Wire up concrete implementations to interfaces in one place:
# config/container.py
from functools import lru_cache
from myproject.infrastructure.repositories.django_order_repository import DjangoOrderRepository
from myproject.infrastructure.repositories.django_product_repository import DjangoProductRepository
from myproject.application.use_cases.create_order import CreateOrderUseCase
class Container:
@property
def order_repository(self):
return DjangoOrderRepository()
@property
def product_repository(self):
return DjangoProductRepository()
@property
def create_order_use_case(self) -> CreateOrderUseCase:
return CreateOrderUseCase(
order_repo=self.order_repository,
product_repo=self.product_repository,
)
@lru_cache(maxsize=1)
def get_container() -> Container:
return Container()
Testing Strategy
The biggest win of Clean Architecture is testability. Use cases can be tested with in-memory repositories — no DB, no Django test client, no fixtures:
def test_create_order_calculates_correct_total():
order_repo = InMemoryOrderRepository()
product_repo = InMemoryProductRepository([
Product(id=1, name="Book", price=Decimal("29.99")),
Product(id=2, name="Pen", price=Decimal("4.99")),
])
use_case = CreateOrderUseCase(order_repo, product_repo)
output = use_case.execute(CreateOrderInput(user_id=1, product_ids=[1, 2]))
assert output.total == Decimal("34.98")
assert len(order_repo.find_by_user(user_id=1)) == 1
Key Rules
- Domain models never import from Django.
- Use cases never import from Django.
- Repositories in the domain layer are abstract (Protocol); concrete ones live in infrastructure.
- Views are thin: parse → use case → serialize. No business logic in views.
- Django ORM models (for migrations and DB access) live in
infrastructure/and are separate from domain models.
Source: bloom-tool/bloom — distributed by TomeVault.
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核