create-tigra 3.2.0 → 4.0.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.
Files changed (209) hide show
  1. package/README.md +81 -12
  2. package/bin/create-tigra.js +495 -472
  3. package/lib/patchers/email-verification.patcher.js +160 -44
  4. package/modules/email-verification/client/hooks/useVerification.ts +4 -1
  5. package/modules/email-verification/server/__tests__/verification.integration.test.ts +115 -0
  6. package/modules/email-verification/server/verification.controller.ts +3 -1
  7. package/modules/email-verification/server/verification.service.ts +81 -21
  8. package/package.json +3 -2
  9. package/template/.github/dependabot.yml +47 -0
  10. package/template/.github/workflows/audit.yml +36 -0
  11. package/template/.github/workflows/ci.yml +79 -0
  12. package/template/AGENTS.md +18 -9
  13. package/template/client/.dockerignore +1 -0
  14. package/template/client/.env.example.production +13 -2
  15. package/template/client/AGENTS.md +13 -5
  16. package/template/client/Dockerfile +186 -14
  17. package/template/client/next.config.ts +1 -1
  18. package/template/client/package-lock.json +15983 -14181
  19. package/template/client/package.json +56 -48
  20. package/template/client/scripts/check-sharp.mjs +53 -0
  21. package/template/client/scripts/next-dev.cjs +5 -1
  22. package/template/client/src/__tests__/proxy.test.ts +92 -0
  23. package/template/client/src/app/healthz/route.ts +16 -0
  24. package/template/client/src/app/layout.tsx +9 -3
  25. package/template/client/src/app/page.tsx +2 -2
  26. package/template/client/src/app/providers.tsx +23 -4
  27. package/template/client/src/components/layout/Header.tsx +7 -3
  28. package/template/client/src/features/admin/hooks/useAdminSessions.ts +2 -1
  29. package/template/client/src/features/admin/hooks/useAdminUsers.ts +3 -1
  30. package/template/client/src/features/admin/types/admin.types.ts +2 -3
  31. package/template/client/src/features/auth/components/AuthInitializer.tsx +38 -19
  32. package/template/client/src/features/auth/components/ForgotPasswordForm.tsx +107 -0
  33. package/template/client/src/features/auth/components/LimitNotice.tsx +28 -0
  34. package/template/client/src/features/auth/components/LoginForm.tsx +18 -4
  35. package/template/client/src/features/auth/components/RegisterForm.tsx +23 -7
  36. package/template/client/src/features/auth/hooks/useAuth.ts +27 -7
  37. package/template/client/src/features/auth/hooks/usePasswordReset.ts +7 -1
  38. package/template/client/src/features/auth/services/auth.service.ts +8 -3
  39. package/template/client/src/features/auth/store/authSlice.ts +7 -2
  40. package/template/client/src/features/auth/types/auth.types.ts +3 -0
  41. package/template/client/src/instrumentation-client.ts +9 -1
  42. package/template/client/src/instrumentation.ts +6 -0
  43. package/template/client/src/lib/api/__tests__/axios.config.test.ts +183 -0
  44. package/template/client/src/lib/api/api.types.ts +14 -0
  45. package/template/client/src/lib/api/axios.config.ts +101 -15
  46. package/template/client/src/lib/api/hard-redirect.ts +8 -0
  47. package/template/client/src/lib/api/session-events.ts +29 -0
  48. package/template/client/src/lib/constants/routes.ts +12 -0
  49. package/template/client/src/lib/observability/sentry-scrub.ts +71 -0
  50. package/template/client/src/lib/utils/__tests__/error.test.ts +119 -0
  51. package/template/client/src/lib/utils/__tests__/form.test.ts +42 -0
  52. package/template/client/src/lib/utils/__tests__/paths.test.ts +43 -0
  53. package/template/client/src/lib/utils/__tests__/security.test.ts +40 -0
  54. package/template/client/src/lib/utils/__tests__/session-marker.test.ts +27 -0
  55. package/template/client/src/lib/utils/error.ts +86 -1
  56. package/template/client/src/lib/utils/form.ts +31 -0
  57. package/template/client/src/lib/utils/paths.ts +18 -0
  58. package/template/client/src/lib/utils/security.ts +37 -0
  59. package/template/client/src/lib/utils/session-marker.ts +24 -0
  60. package/template/client/src/{middleware.ts → proxy.ts} +25 -11
  61. package/template/client/src/store/__tests__/store.test.ts +44 -0
  62. package/template/client/src/store/index.ts +26 -8
  63. package/template/client/vitest.config.mts +48 -0
  64. package/template/server/.env.example +280 -269
  65. package/template/server/.env.example.production +283 -236
  66. package/template/server/AGENTS.md +13 -4
  67. package/template/server/Dockerfile +181 -14
  68. package/template/server/docker-compose.yml +4 -2
  69. package/template/server/docs/deployment.md +63 -0
  70. package/template/server/docs/logging.md +52 -4
  71. package/template/server/docs/rate-limits.md +153 -0
  72. package/template/server/docs/testing.md +63 -0
  73. package/template/server/eslint.config.mjs +19 -0
  74. package/template/server/package-lock.json +8784 -8743
  75. package/template/server/package.json +79 -75
  76. package/template/server/prisma/migrations/0_init/migration.sql +82 -0
  77. package/template/server/prisma/migrations/migration_lock.toml +3 -0
  78. package/template/server/prisma/schema.prisma +19 -6
  79. package/template/server/prisma/seed.ts +13 -5
  80. package/template/server/scripts/check-heic.mjs +40 -0
  81. package/template/server/scripts/check-sharp.mjs +53 -0
  82. package/template/server/src/__tests__/routes.integration.test.ts +280 -0
  83. package/template/server/src/app.ts +248 -335
  84. package/template/server/src/config/__tests__/env.test.ts +219 -0
  85. package/template/server/src/config/__tests__/rate-limit.config.test.ts +158 -0
  86. package/template/server/src/config/env.ts +326 -171
  87. package/template/server/src/config/rate-limit.config.ts +157 -106
  88. package/template/server/src/jobs/__tests__/cleanup-deleted-accounts.job.test.ts +110 -0
  89. package/template/server/src/jobs/__tests__/cleanup-expired-auth.job.test.ts +44 -0
  90. package/template/server/src/jobs/__tests__/jobs.integration.test.ts +88 -0
  91. package/template/server/src/jobs/__tests__/schedule.test.ts +92 -0
  92. package/template/server/src/jobs/cleanup-deleted-accounts.job.ts +81 -65
  93. package/template/server/src/jobs/cleanup-expired-auth.job.ts +32 -24
  94. package/template/server/src/jobs/index.ts +12 -2
  95. package/template/server/src/jobs/refresh-cloudflare-ranges.job.ts +28 -0
  96. package/template/server/src/jobs/schedule.ts +50 -0
  97. package/template/server/src/libs/__tests__/auth.test.ts +168 -0
  98. package/template/server/src/libs/__tests__/client-ip.test.ts +257 -121
  99. package/template/server/src/libs/__tests__/cloudflare-ranges.test.ts +79 -0
  100. package/template/server/src/libs/__tests__/cookies.test.ts +113 -0
  101. package/template/server/src/libs/__tests__/email-quota.test.ts +81 -0
  102. package/template/server/src/libs/__tests__/email.test.ts +68 -0
  103. package/template/server/src/libs/__tests__/error-handler.test.ts +162 -0
  104. package/template/server/src/libs/__tests__/health-db-down.integration.test.ts +37 -0
  105. package/template/server/src/libs/__tests__/health-redis-down.integration.test.ts +45 -0
  106. package/template/server/src/libs/__tests__/health-routes.test.ts +83 -0
  107. package/template/server/src/libs/__tests__/health.integration.test.ts +118 -0
  108. package/template/server/src/libs/__tests__/http.test.ts +74 -2
  109. package/template/server/src/libs/__tests__/ip-block.test.ts +179 -62
  110. package/template/server/src/libs/__tests__/logger.test.ts +50 -0
  111. package/template/server/src/libs/__tests__/monitoring.test.ts +185 -0
  112. package/template/server/src/libs/__tests__/outbound.integration.test.ts +48 -0
  113. package/template/server/src/libs/__tests__/prisma-client.test.ts +28 -0
  114. package/template/server/src/libs/__tests__/query-counter.integration.test.ts +53 -0
  115. package/template/server/src/libs/__tests__/rate-limiting.test.ts +146 -0
  116. package/template/server/src/libs/__tests__/rate-limits.integration.test.ts +53 -0
  117. package/template/server/src/libs/__tests__/redis-required.test.ts +30 -0
  118. package/template/server/src/libs/__tests__/redis.test.ts +59 -0
  119. package/template/server/src/libs/__tests__/request-id.test.ts +25 -0
  120. package/template/server/src/libs/__tests__/requestLogger.test.ts +126 -0
  121. package/template/server/src/libs/__tests__/safe-http.test.ts +138 -0
  122. package/template/server/src/libs/__tests__/sentry-scrub.test.ts +82 -0
  123. package/template/server/src/libs/__tests__/shutdown.test.ts +89 -0
  124. package/template/server/src/libs/__tests__/url-safety.test.ts +130 -80
  125. package/template/server/src/libs/account-status.ts +52 -0
  126. package/template/server/src/libs/auth.ts +51 -12
  127. package/template/server/src/libs/client-ip.ts +158 -77
  128. package/template/server/src/libs/cloudflare-ranges.ts +132 -0
  129. package/template/server/src/libs/cookies.ts +91 -24
  130. package/template/server/src/libs/email-quota.ts +74 -0
  131. package/template/server/src/libs/email.ts +46 -9
  132. package/template/server/src/libs/error-handler.ts +111 -0
  133. package/template/server/src/libs/health-routes.ts +53 -0
  134. package/template/server/src/libs/http.ts +139 -47
  135. package/template/server/src/libs/ip-address.ts +37 -0
  136. package/template/server/src/libs/ip-block.ts +284 -220
  137. package/template/server/src/libs/logger.ts +41 -12
  138. package/template/server/src/libs/monitoring.ts +131 -42
  139. package/template/server/src/libs/observability/sentry.ts +80 -0
  140. package/template/server/src/libs/origin-check.ts +9 -7
  141. package/template/server/src/libs/prisma.ts +47 -4
  142. package/template/server/src/libs/query-counter.ts +71 -59
  143. package/template/server/src/libs/rate-limiting.ts +110 -0
  144. package/template/server/src/libs/redis-required.ts +28 -0
  145. package/template/server/src/libs/redis.ts +108 -18
  146. package/template/server/src/libs/request-id.ts +18 -0
  147. package/template/server/src/libs/requestLogger.ts +112 -17
  148. package/template/server/src/libs/safe-http.ts +101 -0
  149. package/template/server/src/libs/shutdown.ts +87 -0
  150. package/template/server/src/libs/storage/__tests__/fixtures/tiny-heic.ts +13 -0
  151. package/template/server/src/libs/storage/__tests__/image-optimizer.test.ts +143 -0
  152. package/template/server/src/libs/storage/__tests__/multipart-limits.test.ts +91 -0
  153. package/template/server/src/libs/storage/__tests__/upload-persistence.test.ts +52 -0
  154. package/template/server/src/libs/storage/file-storage.service.ts +104 -83
  155. package/template/server/src/libs/storage/file-validator.ts +48 -46
  156. package/template/server/src/libs/storage/image-optimizer.service.ts +78 -72
  157. package/template/server/src/libs/token-hash.ts +18 -0
  158. package/template/server/src/libs/url-safety.ts +127 -121
  159. package/template/server/src/libs/validation-errors.ts +86 -0
  160. package/template/server/src/modules/admin/__tests__/admin-actions.integration.test.ts +255 -0
  161. package/template/server/src/modules/admin/__tests__/admin.health.test.ts +82 -0
  162. package/template/server/src/modules/admin/__tests__/admin.repo.test.ts +55 -0
  163. package/template/server/src/modules/admin/__tests__/admin.schemas.test.ts +38 -0
  164. package/template/server/src/modules/admin/__tests__/admin.service.test.ts +162 -0
  165. package/template/server/src/modules/admin/admin.controller.ts +66 -49
  166. package/template/server/src/modules/admin/admin.repo.ts +56 -13
  167. package/template/server/src/modules/admin/admin.routes.ts +48 -2
  168. package/template/server/src/modules/admin/admin.schemas.ts +18 -6
  169. package/template/server/src/modules/admin/admin.service.ts +73 -7
  170. package/template/server/src/modules/auth/__tests__/auth.controller.test.ts +39 -0
  171. package/template/server/src/modules/auth/__tests__/auth.integration.test.ts +9 -3
  172. package/template/server/src/modules/auth/__tests__/auth.service.dummy-hash.test.ts +34 -0
  173. package/template/server/src/modules/auth/__tests__/auth.service.test.ts +332 -49
  174. package/template/server/src/modules/auth/__tests__/session-cleanup.test.ts +39 -0
  175. package/template/server/src/modules/auth/__tests__/sessions.integration.test.ts +246 -0
  176. package/template/server/src/modules/auth/__tests__/token-fingerprints.test.ts +119 -0
  177. package/template/server/src/modules/auth/auth.controller.ts +133 -128
  178. package/template/server/src/modules/auth/auth.repo.ts +60 -42
  179. package/template/server/src/modules/auth/auth.schemas.ts +5 -2
  180. package/template/server/src/modules/auth/auth.service.ts +197 -109
  181. package/template/server/src/modules/auth/session.repo.ts +12 -12
  182. package/template/server/src/modules/files/__tests__/files.integration.test.ts +5 -5
  183. package/template/server/src/modules/users/__tests__/avatar-upload.test.ts +120 -0
  184. package/template/server/src/modules/users/__tests__/name-rules.test.ts +46 -0
  185. package/template/server/src/modules/users/__tests__/users.integration.test.ts +295 -0
  186. package/template/server/src/modules/users/__tests__/users.repo.test.ts +37 -0
  187. package/template/server/src/modules/users/__tests__/users.service.test.ts +129 -0
  188. package/template/server/src/modules/users/users.controller.ts +9 -38
  189. package/template/server/src/modules/users/users.repo.ts +25 -7
  190. package/template/server/src/modules/users/users.routes.ts +3 -22
  191. package/template/server/src/modules/users/users.schemas.ts +15 -9
  192. package/template/server/src/modules/users/users.service.ts +105 -93
  193. package/template/server/src/scripts/make-admin.ts +48 -0
  194. package/template/server/src/server.ts +48 -26
  195. package/template/server/src/shared/errors/AppError.ts +27 -1
  196. package/template/server/src/shared/errors/errors.ts +42 -5
  197. package/template/server/src/shared/responses/successResponse.ts +22 -3
  198. package/template/server/src/shared/types/index.ts +7 -0
  199. package/template/server/src/test/__tests__/integration-services.test.ts +66 -0
  200. package/template/server/src/test/integration-helpers.ts +343 -0
  201. package/template/server/src/test/integration-services.ts +74 -0
  202. package/template/server/src/test/integration.global-setup.ts +144 -0
  203. package/template/server/src/test/integration.setup.ts +35 -158
  204. package/template/server/src/test/setup.ts +23 -8
  205. package/template/server/tsconfig.build.json +1 -1
  206. package/template/server/tsconfig.json +1 -0
  207. package/template/server/vitest.config.ts +17 -4
  208. package/template/server/vitest.integration.config.ts +18 -13
  209. package/template/server/src/libs/storage/filename-sanitizer.ts +0 -71
