@cubocicloide/stack-react-django 3.1.0 → 3.3.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 +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/base/.claude/skills/create-route/SKILL.md +1 -1
- package/templates/base/CLAUDE.md.hbs +19 -2
- package/templates/base/README.md.hbs +3 -3
- package/templates/base/backend/README.md.hbs +22 -3
- package/templates/base/backend/apps/core/views.py +8 -2
- package/templates/base/backend/apps/users/admin.py +19 -2
- package/templates/base/backend/apps/users/views.py +19 -0
- package/templates/base/backend/config/api_docs.py.hbs +123 -0
- package/templates/base/backend/config/settings/base.py.hbs +57 -2
- package/templates/base/backend/config/urls.py.hbs +5 -3
- package/templates/base/backend/pyproject.toml.hbs +3 -0
- package/templates/base/backend/templates/api-docs.html.hbs +98 -0
- package/templates/base/docs/docs/dude.md.hbs +3 -3
- package/templates/base/docs/docs/index.md.hbs +2 -2
- package/templates/base/frontend/src/openapi/utils/openapi.yaml.hbs +9 -6
- package/templates/s3/backend/apps/files/admin.py +4 -1
- package/templates/s3/backend/apps/files/views.py +26 -3
package/package.json
CHANGED
|
@@ -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.
|
|
@@ -151,8 +151,20 @@ Migrations also run automatically when the backend container boots.
|
|
|
151
151
|
| `dude api review` | Validate `frontend/src/openapi/` against the saved spec |
|
|
152
152
|
|
|
153
153
|
**Workflow**: always run `dude api sync` after changing backend endpoints, then
|
|
154
|
-
commit the updated `frontend/src/openapi/` alongside the change.
|
|
155
|
-
served at http://localhost:8000/api/docs
|
|
154
|
+
commit the updated `frontend/src/openapi/` alongside the change. The reference is
|
|
155
|
+
served at http://localhost:8000/api/docs/ (Scalar).
|
|
156
|
+
|
|
157
|
+
**Documenting an endpoint** — the schema only carries what the code declares:
|
|
158
|
+
|
|
159
|
+
- Every view gets a `@extend_schema` (or `@extend_schema_view`) with a `tags`
|
|
160
|
+
entry, an imperative `summary` (≤ 6 words) and a `description` that says
|
|
161
|
+
something the schema does not already show — preconditions, side effects, who
|
|
162
|
+
may call it, which error a wrong call returns.
|
|
163
|
+
- Every tag used must exist in `API_TAGS` in `backend/config/api_docs.py`, or the
|
|
164
|
+
operation lands ungrouped at the bottom of the sidebar. `API_TAGS` order **is**
|
|
165
|
+
the sidebar order.
|
|
166
|
+
- Cross-cutting prose (auth header, conventions, the domain lifecycle) belongs in
|
|
167
|
+
`API_DESCRIPTION` in the same file, not repeated per endpoint.
|
|
156
168
|
|
|
157
169
|
### Testing
|
|
158
170
|
|
|
@@ -326,6 +338,11 @@ dude db migrate
|
|
|
326
338
|
fields (BE010), explicit `related_name` (BE011); every change ships a
|
|
327
339
|
committed migration (BE006).
|
|
328
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`.
|
|
329
346
|
- `tests/` — required for every app (BE014). No raw SQL (BE004), no `print()` (BE012).
|
|
330
347
|
|
|
331
348
|
### Frontend (`frontend/src/`)
|
|
@@ -62,10 +62,10 @@ Once the containers are up, open the URLs below.
|
|
|
62
62
|
|---------|-----|-------|
|
|
63
63
|
| **Frontend** | http://localhost:5173 | React + Vite — HMR active |
|
|
64
64
|
| **API** | http://localhost:8000 | Django REST Framework |
|
|
65
|
-
| **
|
|
66
|
-
| **OpenAPI schema** | http://localhost:8000/api/schema/ | Raw schema (YAML) |
|
|
65
|
+
| **API reference** | http://localhost:8000/api/docs/ | Interactive reference (Scalar) — narrative in `backend/config/api_docs.py` |
|
|
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.
|
|
@@ -79,9 +93,14 @@ uv run python manage.py migrate
|
|
|
79
93
|
uv run python manage.py runserver 0.0.0.0:8000
|
|
80
94
|
```
|
|
81
95
|
|
|
82
|
-
Then open <http://localhost:8000/api/health/> — interactive API
|
|
83
|
-
<http://localhost:8000/api/docs/> (
|
|
84
|
-
the raw OpenAPI schema at
|
|
96
|
+
Then open <http://localhost:8000/api/health/> — the interactive API reference
|
|
97
|
+
lives at <http://localhost:8000/api/docs/> (Scalar, rendered from
|
|
98
|
+
`backend/templates/api-docs.html`) and the raw OpenAPI schema at
|
|
99
|
+
<http://localhost:8000/api/schema/>.
|
|
100
|
+
|
|
101
|
+
The reference's prose — authentication, conventions, the domain lifecycle — is
|
|
102
|
+
hand-written in `backend/config/api_docs.py`. Keep it current: the schema is
|
|
103
|
+
generated, that file is not.
|
|
85
104
|
|
|
86
105
|
## Tests
|
|
87
106
|
|
|
@@ -14,9 +14,15 @@ class HealthView(APIView):
|
|
|
14
14
|
|
|
15
15
|
@extend_schema(
|
|
16
16
|
operation_id="health_retrieve",
|
|
17
|
-
|
|
17
|
+
summary="Check service health",
|
|
18
|
+
description=(
|
|
19
|
+
'Returns `{"status": "ok"}` while the process is accepting requests. '
|
|
20
|
+
"This is a liveness probe, not a status page — it does not test the "
|
|
21
|
+
"database, the cache or any downstream service. The only endpoint that "
|
|
22
|
+
"needs no credentials."
|
|
23
|
+
),
|
|
18
24
|
responses=HealthSerializer,
|
|
19
|
-
tags=["
|
|
25
|
+
tags=["Health"],
|
|
20
26
|
auth=[],
|
|
21
27
|
)
|
|
22
28
|
def get(self, request: Request) -> Response:
|
|
@@ -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
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from drf_spectacular.utils import extend_schema, extend_schema_view
|
|
1
2
|
from rest_framework.permissions import AllowAny
|
|
2
3
|
from rest_framework.viewsets import ReadOnlyModelViewSet
|
|
3
4
|
|
|
@@ -5,6 +6,24 @@ from apps.users.models import User
|
|
|
5
6
|
from apps.users.serializers import UserSerializer
|
|
6
7
|
|
|
7
8
|
|
|
9
|
+
@extend_schema(tags=["Users"])
|
|
10
|
+
@extend_schema_view(
|
|
11
|
+
list=extend_schema(
|
|
12
|
+
summary="List users",
|
|
13
|
+
description=(
|
|
14
|
+
"Paginated and ordered by `id` ascending. Select a page with "
|
|
15
|
+
"`?page=<n>`; the page size is fixed at 50. Results always come back "
|
|
16
|
+
"in the envelope (`count`, `next`, `previous`, `results`), never as a "
|
|
17
|
+
"bare array."
|
|
18
|
+
),
|
|
19
|
+
),
|
|
20
|
+
retrieve=extend_schema(
|
|
21
|
+
summary="Retrieve a user",
|
|
22
|
+
description=(
|
|
23
|
+
'An unknown id returns `404` with `{"detail": "No User matches the given query."}`.'
|
|
24
|
+
),
|
|
25
|
+
),
|
|
26
|
+
)
|
|
8
27
|
class UserViewSet(ReadOnlyModelViewSet):
|
|
9
28
|
"""List (paginated) and retrieve users.
|
|
10
29
|
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Narrative + sidebar structure for the public API reference.
|
|
2
|
+
|
|
3
|
+
`API_DESCRIPTION` becomes `info.description` in the OpenAPI schema and renders as
|
|
4
|
+
the landing page of the reference at ``/api/docs/``. `API_TAGS` is the sidebar:
|
|
5
|
+
its order is the sidebar order (``SORT_OPERATIONS`` is off), and every tag used
|
|
6
|
+
by a view must appear here or the operation lands ungrouped at the bottom.
|
|
7
|
+
|
|
8
|
+
Both are wired up in ``config/settings/base.py`` (``SPECTACULAR_SETTINGS``).
|
|
9
|
+
|
|
10
|
+
This file is where the reference stops being generated and starts being written.
|
|
11
|
+
Edit it as the API grows — the sections marked **TODO** describe your product,
|
|
12
|
+
not the scaffold.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
API_DESCRIPTION = """
|
|
16
|
+
The **{{projectName}}** HTTP API. It is consumed by the {{projectName}} web frontend and by any
|
|
17
|
+
service you authorise. Every response is JSON; every path below is relative to
|
|
18
|
+
`/api/`.
|
|
19
|
+
|
|
20
|
+
<!-- TODO: replace this paragraph with what the API actually is — the domain in
|
|
21
|
+
plain words, who calls it, and what a caller can accomplish with it. If it is
|
|
22
|
+
internal-only, say so here rather than making integrators discover it from a 401. -->
|
|
23
|
+
|
|
24
|
+
## Authentication
|
|
25
|
+
|
|
26
|
+
The scaffold ships Django REST Framework's default authenticators — **session
|
|
27
|
+
cookie** and **HTTP Basic**. Every endpoint requires an authenticated user unless
|
|
28
|
+
its view opts out with an explicit `permission_classes` declaration.
|
|
29
|
+
|
|
30
|
+
Session (browser, same-origin — what the frontend uses):
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
Cookie: sessionid=<session-id>
|
|
34
|
+
X-CSRFToken: <csrf-token>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
HTTP Basic (scripts and `curl`):
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
Authorization: Basic <base64(username:password)>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Create a user with `dude db superuser`, then log in at `/admin/` to get a session.
|
|
44
|
+
|
|
45
|
+
<!-- TODO: swap in the real scheme before exposing this API. Add
|
|
46
|
+
`DEFAULT_AUTHENTICATION_CLASSES` to `REST_FRAMEWORK` in
|
|
47
|
+
`config/settings/base.py` (e.g. `djangorestframework-simplejwt`), then document
|
|
48
|
+
the exact header verbatim here, plus token lifetimes and how a caller obtains
|
|
49
|
+
credentials. Prefix mistakes are the most common integration failure — spell the
|
|
50
|
+
header out, do not paraphrase it. -->
|
|
51
|
+
|
|
52
|
+
## Base URLs
|
|
53
|
+
|
|
54
|
+
| Environment | Base URL |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| Local development | `http://localhost:8000` |
|
|
57
|
+
|
|
58
|
+
<!-- TODO: add the deployed environments and mirror them in `SERVERS`
|
|
59
|
+
(`SPECTACULAR_SETTINGS`, `config/settings/base.py`) so the **Test Request**
|
|
60
|
+
panel can target them. -->
|
|
61
|
+
|
|
62
|
+
## Conventions
|
|
63
|
+
|
|
64
|
+
- **Trailing slashes are required.** DRF's routers register `/api/users/`, not
|
|
65
|
+
`/api/users`. Without the slash Django replies `301` and most HTTP clients drop
|
|
66
|
+
the request body on the redirect.
|
|
67
|
+
- **Pagination** — list endpoints return an envelope, never a bare array:
|
|
68
|
+
`{"count": 123, "next": "…?page=3", "previous": "…?page=1", "results": [...]}`.
|
|
69
|
+
Page size is 50; select a page with `?page=<n>`. `next`/`previous` are `null` at
|
|
70
|
+
the ends.
|
|
71
|
+
- **Timestamps** — ISO-8601 with an offset, always UTC (`2026-01-31T09:15:00Z`).
|
|
72
|
+
- **IDs** — sequential integers, not UUIDs. Do not assume they are unguessable.
|
|
73
|
+
- **Errors** — two distinct body shapes:
|
|
74
|
+
- non-field failures (401, 403, 404, 405, throttled): `{"detail": "Not found."}`
|
|
75
|
+
- validation failures (400): a map of field name → list of messages,
|
|
76
|
+
`{"email": ["Enter a valid email address."]}`, with non-field problems under
|
|
77
|
+
the `non_field_errors` key.
|
|
78
|
+
{{#if withS3}}
|
|
79
|
+
- **Files** — uploads are `multipart/form-data` on the `file` field. The response
|
|
80
|
+
never contains the binary: it returns metadata plus `url`, a **presigned link
|
|
81
|
+
that expires**. Fetch it fresh from the API rather than storing it.
|
|
82
|
+
{{/if}}
|
|
83
|
+
|
|
84
|
+
## Lifecycle
|
|
85
|
+
|
|
86
|
+
<!-- TODO: this section carries the most weight in the whole reference, and the
|
|
87
|
+
scaffold cannot write it for you. Describe the state machine a caller must
|
|
88
|
+
respect: which state an object starts in, what each transition requires as a
|
|
89
|
+
precondition, what locks afterwards, and which status code a premature call
|
|
90
|
+
gets. Per-endpoint docs cannot express this; leaving it out is what makes
|
|
91
|
+
integrators guess. Delete this section only if the domain genuinely has no
|
|
92
|
+
stateful objects. -->
|
|
93
|
+
|
|
94
|
+
## Status
|
|
95
|
+
|
|
96
|
+
- The API is **unversioned**. Breaking changes ship without a path bump — pin
|
|
97
|
+
nothing, read the changelog.
|
|
98
|
+
- `GET /api/health/` is the only unauthenticated endpoint. It is a liveness probe,
|
|
99
|
+
not a status page: it reports that the process is up, not that the database is.
|
|
100
|
+
{{#if withS3}}
|
|
101
|
+
- File storage runs against MinIO locally and S3 in deployed environments. Presigned
|
|
102
|
+
URL lifetimes differ between the two.
|
|
103
|
+
{{/if}}
|
|
104
|
+
- No webhooks, no rate limiting, and no API keys yet.
|
|
105
|
+
""".strip()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
API_TAGS = [
|
|
109
|
+
{
|
|
110
|
+
"name": "Health",
|
|
111
|
+
"description": "Liveness probe. Unauthenticated, used by container health checks and the frontend boot sequence.",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name": "Users",
|
|
115
|
+
"description": "The accounts that authenticate against this API. Read-only in the scaffold — user creation lives in `apps.users.services`.",
|
|
116
|
+
},
|
|
117
|
+
{{#if withS3}}
|
|
118
|
+
{
|
|
119
|
+
"name": "Files",
|
|
120
|
+
"description": "Binaries stored on the object-storage backend. Uploaded as multipart, read back through short-lived presigned URLs.",
|
|
121
|
+
},
|
|
122
|
+
{{/if}}
|
|
123
|
+
]
|
|
@@ -13,6 +13,8 @@ from pathlib import Path
|
|
|
13
13
|
|
|
14
14
|
import environ
|
|
15
15
|
|
|
16
|
+
from config.api_docs import API_DESCRIPTION, API_TAGS
|
|
17
|
+
|
|
16
18
|
env = environ.Env()
|
|
17
19
|
|
|
18
20
|
# backend/ directory (contains manage.py) — /app inside the container
|
|
@@ -20,6 +22,23 @@ BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
|
|
20
22
|
|
|
21
23
|
# ── Application definition ────────────────────────────────────────────────────
|
|
22
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
|
+
|
|
23
42
|
DJANGO_APPS = [
|
|
24
43
|
"django.contrib.admin",
|
|
25
44
|
"django.contrib.auth",
|
|
@@ -46,7 +65,7 @@ LOCAL_APPS = [
|
|
|
46
65
|
{{/if}}
|
|
47
66
|
]
|
|
48
67
|
|
|
49
|
-
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
|
|
68
|
+
INSTALLED_APPS = ADMIN_APPS + DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
|
|
50
69
|
|
|
51
70
|
MIDDLEWARE = [
|
|
52
71
|
"django.middleware.security.SecurityMiddleware",
|
|
@@ -65,7 +84,8 @@ ROOT_URLCONF = "config.urls"
|
|
|
65
84
|
TEMPLATES = [
|
|
66
85
|
{
|
|
67
86
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
68
|
-
|
|
87
|
+
# backend/templates/ — holds api-docs.html (the API reference page).
|
|
88
|
+
"DIRS": [BASE_DIR / "templates"],
|
|
69
89
|
"APP_DIRS": True,
|
|
70
90
|
"OPTIONS": {
|
|
71
91
|
"context_processors": [
|
|
@@ -145,6 +165,30 @@ AWS_DEFAULT_ACL = None
|
|
|
145
165
|
AWS_QUERYSTRING_AUTH = True # serve files via presigned URLs
|
|
146
166
|
{{/if}}
|
|
147
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
|
+
|
|
148
192
|
# ── Django REST Framework ─────────────────────────────────────────────────────
|
|
149
193
|
|
|
150
194
|
REST_FRAMEWORK = {
|
|
@@ -156,10 +200,21 @@ REST_FRAMEWORK = {
|
|
|
156
200
|
"DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
|
|
157
201
|
}
|
|
158
202
|
|
|
203
|
+
# ── OpenAPI schema (drf-spectacular) ──────────────────────────────────────────
|
|
204
|
+
# The reference is served at /api/docs/ by Scalar; the prose lives in
|
|
205
|
+
# config/api_docs.py. Regenerate the frontend client with `dude api sync`.
|
|
206
|
+
|
|
159
207
|
SPECTACULAR_SETTINGS = {
|
|
160
208
|
"TITLE": env("APP_TITLE", default="{{projectName}}") + " API",
|
|
209
|
+
"DESCRIPTION": API_DESCRIPTION,
|
|
161
210
|
"VERSION": "1.0.0",
|
|
211
|
+
# The schema endpoint is not itself an operation.
|
|
162
212
|
"SERVE_INCLUDE_SCHEMA": False,
|
|
213
|
+
# Keep the author-chosen order — TAGS drives the sidebar, not the alphabet.
|
|
214
|
+
"SORT_OPERATIONS": False,
|
|
215
|
+
"TAGS": API_TAGS,
|
|
216
|
+
# Add deployed environments here so the "Test Request" panel can target them.
|
|
217
|
+
"SERVERS": [{"url": "http://localhost:8000", "description": "Local development"}],
|
|
163
218
|
}
|
|
164
219
|
{{#if withCelery}}
|
|
165
220
|
|
|
@@ -6,7 +6,8 @@ declares its own routes (and an ``app_name``) in ``apps/<app>/urls.py``.
|
|
|
6
6
|
|
|
7
7
|
from django.contrib import admin
|
|
8
8
|
from django.urls import include, path
|
|
9
|
-
from
|
|
9
|
+
from django.views.generic import TemplateView
|
|
10
|
+
from drf_spectacular.views import SpectacularAPIView
|
|
10
11
|
|
|
11
12
|
urlpatterns = [
|
|
12
13
|
path("admin/", admin.site.urls),
|
|
@@ -16,7 +17,8 @@ urlpatterns = [
|
|
|
16
17
|
{{#if withS3}}
|
|
17
18
|
path("api/", include("apps.files.urls")),
|
|
18
19
|
{{/if}}
|
|
19
|
-
# OpenAPI schema +
|
|
20
|
+
# OpenAPI schema (drf-spectacular) + the reference page (Scalar, rendered from
|
|
21
|
+
# backend/templates/api-docs.html). One docs URL — no Swagger UI, no ReDoc.
|
|
20
22
|
path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
|
|
21
|
-
path("api/docs/",
|
|
23
|
+
path("api/docs/", TemplateView.as_view(template_name="api-docs.html"), name="docs"),
|
|
22
24
|
]
|
|
@@ -9,6 +9,7 @@ dependencies = [
|
|
|
9
9
|
"drf-spectacular>=0.28.0",
|
|
10
10
|
"django-environ>=0.11.0",
|
|
11
11
|
"django-cors-headers>=4.6.0",
|
|
12
|
+
"django-unfold>=0.102.0",
|
|
12
13
|
"whitenoise>=6.8.0",
|
|
13
14
|
"gunicorn>=23.0.0",
|
|
14
15
|
{{#if withPostgres}}
|
|
@@ -42,6 +43,8 @@ target-version = "py313"
|
|
|
42
43
|
select = ["E", "F", "I", "N", "UP", "B", "S", "RUF"]
|
|
43
44
|
|
|
44
45
|
[tool.ruff.lint.per-file-ignores]
|
|
46
|
+
# Markdown narrative + tag prose — line length is not a useful rule there.
|
|
47
|
+
"config/api_docs.py" = ["E501"]
|
|
45
48
|
# Tests use asserts (S101) and throw-away credentials (S105/S106).
|
|
46
49
|
"apps/*/tests/*" = ["S101", "S105", "S106"]
|
|
47
50
|
# Hand-written / autogenerated migrations may exceed the line length.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>{{projectName}} API reference</title>
|
|
7
|
+
<link
|
|
8
|
+
rel="icon"
|
|
9
|
+
href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Crect width='48' height='48' rx='12' fill='%231677ff'/%3E%3C/svg%3E"
|
|
10
|
+
/>
|
|
11
|
+
<style>
|
|
12
|
+
html,
|
|
13
|
+
body {
|
|
14
|
+
margin: 0;
|
|
15
|
+
}
|
|
16
|
+
:root {
|
|
17
|
+
--scalar-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
|
|
18
|
+
Arial, sans-serif;
|
|
19
|
+
--scalar-font-code: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
20
|
+
}
|
|
21
|
+
/* Brand accent — matches the frontend's antd primary colour. */
|
|
22
|
+
.light-mode {
|
|
23
|
+
--scalar-color-accent: #1677ff;
|
|
24
|
+
}
|
|
25
|
+
.dark-mode {
|
|
26
|
+
--scalar-color-accent: #4096ff;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* Brand bar. Delete this block and the <header> below together if you'd
|
|
30
|
+
rather have Scalar's own header on its own. */
|
|
31
|
+
.brandbar {
|
|
32
|
+
position: sticky;
|
|
33
|
+
top: 0;
|
|
34
|
+
z-index: 1000;
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
gap: 0.75rem;
|
|
38
|
+
height: 56px;
|
|
39
|
+
padding: 0 1.25rem;
|
|
40
|
+
background: #1677ff;
|
|
41
|
+
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
|
|
42
|
+
}
|
|
43
|
+
.brandbar .name {
|
|
44
|
+
color: #fff;
|
|
45
|
+
font: 600 1rem/1 system-ui, -apple-system, sans-serif;
|
|
46
|
+
}
|
|
47
|
+
.brandbar .spacer {
|
|
48
|
+
flex: 1;
|
|
49
|
+
}
|
|
50
|
+
.brandbar .tag {
|
|
51
|
+
color: #fff;
|
|
52
|
+
opacity: 0.92;
|
|
53
|
+
font: 600 0.78rem/1 system-ui, -apple-system, sans-serif;
|
|
54
|
+
letter-spacing: 0.06em;
|
|
55
|
+
text-transform: uppercase;
|
|
56
|
+
}
|
|
57
|
+
</style>
|
|
58
|
+
</head>
|
|
59
|
+
<body>
|
|
60
|
+
<header class="brandbar">
|
|
61
|
+
<span class="name">{{projectName}}</span>
|
|
62
|
+
<span class="spacer"></span>
|
|
63
|
+
<span class="tag">API reference</span>
|
|
64
|
+
</header>
|
|
65
|
+
<div id="app"></div>
|
|
66
|
+
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
|
67
|
+
<script>
|
|
68
|
+
Scalar.createApiReference('#app', {
|
|
69
|
+
url: "{% url 'schema' %}",
|
|
70
|
+
theme: 'default',
|
|
71
|
+
layout: 'modern',
|
|
72
|
+
hideDownloadButton: true,
|
|
73
|
+
showDeveloperTools: 'never',
|
|
74
|
+
persistAuth: true,
|
|
75
|
+
withDefaultFonts: false,
|
|
76
|
+
metaData: {
|
|
77
|
+
title: '{{projectName}} API reference',
|
|
78
|
+
description: 'HTTP API reference for {{projectName}}.',
|
|
79
|
+
},
|
|
80
|
+
// Preselect a scheme so the Authentication panel opens with a filled
|
|
81
|
+
// field instead of "No authentication selected". Change this key when you
|
|
82
|
+
// swap the authenticators — it must match one of the keys drf-spectacular
|
|
83
|
+
// emits under components.securitySchemes (basicAuth, cookieAuth, jwtAuth…).
|
|
84
|
+
authentication: {
|
|
85
|
+
preferredSecurityScheme: 'basicAuth',
|
|
86
|
+
},
|
|
87
|
+
customCss: `
|
|
88
|
+
:root {
|
|
89
|
+
/* Room for the brand bar so Scalar still fits the viewport. Drop
|
|
90
|
+
this line together with the <header> if you remove the bar. */
|
|
91
|
+
--scalar-custom-header-height: 56px;
|
|
92
|
+
}
|
|
93
|
+
a[href*="scalar.com"] { display: none !important; }
|
|
94
|
+
`,
|
|
95
|
+
})
|
|
96
|
+
</script>
|
|
97
|
+
</body>
|
|
98
|
+
</html>
|
|
@@ -54,10 +54,10 @@ Once the stack is up, open these URLs:
|
|
|
54
54
|
|---------|-----|-------|
|
|
55
55
|
| **Frontend** | http://localhost:5173 | React + Vite — HMR active |
|
|
56
56
|
| **API** | http://localhost:8000 | Django REST Framework |
|
|
57
|
-
| **
|
|
58
|
-
| **OpenAPI schema** | http://localhost:8000/api/schema/ | Raw schema (YAML) |
|
|
57
|
+
| **API reference** | http://localhost:8000/api/docs/ | Interactive reference (Scalar) |
|
|
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 |
|
|
@@ -55,10 +55,10 @@ dude docs # → http://localhost:8001
|
|
|
55
55
|
|----------|-----|
|
|
56
56
|
| Frontend (dev) | <http://localhost:5173> |
|
|
57
57
|
| Backend API | <http://localhost:8000> |
|
|
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}}
|
|
@@ -6,9 +6,10 @@ paths:
|
|
|
6
6
|
/api/health/:
|
|
7
7
|
get:
|
|
8
8
|
operationId: health_retrieve
|
|
9
|
-
|
|
9
|
+
summary: Check service health
|
|
10
|
+
description: 'Returns `{"status": "ok"}` while the process is accepting requests.'
|
|
10
11
|
tags:
|
|
11
|
-
-
|
|
12
|
+
- Health
|
|
12
13
|
security:
|
|
13
14
|
- {}
|
|
14
15
|
responses:
|
|
@@ -21,7 +22,8 @@ paths:
|
|
|
21
22
|
/api/users/:
|
|
22
23
|
get:
|
|
23
24
|
operationId: users_list
|
|
24
|
-
|
|
25
|
+
summary: List users
|
|
26
|
+
description: Paginated and ordered by `id` ascending.
|
|
25
27
|
parameters:
|
|
26
28
|
- name: page
|
|
27
29
|
required: false
|
|
@@ -30,7 +32,7 @@ paths:
|
|
|
30
32
|
schema:
|
|
31
33
|
type: integer
|
|
32
34
|
tags:
|
|
33
|
-
-
|
|
35
|
+
- Users
|
|
34
36
|
security:
|
|
35
37
|
- {}
|
|
36
38
|
responses:
|
|
@@ -43,7 +45,8 @@ paths:
|
|
|
43
45
|
/api/users/{id}/:
|
|
44
46
|
get:
|
|
45
47
|
operationId: users_retrieve
|
|
46
|
-
|
|
48
|
+
summary: Retrieve a user
|
|
49
|
+
description: An unknown id returns `404`.
|
|
47
50
|
parameters:
|
|
48
51
|
- name: id
|
|
49
52
|
in: path
|
|
@@ -52,7 +55,7 @@ paths:
|
|
|
52
55
|
schema:
|
|
53
56
|
type: integer
|
|
54
57
|
tags:
|
|
55
|
-
-
|
|
58
|
+
- Users
|
|
56
59
|
security:
|
|
57
60
|
- {}
|
|
58
61
|
responses:
|
|
@@ -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",)
|