Agent skill

Dj Scaffold

by dvf in dvf/opinionated-django

Set up a Django project into the op-django layout so the architecture, signals, and settings skills have a foundation to build on.

MITAuto-check: notesBackend & APIs

Install Dj Scaffold

skills CLI
$ npx skills add dvf/opinionated-django --skill dj-scaffold -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install dvf/opinionated-django dj-scaffold --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/dvf/opinionated-django.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/dj-scaffold .claude/skills/dj-scaffold && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
dj-scaffold
GitHub stars
109
Token cost
~3.3k tokens
SKILL.md length
664 words
Files
1
Skills in repo
9
Repo updated
First seen
Licence
MIT

At a glance

Set up a Django project into the op-django layout so the architecture, signals, and settings skills have a foundation to build on.

  • Works in 8 steps: Dependencies → src/project/ids.py → src/project/services.py → …
  • Starting a new project from scratch
  • SKILL.md covers BEFORE WRITING CODE, Target Layout, Step 1: Dependencies and Step 2: src/project/ids.py, plus 9 more sections
  • Calls uv and django-admin

What it does

Dj Scaffold is an agent skill from dvf/opinionated-django. Set up a Django project into the op-django layout so the architecture, signals, and settings skills have a foundation to build on. Use when starting a new project from scratch, or when converting an existing Django project to follow this opinionated structure. Creates the src/project/ shell (ids, services registry, api, reliable signals), installs dependencies with uv, and establishes the per-app directory conventions.

Its SKILL.md is about 3.3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Backend & APIs, covering Backend development. It works with Django. The repository describes itself as: An opinionated Django project with Repository pattern, Pydantic DTOs, svcs DI, and Stripe-style ULID IDs. The licence is MIT.

When your agent uses it

  • Starting a new project from scratch
  • Converting an existing Django project to follow this opinionated structure

Example prompts

  • “/dj-scaffold”

Requirements

  • Python 3
  • Pre-approved tools (allowed-tools): Read, Write, Edit, Bash, Grep, Glob

Workflow steps

8 steps, taken from the step headings in SKILL.md.

  1. Dependencies
  2. src/project/ids.py
  3. src/project/services.py
  4. src/project/signals.py — Reliable Signals
  5. Celery
  6. Settings
  7. Tooling config in pyproject.toml
  8. Verify

What it can do on your machine

Read from SKILL.md and the folder at commit f17fc2d. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read
    • Write
    • Edit
    • Bash
    • Grep
    • Glob

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • uv
    • django-admin

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • pyrefly.org

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Dj Scaffold loads about 3.3k tokens when it runs. Until then it costs about 109 tokens; SKILL.md has 664 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~109
When it runs · the whole SKILL.md, loaded when a task matches
~3.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NotePre-approves every shell command (allowed-tools: Bash)SKILL.md
    allowed-tools: Read, Write, Edit, Bash, Grep, Glob

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from dvf/opinionated-django at commit f17fc2d, republished under its MIT licence (© dvf). 664 words, ~3,339 tokens.