@@ -0,0 +1,47 @@
1
+ # Dependabot.
2
+ #
3
+ # npm packages and GitHub Actions: security updates only. A pull request when a
4
+ # dependency has a known vulnerability with a fix, and no routine version-bump
5
+ # pull requests (open-pull-requests-limit: 0 turns those off; security updates
6
+ # have their own limit). Turn them on once per repository: Settings → Advanced
7
+ # Security → "Dependabot security updates".
8
+ #
9
+ # Docker base images: monthly version updates (Dependabot has no security
10
+ # updates for Docker). Both Dockerfiles pin node:24-alpine by digest, and a
11
+ # digest pin never changes by itself: without this the images would never
12
+ # get Node or Alpine security fixes. Node major versions (24 -> 25) are left
13
+ # out on purpose: upgrade those deliberately. Both Dockerfiles must keep the
14
+ # same digest, so merge the server and client pull requests together.
15
+ version: 2
16
+ updates:
17
+ - package-ecosystem: npm
18
+ directory: /server
19
+ schedule:
20
+ interval: weekly
21
+ open-pull-requests-limit: 0
22
+ - package-ecosystem: npm
23
+ directory: /client
24
+ schedule:
25
+ interval: weekly
26
+ open-pull-requests-limit: 0
27
+ - package-ecosystem: github-actions
28
+ directory: /
29
+ schedule:
30
+ interval: weekly
31
+ open-pull-requests-limit: 0
32
+ - package-ecosystem: docker
33
+ directory: /server
34
+ schedule:
35
+ interval: monthly
36
+ open-pull-requests-limit: 2
37
+ ignore:
38
+ - dependency-name: node
39
+ update-types: ['version-update:semver-major']
40
+ - package-ecosystem: docker
41
+ directory: /client
42
+ schedule:
43
+ interval: monthly
44
+ open-pull-requests-limit: 2
45
+ ignore:
46
+ - dependency-name: node
47
+ update-types: ['version-update:semver-major']
@@ -0,0 +1,36 @@
1
+ name: Dependency audit
2
+
3
+ # Once a week: does anything production installs have a known CRITICAL
4
+ # advisory? Not part of CI, so it never blocks a merge; a red run is the
5
+ # signal to update. Critical, not high: some high advisories sit in tooling
6
+ # that only a major upgrade fixes (Prisma's config loader, until Prisma 7),
7
+ # and a check that is red from day one teaches everyone to ignore it. Fixable
8
+ # high advisories reach you as Dependabot security pull requests
9
+ # (.github/dependabot.yml).
10
+ on:
11
+ schedule:
12
+ - cron: '17 6 * * 1' # Mondays 06:17 UTC
13
+ workflow_dispatch:
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ audit:
20
+ name: npm audit (${{ matrix.app }}, production dependencies)
21
+ runs-on: ubuntu-latest
22
+ strategy:
23
+ fail-fast: false
24
+ matrix:
25
+ app: [server, client]
26
+ defaults:
27
+ run:
28
+ working-directory: ${{ matrix.app }}
29
+ steps:
30
+ - uses: actions/checkout@v4
31
+ - uses: actions/setup-node@v4
32
+ with:
33
+ node-version: 24
34
+ # Reads package-lock.json; nothing is installed.
35
+ - name: Audit
36
+ run: npm audit --omit=dev --audit-level=critical
@@ -0,0 +1,79 @@
1
+ name: CI
2
+
3
+ # Every push and pull request: typecheck, lint, tests and builds for both
4
+ # apps. Checks only — it never deploys. See server/docs/testing.md.
5
+ on:
6
+ push:
7
+ pull_request:
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ server:
14
+ name: server (typecheck · lint · unit tests + coverage · build)
15
+ runs-on: ubuntu-latest
16
+ defaults:
17
+ run:
18
+ working-directory: server
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: actions/setup-node@v4
22
+ with:
23
+ node-version: 24
24
+ - name: Install dependencies (exactly the lockfile)
25
+ run: npm ci --include=optional
26
+ - name: Generate Prisma client
27
+ run: npx prisma generate
28
+ - name: Typecheck
29
+ run: npm run typecheck
30
+ - name: Lint
31
+ run: npm run lint
32
+ # Unit tests with the coverage ratchet (vitest.config.ts): fails when
33
+ # coverage drops below the recorded numbers.
34
+ - name: Unit tests and coverage
35
+ run: npm run test:coverage
36
+ - name: Build
37
+ run: npm run build
38
+
39
+ server-integration:
40
+ name: server integration tests (real MySQL + Redis)
41
+ runs-on: ubuntu-latest
42
+ defaults:
43
+ run:
44
+ working-directory: server
45
+ steps:
46
+ - uses: actions/checkout@v4
47
+ - uses: actions/setup-node@v4
48
+ with:
49
+ node-version: 24
50
+ - name: Install dependencies (exactly the lockfile)
51
+ run: npm ci --include=optional
52
+ - name: Generate Prisma client
53
+ run: npx prisma generate
54
+ # Testcontainers starts a throwaway MySQL 8.4 and Redis 7 (GitHub's
55
+ # Ubuntu runners have Docker) and applies prisma/migrations.
56
+ - name: Integration tests
57
+ run: npm run test:integration
58
+
59
+ client:
60
+ name: client (typecheck · lint · unit tests + coverage · build)
61
+ runs-on: ubuntu-latest
62
+ defaults:
63
+ run:
64
+ working-directory: client
65
+ steps:
66
+ - uses: actions/checkout@v4
67
+ - uses: actions/setup-node@v4
68
+ with:
69
+ node-version: 24
70
+ - name: Install dependencies (exactly the lockfile)
71
+ run: npm ci --include=optional
72
+ - name: Typecheck
73
+ run: npm run typecheck
74
+ - name: Lint
75
+ run: npm run lint
76
+ - name: Unit tests and coverage
77
+ run: npm run test:coverage
78
+ - name: Build
79
+ run: npm run build
@@ -1,4 +1,6 @@
1
- # Tigra Codex instructions
1
+ # Agent instructions
2
+
3
+ **Read the scoped file first.** Before changing anything in `server/`, read `server/AGENTS.md`; before changing anything in `client/`, read `client/AGENTS.md`. Claude Code loads them by itself when it opens files there. Codex does not: it loads only the AGENTS.md files from the project root down to the folder it was started in, so started here it never sees them.
2
4
 
