PetraCore 's Django project/app scaffolder with services layer and messaging functionalities
Project description
Petracore Django Starter
A batteries-included starter for Django + Django REST Framework projects. It ships with a clean architecture, an opinionated core app, an app scaffolder (startapp_plus), and a messaging module you can import in any project.
TL;DR
- petracore_django new — create a Django project in the current directory, core + user apps included automatically.
- python manage.py startapp_plus <app_name> — generate a full CRUD app (models, services, serializers, views, urls) with consistent stubs.
- from petracore_django.messaging import MessagingService — import messaging; configure RESEND Variables in settings.py.
Table of Contents
- Why this exists (General Provisions & Benefits)
- Installation
- Quick Start
- What gets generated
- Core app features
- URL auto-discovery
- Service layer
- Shared model base & serializers
- App scaffolder: startapp_plus
- Usage
- Field specification format
- Benefits
- Messaging service
- Importing & basic usage
- Settings you must provide
- Troubleshooting
- Requirements
- License
Why this exists (General Provisions & Benefits)
Petracore Django Starter gives you a repeatable project skeleton that:
- Keeps your apps consistent: each new app gets models → services → serializers → views → urls in one go.
- Encourages a clean service layer so business logic doesn’t leak into views/serializers.
- Wires a core URL aggregator so any local app with a urls.py is automatically available under your API prefix.
- Exposes a messaging module you can import anywhere (email/SMS), with a simple settings-based configuration.
- Works great for teams: predictable structure, fewer bikeshed debates, and faster onboarding.
Installation
into your virtualenv
pip install petracore-django-starter
This installs:
- The CLI command: petracore_django
- The Python package: petracore_django (templates + scaffolder + messaging)
Quick Start
mkdir my_api && cd my_api
python3 -m venv .venv
source .venv/bin/activate
petracore_django new --name myproject
--name defaults to current folder name if omitted
python manage.py makemigrations
python manage.py migrate
python manage.py runserver`
You’ll now have:
- core/ (the opinionated core app, including startapp_plus)
- user/ (a simple custom user app wired as AUTH_USER_MODEL, serilizers, views and urls)
- Your project settings.py patched with:
- INSTALLED_APPS += ["core", "user", "rest_framework"]
- AUTH_USER_MODEL = "user.User"
- Your project urls.py patched with:
path("api/v1/", include("core.urls")),
Any local app that declares a urls.py is automatically included under /api/v1/.
What gets generated
.
├─ manage.py
├─ myproject/ # your Django settings/urls
│ ├─ settings.py
│ └─ urls.py
├─ core/
│ ├─ urls.py # auto-aggregates app urls
│ ├─ base_service.py # Repository.create_service(...)
│ ├─ models.py # CreatedModified base
│ ├─ serializers.py # basic shared serializers
│ └─ management/commands/
│ └─ startapp_plus.py # app scaffolder
└─ user/
├─ models.py # custom User
├─ serializers.py
├─ services.py
├─ views.py
└─ urls.py
Core app features
URL auto-discovery
core/urls.py automatically includes every local app (under your project folder) that exposes a urls.py. Mounting a single line in your main urls.py…
myproject/urls.py
from django.urls import include, path
urlpatterns = [
path("api/v1/", include("core.urls")), # one line to rule them all
]
…makes all app routes available under /api/v1/… with zero extra wiring.
It skips third-party apps and core itself, so you don’t get recursion or noise.
Service layer
core/base_service.py exposes a small Repository helper you can use to generate base services for your models:
from core.base_service import Repository
from .models import Thing
BaseThingService = Repository.create_service(Thing)
class ThingService(BaseThingService):
# Put your domain logic here (hooks, guards, events, etc.)
pass
Views call the service (not .objects) so your logic stays centralized.
Shared model base & serializers
- core.models.CreatedModified gives you date_created / date_modified on all models.
- core.serializers includes a couple of basic response serializers for consistency.
App scaffolder: startapp_plus
A management command that creates a full app with stubs matching the pragmatic style.
Usage
basic: derive model name from app name (drop trailing 's')
python manage.py startapp_plus reports
explicit model name
python manage.py startapp_plus invoices --model Invoice
add initial fields (CSV "name:FieldType(args)")
python manage.py startapp_plus tickets \
--model Ticket \
--fields "title:CharField(max_length=200),is_open:BooleanField(default=True)"
overwrite generated files if they exist
python manage.py startapp_plus notes --force
It generates:
- models.py (subclassing CreatedModified, ordered by -date_created)
- services.py (using Repository.create_service(Model) + a concrete ModelService)
- serializers.py (a ModelSerializer + an input CreateUpdateSerializer)
- views.py (DRF ModelViewSet wired to the service; separate input/output serializers)
- urls.py (DRF router registering <model_name.lower()>s)
Once generated, the routes appear automatically under /api/v1/… thanks to core/urls.py.
Field specification format
--fields expects a CSV of name:FieldType(args) where FieldType is a Django model field.
Examples:
- title:CharField(max_length=200)
- is_done:BooleanField(default=False)
Tip: If a field RHS doesn’t start with models., it will be added for you.
Benefits
- Consistency (every app looks the same)
- Speed (CRUD scaffolds in seconds)
- Clean layering (service layer by default)
- Zero URL plumbing (core URL aggregator)
Messaging service
A thin, importable messaging layer that you can use across apps. It supports email out of the box (via Resend), with SMS extensibility.
Importing & basic usage
import the default classes
`from petracore_django.messaging import MessagingService`
MessagingService.send_text(recipients=["09123456789"], message="hellow world")
MessagingService.send_email(recipients=["test@gmail.com"], message="Hellow world", subject="subject")
MessagingService.send_push(recipients=["3003030303"], message="the push message", subject="subject")
The module defers reading django.conf.settings until runtime, so it plays nicely with Django initialization and static linters.
Settings you must provide
Email (Resend)
Add this to your settings.py:
Required
RESEND_API_KEY = os.getenv("RESEND_API_KEY")
RESEND_BASE_URL = os.getenv("RESEND_BASE_URL")
RESEND_SENDER_ID = os.getenv("RESEND_SENDER_ID")
Troubleshooting
“Unknown command: startapp_plus”
Ensure:
- core is in INSTALLED_APPS
- the file exists at core/management/commands/startapp_plus.py
- both management/ and commands/ have init.py
- “Templates missing” error before scaffolding
The CLI does a preflight check and will tell you which files are missing if your installation didn’t include package data. If you’re hacking locally, do:
pip install -e /ABS/PATH/TO/petracore_django_starter
Django won’t startproject in non-empty director”
petracore_django new runs django-admin startproject . — run it inside an empty folder, or initialize your own project and re-run to only add scaffolding.
Requirements
• Python 3.10+
• Django 4.2+
• Django REST Framework 3.15+
Runtime dependencies installed for you:
Django, djangorestframework, PyJWT, requests
License
MIT — do whatever you want, just keep the license and acknowledge the authors. 🙌
One more thing
If you have a specific house style (lint/format/testing, CI, Docker, Celery, Postgres, etc.), this starter is intentionally small and composable—extend the templates to fit your team, and the scaffolder will keep every new app on-rails.
Made with Love by Petracore 💚.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file petracore_django_backend_starter-0.1.1.tar.gz.
File metadata
- Download URL: petracore_django_backend_starter-0.1.1.tar.gz
- Upload date:
- Size: 30.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d9b83bd52cefdfa97e040ee42392e02e0e3ec261e95abb98e0a73b0e85a347a
|
|
| MD5 |
d563dc29e68f809bcdaee02e1fc36e86
|
|
| BLAKE2b-256 |
8d2febf583c0da874567bbd02eda225c7b27c9c88275028d7c90236a53245912
|
File details
Details for the file petracore_django_backend_starter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: petracore_django_backend_starter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 34.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
252c94c2843b0073df6c4fcc11521358d5d00b8a92383215f6abe06b2057cb37
|
|
| MD5 |
5afb8d96af3a32ced93abb394fe0031e
|
|
| BLAKE2b-256 |
8dfc59766cf476ade23224d0fb64c5c0fa0e5fe7f6c69462ab6178d83e9b315e
|