Generators: create the baseline first
Generator documentation reviewed: 2026-10-23. Evidence: documentation-reviewed; commands not executed.
Required workflow
- Before writing a new project's application files, read its profile's starting points and use the official framework or language initializer appropriate to the component. Do not hand-recreate a generated skeleton. Where no full application generator exists, use the documented module/package initializer and assemble only the missing application pieces.
- Choose one starting point per component. Check the installed generator's version and help, prerequisites, template, database, UI, test and runtime options. Commands are examples: replace names and paths, resolve compatible versions, and record the exact invocation and selected options. Do not blindly run every listed generator.
- Generate in a new empty destination. For an existing repository, preserve its conventions and use relevant incremental generators. If a baseline comparison is needed, generate a separate disposable reference with matching versions/options and reconcile deliberately; never regenerate over existing work.
- Keep applicable generated configuration, hidden files, formatter/linter settings, ignore rules, manifests, lockfiles, tests, wrappers and entry points. Extend them for the project instead of replacing them with abbreviated handwritten copies. A generator may initialize version control or offer a commit; respect the user's Git instructions.
- Run the generated baseline's documented checks before feature changes, then relevant checks after configuration and implementation. Inspect what version control would include, including hidden files, build output, local secrets and operating-system metadata. Add needed ignore rules explicitly: no generator guarantees that .DS_Store or every local artifact is ignored.
- Use follow-up generators only when their feature or tool is selected. Review generated changes and dependencies, apply required migrations in the intended environment, and exercise the generated behavior. Scaffolding does not establish authorization, safe retries, production readiness or every best practice.
- If the required generator, template or IDE is unavailable, report the missing prerequisite and the documented route. Do not silently substitute a handwritten scaffold. Keep documentation review, generator execution, baseline checks and application qualification as separate evidence.
Choose a starting point
uv environment plus native Django project generator
Use when: A new Django product application; preserve the established layout and packaging workflow when extending an existing app.
- Install uv and inspect uv --version and uv init --help. Replace /path/to/local/source with an existing local source parent; use a new, absent target directory. Set PYTHON_VERSION to a supported Python minor compatible with the selected framework and dependencies. Record generator versions, selected flags and deliberate deviations.
- Run commands in the stated directories in order. Use explicit --no-package for the conventional root manage.py layout; uv default application layouts vary by version.
- After scaffolding, inspect the uv sample main.py and deliberately remove or repurpose that sample if Django manage.py is the only entry point. Configure secrets, database and installed apps before feature work.
Working directory: /path/to/local/source
Create the managed project metadata and selected Python environment.
uv init --no-package --python "$PYTHON_VERSION" django-app
Working directory: /path/to/local/source/django-app
Resolve Django into the project environment and lock.
uv add django
Working directory: /path/to/local/source/django-app
Generate manage.py and the Django settings, URLs, WSGI and ASGI package.
uv run django-admin startproject config .
- This is a composed bootstrap: uv owns Python packaging; django-admin owns framework scaffolding. Do not hand-create a substitute Django skeleton.
- Django scaffolding does not make production settings safe. Configure environment-owned secrets, DEBUG, ALLOWED_HOSTS and the selected production database/server.
- Choose a source parent outside another uv workspace, or intentionally use --no-workspace when creating an independent project under a directory with parent pyproject.toml metadata.
Conditional follow-up generators
Conditional Django REST Framework API layer
Use when: Only after completing the Django project bootstrap above, and only when the application needs JSON API endpoints. Django has no built-in API-only project mode.
Working directory: /path/to/local/source/django-app
Install and lock the optional REST API framework in this project.
uv add djangorestframework
Working directory: /path/to/local/source/django-app
Generate the app that will own API serializers, views and routes.
uv run python manage.py startapp api
- Django's own `startproject` remains the general project bootstrap; DRF is a separately installed library and API layer, not a native Django API-only generator. Add both `rest_framework` and `api.apps.ApiConfig` (or the chosen generated API AppConfig) to INSTALLED_APPS, then follow the upstream quickstart for serializers, views, routers and API tests.
- DRF's default permission policy is AllowAny. Set an intentional global or per-view permission policy and add object/tenant checks where needed; authentication alone does not authorize access. Select authentication based on client type, and treat session-authenticated browser requests' CSRF requirements deliberately.
- Add CORS middleware/package and narrowly allow required origins only if a browser client actually calls the API cross-origin. Same-origin, server-to-server and native clients need different handling; do not install CORS or token-auth packages by default.
Django application module
Use when: A new domain app is needed inside the existing project; substitute a domain name for core.
Working directory: /path/to/local/source/django-app
Generate the app configuration, models, admin, tests and migrations package.
uv run python manage.py startapp core
- Register core.apps.CoreConfig in INSTALLED_APPS and implement the domain. The generator does not wire URLs, permissions or product behavior.
Django schema and data migrations
Use when: Registered application models change; use the configured disposable development database first.
Working directory: /path/to/local/source/django-app
Generate a migration from implemented model changes.
uv run python manage.py makemigrations core
Working directory: /path/to/local/source/django-app
Alternative for an intentional data migration: generate its empty revision.
uv run python manage.py makemigrations --empty core --name populate_reference_data
Working directory: /path/to/local/source/django-app
Inspect the configured database migration plan.
uv run python manage.py migrate --plan
Working directory: /path/to/local/source/django-app
Apply reviewed migrations to the development database.
uv run python manage.py migrate
- The empty data migration is conditional, not a mandatory extra step. Implement it using historical models and review reversibility. Review generated operations before applying; commit migration sources with model changes.
- Use Django ORM/migrations for this profile; do not add a second default migration system. PostgreSQL requires its driver and settings before database commands.
Preserve the generated foundation
- Keep generator-created project metadata, Python requirements, version selection and ignore rules; extend them rather than replacing them with a handwritten approximation.
- Commit the resolved uv.lock for projects; exclude .venv, caches, secrets and platform debris such as .DS_Store. Do not hand-edit lockfiles.
- Keep source repositories, virtual environments and caches in a local development workspace outside cloud-synced document folders.
- Retain the generated manage.py, app configuration, middleware/security defaults, URL setup and WSGI/ASGI interfaces unless a documented application need changes them.
- Retain and review migration history; never regenerate an existing project over maintained code.
Baseline and generation checks
- From /path/to/local/source/django-app: uv sync --locked; uv run python manage.py check; uv run python manage.py makemigrations --check --dry-run.
- For a DRF API, test explicit public/protected permissions, object/tenant denials, input validation and response contracts with DRF APIClient/APIRequestFactory; test session CSRF and narrowly allowed/rejected CORS origins when browser clients require them.
- After reviewed migrations on the configured development database: uv run python manage.py migrate --check. Run application tests using its configured runner and a production-relevant isolated database.
- Run uv run python manage.py check --deploy against the actual production settings module once it exists; runserver is a development server.
- Compare a disposable scaffold made with the same uv/Django versions and flags; review the generated baseline and document deviations. Inspect tracked/staged files and verify ignore rules against local debris, caches and secrets.
Generation receipt
- Component and selected starting point, or the documented absence of a full application generator
- Generator/toolchain versions, exact commands or IDE template/settings, working directory and generated destination
- Generated files retained, deliberate deviations with reasons, and required supplemental ignore rules
- Baseline checks and later checks actually run, results and remaining prerequisites or untested behavior
Generator sources