@cubocicloide/stack-react-django 3.2.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/templates/base/.claude/skills/create-route/SKILL.md +1 -1
- package/templates/base/.claude/skills/fix-issues/SKILL.md +6 -6
- package/templates/base/.dude/lint/checks/PRJ/001.md +34 -0
- package/templates/base/.dude/lint/checks/README.md +20 -3
- package/templates/base/CLAUDE.md.hbs +5 -0
- package/templates/base/README.md.hbs +1 -1
- package/templates/base/backend/README.md.hbs +14 -0
- package/templates/base/backend/apps/users/admin.py +19 -2
- package/templates/base/backend/config/settings/base.py.hbs +42 -1
- package/templates/base/backend/pyproject.toml.hbs +1 -0
- package/templates/base/docs/docs/dude.md.hbs +20 -3
- package/templates/base/docs/docs/index.md.hbs +1 -1
- package/templates/s3/backend/apps/files/admin.py +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubocicloide/stack-react-django",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "React (Vite) + Django REST Framework stack plugin for the dude CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"openapi-typescript": "^7.13.0",
|
|
21
21
|
"pathe": "^1.1.2",
|
|
22
22
|
"yaml": "^2.6.0",
|
|
23
|
-
"@cubocicloide/dude": "0.
|
|
23
|
+
"@cubocicloide/dude": "0.17.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^26.1.2",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"vitest": "^2.1.9"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
|
-
"node": ">=20"
|
|
32
|
+
"node": ">=20.19"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "tsup",
|
|
@@ -76,7 +76,7 @@ A **new app** touches all of these; extending an existing app touches a subset.
|
|
|
76
76
|
| `apps/<app>/views.py` | BE003, BE013 | ViewSet/APIView with explicit `permission_classes` and `serializer_class` (or `@extend_schema`) |
|
|
77
77
|
| `apps/<app>/urls.py` | BE008 | `app_name = "<app>"` + DRF router |
|
|
78
78
|
| `config/urls.py` | BE008 | `path("api/", include("apps.<app>.urls"))` |
|
|
79
|
-
| `apps/<app>/admin.py` | — | register the model |
|
|
79
|
+
| `apps/<app>/admin.py` | — | register the model — subclass `unfold.admin.ModelAdmin`, never `admin.ModelAdmin` (Unfold theme) |
|
|
80
80
|
| `apps/<app>/tests/test_*.py` | BE014 | model + view tests (pytest-django, `APIClient`) |
|
|
81
81
|
|
|
82
82
|
Skip rows that don't apply. Present the list, then wait for an OK.
|
|
@@ -138,16 +138,16 @@ Run on the consolidated branch (or the single agent branch):
|
|
|
138
138
|
dude lint
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
`dude help`), run it next:
|
|
141
|
+
Run the project's own test suite next:
|
|
143
142
|
|
|
144
143
|
```bash
|
|
145
|
-
dude test
|
|
146
|
-
# or:
|
|
147
|
-
cd backend && python -m pytest
|
|
148
|
-
cd frontend && pnpm test
|
|
144
|
+
dude test
|
|
149
145
|
```
|
|
150
146
|
|
|
147
|
+
`dude help test` lists the suites this project actually exposes (`--backend`,
|
|
148
|
+
`--e2e`, …) — they differ per stack. If the change is scoped to one suite, run
|
|
149
|
+
that one rather than the lot.
|
|
150
|
+
|
|
151
151
|
If any step fails, report the output and stop — do **not** create a PR.
|
|
152
152
|
|
|
153
153
|
---
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# PRJ001 — Example project rule
|
|
2
|
+
|
|
3
|
+
This file is the prose half of the example project check
|
|
4
|
+
(`.dude/lint/checks/PRJ/001.ts`). Rename, edit or delete both together.
|
|
5
|
+
|
|
6
|
+
## What it does
|
|
7
|
+
|
|
8
|
+
Nothing yet — the shipped check returns no diagnostics. It exists so you have a
|
|
9
|
+
working pair to copy: a rule module, and the Markdown that explains it.
|
|
10
|
+
|
|
11
|
+
## Why the file is here
|
|
12
|
+
|
|
13
|
+
`dude explain PRJ001` prints **this file**, and `dude cheatsheet` uses its first
|
|
14
|
+
heading as the rule's one-line title. A project rule with no Markdown beside it
|
|
15
|
+
still runs, but it can only ever be listed as a bare code — which tells whoever
|
|
16
|
+
hits the diagnostic (a teammate, or a coding agent) nothing about how to fix it.
|
|
17
|
+
|
|
18
|
+
The convention is a sibling file, matching the check's path:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
.dude/lint/checks/PRJ/001.ts ← the rule
|
|
22
|
+
.dude/lint/checks/PRJ/001.md ← this file
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`dude lint` ignores non-module files, so the Markdown never runs as a check.
|
|
26
|
+
|
|
27
|
+
> Stack rules follow the mirror-image convention — their prose lives under
|
|
28
|
+
> `.claude/rules/<GROUP>/<NNN>.md`. Both are served by `dude explain <CODE>`.
|
|
29
|
+
|
|
30
|
+
## How to fix a violation
|
|
31
|
+
|
|
32
|
+
Describe the fix here, concretely enough that someone can act on it without
|
|
33
|
+
opening the check's source. Start the file with `# <CODE> — <title>` so the
|
|
34
|
+
title is picked up.
|
|
@@ -38,9 +38,26 @@ export default function check(root: string): RawDiagnostic[] {
|
|
|
38
38
|
Checks are loaded with [jiti](https://github.com/unjs/jiti), so you can write
|
|
39
39
|
real TypeScript and `import` any package you add to the project.
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
## Documenting a rule
|
|
42
|
+
|
|
43
|
+
Put a Markdown file next to the check, named after it:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
.dude/lint/checks/PRJ/001.ts ← the rule
|
|
47
|
+
.dude/lint/checks/PRJ/001.md ← what it means and how to fix it
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`dude explain PRJ001` prints that file, and `dude cheatsheet` uses its first
|
|
51
|
+
heading (`# PRJ001 — <title>`) as the rule's one-line title. Without it the rule
|
|
52
|
+
still runs, but it can only be reported as a bare code — which tells whoever hits
|
|
53
|
+
the diagnostic nothing about how to fix it. The shipped `PRJ/001.md` is a worked
|
|
54
|
+
example.
|
|
55
|
+
|
|
56
|
+
`dude lint` ignores non-module files, so the Markdown never runs as a check.
|
|
57
|
+
Co-located tests (`001.test.ts`) are ignored too.
|
|
58
|
+
|
|
59
|
+
> Stack rules use the mirror-image location, `.claude/rules/<GROUP>/<NNN>.md`.
|
|
60
|
+
> `dude explain <CODE>` serves both.
|
|
44
61
|
|
|
45
62
|
## Choosing codes
|
|
46
63
|
|
|
@@ -338,6 +338,11 @@ dude db migrate
|
|
|
338
338
|
fields (BE010), explicit `related_name` (BE011); every change ships a
|
|
339
339
|
committed migration (BE006).
|
|
340
340
|
- `urls.py` — `app_name` + DRF router, mounted under `/api/` in `config/urls.py` (BE008).
|
|
341
|
+
- `admin.py` — subclass **`unfold.admin.ModelAdmin`**, never `django.contrib.admin.ModelAdmin`.
|
|
342
|
+
The admin is themed by [django-unfold](https://unfoldadmin.com) (`UNFOLD` in
|
|
343
|
+
`config/settings/base.py`); Django's own `ModelAdmin` still works but renders
|
|
344
|
+
unstyled inside the themed layout. For the auth user model, keep Unfold's form
|
|
345
|
+
overrides — see `apps/users/admin.py`.
|
|
341
346
|
- `tests/` — required for every app (BE014). No raw SQL (BE004), no `print()` (BE012).
|
|
342
347
|
|
|
343
348
|
### Frontend (`frontend/src/`)
|
|
@@ -65,7 +65,7 @@ Once the containers are up, open the URLs below.
|
|
|
65
65
|
| **API reference** | http://localhost:8000/api/docs/ | Interactive reference (Scalar) — narrative in `backend/config/api_docs.py` |
|
|
66
66
|
| **OpenAPI schema** | http://localhost:8000/api/schema/ | Raw schema (YAML, drf-spectacular) |
|
|
67
67
|
| **Health** | http://localhost:8000/api/health/ | JSON health check |
|
|
68
|
-
| **Django admin** | http://localhost:8000/admin/ |
|
|
68
|
+
| **Django admin** | http://localhost:8000/admin/ | Themed by [Unfold](https://unfoldadmin.com); create an account with `dude db superuser` |
|
|
69
69
|
{{#if withS3}}
|
|
70
70
|
| **MinIO console** | http://localhost:9001 | Object-storage UI (minioadmin/minioadmin) |
|
|
71
71
|
{{/if}}
|
|
@@ -65,6 +65,20 @@ Create an admin account for <http://localhost:8000/admin/>:
|
|
|
65
65
|
```bash
|
|
66
66
|
dude db superuser
|
|
67
67
|
```
|
|
68
|
+
|
|
69
|
+
The admin is themed by [django-unfold](https://unfoldadmin.com) (configured via
|
|
70
|
+
`UNFOLD` in `config/settings/base.py`). When you register a new model, subclass
|
|
71
|
+
**Unfold's** `ModelAdmin`, not Django's — Django's renders unstyled inside the
|
|
72
|
+
themed layout:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from django.contrib import admin
|
|
76
|
+
from unfold.admin import ModelAdmin
|
|
77
|
+
|
|
78
|
+
@admin.register(MyModel)
|
|
79
|
+
class MyModelAdmin(ModelAdmin):
|
|
80
|
+
...
|
|
81
|
+
```
|
|
68
82
|
{{#if withCelery}}
|
|
69
83
|
|
|
70
84
|
Celery worker{{#if withCeleryBeat}}, beat scheduler{{/if}} and Flower monitor are started automatically by docker compose.
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
from django.contrib import admin
|
|
2
|
-
from django.contrib.auth.admin import UserAdmin
|
|
2
|
+
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
|
3
|
+
from unfold.admin import ModelAdmin
|
|
4
|
+
from unfold.forms import AdminPasswordChangeForm, UserChangeForm, UserCreationForm
|
|
3
5
|
|
|
4
6
|
from apps.users.models import User
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
@admin.register(User)
|
|
10
|
+
class UserAdmin(BaseUserAdmin, ModelAdmin):
|
|
11
|
+
"""Django's user admin, restyled by Unfold.
|
|
12
|
+
|
|
13
|
+
``BaseUserAdmin`` comes first so its fieldsets and password handling win;
|
|
14
|
+
``ModelAdmin`` (Unfold's) supplies the templates.
|
|
15
|
+
|
|
16
|
+
The three form overrides are not optional: Django's auth forms ship their own
|
|
17
|
+
widgets, so without Unfold's replacements the add / change / set-password
|
|
18
|
+
screens render unstyled inside the themed layout.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
form = UserChangeForm
|
|
22
|
+
add_form = UserCreationForm
|
|
23
|
+
change_password_form = AdminPasswordChangeForm
|
|
@@ -22,6 +22,23 @@ BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
|
|
22
22
|
|
|
23
23
|
# ── Application definition ────────────────────────────────────────────────────
|
|
24
24
|
|
|
25
|
+
# django-unfold — the admin theme. Every entry MUST precede
|
|
26
|
+
# "django.contrib.admin": Unfold works by overriding the admin's templates, and
|
|
27
|
+
# Django resolves templates in INSTALLED_APPS order, so listing it later silently
|
|
28
|
+
# gives you the stock admin back.
|
|
29
|
+
#
|
|
30
|
+
# The three contrib modules below pull in no extra packages. The remaining ones
|
|
31
|
+
# each need their own dependency, so add both together if you want them:
|
|
32
|
+
# unfold.contrib.import_export (django-import-export),
|
|
33
|
+
# unfold.contrib.guardian (django-guardian),
|
|
34
|
+
# unfold.contrib.simple_history (django-simple-history).
|
|
35
|
+
ADMIN_APPS = [
|
|
36
|
+
"unfold",
|
|
37
|
+
"unfold.contrib.filters",
|
|
38
|
+
"unfold.contrib.forms",
|
|
39
|
+
"unfold.contrib.inlines",
|
|
40
|
+
]
|
|
41
|
+
|
|
25
42
|
DJANGO_APPS = [
|
|
26
43
|
"django.contrib.admin",
|
|
27
44
|
"django.contrib.auth",
|
|
@@ -48,7 +65,7 @@ LOCAL_APPS = [
|
|
|
48
65
|
{{/if}}
|
|
49
66
|
]
|
|
50
67
|
|
|
51
|
-
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
|
|
68
|
+
INSTALLED_APPS = ADMIN_APPS + DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
|
|
52
69
|
|
|
53
70
|
MIDDLEWARE = [
|
|
54
71
|
"django.middleware.security.SecurityMiddleware",
|
|
@@ -148,6 +165,30 @@ AWS_DEFAULT_ACL = None
|
|
|
148
165
|
AWS_QUERYSTRING_AUTH = True # serve files via presigned URLs
|
|
149
166
|
{{/if}}
|
|
150
167
|
|
|
168
|
+
# ── Admin theme (django-unfold) ───────────────────────────────────────────────
|
|
169
|
+
# Needs no URL wiring — Unfold themes the stock admin site at /admin/ by
|
|
170
|
+
# overriding its templates. ModelAdmin classes must subclass
|
|
171
|
+
# `unfold.admin.ModelAdmin` to pick up the styling (see apps/users/admin.py).
|
|
172
|
+
#
|
|
173
|
+
# Full option list: https://unfoldadmin.com/docs/configuration/settings/
|
|
174
|
+
UNFOLD = {
|
|
175
|
+
"SITE_TITLE": env("APP_TITLE", default="{{projectName}}") + " admin",
|
|
176
|
+
"SITE_HEADER": env("APP_TITLE", default="{{projectName}}"),
|
|
177
|
+
# Link the header back to the frontend.
|
|
178
|
+
"SITE_URL": "/",
|
|
179
|
+
"SHOW_HISTORY": True,
|
|
180
|
+
"SHOW_VIEW_ON_SITE": True,
|
|
181
|
+
"SIDEBAR": {
|
|
182
|
+
"show_search": True,
|
|
183
|
+
# No "navigation" key → Unfold renders the standard app/model list.
|
|
184
|
+
# Add one to hand-order the sidebar as the project grows.
|
|
185
|
+
},
|
|
186
|
+
# To match the frontend's accent, add a "COLORS" ramp here — Unfold wants
|
|
187
|
+
# space-separated RGB channels per Tailwind shade, e.g.
|
|
188
|
+
# "COLORS": {"primary": {"500": "22 119 255", …}}. Omitted so the scaffold
|
|
189
|
+
# ships Unfold's own tested palette rather than a half-filled one.
|
|
190
|
+
}
|
|
191
|
+
|
|
151
192
|
# ── Django REST Framework ─────────────────────────────────────────────────────
|
|
152
193
|
|
|
153
194
|
REST_FRAMEWORK = {
|
|
@@ -57,7 +57,7 @@ Once the stack is up, open these URLs:
|
|
|
57
57
|
| **API reference** | http://localhost:8000/api/docs/ | Interactive reference (Scalar) |
|
|
58
58
|
| **OpenAPI schema** | http://localhost:8000/api/schema/ | Raw schema (YAML, drf-spectacular) |
|
|
59
59
|
| **Health** | http://localhost:8000/api/health/ | JSON health check |
|
|
60
|
-
| **Django admin** | http://localhost:8000/admin/ |
|
|
60
|
+
| **Django admin** | http://localhost:8000/admin/ | Themed by [Unfold](https://unfoldadmin.com); create an account with `dude db superuser` |
|
|
61
61
|
{{#if withS3}}| **MinIO console** | http://localhost:9001 | Object-storage UI (minioadmin/minioadmin) |
|
|
62
62
|
{{/if}}
|
|
63
63
|
{{#if withCelery}}| **Flower** | http://localhost:5555 | Celery task monitor |
|
|
@@ -94,6 +94,7 @@ defines every service.
|
|
|
94
94
|
| Command | Description |
|
|
95
95
|
|---------|-------------|
|
|
96
96
|
| `dude lint` | Run all structural lint checks (naming, layout conventions) |
|
|
97
|
+
| `dude explain <CODE>` | Print the prose behind a lint code — why the rule exists and how to fix it |
|
|
97
98
|
| `dude format` | Format code — `ruff` (backend) + `prettier` (frontend) |
|
|
98
99
|
| `dude upgrade` | Update the pinned `dude` CLI and stack versions for this project |
|
|
99
100
|
| `dude review` | Run lint + ESLint + API contract review in one pass |
|
|
@@ -103,13 +104,29 @@ defines every service.
|
|
|
103
104
|
`dude lint` also runs any rules you define under `.dude/lint/checks/` — the
|
|
104
105
|
rule code is derived from the path (`.dude/lint/checks/PRJ/001.ts` → `PRJ001`)
|
|
105
106
|
and the contract is the same one the stack's own checks use. See
|
|
106
|
-
`.dude/lint/checks/README.md` and the `PRJ/001.ts` example.
|
|
107
|
-
|
|
107
|
+
`.dude/lint/checks/README.md` and the `PRJ/001.ts` example. Document a rule with
|
|
108
|
+
a Markdown file next to it (`PRJ/001.md`) and `dude explain PRJ001` serves it.
|
|
109
|
+
To disable a built-in rule, list its code in `dude.json`:
|
|
108
110
|
|
|
109
111
|
```json
|
|
110
112
|
{ "lint": { "disable": ["BE003"] } }
|
|
111
113
|
```
|
|
112
114
|
|
|
115
|
+
### Verifying your work mechanically
|
|
116
|
+
|
|
117
|
+
`dude lint` and `dude explain` are designed to be used together — the fastest
|
|
118
|
+
loop for anyone, human or coding agent, working in this project:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
dude lint --format json # what broke, where, and under which rule code
|
|
122
|
+
dude explain BE003 # why that rule exists and how to satisfy it
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`--format json` writes nothing but the JSON document to stdout, so it pipes
|
|
126
|
+
cleanly (`dude lint --format json | jq '.diagnostics[].code'`). Exit codes are
|
|
127
|
+
the same as the human format: non-zero only when there is at least one error.
|
|
128
|
+
Run `dude explain` with no code to list every rule that applies here.
|
|
129
|
+
|
|
113
130
|
### Upgrading pinned versions
|
|
114
131
|
|
|
115
132
|
`dude upgrade` updates version pins only. It does **not** migrate existing
|
|
@@ -58,7 +58,7 @@ dude docs # → http://localhost:8001
|
|
|
58
58
|
| API reference (Scalar) | <http://localhost:8000/api/docs/> |
|
|
59
59
|
| OpenAPI schema | <http://localhost:8000/api/schema/> |
|
|
60
60
|
| API health | <http://localhost:8000/api/health/> |
|
|
61
|
-
| Django admin | <http://localhost:8000/admin/> |
|
|
61
|
+
| Django admin (Unfold theme) | <http://localhost:8000/admin/> |
|
|
62
62
|
{{#if withS3}}
|
|
63
63
|
| MinIO console | <http://localhost:9001> |
|
|
64
64
|
{{/if}}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
from django.contrib import admin
|
|
2
|
+
from unfold.admin import ModelAdmin
|
|
2
3
|
|
|
3
4
|
from apps.files.models import FileUpload
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
@admin.register(FileUpload)
|
|
7
|
-
class FileUploadAdmin(
|
|
8
|
+
class FileUploadAdmin(ModelAdmin):
|
|
9
|
+
# Unfold's ModelAdmin, not django.contrib.admin's — that is what applies the
|
|
10
|
+
# admin theme (see UNFOLD in config/settings/base.py).
|
|
8
11
|
list_display = ("id", "original_name", "content_type", "size", "created_at")
|
|
9
12
|
readonly_fields = ("created_at",)
|