Download SKILL.mdSave it as .claude/skills/dj-scaffold/SKILL.md (or your agent's skills folder).
name
dj-scaffold
description
Set up a Django project into the op-django layout so the architecture, signals, and settings skills have a foundation to build on. Use when starting a new project from scratch, or when converting an existing Django project to follow this opinionated structure. Creates the src/project/ shell (ids, services registry, api, reliable signals), installs dependencies with uv, and establishes the per-app directory conventions.
allowed-tools
Read, Write, Edit, Bash, Grep, Glob

Scaffold an op-django Project

You are preparing a Django project to use the op-django patterns. After this skill runs, the dj-architecture and dj-signals skills can add features on top without any further setup.

BEFORE WRITING CODE

Figure out which situation you're in:

  • Greenfield — no Django project exists yet. You will run uv init and django-admin startproject, then transform the result.
  • Existing Django project — a manage.py, settings.py, and at least one app already exist. You will add the src/project/ shell alongside what's there and relocate files only if asked.

Read pyproject.toml (if present) and locate manage.py and settings.py so you know the project's current layout. Confirm with the user before moving any existing files.

Target Layout

src/
  manage.py
  project/
    __init__.py
    settings.py
    urls.py
    wsgi.py
    asgi.py
    api/
      __init__.py   # NinjaAPI() instance, exception handlers, mounts all resource routers
      <resource>/
        __init__.py  # re-exports router
        routes.py    # handler functions
        schemas.py   # ninja.Schema input types
    types.py        # AuthedRequest and other shared typing aliases
    ids.py          # prefixed ULID generators
    services.py    # svcs registry + get() helper
    signals.py     # ReliableSignal base + send_reliable machinery
  <app>/
    __init__.py
    apps.py
    admin.py
    models/
      __init__.py
      <entity>.py
    dtos/
      __init__.py
      <entity>.py
    repositories/
      __init__.py
      <entity>.py
    services/
      __init__.py
      <entity>.py
    signals.py      # optional, defines ReliableSignal instances
    receivers.py    # optional, @receiver handlers — must be idempotent
tests/
  <app>/
    test_repo.py
    test_service.py
    test_api.py
pyproject.toml

Per-app models/, dtos/, repositories/, services/ are packages, not single files — one module per entity.

Step 1: Dependencies

Use uv for everything. Never pip or poetry.

bash
uv add 'django>=6.0' 'django-ninja>=1.6' 'pydantic>=2.0' 'svcs>=25.1' \
       'python-ulid>=3.0' 'celery>=5.4' python-decouple
uv add --dev ruff 'pyrefly>=0.42' django-stubs pytest pytest-django

Pyrefly auto-recognizes Django constructs as long as django-stubs is installed — no plugin, no mypy_django_plugin-style config. See pyrefly.org/en/docs/django for the current support matrix.

Step 2: src/project/ids.py

python
from ulid import ULID


def prefixed_ulid(prefix: str) -> str:
    return f"{prefix}_{str(ULID()).lower()}"


def _make_generator(prefix: str):
    def generate() -> str:
        return prefixed_ulid(prefix)

    generate.__name__ = f"generate_{prefix}_id"
    generate.__qualname__ = f"generate_{prefix}_id"
    return generate


# Add one generator per aggregate root, with a unique 3-4 char prefix.
# Example:
# generate_prd_id = _make_generator("prd")

Step 3: src/project/services.py

python
import svcs

registry = svcs.Registry()


def register_services(registry: svcs.Registry) -> None:
    """Register every real factory. Tests re-run this to restore overrides."""
    # Register repositories and services here as the project grows.
    # Example:
    # from products.repositories.product import ProductRepository
    # from products.services.product import ProductService
    #
    # registry.register_factory(ProductRepository, ProductRepository)
    #
    # def _product_service_factory(container: svcs.Container) -> ProductService:
    #     return ProductService(container.get(ProductRepository))
    #
    # registry.register_factory(ProductService, _product_service_factory)


register_services(registry)


def get[T](service_type: type[T]) -> T:
    """Get a service from the registry. Works anywhere — views, tasks, commands."""
    return svcs.Container(registry).get(service_type)

Step 4a: src/project/types.py

Narrows request.user to a guaranteed-authenticated Django User so handlers don't have to deal with AnonymousUser unions.

python
# If the project swaps AUTH_USER_MODEL for a custom user (see dj-models),
# import that model here instead — a stale stock-User import makes this
# type silently wrong everywhere it's used.
from django.contrib.auth.models import User
from django.http import HttpRequest


class AuthedRequest(HttpRequest):
    """
    An HttpRequest whose `user` attribute is guaranteed to be an authenticated User.

    Use as the first-argument annotation on any django-ninja handler that requires
    auth. The narrowing is a contract, not runtime enforcement — pair this with
    ninja's `auth=` on the router or a middleware that rejects anonymous requests.
    """
    user: User  # type: ignore[assignment]

Step 4b: src/project/api/ package

The API lives in a package, not a single file. src/project/api/__init__.py owns the NinjaAPI() instance and central exception handlers, and mounts one router per resource subpackage. Each resource subpackage (src/project/api/<resource>/) contains routes.py (handler functions), schemas.py (ninja Schema input types), and an __init__.py that re-exports the router.

src/project/api/__init__.py:

python
from ninja import NinjaAPI

# Import resource routers and mount them below.
# from project.api.products import router as products_router

# TODO: no auth wired — every route is public at this mount point.
# `AuthedRequest` is a typing contract only; it enforces nothing at runtime.
# Wire real auth before shipping, e.g. NinjaAPI(auth=django_auth) or a
# per-router `auth=` argument.
api = NinjaAPI()

# api.add_router("/products", products_router)


@api.exception_handler(ValueError)
def on_value_error(request, exc: ValueError):
    return api.create_response(request, {"detail": str(exc)}, status=400)


@api.exception_handler(LookupError)
def on_lookup_error(request, exc: LookupError):
    return api.create_response(request, {"detail": str(exc)}, status=404)


@api.exception_handler(PermissionError)
def on_permission_error(request, exc: PermissionError):
    return api.create_response(request, {"detail": str(exc)}, status=403)

Example resource subpackage — src/project/api/products/routes.py:

python
from typing import List

from ninja import Router

from products.dtos.product import ProductDTO
from products.services.product import ProductService
from project.services import get
from project.types import AuthedRequest

from .schemas import CreateProductIn

router = Router()


@router.get("/", response=List[ProductDTO])
def list_products(request: AuthedRequest):
    return get(ProductService).list_products()

src/project/api/products/schemas.py:

python
from decimal import Decimal

from ninja import Schema


class CreateProductIn(Schema):
    name: str
    price: Decimal
    stock: int

src/project/api/products/__init__.py:

python
from .routes import router

__all__ = ["router"]

To add a new resource router: (a) create src/project/api/<resource>/ with routes.py, schemas.py, and __init__.py, then (b) import and mount the router in src/project/api/__init__.py via api.add_router("/<resource>", <resource>_router).

Wire api.urls into src/project/urls.py:

python
from django.contrib import admin
from django.urls import path
from project.api import api

urlpatterns = [
    path("admin/", admin.site.urls),
    path("api/", api.urls),
]

Step 5: src/project/signals.py — Reliable Signals

This module provides the ReliableSignal base that apps import. Receivers run asynchronously via Celery, and send_reliable() enqueues them inside the current DB transaction so rollbacks are respected.

python
import json

from celery import shared_task
from django.db import transaction
from django.dispatch import Signal
from django.utils.module_loading import import_string


@shared_task
def _dispatch_reliable_receiver(receiver_path: str, kwargs_json: str) -> None:
    receiver = import_string(receiver_path)
    receiver(**json.loads(kwargs_json))


class ReliableSignal(Signal):
    """A Django Signal whose receivers run asynchronously via Celery.

    - `send_reliable()` must be called inside a `transaction.atomic()` block.
    - Receiver tasks are enqueued on transaction commit, so rollbacks are respected.
    - Delivery is at-least-once. Every receiver MUST be idempotent.
    - Arguments MUST be JSON-serializable (pass IDs, never model instances).
    """

    def send_reliable(self, sender, **kwargs) -> None:
        payload = json.dumps(kwargs)
        # _live_receivers() is a private Django API; since Django 5.0 it returns
        # a (sync_receivers, async_receivers) tuple. Re-check on Django upgrades.
        sync_receivers, async_receivers = self._live_receivers(sender)
        for receiver in (*sync_receivers, *async_receivers):
            path = f"{receiver.__module__}.{receiver.__qualname__}"
            transaction.on_commit(
                lambda p=path: _dispatch_reliable_receiver.delay(p, payload)
            )

This is a minimal implementation — feel free to harden it (dead-letter queue, replay tooling, explicit retry policy) as the project matures.

Step 6: Celery

Create src/project/celery.py:

python
import os

from celery import Celery

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")

app = Celery("project")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()

In src/project/__init__.py:

python
from .celery import app as celery_app

__all__ = ("celery_app",)

Step 7: Settings

Hand off to the dj-settings skill to lay out settings.py with banner sections. At minimum it must include:

  • INSTALLED_APPS with each project app as "<app>.apps.<App>Config"
  • CELERY_BROKER_URL and CELERY_RESULT_BACKEND (read via python-decouple)
  • DEFAULT_AUTO_FIELD is irrelevant — all PKs are ULID CharFields
Show full SKILL.md (288 more words)Show less

Step 8: Tooling config in pyproject.toml

toml
[tool.ruff]
line-length = 100
target-version = "py312"

[tool.pyrefly]
project-includes = ["src"]
python-version = "3.12"

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "project.settings"
python_files = ["test_*.py"]
pythonpath = ["src"]

Pyrefly + Django caveats (from pyrefly.org/en/docs/django):

  • Pyrefly has built-in Django support. Install django-stubs and it just works — no plugin to enable, no extra [tool.pyrefly] keys required.
  • Reverse relations are not yet supported. Accessing user.order_set (the implicit reverse manager Django generates from a ForeignKey) will flag as an attribute error. Work around it in the repository layer by either (a) querying the child model directly — OrderRepository().list_for_user(user_id) — or (b) using an explicit related_name and a narrow cast / # type: ignore[attr-defined] at the call site. Do not paper over this in services or DTOs; push it down to the repo.
  • ManyRelatedManager is generic over [Parent, Model] rather than the concrete child type (unlike mypy's django-plugin). For DTO coercion this doesn't matter — the coerce_related_manager validator handles it — but don't rely on pyrefly to catch mistyped M2M targets.
  • Django's QuerySet typing beyond .all() is still thin. Keep chained queryset expressions inside the repository where you can annotate the return type as list[SomeDTO] and let the caller rely on that.
  • Pyrefly's Django support is actively evolving; re-check the docs when upgrading pyrefly and remove workarounds as they become unnecessary.

Step 9: Verify

bash
uv run python src/manage.py check
uv run ruff check src
uv run ruff format --check src
uv run pyrefly check src
uv run pytest

All five must pass. Fix any issue rather than silencing it.

COMPLETION CHECKLIST

  • Dependencies added via uv add
  • src/project/ids.py with _make_generator helper
  • src/project/services.py with registry and get()
  • src/project/types.py with AuthedRequest
  • src/project/api/__init__.py with NinjaAPI instance (per-resource routers live in src/project/api/<resource>/ subpackages)
  • Central exception handlers registered (ValueError → 400, LookupError → 404, PermissionError → 403)
  • src/project/signals.py with ReliableSignal base
  • src/project/celery.py + __init__.py export
  • urls.py mounts api.urls
  • Settings organized via the dj-settings skill
  • pyproject.toml has ruff / pyrefly / pytest config
  • django check, ruff, pyrefly, pytest all pass

Once this checklist is complete, the dj-architecture and dj-signals skills can build features on top without any extra setup.

© dvf, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/dj-scaffold of dvf/opinionated-django.

Open the folder on GitHubat commit f17fc2d

Compare with similar skills

Dj Scaffold next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Dj Scaffold compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Dj Scaffold this skilldvf/opinionated-django109—~3.3kAutomated safety check: NotesMIT
Saleor Django Schema Migrationsaleor/saleor23k—~1kAutomated safety check: PassBSD-3-Clause
Django Access Reviewgetsentry/skills1k3 repos~2.6kAutomated safety check: NotesApache-2.0
Silk Profilerbaserow/baserow6.1k—~2.9kAutomated safety check: PassCustom licence
Arch Wikiahmedemad3/arch-wiki250—~5.1kAutomated safety check: PassNone
Run Testsnetboxlabs/netbox-branching155—~1.2kAutomated safety check: PassCustom licence

Similar skills

  • Generates and splits Django schema migrations for Saleor with manage.py makemigrations, enforcing one new model or one field change per migration file.

    23k GitHub stars~1k tokensUpdated today
    Backend & APIsAuto-check passed
  • Django Access Review

    getsentry/skills

    Official

    Django access control and IDOR security review. An agent skill from getsentry/skills.

    1k GitHub starsUsed in 3 repos~2.6k tokens
    Backend & APIsAuto-check: notes
  • Silk Profiler

    baserow/baserow

    Investigate backend performance using Django Silk profiling data.

    6.1k GitHub stars~2.9k tokensUpdated today
    Backend & APIsAuto-check passed
  • Arch Wiki

    ahmedemad3/arch-wiki

    Scans any project codebase for new/changed modules, endpoints, middleware, infrastructure, Docker topologies, SQL queries, or permissions and updates docs/architecture/architecture.json.

    250 GitHub stars~5.1k tokensUpdated 19 days ago
    Backend & APIsAuto-check passed
  • Run Tests

    netboxlabs/netbox-branching

    Run the netboxbranching plugin's Django test suite against a local NetBox checkout.

    155 GitHub stars~1.2k tokensUpdated today
    Backend & APIsAuto-check passed
  • Add or change a CLIST Django management command, including arguments, resource selection, EventLog monitoring, or cron and Healthchecks wiring.

    439 GitHub stars~848 tokensUpdated 4 days ago
    Backend & APIsAuto-check passed

More from dvf/opinionated-django

All 9 skills in this repo
  • Dj Architecture

    dvf/opinionated-django

    Implement a Django feature following the opinionated architecture — prefixed ULID IDs, repository pattern, Pydantic DTOs, svcs service locator, project-scoped django-ninja API, Celery reliable…

    109 GitHub stars~4k tokensUpdated 1 mo ago
    Auto-check: notes
  • Dj Models

    dvf/opinionated-django

    Structure Django models with proper Meta classes, verbose names, and optimized indexes.

    109 GitHub stars~4.9k tokensUpdated 1 mo ago
    Auto-check: notes
  • Dj Prefixed Ulids

    dvf/opinionated-django

    Use Stripe-style prefixed ULID primary keys (e.g. An agent skill from dvf/opinionated-django.

    109 GitHub stars~1.4k tokensUpdated 1 mo ago
    Auto-check: notes
  • Dj Pytest

    dvf/opinionated-django

    Set up and write pytest tests for an op-django project — pytest-django configuration, two-sided Celery testing (patched dispatch sites + plain-function task bodies, never eager mode), freezegun for…

    109 GitHub stars~4.3k tokensUpdated 1 mo ago
    Auto-check: notes
  • Dj Services

    dvf/opinionated-django

    Structure Django business logic as plain services that receive their dependencies via constructor injection, and wire them through an svcs registry so they can be resolved anywhere — views, Celery…

    109 GitHub stars~3k tokensUpdated 1 mo ago
    Auto-check: notes
  • Dj Signals

    dvf/opinionated-django

    Add reliable signals (async side-effects via Celery) to a Django feature.

    109 GitHub stars~1k tokensUpdated 1 mo ago
    Auto-check: notes

Works with

Categories

Questions about Dj Scaffold

What does Dj Scaffold do?

Set up a Django project into the op-django layout so the architecture, signals, and settings skills have a foundation to build on. Dj Scaffold is an agent skill from dvf/opinionated-django. Set up a Django project into the op-django layout so the architecture, signals, and settings skills have a foundation to build on.

When should I use Dj Scaffold?

Dj Scaffold fits situations like: starting a new project from scratch; converting an existing Django project to follow this opinionated structure.

How do I install Dj Scaffold in Claude Code?

Run `npx skills add dvf/opinionated-django --skill dj-scaffold -a claude-code`. Or copy the skill folder (skills/dj-scaffold in dvf/opinionated-django) into .claude/skills/dj-scaffold in your project. Claude Code loads it when a task matches its description.

How do I install Dj Scaffold in Codex?

Run `npx skills add dvf/opinionated-django --skill dj-scaffold -a codex`. Or copy the skill folder (skills/dj-scaffold in dvf/opinionated-django) into .agents/skills/dj-scaffold in your project. Codex loads it when a task matches its description.

Can I use Dj Scaffold in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add dvf/opinionated-django --skill dj-scaffold -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/dj-scaffold, .gemini/skills/dj-scaffold, .github/skills/dj-scaffold and .opencode/skills/dj-scaffold in your project.

What does Dj Scaffold need to run?

Going by SKILL.md and its folder, Dj Scaffold needs the command-line tools its instructions call (uv and django-admin). Our summary lists: Python 3. Its frontmatter pre-approves these tools: Read, Write, Edit, Bash, Grep, Glob.

Does Dj Scaffold access the network?

SKILL.md names 1 domain. As links in the text: pyrefly.org. This is read from the text; nothing was executed.

Is Dj Scaffold safe to install?

Our automated static check of SKILL.md found notes only (pre-approves every shell command (allowed-tools: bash)), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does Dj Scaffold use?

Dj Scaffold is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Dj Scaffold use?

About 3.3k tokens (SKILL.md is roughly 13k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Dj Scaffold?

Skills that share tags, products or a category with Dj Scaffold: Saleor Django Schema Migration (saleor/saleor, 23k stars), Django Access Review (getsentry/skills, 1k stars), Silk Profiler (baserow/baserow, 6.1k stars) and Arch Wiki (ahmedemad3/arch-wiki, 250 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Dj Scaffold?

dvf (a GitHub user) maintains it in dvf/opinionated-django, which has 109 GitHub stars. The repository holds 9 skills in this directory. The repository was last updated on August 14, 2026.

Source: dvf/opinionated-django on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.