Setup DRF Project
Workflow
Use this skill to create a new DRF backend in the current directory or to carefully adapt an incomplete project. Prefer the bundled script for new or mostly empty directories:
python /home/mf/.codex/skills/setup-drf-project/scripts/setup_drf_project.py .
When the backend lives in a backend/ directory, run the script from that directory or pass that directory as the target. The generated project is isolated and owns its local development infrastructure:
backend/
├── database/
│ └── Dockerfile
├── docker-compose.yml
├── Dockerfile
└── ...
Use --force only after inspecting the target directory and confirming overwrites are intended:
python /home/mf/.codex/skills/setup-drf-project/scripts/setup_drf_project.py . --force
The script creates:
core/Django project filesapps/accounts/with a customUser, admin, serializer with password hashing, authenticated user CRUD,MeView, URLs, and migrations package- backend files:
.env,.env.example,.gitignore,requirements.txt, andDockerfile - architecture decision records under
docs/adr/ - local infrastructure files:
database/Dockerfileanddocker-compose.ymlinside the backend directory - split settings for development and production, django-environ, PostgreSQL, DRF, Simple JWT, CORS, default authenticated permissions, page-number pagination,
AUTH_USER_MODEL, Portuguese/Brazilian locale, andAmerica/Manaus - production-ready defaults: Gunicorn container command,
.dockerignore, console logging, production security settings, andGET /api/health/
If docker-compose.yml already exists in the backend directory, inspect it and add only the PostgreSQL db service pointing to ./database/Dockerfile, plus the postgres_data volume if missing. Preserve existing services and do not rewrite the whole compose file unless the user explicitly asks.
Manual Fallback
If the script cannot be used, perform the same steps incrementally:
- Install dependencies:
pip install django djangorestframework djangorestframework-simplejwt "psycopg[binary]" django-environ django-cors-headers
- Start the project before creating app files:
django-admin startproject core .
mkdir -p apps
touch apps/__init__.py
mkdir -p apps/accounts
python manage.py startapp accounts apps/accounts
- Configure
apps/accounts/apps.pywithname = "apps.accounts". - Create
apps/accounts/models.pywithUser(AbstractUser)and uniqueemail. - Register
CustomUserAdmininapps/accounts/admin.py. - Replace the generated
core/settings.pywith acore/settings/package before migrations:core/settings/base.pycore/settings/development.pycore/settings/production.pycore/settings/__init__.py
- Configure settings:
- import
environandtimedelta - read
BASE_DIR / ".env" - use
SECRET_KEY = env("SECRET_KEY"),DEBUG = env("DEBUG"),ALLOWED_HOSTS = env.list(...) - add
rest_framework,rest_framework_simplejwt,corsheaders, andapps.accounts.apps.AccountsConfig - put
corsheaders.middleware.CorsMiddlewarebefore common/session middleware - set
AUTH_USER_MODEL = "accounts.User" - set
DATABASES = {"default": env.db("DATABASE_URL")} - configure
CORS_ALLOWED_ORIGINS,REST_FRAMEWORK, andSIMPLE_JWT - set DRF pagination with
DEFAULT_PAGINATION_CLASS = "core.pagination.DefaultPagination",PAGE_SIZE = 10, andMAX_PAGE_SIZE = 100 - configure production security settings in
production.py - configure console logging
- import
- Update
manage.pyandasgi.pyto default tocore.settings.development; updatewsgi.pyto default tocore.settings.production. - Update
core/urls.pywith admin,GET /api/health/, Simple JWT token endpoints, andpath("api/accounts/", include("apps.accounts.urls")). - Add
core/pagination.pywith aDefaultPaginationclass usingpage_size_query_param = "page_size"andmax_page_sizefrom settings. - Add
core/views.pywith an unauthenticatedHealthCheckView. - Add
serializers.py,views.py, andurls.pyforGET /api/accounts/me/and authenticated user CRUD under/api/accounts/users/; restrict the user CRUD viewset to admin users. - Add backend files:
.env,.env.example,requirements.txt,.gitignore,.dockerignore, andDockerfile. - Add ADRs under
docs/adr/documenting the backend architecture, isolated Compose decision, and production-readiness settings. - Add
database/Dockerfileinside the backend directory. - Add or update the backend
docker-compose.yml; if it already exists, add only thedbservice that builds from./database/Dockerfileand thepostgres_datavolume if missing.
Always inspect existing files before replacing them. Preserve unrelated existing code and report any conflict instead of deleting it.
Validation
Run validation only after AUTH_USER_MODEL and INSTALLED_APPS are correct:
python manage.py makemigrations
python manage.py migrate
python manage.py check
For Docker:
docker compose up --build
Optionally create a superuser:
python manage.py createsuperuser
Endpoint Checks
After the server is running and a user exists, test JWT:
curl -X POST http://localhost:8000/api/auth/token/ \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "admin"}'
Use the token:
curl http://localhost:8000/api/accounts/me/ \
-H "Authorization: Bearer ACCESS_TOKEN_AQUI"
List users:
curl http://localhost:8000/api/accounts/users/ \
-H "Authorization: Bearer ACCESS_TOKEN_AQUI"
Create a user:
curl -X POST http://localhost:8000/api/accounts/users/ \
-H "Authorization: Bearer ACCESS_TOKEN_AQUI" \
-H "Content-Type: application/json" \
-d '{"username": "user1", "email": "user1@example.com", "password": "change-me"}'
Update and delete use /api/accounts/users/<id>/ with PUT, PATCH, or DELETE.
Health check:
curl http://localhost:8000/api/health/
Reporting
At the end, summarize files created or changed, validation results, commands to run the project, and the two curl examples above. If migrations or Docker are not run, state exactly why.
Also mention the generated ADR path and summarize the decisions it records.