3
5
  ## MUST FOLLOW — comment important code
4
6
 
@@ -33,30 +35,37 @@ Every implementation change MUST include a human-readability pass. Add or update
33
35
 
34
36
  - Use functional kebab-case for project names and anything surfaced in CLIs, logs, queues, jobs, or worker/process names.
35
37
  - Use camelCase for TypeScript values/functions, PascalCase for components/types/classes, and UPPER_SNAKE_CASE for true constants.
36
- - Keep domain folders and route paths lowercase and functional; follow the scoped client/server naming rules below.
38
+ - Keep domain folders and route paths lowercase and functional; the file naming rules of each app are in `server/AGENTS.md` and `client/AGENTS.md`.
37
39
 
38
40
  ## Deployment boundaries
39
41
 
40
42
  - The Dockerfile in each app is its production contract. Re-check it when changing ports, entry points, build output, native dependencies, runtime files, health routes, or environment variables.
41
- - The client must retain Next.js `output: "standalone"`; every `NEXT_PUBLIC_*` value is public and must be available at Docker build time.
42
- - The server container applies `prisma migrate deploy` before startup and exposes unauthenticated `GET /api/v1/live` for orchestration.
43
+ - The client must retain Next.js `output: "standalone"`; every `NEXT_PUBLIC_*` value is public and must be available at Docker build time. The client build stops when `NEXT_PUBLIC_API_BASE_URL` is empty. Its health check is `GET /healthz` (`client/src/app/healthz/route.ts`), which must keep answering 200 without rendering a page.
44
+ - The server container applies `prisma migrate deploy` before startup and exposes unauthenticated `GET /api/v1/live` for orchestration. It refuses to start when the image has no migrations (the database would have no tables), so keep `server/prisma/migrations/` committed, starting with the shipped `0_init`, and never switch to `prisma db push` for production. In production it also refuses to start when Redis is not reachable within 10 s: rate limits, login lockout and IP blocks run on Redis.
45
+ - Every deploy applies the new migrations while the old version is still serving, so a migration must work with the code that is still running. Follow expand / deploy / contract (`server/docs/deployment.md`): never drop, rename, retype or make a column required in the same deploy as the code that stops using it.
46
+ - Both Dockerfiles build sharp against a pinned libvips so images run on CPUs without x86-64-v2. When upgrading sharp (or Next, which brings its own sharp), check the new sharp's `config.libvips` range; if `LIBVIPS_VERSION` no longer satisfies it, bump `LIBVIPS_VERSION` and `LIBVIPS_SHA256` in both Dockerfiles. The build fails with a clear message if they do not match.
47
+ - Write `package-lock.json` with npm 11.19 or newer (`npm -v`). The images run `npm ci` with npm 11.19.1, which rejects lockfiles from npm 10 and from early npm 11 (11.6.1 was seen failing).
43
48
  - `server/docker-compose.yml` is local-development infrastructure, not a production topology. Keep host ports loopback-bound and admin UIs opt-in through the `tools` profile.
