@cubocicloide/stack-react-django 3.0.4

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.
Files changed (289) hide show
  1. package/LICENSE +33 -0
  2. package/README.md +66 -0
  3. package/dist/commands/lint/checks/BE/001.d.ts +6 -0
  4. package/dist/commands/lint/checks/BE/001.js +94 -0
  5. package/dist/commands/lint/checks/BE/001.js.map +1 -0
  6. package/dist/commands/lint/checks/BE/002.d.ts +6 -0
  7. package/dist/commands/lint/checks/BE/002.js +136 -0
  8. package/dist/commands/lint/checks/BE/002.js.map +1 -0
  9. package/dist/commands/lint/checks/BE/003.d.ts +6 -0
  10. package/dist/commands/lint/checks/BE/003.js +89 -0
  11. package/dist/commands/lint/checks/BE/003.js.map +1 -0
  12. package/dist/commands/lint/checks/BE/004.d.ts +6 -0
  13. package/dist/commands/lint/checks/BE/004.js +68 -0
  14. package/dist/commands/lint/checks/BE/004.js.map +1 -0
  15. package/dist/commands/lint/checks/BE/005.d.ts +6 -0
  16. package/dist/commands/lint/checks/BE/005.js +55 -0
  17. package/dist/commands/lint/checks/BE/005.js.map +1 -0
  18. package/dist/commands/lint/checks/BE/006.d.ts +6 -0
  19. package/dist/commands/lint/checks/BE/006.js +95 -0
  20. package/dist/commands/lint/checks/BE/006.js.map +1 -0
  21. package/dist/commands/lint/checks/BE/007.d.ts +6 -0
  22. package/dist/commands/lint/checks/BE/007.js +53 -0
  23. package/dist/commands/lint/checks/BE/007.js.map +1 -0
  24. package/dist/commands/lint/checks/BE/008.d.ts +6 -0
  25. package/dist/commands/lint/checks/BE/008.js +70 -0
  26. package/dist/commands/lint/checks/BE/008.js.map +1 -0
  27. package/dist/commands/lint/checks/BE/009.d.ts +6 -0
  28. package/dist/commands/lint/checks/BE/009.js +112 -0
  29. package/dist/commands/lint/checks/BE/009.js.map +1 -0
  30. package/dist/commands/lint/checks/BE/010.d.ts +6 -0
  31. package/dist/commands/lint/checks/BE/010.js +76 -0
  32. package/dist/commands/lint/checks/BE/010.js.map +1 -0
  33. package/dist/commands/lint/checks/BE/011.d.ts +6 -0
  34. package/dist/commands/lint/checks/BE/011.js +76 -0
  35. package/dist/commands/lint/checks/BE/011.js.map +1 -0
  36. package/dist/commands/lint/checks/BE/012.d.ts +6 -0
  37. package/dist/commands/lint/checks/BE/012.js +61 -0
  38. package/dist/commands/lint/checks/BE/012.js.map +1 -0
  39. package/dist/commands/lint/checks/BE/013.d.ts +6 -0
  40. package/dist/commands/lint/checks/BE/013.js +98 -0
  41. package/dist/commands/lint/checks/BE/013.js.map +1 -0
  42. package/dist/commands/lint/checks/BE/014.d.ts +6 -0
  43. package/dist/commands/lint/checks/BE/014.js +64 -0
  44. package/dist/commands/lint/checks/BE/014.js.map +1 -0
  45. package/dist/commands/lint/checks/E2E/001.d.ts +6 -0
  46. package/dist/commands/lint/checks/E2E/001.js +35 -0
  47. package/dist/commands/lint/checks/E2E/001.js.map +1 -0
  48. package/dist/commands/lint/checks/E2E/002.d.ts +6 -0
  49. package/dist/commands/lint/checks/E2E/002.js +37 -0
  50. package/dist/commands/lint/checks/E2E/002.js.map +1 -0
  51. package/dist/commands/lint/checks/E2E/003.d.ts +6 -0
  52. package/dist/commands/lint/checks/E2E/003.js +42 -0
  53. package/dist/commands/lint/checks/E2E/003.js.map +1 -0
  54. package/dist/commands/lint/checks/E2E/004.d.ts +6 -0
  55. package/dist/commands/lint/checks/E2E/004.js +37 -0
  56. package/dist/commands/lint/checks/E2E/004.js.map +1 -0
  57. package/dist/commands/lint/checks/E2E/005.d.ts +6 -0
  58. package/dist/commands/lint/checks/E2E/005.js +47 -0
  59. package/dist/commands/lint/checks/E2E/005.js.map +1 -0
  60. package/dist/commands/lint/checks/E2E/006.d.ts +6 -0
  61. package/dist/commands/lint/checks/E2E/006.js +28 -0
  62. package/dist/commands/lint/checks/E2E/006.js.map +1 -0
  63. package/dist/commands/lint/checks/E2E/007.d.ts +6 -0
  64. package/dist/commands/lint/checks/E2E/007.js +47 -0
  65. package/dist/commands/lint/checks/E2E/007.js.map +1 -0
  66. package/dist/commands/lint/checks/FE/001.d.ts +6 -0
  67. package/dist/commands/lint/checks/FE/001.js +56 -0
  68. package/dist/commands/lint/checks/FE/001.js.map +1 -0
  69. package/dist/commands/lint/checks/FE/002.d.ts +6 -0
  70. package/dist/commands/lint/checks/FE/002.js +80 -0
  71. package/dist/commands/lint/checks/FE/002.js.map +1 -0
  72. package/dist/commands/lint/checks/FE/003.d.ts +6 -0
  73. package/dist/commands/lint/checks/FE/003.js +65 -0
  74. package/dist/commands/lint/checks/FE/003.js.map +1 -0
  75. package/dist/commands/lint/checks/FE/004.d.ts +6 -0
  76. package/dist/commands/lint/checks/FE/004.js +72 -0
  77. package/dist/commands/lint/checks/FE/004.js.map +1 -0
  78. package/dist/commands/lint/checks/FE/005.d.ts +6 -0
  79. package/dist/commands/lint/checks/FE/005.js +103 -0
  80. package/dist/commands/lint/checks/FE/005.js.map +1 -0
  81. package/dist/commands/lint/checks/FE/006.d.ts +6 -0
  82. package/dist/commands/lint/checks/FE/006.js +102 -0
  83. package/dist/commands/lint/checks/FE/006.js.map +1 -0
  84. package/dist/commands/lint/checks/FE/007.d.ts +6 -0
  85. package/dist/commands/lint/checks/FE/007.js +60 -0
  86. package/dist/commands/lint/checks/FE/007.js.map +1 -0
  87. package/dist/commands/lint/checks/FE/008.d.ts +6 -0
  88. package/dist/commands/lint/checks/FE/008.js +115 -0
  89. package/dist/commands/lint/checks/FE/008.js.map +1 -0
  90. package/dist/commands/lint/checks/FE/009.d.ts +6 -0
  91. package/dist/commands/lint/checks/FE/009.js +83 -0
  92. package/dist/commands/lint/checks/FE/009.js.map +1 -0
  93. package/dist/commands/lint/checks/FE/010.d.ts +6 -0
  94. package/dist/commands/lint/checks/FE/010.js +105 -0
  95. package/dist/commands/lint/checks/FE/010.js.map +1 -0
  96. package/dist/commands/lint/checks/FE/011.d.ts +6 -0
  97. package/dist/commands/lint/checks/FE/011.js +43 -0
  98. package/dist/commands/lint/checks/FE/011.js.map +1 -0
  99. package/dist/commands/lint/checks/FE/012.d.ts +6 -0
  100. package/dist/commands/lint/checks/FE/012.js +150 -0
  101. package/dist/commands/lint/checks/FE/012.js.map +1 -0
  102. package/dist/index.d.ts +5 -0
  103. package/dist/index.js +3436 -0
  104. package/dist/index.js.map +1 -0
  105. package/dude.stack.json +13 -0
  106. package/package.json +43 -0
  107. package/templates/aws-ecs/backend/Dockerfile.prod +34 -0
  108. package/templates/aws-ecs/docs/docs/deploy.md.hbs +54 -0
  109. package/templates/aws-ecs/frontend/Dockerfile.prod +28 -0
  110. package/templates/aws-ecs/frontend/nginx.conf +21 -0
  111. package/templates/aws-ecs/iac/README.md.hbs +75 -0
  112. package/templates/aws-ecs/iac/_gitignore +14 -0
  113. package/templates/aws-ecs/iac/runner/Dockerfile +35 -0
  114. package/templates/aws-ecs/iac/terraform/bootstrap/main.tf.hbs +102 -0
  115. package/templates/aws-ecs/iac/terraform/bootstrap/outputs.tf +19 -0
  116. package/templates/aws-ecs/iac/terraform/bootstrap/variables.tf.hbs +17 -0
  117. package/templates/aws-ecs/iac/terraform/environments/dev/backend.hcl.hbs +12 -0
  118. package/templates/aws-ecs/iac/terraform/environments/dev/terraform.tfvars.hbs +43 -0
  119. package/templates/aws-ecs/iac/terraform/main.tf.hbs +949 -0
  120. package/templates/aws-ecs/iac/terraform/outputs.tf.hbs +71 -0
  121. package/templates/aws-ecs/iac/terraform/providers.tf +19 -0
  122. package/templates/aws-ecs/iac/terraform/variables.tf.hbs +113 -0
  123. package/templates/aws-ecs/iac/terraform/versions.tf +19 -0
  124. package/templates/base/.claude/agents/issue-fixer.md +190 -0
  125. package/templates/base/.claude/agents/security-fixer.md +250 -0
  126. package/templates/base/.claude/rules/BE/001.md +19 -0
  127. package/templates/base/.claude/rules/BE/002.md +21 -0
  128. package/templates/base/.claude/rules/BE/003.md +19 -0
  129. package/templates/base/.claude/rules/BE/004.md +16 -0
  130. package/templates/base/.claude/rules/BE/005.md +23 -0
  131. package/templates/base/.claude/rules/BE/006.md +13 -0
  132. package/templates/base/.claude/rules/BE/007.md +24 -0
  133. package/templates/base/.claude/rules/BE/008.md +19 -0
  134. package/templates/base/.claude/rules/BE/009.md +18 -0
  135. package/templates/base/.claude/rules/BE/010.md +15 -0
  136. package/templates/base/.claude/rules/BE/011.md +17 -0
  137. package/templates/base/.claude/rules/BE/012.md +18 -0
  138. package/templates/base/.claude/rules/BE/013.md +22 -0
  139. package/templates/base/.claude/rules/BE/014.md +15 -0
  140. package/templates/base/.claude/rules/E2E/001.md +13 -0
  141. package/templates/base/.claude/rules/E2E/002.md +14 -0
  142. package/templates/base/.claude/rules/E2E/003.md +10 -0
  143. package/templates/base/.claude/rules/E2E/004.md +23 -0
  144. package/templates/base/.claude/rules/E2E/005.md +15 -0
  145. package/templates/base/.claude/rules/E2E/006.md +13 -0
  146. package/templates/base/.claude/rules/E2E/007.md +18 -0
  147. package/templates/base/.claude/rules/FE/001.md +22 -0
  148. package/templates/base/.claude/rules/FE/002.md +39 -0
  149. package/templates/base/.claude/rules/FE/003.md +19 -0
  150. package/templates/base/.claude/rules/FE/004.md +21 -0
  151. package/templates/base/.claude/rules/FE/005.md +33 -0
  152. package/templates/base/.claude/rules/FE/006.md +24 -0
  153. package/templates/base/.claude/rules/FE/007.md +19 -0
  154. package/templates/base/.claude/rules/FE/008.md +26 -0
  155. package/templates/base/.claude/rules/FE/009.md +30 -0
  156. package/templates/base/.claude/rules/FE/010.md +25 -0
  157. package/templates/base/.claude/rules/FE/011.md +22 -0
  158. package/templates/base/.claude/rules/FE/012.md +32 -0
  159. package/templates/base/.claude/settings.json +53 -0
  160. package/templates/base/.claude/skills/clean-branches/SKILL.md +100 -0
  161. package/templates/base/.claude/skills/create/SKILL.md +47 -0
  162. package/templates/base/.claude/skills/create-jira-issue/SKILL.md +174 -0
  163. package/templates/base/.claude/skills/create-page/SKILL.md +195 -0
  164. package/templates/base/.claude/skills/create-route/SKILL.md +156 -0
  165. package/templates/base/.claude/skills/draft-email/SKILL.md +104 -0
  166. package/templates/base/.claude/skills/fix-issues/SKILL.md +238 -0
  167. package/templates/base/.claude/skills/security-scan/SKILL.md +297 -0
  168. package/templates/base/.claude/skills/verify-security-fixes/SKILL.md +180 -0
  169. package/templates/base/.dude/commands/README.md +85 -0
  170. package/templates/base/.dude/commands/hello.ts +34 -0
  171. package/templates/base/.dude/lint/checks/PRJ/001.ts +26 -0
  172. package/templates/base/.dude/lint/checks/README.md +69 -0
  173. package/templates/base/.vscode/tasks.json +44 -0
  174. package/templates/base/.worktreeinclude +2 -0
  175. package/templates/base/CLAUDE.md.hbs +391 -0
  176. package/templates/base/README.md.hbs +188 -0
  177. package/templates/base/_env.example.hbs +39 -0
  178. package/templates/base/_env.hbs +35 -0
  179. package/templates/base/_gitignore +31 -0
  180. package/templates/base/_npmrc +2 -0
  181. package/templates/base/backend/Dockerfile +16 -0
  182. package/templates/base/backend/README.md.hbs +90 -0
  183. package/templates/base/backend/_dockerignore +12 -0
  184. package/templates/base/backend/apps/__init__.py +0 -0
  185. package/templates/base/backend/apps/core/__init__.py +0 -0
  186. package/templates/base/backend/apps/core/apps.py +6 -0
  187. package/templates/base/backend/apps/core/serializers.py +7 -0
  188. package/templates/base/backend/apps/core/tests/__init__.py +0 -0
  189. package/templates/base/backend/apps/core/tests/test_views.py +16 -0
  190. package/templates/base/backend/apps/core/urls.py +9 -0
  191. package/templates/base/backend/apps/core/views.py +24 -0
  192. package/templates/base/backend/apps/users/__init__.py +0 -0
  193. package/templates/base/backend/apps/users/admin.py +6 -0
  194. package/templates/base/backend/apps/users/apps.py +6 -0
  195. package/templates/base/backend/apps/users/migrations/0001_initial.py +41 -0
  196. package/templates/base/backend/apps/users/migrations/__init__.py +0 -0
  197. package/templates/base/backend/apps/users/models.py +15 -0
  198. package/templates/base/backend/apps/users/serializers.py +16 -0
  199. package/templates/base/backend/apps/users/services.py +25 -0
  200. package/templates/base/backend/apps/users/tests/__init__.py +0 -0
  201. package/templates/base/backend/apps/users/tests/test_models.py +30 -0
  202. package/templates/base/backend/apps/users/tests/test_views.py +55 -0
  203. package/templates/base/backend/apps/users/urls.py +10 -0
  204. package/templates/base/backend/apps/users/views.py +20 -0
  205. package/templates/base/backend/config/__init__.py.hbs +5 -0
  206. package/templates/base/backend/config/asgi.py +9 -0
  207. package/templates/base/backend/config/settings/__init__.py +0 -0
  208. package/templates/base/backend/config/settings/base.py.hbs +197 -0
  209. package/templates/base/backend/config/settings/local.py +31 -0
  210. package/templates/base/backend/config/settings/production.py.hbs +37 -0
  211. package/templates/base/backend/config/urls.py.hbs +22 -0
  212. package/templates/base/backend/config/wsgi.py +9 -0
  213. package/templates/base/backend/manage.py +23 -0
  214. package/templates/base/backend/pyproject.toml.hbs +48 -0
  215. package/templates/base/backend/start.sh +5 -0
  216. package/templates/base/docker-compose.yml.hbs +196 -0
  217. package/templates/base/docs/docs/api.md +21 -0
  218. package/templates/base/docs/docs/dude.md.hbs +305 -0
  219. package/templates/base/docs/docs/index.md.hbs +92 -0
  220. package/templates/base/docs/docs/mkdocs.md +231 -0
  221. package/templates/base/docs/mkdocs.yml.hbs +52 -0
  222. package/templates/base/e2e/.prettierrc.json +1 -0
  223. package/templates/base/e2e/_prettierignore +3 -0
  224. package/templates/base/e2e/cucumber.js +21 -0
  225. package/templates/base/e2e/eslint.config.mjs +14 -0
  226. package/templates/base/e2e/features/example.feature +13 -0
  227. package/templates/base/e2e/package.json.hbs +30 -0
  228. package/templates/base/e2e/pages/ExamplePage.ts +16 -0
  229. package/templates/base/e2e/playwright.config.ts +27 -0
  230. package/templates/base/e2e/steps/common.steps.ts +32 -0
  231. package/templates/base/e2e/steps/example.steps.ts +4 -0
  232. package/templates/base/e2e/support/hooks.ts +72 -0
  233. package/templates/base/e2e/support/world.ts +24 -0
  234. package/templates/base/e2e/tsconfig.json +22 -0
  235. package/templates/base/frontend/.prettierrc.json +6 -0
  236. package/templates/base/frontend/Dockerfile +10 -0
  237. package/templates/base/frontend/_dockerignore +4 -0
  238. package/templates/base/frontend/eslint.config.js +32 -0
  239. package/templates/base/frontend/index.html.hbs +13 -0
  240. package/templates/base/frontend/package.json.hbs +38 -0
  241. package/templates/base/frontend/public/favicon.svg +5 -0
  242. package/templates/base/frontend/src/$components/Layout/$assets/logo.svg +5 -0
  243. package/templates/base/frontend/src/$components/Layout/constants.tsx +8 -0
  244. package/templates/base/frontend/src/$components/Layout/index.tsx +80 -0
  245. package/templates/base/frontend/src/$components/Layout/types.tsx +9 -0
  246. package/templates/base/frontend/src/$components/index.tsx +1 -0
  247. package/templates/base/frontend/src/$hooks/index.tsx +2 -0
  248. package/templates/base/frontend/src/$hooks/useCounterStore/index.tsx +28 -0
  249. package/templates/base/frontend/src/$hooks/useCounterStore/types.tsx +7 -0
  250. package/templates/base/frontend/src/$hooks/usePageTitle/index.tsx +21 -0
  251. package/templates/base/frontend/src/$types/vite-env.d.ts +10 -0
  252. package/templates/base/frontend/src/App.tsx +36 -0
  253. package/templates/base/frontend/src/main.tsx +10 -0
  254. package/templates/base/frontend/src/openapi/utils/openapi.yaml.hbs +129 -0
  255. package/templates/base/frontend/src/pages/constants.tsx +31 -0
  256. package/templates/base/frontend/src/pages/index.tsx +192 -0
  257. package/templates/base/frontend/src/pages/types.tsx +6 -0
  258. package/templates/base/frontend/src/pages/users/[id]/index.tsx +53 -0
  259. package/templates/base/frontend/src/pages/users/index.tsx +57 -0
  260. package/templates/base/frontend/src/pages/users/types.tsx +4 -0
  261. package/templates/base/frontend/src/styles.module.css +7 -0
  262. package/templates/base/frontend/src/utils/constants.tsx +11 -0
  263. package/templates/base/frontend/src/utils/formatters/index.tsx +49 -0
  264. package/templates/base/frontend/src/utils/functions.tsx +70 -0
  265. package/templates/base/frontend/src/utils/index.tsx +3 -0
  266. package/templates/base/frontend/tsconfig.json +24 -0
  267. package/templates/base/frontend/vite.config.ts +20 -0
  268. package/templates/base/package.json.hbs +11 -0
  269. package/templates/base/security/baseline.json +4 -0
  270. package/templates/celery/backend/apps/core/tasks.py +14 -0
  271. package/templates/celery/backend/apps/core/tests/test_tasks.py +6 -0
  272. package/templates/celery/backend/config/celery.py.hbs +26 -0
  273. package/templates/celerybeat/backend/apps/core/tasks_scheduled.py +18 -0
  274. package/templates/celerybeat/backend/apps/core/tests/test_tasks_scheduled.py +6 -0
  275. package/templates/postgres/.dude/commands/reset.ts +83 -0
  276. package/templates/s3/backend/apps/files/__init__.py +0 -0
  277. package/templates/s3/backend/apps/files/admin.py +9 -0
  278. package/templates/s3/backend/apps/files/apps.py +6 -0
  279. package/templates/s3/backend/apps/files/migrations/0001_initial.py +29 -0
  280. package/templates/s3/backend/apps/files/migrations/__init__.py +0 -0
  281. package/templates/s3/backend/apps/files/models.py +21 -0
  282. package/templates/s3/backend/apps/files/serializers.py +27 -0
  283. package/templates/s3/backend/apps/files/services.py +19 -0
  284. package/templates/s3/backend/apps/files/tests/__init__.py +0 -0
  285. package/templates/s3/backend/apps/files/tests/test_models.py +10 -0
  286. package/templates/s3/backend/apps/files/tests/test_views.py +32 -0
  287. package/templates/s3/backend/apps/files/urls.py +10 -0
  288. package/templates/s3/backend/apps/files/views.py +29 -0
  289. package/templates/s3/frontend/src/openapi/utils/openapi.yaml.hbs +253 -0
