python-django-architecture
Use when the user asks about Django, Django ORM queries that are slow, select_related and prefetch_related, Django REST framework (DRF), Django apps structure…
от j4flmao★ 47 звёзд на GitHub
Установить python-django-architecture в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Python Django Architecture
Purpose
Structure Django applications with one app per bounded context, service layer for business logic, thin views, DRF serializers as DTOs, and clean separation of concerns.
Agent Protocol
Trigger
Exact user phrases: "Django structure", "Django architecture", "Django apps", "Django clean arch", "Django ORM", "Django REST framework", "DRF", "Django project layout".
Input Context
Before activating, verify:
- requirements.txt or pyproject.toml has Django dependency.
- The app or feature being created is known.
Output Artifact
No file output. Produces folder structure and code examples as text.
Response Format
Folder structure:
config/
apps/{app}/
models.py, services.py, repositories.py, serializers.py, views.py, urls.py
Code: module-level only. No import statements.
No preamble. No postamble. No explanations. No filler/hedging/transitions. Compress output — why use many token when few do trick.
Completion Criteria
- One Django app per bounded context (not per table or per view).
- Business logic in services.py, not in models.py or views.py.
- Models are thin (fields, basic constraints, string methods only).
- DRF serializers act as DTOs at the API boundary.
- Views are thin (validate input, call service, return response).
- Signals delegate to services, do not contain business logic.
- select_related/prefetch_related used to prevent N+1 queries.
Max Response Length
Folder structure: unlimited. Code: 15 lines per example.
Architecture Decision Trees
Django App Boundaries: Bounded Context vs Table-per-app
| Criterion | Bounded Context (Recommended) | Table-per-app |
|---|---|---|
| Coupling | Loose (context boundary) | Tight (related tables split) |
| Team autonomy | High (per context ownership) | Low (changes affect multiple apps) |
| Reusability | High (complete business capability) | Low (fragmented) |
| Migration complexity | Low (within context) | High (cross-app foreign keys) |
Decision: Business capability grouping → Bounded Context. Quick-and-dirty → you still want bounded context. Never table-per-app.
DRF View Types
| View Type | Boilerplate | Flexibility | Best For |
|---|---|---|---|
| ViewSet + ModelViewSet | Minimal | Low | Standard CRUD |
| GenericAPIView + mixins | Low | Medium | Standard with customization |
| APIView | Manual | High | Complex business logic |
| View + JSONResponse | None | Max | Non-DRF simple endpoints |
Decision: Standard CRUD → ModelViewSet. Custom logic → APIView. Non-DRF → View + JSONResponse.
Workflow
Step 1: Structure by App (Bounded Context)
project_root/
config/
settings/
base.py, dev.py, prod.py
urls.py
wsgi.py
apps/
accounts/
models.py
services.py -- Business logic layer
repositories.py -- Query abstraction
serializers.py -- DRF serializers
views.py -- Thin views (delegate to services)
urls.py
admin.py
tests/
test_services.py
test_views.py
migrations/
orders/
models.py
services.py
repositories.py
serializers.py
views.py
urls.py
shared/
exceptions.py -- Domain exceptions
pagination.py -- Shared pagination
Step 2: Service Layer (Business Logic Here)
# apps/orders/services.py
from dataclasses import dataclass
from django.db import transaction
from apps.orders.models import Order
from apps.orders.repositories import OrderRepository
from apps.notifications.services import NotificationService
class OrderService:
def __init__(self):
self.repo = OrderRepository()
self.notifications = NotificationService()
@transaction.atomic
def place_order(self, user_id: int, items: list[dict]) -> Order:
order = self.repo.create(user_id=user_id, status="pending")
for item in items:
self.repo.add_item(order, **item)
total = sum(item.price * item.quantity for item in order.items.all())
order.status = "confirmed" if total <= 10000 else "pending_approval"
order.total = total
order.save()
self.notifications.send_order_confirmation(order)
return order
def cancel_order(self, order_id: int) -> Order:
order = self.repo.get_by_id(order_id)
if not order.can_be_cancelled():
raise SharedException("Order cannot be cancelled in current status")
order.status = "cancelled"
order.save()
self.notifications.send_order_cancellation(order)
return order
Step 3: Repository Layer (Query Abstraction)
# apps/orders/repositories.py
from django.db.models import Prefetch
from apps.orders.models import Order, OrderItem
class OrderRepository:
def get_by_id(self, order_id: int) -> Order | None:
return
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/django-advanced.md
- references/django-celery.md
- references/django-orm-patterns.md
- references/django-rest-framework.md
- references/django-signals.md
- references/django-structure.md
FAQ
Что делает скилл python-django-architecture?
Use when the user asks about Django, Django ORM queries that are slow, select_related and prefetch_related, Django REST framework (DRF), Django apps structure or migrations. Produces Django code with a service layer and N+1-free queries. Not for FastAPI (use python-fastapi-architecture).
Как установить скилл python-django-architecture?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл python-django-architecture запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…