44
49
 
45
50
  ## Non-obvious security rules
46
51
 
47
52
  - Never commit `.env` files, credentials, tokens, or production data. Never place a secret in `NEXT_PUBLIC_*` or client-side code.
48
53
  - Authentication uses server-issued httpOnly cookies. Do not copy tokens into localStorage, sessionStorage, Redux, logs, URLs, or response bodies.
49
- - Validate every external input at the server boundary with Zod, use Prisma parameterization, enforce authorization in server services/routes, and return user-safe errors.
54
+ - Validate every external input at the server boundary with Zod, use Prisma parameterization, enforce authorization in server services/routes, and return user-safe errors. Wrong input always answers 422 `VALIDATION_FAILED` with `error.fields` (field + message, never the submitted values); the client reads them with `getFieldErrors`.
50
55
  - Preserve origin/CORS checks for state-changing cookie-authenticated requests, rate limits on public/auth-sensitive endpoints, and the split between statically served public uploads and authenticated owner-scoped private files.
51
56
 
52
- ## Required server security workflow
57
+ ## Required security workflow
53
58
 
54
59
  - For every meaningful server implementation, bug fix, refactor, dependency update, or configuration change, use the repository-local `security-audit` skill in guidance mode while designing and reviewing the change. Treat authentication, authorization, validation, database access, outbound requests, uploads, cookies, CORS/origin handling, rate limits, environment configuration, and deployment behavior as security-sensitive surfaces.
