/django-patterns
Django architecture patterns including DRF, ORM optimization, signals, middleware, and project structure
$ npx -y skills add rohitg00/awesome-claude-code-toolkit --skill django-patterns --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/django-patterns
Context preview
The summary Claude sees to decide when to auto-load this skill.
Django architecture patterns including DRF, ORM optimization, signals, middleware, and project structure
SKILL.md
django-patterns.SKILL.mdname: django-patterns
description: Django architecture patterns including DRF, ORM optimization, signals, middleware, and project structure
Django Patterns
Project Structure
Organize Django projects with a clear separation between apps, shared utilities, and configuration.
project/
config/
settings/
base.py
local.py
production.py
urls.py
wsgi.py
apps/
users/
models.py
serializers.py
views.py
services.py
selectors.py
urls.py
tests/
orders/
...
common/
models.py
permissions.py
pagination.pyKeep business logic in `services.py` (write operations) and `selectors.py` (read operations). Views should remain thin.
ORM Optimization
# select_related for ForeignKey / OneToOne (SQL JOIN)
orders = Order.objects.select_related("customer", "customer__profile").all()
# prefetch_related for ManyToMany / reverse FK (separate query)
authors = Author.objects.prefetch_related(
Prefetch("books", queryset=Book.objects.filter(published=True))
).all()
# Defer fields you don't need
posts = Post.objects.defer("body", "metadata").filter(status="published")
# Use .only() when you need just a few columns
emails = User.objects.only("id", "email").filter(is_active=True)
# Bulk operations
Product.objects.bulk_create(products, batch_size=1000)
Product.objects.bulk_update(products, ["price", "stock"], batch_size=1000)Always check queries with `django-debug-toolbar` or `connection.queries` in tests.
Django REST Framework Serializers
class OrderSerializer(serializers.ModelSerializer):
customer_name = serializers.CharField(source="customer.full_name", read_only=True)
items = OrderItemSerializer(many=True, read_only=True)
total = serializers.SerializerMethodField()
class Meta:
model = Order
fields = ["id", "customer_name", "items", "total", "created_at"]
read_only_fields = ["id", "created_at"]
def get_total(self, obj):
return sum(item.price * item.quantity for item in obj.items.all())
def validate(self, data):
if data.get("start_date") and data.get("end_date"):
if data["start_date"] >= data["end_date"]:
raise serializers.ValidationError("end_date must be after start_date")
return dataSignals
from django.db.models.signals import post_save
from django.dispatch import receiver
@receiver(post_save, sender=Order)
def order_created_handler(sender, instance, created, **kwargs):
if created:
send_order_confirmation.delay(instance.id)
update_inventory.delay(instance.id)Prefer signals for cross-app side effects. For same-app logic, call services directly.
Custom Middleware
import time
import logging
logger = logging.getLogger(__name__)
class RequestTimingMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
start = time.monotonic()
response = self.get_response(request)
duration = time.monotonic() - start
logger.info(f"{request.method} {request.path} {response.status_code} {duration:.3f}s")
return responseAnti-Patterns
- Putting business logic in views or serializers instead of service layers
- Using `Model.objects.all()` without pagination in list endpoints
- N+1 queries from missing `select_related` / `prefetch_related`
- Overusing signals for same-app logic (makes flow hard to trace)
- Storing secrets in `settings.py` instead of environment variables
- Running raw SQL without parameterized queries
Checklist
- [ ] Business logic lives in services/selectors, not views
- [ ] All list queries use `select_related` or `prefetch_related` where needed
- [ ] Serializers validate input data with custom `validate` methods
- [ ] Settings split into base/local/production modules
- [ ] Migrations are reviewed before merging
- [ ] Bulk operations used for batch inserts/updates
- [ ] Custom middleware follows the WSGI callable pattern
- [ ] Tests cover model constraints, serializer validation, and view permissions
Read more
name: django-patterns description: Django architecture patterns including DRF, ORM optimization, signals, middleware, and project structure
Django Patterns
Project Structure
Organize Django projects with a clear separation between apps, shared utilities, and configuration.
project/
config/
settings/
base.py
local.py
production.py
urls.py
wsgi.py
apps/
users/
models.py
serializers.py
views.py
services.py
selectors.py
urls.py
tests/
orders/
...
common/
models.py
permissions.py
pagination.pyKeep business logic in `services.py` (write operations) and `selectors.py` (read operations). Views should remain thin.
ORM Optimization
# select_related for ForeignKey / OneToOne (SQL JOIN)
orders = Order.objects.select_related("customer", "customer__profile").all()
# prefetch_related for ManyToMany / reverse FK (separate query)
authors = Author.objects.prefetch_related(
Prefetch("books", queryset=Book.objects.filter(published=True))
).all()
# Defer fields you don't need
posts = Post.objects.defer("body", "metadata").filter(status="published")
# Use .only() when you need just a few columns
emails = User.objects.only("id", "email").filter(is_active=True)
# Bulk operations
Product.objects.bulk_create(products, batch_size=1000)
Product.objects.bulk_update(products, ["price", "stock"], batch_size=1000)Always check queries with `django-debug-toolbar` or `connection.queries` in tests.
Django REST Framework Serializers
class OrderSerializer(serializers.ModelSerializer):
customer_name = serializers.CharField(source="customer.full_name", read_only=True)
items = OrderItemSerializer(many=True, read_only=True)
total = serializers.SerializerMethodField()
class Meta:
model = Order
fields = ["id", "customer_name", "items", "total", "created_at"]
read_only_fields = ["id", "created_at"]
def get_total(self, obj):
return sum(item.price * item.quantity for item in obj.items.all())
def validate(self, data):
if data.get("start_date") and data.get("end_date"):
if data["start_date"] >= data["end_date"]:
raise serializers.ValidationError("end_date must be after start_date")
return dataSignals
from django.db.models.signals import post_save
from django.dispatch import receiver
@receiver(post_save, sender=Order)
def order_created_handler(sender, instance, created, **kwargs):
if created:
send_order_confirmation.delay(instance.id)
update_inventory.delay(instance.id)Prefer signals for cross-app side effects. For same-app logic, call services directly.
Custom Middleware
import time
import logging
logger = logging.getLogger(__name__)
class RequestTimingMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
start = time.monotonic()
response = self.get_response(request)
duration = time.monotonic() - start
logger.info(f"{request.method} {request.path} {response.status_code} {duration:.3f}s")
return responseAnti-Patterns
- Putting business logic in views or serializers instead of service layers
- Using `Model.objects.all()` without pagination in list endpoints
- N+1 queries from missing `select_related` / `prefetch_related`
- Overusing signals for same-app logic (makes flow hard to trace)
- Storing secrets in `settings.py` instead of environment variables
- Running raw SQL without parameterized queries
Checklist
- [ ] Business logic lives in services/selectors, not views
- [ ] All list queries use `select_related` or `prefetch_related` where needed
- [ ] Serializers validate input data with custom `validate` methods
- [ ] Settings split into base/local/production modules
- [ ] Migrations are reviewed before merging
- [ ] Bulk operations used for batch inserts/updates
- [ ] Custom middleware follows the WSGI callable pattern
- [ ] Tests cover model constraints, serializer validation, and view permissions
The most comprehensive toolkit for Claude Code -- 135 agents, 35 curated skills (+400,000 via SkillKit), 42 commands, 176+ plugins, 20 hooks, 15 rules, 7 templates, 15 MCP configs, 26 companion apps, 53 ecosystem entries, and more.
Repo: rohitg00/awesome-claude-code-toolkit
Other skills on rohitg00-claude-code-toolkit.
- /accessibility-wcag
Web accessibility patterns for WCAG 2.2 compliance including ARIA, keyboard navigation, screen readers, and testing
Open skill - /agentkit-seo
Route broad or ambiguous AgentKit SEO work to the right module while keeping context scoped. Use when a request spans multiple surfaces, asks for overall digital-presence strategy, involves provider or install architecture, needs agent-context planning, or the correct platform
Open skill - /api-design-patterns
REST API design with resource naming, pagination, versioning, and OpenAPI spec generation
Open skill - /authentication-patterns
Authentication and authorization patterns including OAuth2, JWT, RBAC, session management, and PKCE flows
Open skill - /aws-cloud-patterns
AWS cloud patterns for Lambda, ECS, S3, DynamoDB, and Infrastructure as Code with CDK/Terraform
Open skill - /ci-cd-pipelines
CI/CD pipeline patterns for GitHub Actions, GitLab CI, testing strategies, and deployment automation
Open skill