@@ -0,0 +1,4 @@
1
+ {
2
+ "generated_at": "1970-01-01T00:00:00.000Z",
3
+ "entries": {}
4
+ }
@@ -0,0 +1,14 @@
1
+ """Example Celery task — replace with real background work."""
2
+
3
+ import logging
4
+
5
+ from celery import shared_task
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+
10
+ @shared_task
11
+ def ping() -> str:
12
+ """Trivial round-trip task, useful to verify the worker is alive."""
13
+ logger.info("ping task executed")
14
+ return "pong"
@@ -0,0 +1,6 @@
1
+ from apps.core.tasks import ping
2
+
3
+
4
+ def test_ping_returns_pong():
5
+ # .apply() runs the task eagerly in-process — no broker required.
6
+ assert ping.apply().get() == "pong"
@@ -0,0 +1,26 @@
1
+ """Celery application for {{projectName}}.
2
+
3
+ Configuration is read from Django settings under the ``CELERY_`` namespace
4
+ (see ``config/settings/base.py``); tasks are auto-discovered from every
5
+ installed app's ``tasks*.py`` modules.
6
+ """
7
+
8
+ import os
9
+
10
+ from celery import Celery
11
+
12
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
13
+
14
+ app = Celery("config")
15
+ app.config_from_object("django.conf:settings", namespace="CELERY")
16
+ app.autodiscover_tasks()
17
+ {{#if withCeleryBeat}}
18
+
19
+ # Periodic tasks — executed by the `celery_beat` compose service.
20
+ app.conf.beat_schedule = {
21
+ "heartbeat-every-minute": {
22
+ "task": "apps.core.tasks_scheduled.heartbeat",
23
+ "schedule": 60.0,
24
+ },
25
+ }
26
+ {{/if}}
@@ -0,0 +1,18 @@
1
+ """Periodic tasks driven by Celery Beat.
2
+
3
+ The schedule lives in ``config/celery.py`` (``app.conf.beat_schedule``); the
4
+ `celery_beat` compose service dispatches these to the worker.
5
+ """
6
+
7
+ import logging
8
+
9
+ from celery import shared_task
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+
14
+ @shared_task
15
+ def heartbeat() -> str:
16
+ """Log a liveness heartbeat — replace with real scheduled work."""
17
+ logger.info("beat heartbeat")
18
+ return "alive"
@@ -0,0 +1,6 @@
1
+ from apps.core.tasks_scheduled import heartbeat
2
+
3
+
4
+ def test_heartbeat_runs_eagerly():
5
+ # .apply() runs the task eagerly in-process — no broker required.
6
+ assert heartbeat.apply().get() == "alive"
@@ -0,0 +1,83 @@
1
+ import { defineCommand } from '@cubocicloide/dude'
2
+ import { spawnSync } from 'node:child_process'
3
+
4
+ function exec(cmd: string, args: string[], cwd: string): void {
5
+ const result = spawnSync(cmd, args, { cwd, stdio: 'inherit' })
6
+ if (result.status !== 0) process.exit(result.status ?? 1)
7
+ }
8
+
9
+ async function waitForBackend(url: string, retries = 30, intervalMs = 2000): Promise<void> {
10
+ for (let i = 0; i < retries; i++) {
11
+ try {
12
+ const res = await fetch(url)
13
+ if (res.ok) return
14
+ } catch {
15
+ // not ready yet
16
+ }
17
+ await new Promise((resolve) => setTimeout(resolve, intervalMs))
18
+ }
19
+ process.stderr.write(
20
+ `error: backend did not become healthy after ${(retries * intervalMs) / 1000}s\n`,
21
+ )
22
+ process.exit(1)
23
+ }
24
+
25
+ const SEED_SCRIPT = `
26
+ from django.contrib.auth import get_user_model
27
+
28
+ User = get_user_model()
29
+
30
+ users = [
31
+ {"username": "admin", "email": "admin@example.com"},
32
+ {"username": "alice", "email": "alice@example.com"},
33
+ {"username": "bob", "email": "bob@example.com"},
34
+ ]
35
+
36
+ added = 0
37
+ for u in users:
38
+ _, created = User.objects.get_or_create(username=u["username"], defaults={"email": u["email"]})
39
+ added += int(created)
40
+ print(f"Seeded {added} user(s).")
41
+ `
42
+
43
+ export default defineCommand({
44
+ description: 'Drop the database, re-apply all migrations, and seed demo data.',
45
+ async run({ projectRoot }) {
46
+ process.stdout.write('Dropping all containers and volumes...\n')
47
+ exec('docker', ['compose', 'down', '--volumes'], projectRoot)
48
+
49
+ process.stdout.write('Starting services...\n')
50
+ exec('docker', ['compose', 'up', '--detach'], projectRoot)
51
+
52
+ process.stdout.write('Waiting for backend to be ready...\n')
53
+ await waitForBackend('http://localhost:8000/api/health/')
54
+
55
+ // start.sh already migrates on boot; run it again explicitly so the
56
+ // command fails loudly if a migration is broken.
57
+ process.stdout.write('Running migrations...\n')
58
+ exec(
59
+ 'docker',
60
+ [
61
+ 'compose',
62
+ 'exec',
63
+ 'backend',
64
+ 'uv',
65
+ 'run',
66
+ 'python',
67
+ 'manage.py',
68
+ 'migrate',
69
+ '--noinput',
70
+ ],
71
+ projectRoot,
72
+ )
73
+
74
+ process.stdout.write('Seeding demo data...\n')
75
+ exec(
76
+ 'docker',
77
+ ['compose', 'exec', 'backend', 'uv', 'run', 'python', 'manage.py', 'shell', '-c', SEED_SCRIPT],
78
+ projectRoot,
79
+ )
80
+
81
+ process.stdout.write('Reset complete.\n')
82
+ },
83
+ })
File without changes
@@ -0,0 +1,9 @@
1
+ from django.contrib import admin
2
+
3
+ from apps.files.models import FileUpload
4
+
5
+
6
+ @admin.register(FileUpload)
7
+ class FileUploadAdmin(admin.ModelAdmin):
8
+ list_display = ("id", "original_name", "content_type", "size", "created_at")
9
+ readonly_fields = ("created_at",)
@@ -0,0 +1,6 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class FilesConfig(AppConfig):
5
+ default_auto_field = "django.db.models.BigAutoField"
6
+ name = "apps.files"
@@ -0,0 +1,29 @@
1
+ from django.db import migrations, models
2
+
3
+
4
+ class Migration(migrations.Migration):
5
+ initial = True
6
+
7
+ dependencies = []
8
+
9
+ operations = [
10
+ migrations.CreateModel(
11
+ name="FileUpload",
12
+ fields=[
13
+ (
14
+ "id",
15
+ models.BigAutoField(
16
+ auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
17
+ ),
18
+ ),
19
+ ("file", models.FileField(upload_to="uploads/%Y/%m/")),
20
+ ("original_name", models.CharField(blank=True, default="", max_length=255)),
21
+ ("content_type", models.CharField(blank=True, default="", max_length=127)),
22
+ ("size", models.PositiveBigIntegerField(default=0)),
23
+ ("created_at", models.DateTimeField(auto_now_add=True)),
24
+ ],
25
+ options={
26
+ "ordering": ("-created_at",),
27
+ },
28
+ ),
29
+ ]
@@ -0,0 +1,21 @@
1
+ from django.db import models
2
+
3
+
4
+ class FileUpload(models.Model):
5
+ """A file stored on the object-storage backend (S3 / MinIO locally).
6
+
7
+ The binary lives in the bucket; this row keeps the metadata and the
8
+ storage key. Downloads go through presigned URLs (``file.url``).
9
+ """
10
+
11
+ file = models.FileField(upload_to="uploads/%Y/%m/")
12
+ original_name = models.CharField(max_length=255, blank=True, default="")
13
+ content_type = models.CharField(max_length=127, blank=True, default="")
14
+ size = models.PositiveBigIntegerField(default=0)
15
+ created_at = models.DateTimeField(auto_now_add=True)
16
+
17
+ class Meta:
18
+ ordering = ("-created_at",)
19
+
20
+ def __str__(self) -> str:
21
+ return self.original_name or self.file.name
@@ -0,0 +1,27 @@
1
+ from rest_framework import serializers
2
+
3
+ from apps.files.models import FileUpload
4
+ from apps.files.services import create_file_upload
5
+
6
+
7
+ class FileUploadSerializer(serializers.ModelSerializer):
8
+ """Representation of a stored file.
9
+
10
+ ``file`` is write-only (the upload); clients read the presigned ``url``
11
+ instead. Fields are always listed explicitly (lint rule BE002).
12
+ """
13
+
14
+ file = serializers.FileField(write_only=True)
15
+ url = serializers.SerializerMethodField()
16
+
17
+ class Meta:
18
+ model = FileUpload
19
+ fields = ("id", "file", "url", "original_name", "content_type", "size", "created_at")
20
+ read_only_fields = ("id", "original_name", "content_type", "size", "created_at")
21
+
22
+ def get_url(self, obj: FileUpload) -> str:
23
+ # Presigned URL when the S3 backend is active (AWS_QUERYSTRING_AUTH).
24
+ return obj.file.url
25
+
26
+ def create(self, validated_data: dict) -> FileUpload:
27
+ return create_file_upload(uploaded=validated_data["file"])
@@ -0,0 +1,19 @@
1
+ """Write-side operations for the files app.
2
+
3
+ Views never touch the ORM for writes (lint rule BE005) — creation goes
4
+ through this module so upload bookkeeping lives in exactly one place.
5
+ """
6
+
7
+ from django.core.files.uploadedfile import UploadedFile
8
+
9
+ from apps.files.models import FileUpload
10
+
11
+
12
+ def create_file_upload(uploaded: UploadedFile) -> FileUpload:
13
+ """Persist an uploaded file, capturing its original metadata."""
14
+ return FileUpload.objects.create(
15
+ file=uploaded,
16
+ original_name=uploaded.name or "",
17
+ content_type=getattr(uploaded, "content_type", "") or "",
18
+ size=uploaded.size or 0,
19
+ )
@@ -0,0 +1,10 @@
1
+ from apps.files.models import FileUpload
2
+
3
+
4
+ def test_str_uses_original_name():
5
+ upload = FileUpload(original_name="report.pdf")
6
+ assert str(upload) == "report.pdf"
7
+
8
+
9
+ def test_ordering_is_newest_first():
10
+ assert FileUpload._meta.ordering == ("-created_at",)
@@ -0,0 +1,32 @@
1
+ import pytest
2
+ from django.core.files.uploadedfile import SimpleUploadedFile
3
+ from rest_framework.test import APIClient
4
+
5
+
6
+ @pytest.fixture(autouse=True)
7
+ def in_memory_storage(settings):
8
+ # Tests never talk to MinIO/S3 — swap the default backend for an
9
+ # in-memory one so uploads stay inside the test process.
10
+ settings.STORAGES = {
11
+ **settings.STORAGES,
12
+ "default": {"BACKEND": "django.core.files.storage.InMemoryStorage"},
13
+ }
14
+
15
+
16
+ @pytest.mark.django_db
17
+ def test_upload_list_retrieve():
18
+ client = APIClient()
19
+ payload = SimpleUploadedFile("hello.txt", b"hi there", content_type="text/plain")
20
+
21
+ created = client.post("/api/files/", {"file": payload}, format="multipart")
22
+ assert created.status_code == 201
23
+ assert created.data["original_name"] == "hello.txt"
24
+ assert created.data["size"] == 8
25
+
26
+ listed = client.get("/api/files/")
27
+ assert listed.status_code == 200
28
+ assert listed.data["count"] == 1
29
+
30
+ detail = client.get(f"/api/files/{created.data['id']}/")
31
+ assert detail.status_code == 200
32
+ assert detail.data["url"]
@@ -0,0 +1,10 @@
1
+ from rest_framework.routers import DefaultRouter
2
+
3
+ from apps.files.views import FileUploadViewSet
4
+
5
+ app_name = "files"
6
+
7
+ router = DefaultRouter()
8
+ router.register("files", FileUploadViewSet, basename="files")
9
+
10
+ urlpatterns = router.urls
@@ -0,0 +1,29 @@
1
+ from drf_spectacular.utils import extend_schema
2
+ from rest_framework.mixins import CreateModelMixin, ListModelMixin, RetrieveModelMixin
3
+ from rest_framework.parsers import MultiPartParser
4
+ from rest_framework.permissions import AllowAny
5
+ from rest_framework.viewsets import GenericViewSet
6
+
7
+ from apps.files.models import FileUpload
8
+ from apps.files.serializers import FileUploadSerializer
9
+
10
+
11
+ @extend_schema(tags=["files"])
12
+ class FileUploadViewSet(CreateModelMixin, ListModelMixin, RetrieveModelMixin, GenericViewSet):
13
+ """Upload (multipart), list and retrieve stored files.
14
+
15
+ Writes go through ``apps.files.services`` via the serializer (lint rule
16
+ BE005); downloads use presigned URLs generated by the storage backend.
17
+ """
18
+
19
+ queryset = FileUpload.objects.all()
20
+ serializer_class = FileUploadSerializer
21
+ parser_classes = [MultiPartParser]
22
+ # Demo endpoint: AllowAny so the scaffold works out of the box. Tighten to
23
+ # IsAuthenticated before exposing real data — but keep the declaration
24
+ # explicit: every view must declare permission_classes (lint rule BE003).
25
+ permission_classes = [AllowAny]
26
+
27
+ @extend_schema(operation_id="files_create", description="Upload a file (multipart/form-data).")
28
+ def create(self, request, *args, **kwargs):
29
+ return super().create(request, *args, **kwargs)
@@ -0,0 +1,253 @@
1
+ openapi: 3.0.3
2
+ info:
3
+ title: {{projectName}} API
4
+ version: 1.0.0
5
+ paths:
6
+ /api/health/:
7
+ get:
8
+ operationId: health_retrieve
9
+ description: Health-check endpoint.
10
+ tags:
11
+ - health
12
+ security:
13
+ - {}
14
+ responses:
15
+ "200":
16
+ content:
17
+ application/json:
18
+ schema:
19
+ $ref: "#/components/schemas/Health"
20
+ description: ""
21
+ /api/users/:
22
+ get:
23
+ operationId: users_list
24
+ description: List (paginated) and retrieve users.
25
+ parameters:
26
+ - name: page
27
+ required: false
28
+ in: query
29
+ description: A page number within the paginated result set.
30
+ schema:
31
+ type: integer
32
+ tags:
33
+ - users
34
+ security:
35
+ - {}
36
+ responses:
37
+ "200":
38
+ content:
39
+ application/json:
40
+ schema:
41
+ $ref: "#/components/schemas/PaginatedUserList"
42
+ description: ""
43
+ /api/users/{id}/:
44
+ get:
45
+ operationId: users_retrieve
46
+ description: List (paginated) and retrieve users.
47
+ parameters:
48
+ - name: id
49
+ in: path
50
+ required: true
51
+ description: A unique integer value identifying this user.
52
+ schema:
53
+ type: integer
54
+ tags:
55
+ - users
56
+ security:
57
+ - {}
58
+ responses:
59
+ "200":
60
+ content:
61
+ application/json:
62
+ schema:
63
+ $ref: "#/components/schemas/User"
64
+ description: ""
65
+ /api/files/:
66
+ get:
67
+ operationId: files_list
68
+ description: Upload (multipart), list and retrieve stored files.
69
+ parameters:
70
+ - name: page
71
+ required: false
72
+ in: query
73
+ description: A page number within the paginated result set.
74
+ schema:
75
+ type: integer
76
+ tags:
77
+ - files
78
+ security:
79
+ - {}
80
+ responses:
81
+ "200":
82
+ content:
83
+ application/json:
84
+ schema:
85
+ $ref: "#/components/schemas/PaginatedFileUploadList"
86
+ description: ""
87
+ post:
88
+ operationId: files_create
89
+ description: Upload a file (multipart/form-data).
90
+ tags:
91
+ - files
92
+ requestBody:
93
+ content:
94
+ multipart/form-data:
95
+ schema:
96
+ $ref: "#/components/schemas/FileUploadRequest"
97
+ required: true
98
+ security:
99
+ - {}
100
+ responses:
101
+ "201":
102
+ content:
103
+ application/json:
104
+ schema:
105
+ $ref: "#/components/schemas/FileUpload"
106
+ description: ""
107
+ /api/files/{id}/:
108
+ get:
109
+ operationId: files_retrieve
110
+ description: Upload (multipart), list and retrieve stored files.
111
+ parameters:
112
+ - name: id
113
+ in: path
114
+ required: true
115
+ description: A unique integer value identifying this file upload.
116
+ schema:
117
+ type: integer
118
+ tags:
119
+ - files
120
+ security:
121
+ - {}
122
+ responses:
123
+ "200":
124
+ content:
125
+ application/json:
126
+ schema:
127
+ $ref: "#/components/schemas/FileUpload"
128
+ description: ""
129
+ components:
130
+ schemas:
131
+ Health:
132
+ type: object
133
+ description: Response payload of the health-check endpoint.
134
+ properties:
135
+ status:
136
+ type: string
137
+ required:
138
+ - status
139
+ PaginatedUserList:
140
+ type: object
141
+ properties:
142
+ count:
143
+ type: integer
144
+ example: 123
145
+ next:
146
+ type: string
147
+ nullable: true
148
+ format: uri
149
+ example: http://api.example.org/accounts/?page=4
150
+ previous:
151
+ type: string
152
+ nullable: true
153
+ format: uri
154
+ example: http://api.example.org/accounts/?page=2
155
+ results:
156
+ type: array
157
+ items:
158
+ $ref: "#/components/schemas/User"
159
+ required:
160
+ - count
161
+ - results
162
+ User:
163
+ type: object
164
+ description: Public representation of a user.
165
+ properties:
166
+ id:
167
+ type: integer
168
+ readOnly: true
169
+ username:
170
+ type: string
171
+ description: Required. 150 characters or fewer. Letters, digits and @/./+/-/_
172
+ only.
173
+ pattern: ^[\w.@+-]+$
174
+ maxLength: 150
175
+ email:
176
+ type: string
177
+ format: email
178
+ title: Email address
179
+ maxLength: 254
180
+ first_name:
181
+ type: string
182
+ maxLength: 150
183
+ last_name:
184
+ type: string
185
+ maxLength: 150
186
+ date_joined:
187
+ type: string
188
+ format: date-time
189
+ readOnly: true
190
+ required:
191
+ - date_joined
192
+ - id
193
+ - username
194
+ PaginatedFileUploadList:
195
+ type: object
196
+ properties:
197
+ count:
198
+ type: integer
199
+ example: 123
200
+ next:
201
+ type: string
202
+ nullable: true
203
+ format: uri
204
+ example: http://api.example.org/accounts/?page=4
205
+ previous:
206
+ type: string
207
+ nullable: true
208
+ format: uri
209
+ example: http://api.example.org/accounts/?page=2
210
+ results:
211
+ type: array
212
+ items:
213
+ $ref: "#/components/schemas/FileUpload"
214
+ required:
215
+ - count
216
+ - results
217
+ FileUpload:
218
+ type: object
219
+ description: Representation of a stored file.
220
+ properties:
221
+ id:
222
+ type: integer
223
+ readOnly: true
224
+ url:
225
+ type: string
226
+ readOnly: true
227
+ description: Presigned download URL generated by the storage backend.
228
+ original_name:
229
+ type: string
230
+ readOnly: true
231
+ content_type:
232
+ type: string
233
+ readOnly: true
234
+ size:
235
+ type: integer
236
+ readOnly: true
237
+ created_at:
238
+ type: string
239
+ format: date-time
240
+ readOnly: true
241
+ required:
242
+ - created_at
243
+ - id
244
+ - url
245
+ FileUploadRequest:
246
+ type: object
247
+ description: Multipart upload payload.
248
+ properties:
249
+ file:
250
+ type: string
251
+ format: binary
252
+ required:
253
+ - file