55
- - Before completion, review the current working-tree patch with the agent's own security scan when available: in Codex use the Codex Security plugin's `codex-security:security-diff-scan` skill; in Claude Code run `/security-review`. Scope the review to the changed server behavior and the supporting code needed to establish impact; do not expand it into an unrelated repository audit.
56
- - If that scan is unavailable, perform an equivalent focused patch review with the bundled `security-audit` skill and explicitly report that the scan was unavailable. Do not skip the security gate silently.
60
+ - The same workflow applies to client changes in its security code: `client/src/proxy.ts` (security headers, CSP, route protection), the sign-in flow and its redirects (`client/src/features/auth/`), the shared API client (`client/src/lib/api/axios.config.ts`), and anything that renders HTML or untrusted URLs.
61
+ - Before completion, review the patch you are handing over: `git diff HEAD` plus every untracked file (`git status --porcelain`). In Codex, use the Codex Security plugin's `codex-security:security-diff-scan` skill when it is installed. In Claude Code, run the bundled `security-audit` skill in guidance mode on that diff. Claude Code's `/security-review` is not this check: it reviews only `git diff origin/HEAD...` (commits since the remote branch), so it never sees uncommitted work, and a project that was never pushed has no `origin/HEAD` at all. Scope the review to the changed behavior and the supporting code needed to establish impact; do not expand it into an unrelated repository audit.
62
+ - If Codex's scan is unavailable, perform the same focused patch review with the bundled `security-audit` skill and explicitly report that the scan was unavailable. Do not skip the security gate silently.
57
63
  - A full or deep repository audit remains explicit work: do not start one merely because ordinary server code changed. Fix confirmed in-scope findings, rerun affected checks, and disclose any unresolved or unverified security concern before claiming completion.
58
64
  - Documentation-only, comment-only, and formatting-only changes may skip the patch scan when they cannot affect runtime behavior, permissions, deployment, or security policy.
59
65
 
60
66
  ## Verification
61
67
 
62
- Run the smallest relevant lint, typecheck, test, and build commands in each affected app. Database and deployment changes also require migration/Docker compatibility checks.
68
+ - Server (`server/`): `npm run lint`, `npm run typecheck`, `npm test` (unit), `npm run test:coverage` (fails below the floor in `vitest.config.ts`; do not lower it to make a change pass), `npm run test:integration`, `npm run build`. Client (`client/`): `npm run lint`, `npm run typecheck`, `npm test` (unit), `npm run test:coverage` (same floor rule, `vitest.config.mts`), `npm run build`. Run the ones that cover what you changed.
69
+ - `npm run test:integration` needs a real MySQL and Redis: either `INTEGRATION_DATABASE_URL` (a database whose name ends in `_test`) and `INTEGRATION_REDIS_URL` (Redis database 1-15), or Docker for Testcontainers. If neither is available, say that the integration tests did not run instead of reporting the change as tested.
70
+ - Never run `npm run prisma:reset` (`prisma migrate reset`) or `prisma db push` against a database that was not created for the test: they delete or rewrite its data. The integration suite empties its own test database.
71
+ - Database and deployment changes also require migration/Docker compatibility checks.
@@ -39,6 +39,7 @@ coverage
39
39
  **/*.spec.ts
40
40
  **/*.spec.tsx
41
41
  vitest.config.ts
42
+ vitest.config.mts
42
43
  jest.config.ts
43
44
 
44
45
  # Documentation
@@ -1,5 +1,16 @@
1
- # Public API URL - points to the production server's base URL
1
+ # ===================================================================
2
+ # CLIENT APP (in Coolify: the client application only, not the server)
3
+ # ===================================================================
4
+ # Every NEXT_PUBLIC_* value is PUBLIC: Next.js bakes it into the JavaScript
5
+ # that every visitor downloads, at BUILD time. So, unlike the server's
6
+ # variables (which must never be available at build time), each of these
7
+ # needs "Available at Buildtime" ticked in Coolify (keep it available at
8
+ # runtime too). Never put a secret here. Changing one needs a redeploy, which
9
+ # rebuilds the image; a restart is not enough.
10
+
11
+ # The server's public API address, ending in /api/v1. Required: the image
12
+ # build stops when it is empty (client/Dockerfile).
2
13
  NEXT_PUBLIC_API_BASE_URL=https://api.yourdomain.com/api/v1
3
14
 
4
- # App name displayed in the UI
15
+ # App name shown in the UI. Optional (defaults to "My App").
5
16
  NEXT_PUBLIC_APP_NAME={{PROJECT_DISPLAY_NAME}}
@@ -1,4 +1,4 @@
1
- # Client Codex instructions
1
+ # Client agent instructions
2
2
 
3
3
  ## Architecture and naming
4
4
 
@@ -10,14 +10,22 @@
10
10
  ## Sources of truth
11
11
 
12
12
  - Server-rendered page data belongs in Server Components; client-fetched server data belongs in React Query; Redux is limited to the authenticated-user lifecycle; local and URL state stay local or in search params.
13
- - `src/lib/constants/routes.ts` and `api-endpoints.ts` own application and API paths.
13
+ - Redux has one store per visitor (`makeStore` in `src/store/index.ts`, created in `Providers`). Never import a store instance into a module: the API client reports a session that ended through `src/lib/api/session-events.ts`, and `AuthInitializer` clears the user.
14
+ - `src/lib/constants/routes.ts` and `api-endpoints.ts` own application and API paths. `PROTECTED_PATHS` and `AUTH_PATHS` there are the one list each that the proxy and `AuthInitializer` use, matched by whole path segments (`src/lib/utils/paths.ts`): add your protected areas there.
15
+ - The start-up "who am I" check runs only when the browser holds the server's `auth_session` marker (`src/lib/utils/session-marker.ts`), so anonymous visitors make no API calls.
14
16
  - `src/styles/themes/default.css` owns color values. Components use semantic Tailwind tokens; do not hardcode palette values or create competing theme variables.
15
17
  - If a `next/font` CSS variable is referenced by a token declared on `:root`, apply that font's generated variable class to `<html>`. Never attach it only to `<body>`, where it cannot resolve the root-scoped token.
