Skip to main content

dj-scaffold

CI Pipeline PyPI version Python versions License

A modern, interactive scaffolding CLI for Django projects, inspired by frontend tools like create-next-app. It helps developers set up containerized, production-ready Django applications and enforces a clean Service Layer Architecture for modular, testable django applications.


Features

  • Interactive Prompts: Quick setup via terminal menus using arrow keys.
  • 🐳 Dockerized & Auto-Provisioned: Generate production-ready Dockerfile, .env setups, and docker-compose.yml. Executes database migrations and provisions a superuser automatically on startup.
  • 🛡️ Secure by Default: Configures CORS (django-cors-headers) and Content Security Policy (django-csp) middleware out-of-the-box.
  • 🔑 Simple JWT Integration: Auto-configures token-based authentication (djangorestframework-simplejwt) and endpoint routes if an API backend is selected.
  • 🛠️ API Flavors: Choose from Standard Django, Django REST Framework + Spectacular (OpenAPI 3.0), or Django Ninja.
  • 🏗️ Service Layer Architecture: Scaffolding for app structure segregating HTTP API route handlers (apis.py), Business Logic mutations (services.py), Database Queries (selectors.py), and Models (models.py).

Installation

From PyPI

You can install dj-scaffold directly from PyPI:

pip install dj-scaffold-imhotep

For Local Development

To set up the CLI tool for local development:

  1. Clone this repository:
    git clone https://github.com/Imhotep-Tech/dj-scaffold.git
    cd dj-scaffold
    
  2. Install the package in editable mode with development dependencies:
    pip install -e .[dev]
    

CLI Usage

Run dj-scaffold in your terminal with no flags to open the interactive wizard, or use the subcommands directly.

1. Interactive Menu

To open the interactive prompt wizard:

dj-scaffold

Use the arrow keys to move between choices and press Enter to confirm.

2. Creating a New Django Project

To initiate a new Django project:

dj-scaffold create

The CLI will guide you through:

  • Project Name: Enter the name of your new Django project.
  • Database Engine: Choose between PostgreSQL, MySQL, or SQLite.
  • API Framework Flavor: Choose between Django Ninja, DRF + Spectacular, or Standard Django.

Generated Project Configuration

When you scaffold a new project, dj-scaffold sets up the following environments:

1. Docker & Auto-Superuser Setup

The generated project uses a custom entrypoint.sh script to run migrations and create a superuser automatically when you run docker compose up.

Configure the superuser credentials in your generated .env file:

DJANGO_SUPERUSER_USERNAME=admin
DJANGO_SUPERUSER_PASSWORD=adminpassword
DJANGO_SUPERUSER_EMAIL=admin@example.com

2. Security Middleware (CORS & CSP)

Every project has CORS and CSP configured by default in its generated settings.py:

  • CORS: Powered by django-cors-headers, pre-configured with CORS_ALLOW_ALL_ORIGINS = True for easy API testing during development.
  • CSP: Powered by django-csp, setting secure default script, style, and self-origin policies:
    CSP_DEFAULT_SRC = ("'self'",)
    CSP_STYLE_SRC = ("'self'", "'unsafe-inline'")
    CSP_SCRIPT_SRC = ("'self'", "'unsafe-inline'")
    

3. API Authentication (Simple JWT)

If the DRF + Spectacular flavor is chosen, token-based authentication is preconfigured.

  • Settings: Simple JWT config is added to REST_FRAMEWORK and settings:
    REST_FRAMEWORK = {
        'DEFAULT_AUTHENTICATION_CLASSES': [
            'rest_framework_simplejwt.authentication.JWTAuthentication',
        ],
        'DEFAULT_PERMISSION_CLASSES': [
            'rest_framework.permissions.IsAuthenticated',
        ],
    }
    
  • Endpoints: The following routes are registered in your main urls.py:
    • /api/token/ – Exchange username/password for access/refresh tokens.
    • /api/token/refresh/ – Exchange a refresh token for a new access token.

Scaffolding a New App (Service Layer Layout)

To create a new app inside an existing project, run this command from the project root directory (where manage.py resides):

dj-scaffold startapp

You will be prompted for:

  • App Name: Enter the name of the app.
  • Architecture Layout: Choose between Service Layer Pattern (recommended) or Standard Django Layout.

Folder Structure for Service Layer Apps:

your_app/
├── __init__.py
├── apps.py          # Django app configuration
├── models.py        # Database models & relationships
├── apis.py          # API ViewSets, Ninja Routers, or standard views
├── services.py      # Business logic mutators (Write actions)
├── selectors.py     # Pure database query helpers (Read actions)
└── urls.py          # App-specific URL patterns

Architecture: Why the Service Layer Pattern?

Standard Django applications can easily lead to bloated model methods ("Fat Models") or complex views ("Fat Views"). The Service Layer Pattern enforces a strict separation of concerns:

Request ──> APIs (apis.py) ──> Services (services.py) [Mutations] ──> Models (models.py)
              │
              └───────────────> Selectors (selectors.py) [Queries] ──> Models (models.py)
  1. APIs (apis.py): Translates incoming HTTP requests, triggers services or selectors, handles request validation, and serializes responses. Keeps the HTTP layer lightweight.
  2. Services (services.py): Contains your core business logic and database mutators (creating, updating, deleting database records). Wrapped in @transaction.atomic to ensure transactional integrity.
  3. Selectors (selectors.py): Contains pure database query functions. They read and return QuerySets or dictionaries/objects and do not mutate state.
  4. Models (models.py): Pure schema definitions, database relationships, and constraints. Contains minimal or zero business logic.

Local Development & Testing

We use pytest for unit testing the CLI scaffolding functionalities.

Running Tests

To execute the tests locally:

pytest -v

CI/CD Integration

Our GitHub Actions integration tests the package on Python versions 3.10, 3.11, and 3.12. It builds, tests, and publishes the package to PyPI upon successful releases on the main branch.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dj_scaffold_imhotep-1.0.8.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_scaffold_imhotep-1.0.8-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file dj_scaffold_imhotep-1.0.8.tar.gz.

File metadata

  • Download URL: dj_scaffold_imhotep-1.0.8.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dj_scaffold_imhotep-1.0.8.tar.gz
Algorithm Hash digest
SHA256 208c62dbeb4e96b9cfbf5faae1f3e586e5260ae90b8b266887f41a8752f34e6e
MD5 506f34b232720926ae21a94a40dca9f1
BLAKE2b-256 f041aa0be1a8a45c4963e6ff165a663d594be2182b991dd590edc034d768b967

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_scaffold_imhotep-1.0.8.tar.gz:

Publisher: publish-pypi.yml on Imhotep-Tech/dj-scaffold

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dj_scaffold_imhotep-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for dj_scaffold_imhotep-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 87beb4608e05dfc3897b06ad4dcd806ba02e9f67ac60fac0b6e78ca9b2827824
MD5 c49887b67320bffc7945a32a94e0fd73
BLAKE2b-256 eff055d56c6f49c116c976de7e6d57b78cd37e096b726ffdc5e59190ddd77fcd

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_scaffold_imhotep-1.0.8-py3-none-any.whl:

Publisher: publish-pypi.yml on Imhotep-Tech/dj-scaffold

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.1.0

2 files

1.0.11

2 files

1.0.10

2 files

1.0.9

2 files

This release

1.0.8 This release

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page