16
- - `src/middleware.ts` is the single source of truth for security headers and nonce-based CSP. Do not add a second CSP in `next.config.ts`.
18
+ - `src/proxy.ts` (Next 16's name for middleware) is the single source of truth for security headers and nonce-based CSP. Do not add a second CSP in `next.config.ts`.
17
19
 
18
20
  ## Security and deployment
19
21
 
20
- - Treat client validation as UX only; the server must validate and authorize every request.
22
+ - Treat client validation as UX only; the server must validate and authorize every request. Forms put the server's 422 messages on their own fields with `applyFieldErrors` (`src/lib/utils/form.ts`); keep `RegisterForm`'s rules equal to the server's `registerSchema`.
21
23
  - Use the shared credentialed API client. Auth tokens remain in httpOnly cookies and must never enter browser storage or Redux.
22
24
  - Sanitize any intentionally rendered HTML and untrusted URLs. Never log passwords, tokens, credentials, or complete sensitive user objects.
23
- - Preserve `output: "standalone"`, the non-root container, and the root health check. Add every new public environment variable to the Docker builder as `ARG` + `ENV`; public variables are compiled into the bundle.
25
+ - Preserve `output: "standalone"`, the non-root container, and the `/healthz` health check (`src/app/healthz/route.ts`, used by the Dockerfile HEALTHCHECK; keep it answering 200 without rendering a page). Add every new public environment variable to the Docker builder as `ARG` + `ENV`; public variables are compiled into the bundle. The build stops when `NEXT_PUBLIC_API_BASE_URL` is empty (in Coolify it needs "Available at Buildtime").
26
+ - Changes to `src/proxy.ts`, the sign-in flow and its redirects (`src/features/auth/`), the shared API client (`src/lib/api/axios.config.ts`), or anything that renders HTML or untrusted URLs go through the root `AGENTS.md` security workflow.
27
+
28
+ ## Tests
29
+
30
+ - `npm test` (and `npm run test:coverage`, which CI runs and which fails below the floor in `vitest.config.mts`) runs the unit tests in `src/**/__tests__/`. Keep logic in functions under `src/lib/` and test it there; a test file that needs `document` or `window` starts with `// @vitest-environment jsdom`.
31
+ - The template ships no pages on purpose. Screens are proven by hand in a browser against a running server; the logic under them is what the unit tests cover.
@@ -8,11 +8,86 @@
8
8
  # across builds, so a lockfile/dep-change rebuild re-installs from cache
9
9
  # (measured ~2.8x: 49s->18s on a real create-tigra client) instead of
10
10
  # re-downloading every tarball. Requires the `# syntax` line above (BuildKit).
11
+ #
12
+ # Every stage uses the same pinned node:24-alpine image (Node 24.22.0,
13
+ # npm 11.19.1, Alpine 3.24). Node 24 is the template's runtime (package.json
14
+ # engines >=24). `npm ci` below fails when package-lock.json was written by an
15
+ # older npm: npm 10 always, and early npm 11 too (11.6.1 leaves out the
16
+ # @emnapi/* entries this npm requires). Write lockfiles with npm 11.19 or newer.
17
+ #
18
+ # next/image optimizes images at runtime with sharp (GET /_next/image), so the
19
+ # client needs the same CPU-safe sharp as the server: stages 1-2 below.
11
20
 
12
21
  # ===================================================================
13
- # Stage 1: Dependencies (cached layer)
22
+ # Stage 1: libvips that runs on any x86-64 CPU
14
23
  # ===================================================================
15
- FROM node:20-alpine@sha256:fb4cd12c85ee03686f6af5362a0b0d56d50c58a04632e6c0fb8363f609372293 AS dependencies
24
+ # Why this stage exists: sharp's prebuilt addon and the libvips it bundles
25
+ # need an x86-64-v2 CPU (SSE4.2/POPCNT). Many VPS hosts present an older
26
+ # virtual CPU (e.g. "QEMU Virtual CPU"), where the prebuilt sharp refuses to
27
+ # load and the server crashes at start. So we compile a pinned libvips release
28
+ # for the generic x86-64 baseline and build sharp's addon against it (stage 2).
29
+ #
30
+ # KEEP THIS STAGE BYTE-IDENTICAL in server/Dockerfile and client/Dockerfile,
31
+ # so one rule set builds both images. Identical text also lets a plain
32
+ # `docker build` host reuse the compiled layer across the two apps. On
33
+ # Coolify (measured): redeploys of the same app on the same server reused it,
34
+ # but the two apps did not share it, and a change to a build-time variable
35
+ # compiled it again (Coolify passes those into the build). An uncached
36
+ # compile takes about 6-7 min on a small shared VPS.
37
+ #
38
+ # Version coupling: every sharp release needs a minimum libvips (the
39
+ # "config.libvips" range in sharp's package.json, e.g. ">=8.18.7" for sharp
40
+ # 0.35.5). When a sharp upgrade needs more than LIBVIPS_VERSION, bump
41
+ # LIBVIPS_VERSION and LIBVIPS_SHA256 (from the libvips release page) in BOTH
42
+ # Dockerfiles. Stage 2 stops the build with a clear message if you forget.
43
+ FROM node:24-alpine@sha256:44fce696f38ba8c987c4db89954051000bbd05ffd8d8659ba15ed4a8602e937f AS libvips
44
+
45
+ ARG LIBVIPS_VERSION=8.18.7
46
+ ARG LIBVIPS_SHA256=5baaead3b0bb20ffdb9e9ff09aa9fda08620923df77b63b436654cb5e0b3bf94
47
+
48
+ # Compilers and codec headers. python3 serves node-gyp in the stage that
49
+ # builds FROM this one. Every -dev package here needs its runtime library in
50
+ # the production stage's apk list (keep the two lists in sync).
51
+ RUN apk add --no-cache \
52
+ build-base python3 curl xz meson ninja pkgconf \
53
+ glib-dev expat-dev libjpeg-turbo-dev libpng-dev libwebp-dev \
54
+ tiff-dev lcms2-dev libheif-dev libexif-dev
55
+
56
+ ENV PKG_CONFIG_PATH=/opt/vips/lib/pkgconfig \
57
+ LD_LIBRARY_PATH=/opt/vips/lib
58
+
59
+ # --auto-features=disabled turns every optional dependency off; only the
60
+ # formats we use are enabled: JPEG/PNG/WebP/HEIF/TIFF (plus the built-in GIF
61
+ # loader, which Next's image optimizer accepts), colour profiles, and EXIF
62
+ # (needed to read orientation and strip metadata). The rarely used PPM,
63
+ # Analyze and Radiance loaders are off to shrink the parser attack surface.
64
+ # -march=x86-64 is the baseline every x86-64 CPU supports (other
65
+ # architectures keep the compiler default). -j 2 bounds memory on small
66
+ # build hosts.
67
+ RUN set -eu; \
68
+ if [ "$(uname -m)" = "x86_64" ]; then \
69
+ export CFLAGS="-march=x86-64 -mtune=generic" CXXFLAGS="-march=x86-64 -mtune=generic"; \
70
+ fi; \
71
+ curl -fsSL --retry 3 -o /tmp/vips.tar.xz \
72
+ "https://github.com/libvips/libvips/releases/download/v${LIBVIPS_VERSION}/vips-${LIBVIPS_VERSION}.tar.xz"; \
73
+ echo "${LIBVIPS_SHA256} /tmp/vips.tar.xz" | sha256sum -c -; \
74
+ tar -xJf /tmp/vips.tar.xz -C /tmp; \
75
+ meson setup /tmp/vips-build "/tmp/vips-${LIBVIPS_VERSION}" \
76
+ --prefix=/opt/vips --libdir=lib --buildtype=release --auto-features=disabled \
77
+ -Djpeg=enabled -Dpng=enabled -Dwebp=enabled -Dheif=enabled -Dtiff=enabled \
78
+ -Dlcms=enabled -Dzlib=enabled -Dexif=enabled \
79
+ -Dexamples=false -Dppm=false -Danalyze=false -Dradiance=false; \
80
+ meson compile -C /tmp/vips-build -j 2; \
81
+ meson install -C /tmp/vips-build; \
82
+ test "$(pkg-config --modversion vips-cpp)" = "${LIBVIPS_VERSION}"; \
83
+ rm -rf /tmp/vips-build "/tmp/vips-${LIBVIPS_VERSION}" /tmp/vips.tar.xz
84
+
85
+ # ===================================================================
86
+ # Stage 2: Dependencies + CPU-safe sharp addon
87
+ # ===================================================================
88
+ # Built FROM the libvips stage because compiling sharp's addon needs the
89
+ # compilers and every codec -dev package that vips-cpp.pc references.
90
+ FROM libvips AS dependencies
16
91
 
17
92
  WORKDIR /app
18
93
 
@@ -29,17 +104,66 @@ RUN --mount=type=cache,target=/root/.npm \
29
104
  npm ci; \
30
105
  fi
31
106
 
107
+ # Build sharp's native addon against /opt/vips. sharp loads
108
+ # node_modules/sharp/src/build/Release/sharp-<platform>-<version>.node BEFORE
109
+ # its prebuilt addon and without the prebuilt's x86-64-v2 check, so this file
110
+ # is what makes sharp work on older CPUs. Keep this block identical in
111
+ # server/Dockerfile and client/Dockerfile.
112
+ # - It runs after every npm install above, so it targets the sharp version
113
+ # actually installed (read from its package.json, never hard-coded).
114
+ # - SHARP_FORCE_GLOBAL_LIBVIPS makes sharp skip its own libvips version
115
+ # check, so the block checks sharp's "config.libvips" range itself.
116
+ # - node-addon-api and node-gyp are build tools sharp requires but does not
117
+ # install. They go to /tmp/sharp-build (exact pins inside sharp's declared
118
+ # ranges; --ignore-scripts, since neither needs an install script and their
119
+ # unlocked transitive packages must not run code here) and never reach the
120
+ # lockfile or the runtime image.
121
+ # - npm_config_nodedir points node-gyp at this image's own Node headers, so
122
+ # nothing is downloaded and the addon matches the runtime Node exactly.
123
+ # - Intermediate build files are dropped; only the .node file stays, also
124
+ # staged in /opt/sharp-addon for stages that copy it explicitly.
125
+ RUN --mount=type=cache,target=/root/.npm \
126
+ set -eu; \
127
+ npm install --prefix /tmp/sharp-build --no-save --no-audit --no-fund --ignore-scripts \
128
+ node-addon-api@8.9.2 node-gyp@12.4.0; \
129
+ if [ ! -d node_modules/sharp ]; then \
130
+ echo "ERROR: node_modules/sharp is missing. If this app no longer uses sharp, delete this build step and the libvips stage." >&2; \
131
+ exit 1; \
132
+ fi; \
133
+ cd node_modules/sharp; \
134
+ version="$(node -p "require('./package.json').version")"; \
135
+ need="$(node -p "require('./package.json').config.libvips")"; \
136
+ have="$(pkg-config --modversion vips-cpp)"; \
137
+ if ! node -e "process.exit(require('semver').satisfies(process.argv[1], process.argv[2]) ? 0 : 1)" "$have" "$need"; then \
138
+ echo "ERROR: sharp ${version} needs libvips ${need}, but this image builds libvips ${have}. Raise LIBVIPS_VERSION and LIBVIPS_SHA256 in BOTH server/Dockerfile and client/Dockerfile." >&2; \
139
+ exit 1; \
140
+ fi; \
141
+ if [ "$(uname -m)" = "x86_64" ]; then \
142
+ export CFLAGS="-march=x86-64 -mtune=generic" CXXFLAGS="-march=x86-64 -mtune=generic"; \
143
+ fi; \
144
+ SHARP_FORCE_GLOBAL_LIBVIPS=1 npm_config_nodedir=/usr/local \
145
+ NODE_PATH=/tmp/sharp-build/node_modules PATH="/tmp/sharp-build/node_modules/.bin:$PATH" \
146
+ node install/build.js; \
147
+ addon="sharp-linuxmusl-$(node -p "process.arch")-${version}.node"; \
148
+ test -f "src/build/Release/${addon}"; \
149
+ mkdir -p /opt/sharp-addon; \
150
+ cp "src/build/Release/${addon}" /opt/sharp-addon/; \
151
+ rm -rf src/build /tmp/sharp-build; \
152
+ mkdir -p src/build/Release; \
153
+ cp "/opt/sharp-addon/${addon}" src/build/Release/
154
+
32
155
  # ===================================================================
33
- # Stage 2: Build (compile Next.js)
156
+ # Stage 3: Build (compile Next.js)
34
157
  # ===================================================================
35
- FROM node:20-alpine@sha256:fb4cd12c85ee03686f6af5362a0b0d56d50c58a04632e6c0fb8363f609372293 AS builder
158
+ # Built FROM the dependencies stage: node_modules (with the CPU-safe addon)
159
+ # is already in place, and libvips is loadable should the build touch sharp.
160
+ # None of these build tools reach the runtime image.
161
+ FROM dependencies AS builder
36
162
 
37
163
  WORKDIR /app
38
164
 
39
- # Copy dependencies from previous stage
40
- COPY --from=dependencies /app/node_modules ./node_modules
41
-
42
- # Copy source code
165
+ # Copy source code (.dockerignore keeps node_modules out, so the installed
166
+ # modules above are not overwritten)
43
167
  COPY . .
44
168
 
45
169
  # Build arguments for env vars needed at build time
@@ -54,6 +178,19 @@ ENV NEXT_PUBLIC_APP_NAME=$NEXT_PUBLIC_APP_NAME
54
178
  # Disable Next.js telemetry during build
55
179
  ENV NEXT_TELEMETRY_DISABLED=1
56
180
 
181
+ # The API address must be known now. src/lib/env.ts falls back to
182
+ # http://localhost:8000/api/v1 when it is unset (handy for local builds and
183
+ # CI), so without this check an image built without the value builds green
184
+ # and every visitor's browser then calls its own machine: a client that looks
185
+ # deployed but cannot reach its API. A localhost value only warns, because a
186
+ # local docker test may mean it. (Whitespace-only counts as empty.)
187
+ RUN set -eu; \
188
+ url="$(printf '%s' "${NEXT_PUBLIC_API_BASE_URL:-}" | tr -d '[:space:]')"; \
189
+ case "$url" in \
190
+ "") echo "ERROR: NEXT_PUBLIC_API_BASE_URL is empty at build time. NEXT_PUBLIC_* values are baked into the client's JavaScript: in Coolify, set it on the client app and tick 'Available at Buildtime'." >&2; exit 1 ;; \
191
+ *://localhost*|*://127.0.0.1*) echo "WARNING: NEXT_PUBLIC_API_BASE_URL is $url: visitors' browsers would call their own machine. Fine for a local test, wrong for a deployed client." >&2 ;; \
192
+ esac
193
+
57
194
  # Build the application (outputs to .next/standalone)
58
195
  # NOTE: a `--mount=type=cache,target=/app/.next/cache` was tested here and REMOVED —
59
196
  # it measured SLOWER (next build 29s→58s on a real create-tigra client), because Next's
@@ -62,12 +199,29 @@ ENV NEXT_TELEMETRY_DISABLED=1
62
199
  RUN npm run build
63
200
 
64
201
  # ===================================================================
65
- # Stage 3: Production Runtime
202
+ # Stage 4: Production Runtime
66
203
  # ===================================================================
67
- FROM node:20-alpine@sha256:fb4cd12c85ee03686f6af5362a0b0d56d50c58a04632e6c0fb8363f609372293 AS production
204
+ FROM node:24-alpine@sha256:44fce696f38ba8c987c4db89954051000bbd05ffd8d8659ba15ed4a8602e937f AS production
205
+
206
+ # dumb-init: proper signal handling.
207
+ # curl: Coolify's own HTTP health check runs curl (then BusyBox wget) inside
208
+ # the container. Without curl it falls back to wget, which tries only the
209
+ # first address `localhost` resolves to (often IPv6 ::1, while Next listens
210
+ # on IPv4), so Coolify marks a healthy app unhealthy and rolls the deploy
211
+ # back. curl tries both addresses.
212
+ # The rest are the shared libraries our libvips links against (one per -dev
213
+ # package in stage 1; same list as the server image). Alpine ships WebP's
214
+ # mux/demux libraries separately from libwebp and sharp fails to load without
215
+ # them; the libheif plugins decode HEIC (libde265) and AVIF (aom).
216
+ RUN apk add --no-cache \
217
+ dumb-init curl \
218
+ glib expat libjpeg-turbo libpng libwebp libwebpmux libwebpdemux \
219
+ tiff lcms2 libheif libheif-libde265 libheif-aom libexif
68
220
 
69
- # Install dumb-init for proper signal handling
70
- RUN apk add --no-cache dumb-init
221
+ # The libvips built in stage 1. sharp's addon links to it without an rpath,
222
+ # so the dynamic loader is told where it lives.
223
+ COPY --from=libvips /opt/vips/lib /opt/vips/lib
224
+ ENV LD_LIBRARY_PATH=/opt/vips/lib
71
225
 
72
226
  # Create non-root user for security
73
227
  RUN addgroup -g 1001 -S nodejs && \
@@ -84,9 +238,22 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
84
238
  # Copy public folder (favicon, images, etc.)
85
239
  COPY --from=builder --chown=nextjs:nodejs /app/public ./public
86
240
 
241
+ # Ship the CPU-safe sharp addon explicitly. Next's standalone file tracing
242
+ # does not reliably carry a source-built addon (or any libvips .so), so it is
243
+ # copied to the exact path sharp's loader tries first.
244
+ COPY --from=dependencies --chown=nextjs:nodejs /opt/sharp-addon/ ./node_modules/sharp/src/build/Release/
245
+
246
+ # Build-time sharp proof (see the script's header).
247
+ COPY --chown=nextjs:nodejs scripts/check-sharp.mjs ./scripts/check-sharp.mjs
248
+
87
249
  # Switch to non-root user
88
250
  USER nextjs
89
251
 
252
+ # Prove sharp loads our addon and converts images in THIS image, as the
253
+ # runtime user, before the image can ship. A failure fails the build instead
254
+ # of breaking every /_next/image request in production.
255
+ RUN node scripts/check-sharp.mjs
256
+
90
257
  # Disable telemetry at runtime
91
258
  ENV NEXT_TELEMETRY_DISABLED=1
92
259
 
@@ -97,9 +264,14 @@ ENV HOSTNAME="0.0.0.0"
97
264
  ENV PORT=3000
98
265
  EXPOSE 3000
99
266
 
100
- # Health check for container orchestration
267
+ # Health check for container orchestration. Coolify uses this one (not its
268
+ # dashboard check) to decide when a rolling deploy may switch over.
269
+ # /healthz (src/app/healthz/route.ts) answers 200 without rendering a page, so
270
+ # it stays healthy when a project makes its home page redirect; `/` did not.
271
+ # 127.0.0.1, never localhost: Next listens on IPv4 (HOSTNAME=0.0.0.0), and
272
+ # localhost can resolve to IPv6 ::1 first, which would refuse the probe.
101
273
  HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
102
- CMD node -e "const p=process.env.PORT||3000;require('http').get('http://localhost:'+p,(r)=>{process.exit(r.statusCode===200?0:1)})"
274
+ CMD node -e "const p=process.env.PORT||3000;require('http').get('http://127.0.0.1:'+p+'/healthz',(r)=>{process.exit(r.statusCode===200?0:1)})"
103
275
 
104
276
  # Use dumb-init to handle signals properly
105
277
  ENTRYPOINT ["dumb-init", "--"]
@@ -2,7 +2,7 @@ import type { NextConfig } from "next";
2
2
 
3
3
  // SECURITY HEADERS / CSP NOTE:
4
4
  // All security headers — including the Content-Security-Policy — are set in
5
- // src/middleware.ts, which is the SINGLE SOURCE OF TRUTH for them. The CSP is
5
+ // src/proxy.ts, which is the SINGLE SOURCE OF TRUTH for them. The CSP is
6
6
  // per-request and nonce-based ('strict-dynamic'), which a static headers() block
7
7
  // here cannot express, and emitting a CSP from both places would produce a
8
8
  // conflicting duplicate Content-Security-Policy header. Do NOT add a headers()