create-tigra 3.3.0 → 4.0.1

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 (207) hide show
  1. package/CHANGELOG.md +151 -0
  2. package/README.md +264 -56
  3. package/bin/create-tigra.js +497 -472
  4. package/lib/patchers/email-verification.patcher.js +72 -10
  5. package/modules/email-verification/client/hooks/useVerification.ts +4 -1
  6. package/modules/email-verification/server/__tests__/verification.integration.test.ts +115 -0
  7. package/modules/email-verification/server/verification.controller.ts +3 -1
  8. package/modules/email-verification/server/verification.service.ts +44 -13
  9. package/package.json +5 -3
  10. package/template/.github/dependabot.yml +47 -0
  11. package/template/.github/workflows/audit.yml +36 -0
  12. package/template/.github/workflows/ci.yml +79 -0
  13. package/template/AGENTS.md +18 -9
  14. package/template/README.md +79 -0
  15. package/template/client/.dockerignore +1 -0
  16. package/template/client/.env.example.production +13 -2
  17. package/template/client/AGENTS.md +13 -5
  18. package/template/client/Dockerfile +186 -14
  19. package/template/client/README.md +92 -21
  20. package/template/client/next.config.ts +1 -1
  21. package/template/client/package-lock.json +15983 -14181
  22. package/template/client/package.json +56 -48
  23. package/template/client/scripts/check-sharp.mjs +53 -0
  24. package/template/client/scripts/next-dev.cjs +5 -1
  25. package/template/client/src/__tests__/proxy.test.ts +92 -0
  26. package/template/client/src/app/healthz/route.ts +16 -0
  27. package/template/client/src/app/layout.tsx +9 -3
  28. package/template/client/src/app/page.tsx +2 -2
  29. package/template/client/src/app/providers.tsx +23 -4
  30. package/template/client/src/components/layout/Header.tsx +7 -3
  31. package/template/client/src/features/admin/hooks/useAdminSessions.ts +2 -1
  32. package/template/client/src/features/admin/hooks/useAdminUsers.ts +3 -1
  33. package/template/client/src/features/admin/types/admin.types.ts +2 -3
  34. package/template/client/src/features/auth/components/AuthInitializer.tsx +35 -18
  35. package/template/client/src/features/auth/components/ForgotPasswordForm.tsx +107 -0
  36. package/template/client/src/features/auth/components/LimitNotice.tsx +28 -0
  37. package/template/client/src/features/auth/components/LoginForm.tsx +13 -2
  38. package/template/client/src/features/auth/components/RegisterForm.tsx +23 -7
  39. package/template/client/src/features/auth/hooks/useAuth.ts +11 -1
  40. package/template/client/src/features/auth/hooks/usePasswordReset.ts +7 -1
  41. package/template/client/src/features/auth/services/auth.service.ts +8 -3
  42. package/template/client/src/features/auth/store/authSlice.ts +7 -2
  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 +1 -1
  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 +81 -0
  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/session-marker.ts +24 -0
  59. package/template/client/src/{middleware.ts → proxy.ts} +25 -11
  60. package/template/client/src/store/__tests__/store.test.ts +44 -0
  61. package/template/client/src/store/index.ts +26 -8
  62. package/template/client/vitest.config.mts +48 -0
  63. package/template/server/.env.example +280 -270
  64. package/template/server/.env.example.production +283 -242
  65. package/template/server/AGENTS.md +13 -4
  66. package/template/server/Dockerfile +176 -14
  67. package/template/server/README.md +108 -0
  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 +66 -4
  71. package/template/server/docs/rate-limits.md +153 -0
  72. package/template/server/docs/testing.md +81 -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 +0 -3
  79. package/template/server/scripts/check-heic.mjs +40 -0
  80. package/template/server/scripts/check-sharp.mjs +53 -0
  81. package/template/server/src/__tests__/routes.integration.test.ts +280 -0
  82. package/template/server/src/app.ts +248 -346
  83. package/template/server/src/config/__tests__/env.test.ts +219 -0
  84. package/template/server/src/config/__tests__/rate-limit.config.test.ts +158 -0
  85. package/template/server/src/config/env.ts +326 -182
  86. package/template/server/src/config/rate-limit.config.ts +157 -106
  87. package/template/server/src/jobs/__tests__/cleanup-deleted-accounts.job.test.ts +60 -8
  88. package/template/server/src/jobs/__tests__/cleanup-expired-auth.job.test.ts +44 -0
  89. package/template/server/src/jobs/__tests__/jobs.integration.test.ts +88 -0
  90. package/template/server/src/jobs/__tests__/schedule.test.ts +92 -0
  91. package/template/server/src/jobs/cleanup-deleted-accounts.job.ts +38 -36
  92. package/template/server/src/jobs/cleanup-expired-auth.job.ts +32 -24
  93. package/template/server/src/jobs/index.ts +12 -2
  94. package/template/server/src/jobs/refresh-cloudflare-ranges.job.ts +28 -0
  95. package/template/server/src/jobs/schedule.ts +50 -0
  96. package/template/server/src/libs/__tests__/auth.test.ts +98 -7
  97. package/template/server/src/libs/__tests__/client-ip.test.ts +257 -121
  98. package/template/server/src/libs/__tests__/cloudflare-ranges.test.ts +79 -0
  99. package/template/server/src/libs/__tests__/cookies.test.ts +53 -2
  100. package/template/server/src/libs/__tests__/email-quota.test.ts +81 -0
  101. package/template/server/src/libs/__tests__/email.test.ts +68 -0
  102. package/template/server/src/libs/__tests__/error-handler.test.ts +162 -0
  103. package/template/server/src/libs/__tests__/health-db-down.integration.test.ts +37 -0
  104. package/template/server/src/libs/__tests__/health-redis-down.integration.test.ts +45 -0
  105. package/template/server/src/libs/__tests__/health-routes.test.ts +83 -0
  106. package/template/server/src/libs/__tests__/health.integration.test.ts +118 -0
  107. package/template/server/src/libs/__tests__/http.test.ts +74 -2
  108. package/template/server/src/libs/__tests__/ip-block.test.ts +179 -62
  109. package/template/server/src/libs/__tests__/logger.test.ts +50 -0
  110. package/template/server/src/libs/__tests__/monitoring.test.ts +185 -0
  111. package/template/server/src/libs/__tests__/outbound.integration.test.ts +48 -0
  112. package/template/server/src/libs/__tests__/prisma-client.test.ts +28 -0
  113. package/template/server/src/libs/__tests__/query-counter.integration.test.ts +53 -0
  114. package/template/server/src/libs/__tests__/rate-limiting.test.ts +146 -0
  115. package/template/server/src/libs/__tests__/rate-limits.integration.test.ts +53 -0
  116. package/template/server/src/libs/__tests__/redis-required.test.ts +30 -0
  117. package/template/server/src/libs/__tests__/redis.test.ts +38 -2
  118. package/template/server/src/libs/__tests__/request-id.test.ts +25 -0
  119. package/template/server/src/libs/__tests__/requestLogger.test.ts +126 -0
  120. package/template/server/src/libs/__tests__/safe-http.test.ts +138 -0
  121. package/template/server/src/libs/__tests__/sentry-scrub.test.ts +82 -80
  122. package/template/server/src/libs/__tests__/shutdown.test.ts +89 -0
  123. package/template/server/src/libs/__tests__/url-safety.test.ts +130 -80
  124. package/template/server/src/libs/auth.ts +39 -10
  125. package/template/server/src/libs/client-ip.ts +158 -77
  126. package/template/server/src/libs/cloudflare-ranges.ts +132 -0
  127. package/template/server/src/libs/cookies.ts +53 -14
  128. package/template/server/src/libs/email-quota.ts +74 -0
  129. package/template/server/src/libs/email.ts +46 -9
  130. package/template/server/src/libs/error-handler.ts +111 -0
  131. package/template/server/src/libs/health-routes.ts +53 -0
  132. package/template/server/src/libs/http.ts +139 -47
  133. package/template/server/src/libs/ip-address.ts +37 -0
  134. package/template/server/src/libs/ip-block.ts +284 -221
  135. package/template/server/src/libs/logger.ts +41 -12
  136. package/template/server/src/libs/monitoring.ts +127 -41
  137. package/template/server/src/libs/observability/sentry.ts +1 -1
  138. package/template/server/src/libs/origin-check.ts +9 -7
  139. package/template/server/src/libs/prisma.ts +47 -4
  140. package/template/server/src/libs/query-counter.ts +71 -59
  141. package/template/server/src/libs/rate-limiting.ts +110 -0
  142. package/template/server/src/libs/redis-required.ts +28 -0
  143. package/template/server/src/libs/redis.ts +27 -1
  144. package/template/server/src/libs/request-id.ts +18 -0
  145. package/template/server/src/libs/requestLogger.ts +112 -17
  146. package/template/server/src/libs/safe-http.ts +101 -0
  147. package/template/server/src/libs/shutdown.ts +87 -0
  148. package/template/server/src/libs/storage/__tests__/fixtures/tiny-heic.ts +13 -0
  149. package/template/server/src/libs/storage/__tests__/image-optimizer.test.ts +59 -0
  150. package/template/server/src/libs/storage/__tests__/multipart-limits.test.ts +91 -0
  151. package/template/server/src/libs/storage/__tests__/upload-persistence.test.ts +52 -0
  152. package/template/server/src/libs/storage/file-storage.service.ts +94 -84
  153. package/template/server/src/libs/storage/file-validator.ts +48 -46
  154. package/template/server/src/libs/storage/image-optimizer.service.ts +16 -5
  155. package/template/server/src/libs/token-hash.ts +18 -0
  156. package/template/server/src/libs/url-safety.ts +127 -121
  157. package/template/server/src/libs/validation-errors.ts +86 -0
  158. package/template/server/src/modules/admin/__tests__/admin-actions.integration.test.ts +255 -0
  159. package/template/server/src/modules/admin/__tests__/admin.health.test.ts +82 -0
  160. package/template/server/src/modules/admin/__tests__/admin.repo.test.ts +55 -0
  161. package/template/server/src/modules/admin/__tests__/admin.schemas.test.ts +38 -0
  162. package/template/server/src/modules/admin/__tests__/admin.service.test.ts +162 -0
  163. package/template/server/src/modules/admin/admin.controller.ts +66 -49
  164. package/template/server/src/modules/admin/admin.repo.ts +49 -10
  165. package/template/server/src/modules/admin/admin.routes.ts +48 -2
  166. package/template/server/src/modules/admin/admin.schemas.ts +18 -6
  167. package/template/server/src/modules/admin/admin.service.ts +66 -4
  168. package/template/server/src/modules/auth/__tests__/auth.controller.test.ts +39 -0
  169. package/template/server/src/modules/auth/__tests__/auth.integration.test.ts +9 -3
  170. package/template/server/src/modules/auth/__tests__/auth.service.dummy-hash.test.ts +34 -0
  171. package/template/server/src/modules/auth/__tests__/auth.service.test.ts +197 -37
  172. package/template/server/src/modules/auth/__tests__/session-cleanup.test.ts +39 -0
  173. package/template/server/src/modules/auth/__tests__/sessions.integration.test.ts +246 -0
  174. package/template/server/src/modules/auth/__tests__/token-fingerprints.test.ts +119 -0
  175. package/template/server/src/modules/auth/auth.controller.ts +133 -128
  176. package/template/server/src/modules/auth/auth.repo.ts +44 -44
  177. package/template/server/src/modules/auth/auth.schemas.ts +4 -2
  178. package/template/server/src/modules/auth/auth.service.ts +167 -96
  179. package/template/server/src/modules/auth/session.repo.ts +12 -0
  180. package/template/server/src/modules/files/__tests__/files.integration.test.ts +5 -5
  181. package/template/server/src/modules/users/__tests__/avatar-upload.test.ts +120 -0
  182. package/template/server/src/modules/users/__tests__/name-rules.test.ts +46 -0
  183. package/template/server/src/modules/users/__tests__/users.integration.test.ts +295 -0
  184. package/template/server/src/modules/users/__tests__/users.repo.test.ts +37 -0
  185. package/template/server/src/modules/users/__tests__/users.service.test.ts +129 -0
  186. package/template/server/src/modules/users/users.controller.ts +9 -38
  187. package/template/server/src/modules/users/users.repo.ts +23 -7
  188. package/template/server/src/modules/users/users.routes.ts +3 -22
  189. package/template/server/src/modules/users/users.schemas.ts +15 -9
  190. package/template/server/src/modules/users/users.service.ts +105 -93
  191. package/template/server/src/scripts/make-admin.ts +48 -0
  192. package/template/server/src/server.ts +48 -26
  193. package/template/server/src/shared/errors/AppError.ts +27 -1
  194. package/template/server/src/shared/errors/errors.ts +42 -5
  195. package/template/server/src/shared/responses/successResponse.ts +22 -3
  196. package/template/server/src/shared/types/index.ts +7 -0
  197. package/template/server/src/test/__tests__/integration-services.test.ts +66 -0
  198. package/template/server/src/test/integration-helpers.ts +343 -0
  199. package/template/server/src/test/integration-services.ts +74 -0
  200. package/template/server/src/test/integration.global-setup.ts +144 -0
  201. package/template/server/src/test/integration.setup.ts +35 -158
  202. package/template/server/src/test/setup.ts +3 -10
  203. package/template/server/tsconfig.build.json +1 -1
  204. package/template/server/tsconfig.json +1 -0
  205. package/template/server/vitest.config.ts +17 -4
  206. package/template/server/vitest.integration.config.ts +18 -13
  207. package/template/server/src/libs/storage/filename-sanitizer.ts +0 -71
package/CHANGELOG.md ADDED
@@ -0,0 +1,151 @@
1
+ # Changelog
2
+
3
+ A generated project never changes after it is created: these notes say what new projects get. To bring an older
4
+ project along, port the changes you need; the guides in [docs/](docs/) cover the ones that need care.
5
+
6
+ ## 4.0.1 (2026-10-20)
7
+
8
+ Documentation only, no code changes.
9
+
10
+ - The README explains what create-tigra builds, area by area, how a request travels, the pages you add yourself,
11
+ the everyday commands, `create-tigra add`, and where every guide lives.
12
+ - Generated projects get a root `README.md`, a `server/README.md` and a rewritten `client/README.md` (it was
13
+ create-next-app's default text).
14
+ - `server/docs/testing.md` covers the client tests and the route-contract rule; `server/docs/logging.md` covers
15
+ secret redaction.
16
+ - This changelog, now shipped in the npm package.
17
+ - The CLI fills the project's name, database and local ports into its new README.
18
+
19
+ ## 4.0.0 (2026-10-20)
20
+
21
+ A full review of the template, area by area. Every change was tested on fresh projects with and without the
22
+ email-verification module, and the Docker images were built and run on Coolify.
23
+
24
+ ### Breaking for new projects
25
+
26
+ - Generated apps need **Node 24 and npm 11.19+** (the 3.3.0 images ran Node 20). The images use `node:24-alpine`
27
+ pinned by digest, and the tested lockfiles ship with every project and install with `npm ci`.
28
+ - Local and test MySQL is **8.4**.
29
+ - In production the server refuses to start without any migration, without `REDIS_URL`, or when Redis cannot be
30
+ reached within 10 s of starting.
31
+ - `TRUST_CLOUDFLARE`, `DATABASE_POOL_MIN` and `DATABASE_POOL_MAX` are gone; `CLOUDFLARE_ORIGIN_SECRET` is new.
32
+ - Wrong input always answers `422 VALIDATION_FAILED` with the list of fields.
33
+ - The public `/api/v1/health` answers only its status; the full report moved to `GET /api/v1/admin/health`.
34
+ - Client: `src/middleware.ts` is now `src/proxy.ts` (Next 16's name), and the Redux store is created per visitor
35
+ with `makeStore()` instead of being one exported `store`.
36
+ - `create-tigra add email-verification` is meant for 4.x projects: it copies tests that use the 4.x test helpers.
37
+
38
+ ### Generator
39
+
40
+ - New projects ship their first migration (`0_init`); a check keeps it equal to the schema.
41
+ - The README no longer tells you to copy `.env.example` over the `.env` that holds the generated secrets.
42
+ - The CLI warns when Node is older than 24 or npm older than 11.19.
43
+
44
+ ### Foundation and configuration
45
+
46
+ - `REDIS_URL` is required in production; on/off switches accept only `true` or `false`.
47
+ - `CLIENT_URL` is required in production only when emails can go out.
48
+ - Email verification is off unless the email module is installed.
49
+ - The production example uses `PORT=8000` and caps the database pool (`?connection_limit=5`).
50
+
51
+ ### Request pipeline
52
+
53
+ - The client IP is verified before it is believed: behind Cloudflare, behind Coolify's Traefik, or direct
54
+ ([guide](docs/client-ip-behind-proxies.md)).
55
+ - Rate limits for public use: clear wait times (`retryAfterSeconds`), a per-address email cap, overrides through
56
+ env (`RATE_LIMIT_OVERRIDES`, `RATE_LIMIT_MULTIPLIER`); token flows answer a clear 503 while Redis is down.
57
+ - `CORS_ORIGIN` is checked at boot (bare origins only, with the fix printed).
58
+ - Auth cookies are never `SameSite=None`: the tokens are Strict and the session marker is Lax, so a link from
59
+ another site no longer bounces a signed-in user to `/login`.
60
+ - A warning when production runs on plain http (the browser would drop the login cookies).
61
+ - Log redaction covers secrets at every level it promises; an inbound `X-Request-Id` is kept only when short and
62
+ plain.
63
+
64
+ ### Sessions and accounts
65
+
66
+ - Two tabs refreshing at once: exactly one wins and the other keeps its session.
67
+ - Refresh, reset and verification tokens are stored as SHA-256 fingerprints only.
68
+ - Signing out, signing out everywhere, a password reset and an admin revoke end the access token at once; a banned
69
+ user's token answers `403 ACCOUNT_DEACTIVATED` at once.
70
+ - A password-reset link works once, even when used twice at the same moment.
71
+ - A wrong password on change-password or delete-account answers 422, not 401; changing your own password keeps
72
+ this device signed in.
73
+ - Strangers can no longer use up a user's verification emails.
74
+
75
+ ### Users and files
76
+
77
+ - Multipart fields are capped, so one upload cannot hold about 1 GB of memory; a file cut at the size limit
78
+ answers 413.
79
+ - Avatar formats are judged by their bytes (JPEG, PNG, WebP, HEIC, AVIF); HEIC is proven to decode in the image
80
+ build. Every avatar gets a new file name, and the old file goes only after the swap.
81
+ - A deleted account's photo stops being public at once; names are trimmed before their length is checked.
82
+ - The server warns at boot when uploads are not on a persistent volume.
83
+
84
+ ### Admin API
85
+
86
+ - An admin cannot ban themselves, and the last admin cannot delete their own account.
87
+ - IP blocks use one canonical spelling, match however they were written, and cannot block an admin's own or a
88
+ private address.
89
+ - Deleted accounts can be listed and restored during their 30 days.
90
+ - `make-admin` promotes an existing account to admin (the first admin, or recovery).
91
+ - User detail says `lastActiveAt`; the user list's filters work again.
92
+
93
+ ### Background jobs
94
+
95
+ - Jobs run about a minute after every start, then on their schedule, so frequent deploys never postpone them
96
+ (before, an app deployed at least daily never purged deleted accounts).
97
+ - Expired automatic IP blocks are pruned hourly; an account another process already purged is not a failure.
98
+
99
+ ### Outbound requests and email
100
+
101
+ - `safeHttpClient` for URLs a user supplied: it refuses internal addresses on every redirect hop. The
102
+ internal-address check no longer misses hex IPv4-mapped forms.
103
+ - Outbound URLs are logged redacted; failures carry their status and kind.
104
+ - Sending email gives up after 10 s, and recipients are logged masked. Production refuses the placeholder Resend
105
+ key and sender.
106
+
107
+ ### Health, logs and shutdown
108
+
109
+ - Memory is judged against the heap limit; a failing check logs the real error.
110
+ - The database and Redis are checked at most once per 5 s for all probes together.
111
+ - Request lines carry JSON fields in production and never keep the query string.
112
+ - Crashes and failed starts exit 1, and shutdown has an 8 s deadline (inside Docker's 10 s).
113
+
114
+ ### Testing and CI
115
+
116
+ - The critical advisories in the shipped dependencies are cleared.
117
+ - Integration tests ship with every project (166, or 172 with the email module): every route's contract, plus identity, users, admin, jobs, health
118
+ and email behaviour, against a real MySQL and Redis (Testcontainers, or services you already run). The route
119
+ contract fails when a new route is never called.
120
+ - An honest coverage floor counts every file, on the server and now on the client.
121
+ - The server's lint refuses unawaited and misused promises.
122
+ - New projects ship CI, a weekly audit of production dependencies and Dependabot (security updates for npm and
123
+ Actions, monthly base-image updates).
124
+
125
+ ### Deployment
126
+
127
+ - The images run on any x86-64 CPU: sharp is built on a pinned libvips, so VPSes without x86-64-v2 work.
128
+ - curl health checks; plain (uncoloured) production logs.
129
+ - The client image build stops when `NEXT_PUBLIC_API_BASE_URL` is missing; the client health check is `/healthz`,
130
+ which works even when the home page redirects.
131
+ - A Coolify checklist in the README and `server/docs/deployment.md`: what a deploy does, safe migrations (expand,
132
+ deploy, contract), rollback, and the libvips build time.
133
+
134
+ ### Guidance for AI agents
135
+
136
+ - The completion check reviews the patch actually handed over (`git diff HEAD` plus new files). Claude Code's
137
+ `/security-review` is not that check: it only sees commits.
138
+ - The root `AGENTS.md` tells Codex to read the server and client files, which it does not load by itself.
139
+ - The agent files now carry the migration, job, deployment and test rules, and the security workflow covers the
140
+ client's security code.
141
+
142
+ ### Client
143
+
144
+ - A Vitest unit suite (session rules, the proxy, redirect safety, error parsing) runs in CI with a coverage floor.
145
+ - A refresh race lost to another tab is replayed instead of signing out; a ban mid-session signs out at once.
146
+ - Anonymous visitors make no API calls (it was two failing calls per page view).
147
+ - Protected paths match whole segments (`/administrator` is no longer treated as `/admin`).
148
+ - The server's field errors show under their fields; the register rules mirror the server's.
149
+ - The header is right on the first render, and hydration uses the server's state (a second tab could hit a
150
+ hydration mismatch).
151
+ - The welcome page links to this repository.
package/README.md CHANGED
@@ -1,92 +1,300 @@
1
1
  # create-tigra
2
2
 
3
- Scaffold a production-ready full-stack application with **Next.js 16** + **Fastify 5** + **Prisma** + **Redis**.
3
+ `create-tigra` generates a full-stack TypeScript app that is ready for production on day one: a **Fastify 5** API
4
+ with **Prisma** (MySQL 8.4) and **Redis 7**, and a **Next.js 16** client. Sign-in and sessions, abuse protection,
5
+ uploads, an admin API, background jobs, health checks, tests, CI and Docker images for Coolify are already built,
6
+ tested and documented, so a new project starts at its own features instead of its plumbing.
4
7
 
5
- ## Quick Start
8
+ The client ships the wiring, not the screens. Every app looks different, so you write the pages; the template gives
9
+ them the API client, the sign-in flow, the forms and the security headers they need.
6
10
 
7
11
  ```bash
8
12
  npx create-tigra my-app
9
13
  ```
10
14
 
11
- ## What's Included
15
+ The CLI asks for a project name and whether new users must verify their email, then writes the project with fresh
16
+ secrets in its git-ignored `.env` files.
12
17
 
13
- ### Client (Next.js 16)
18
+ - [What you get](#what-you-get)
19
+ - [Quick start](#quick-start)
20
+ - [Everyday commands](#everyday-commands)
21
+ - [Testing and CI](#testing-and-ci)
22
+ - [Deploying to Coolify](#deploying-to-coolify)
23
+ - [Adding a module later](#adding-a-module-later)
24
+ - [Documentation](#documentation)
25
+ - [Upgrading from 3.x](#upgrading-from-3x)
14
26
 
15
- | Feature | Technology |
27
+ ## What you get
28
+
29
+ ```text
30
+ my-app/
31
+ ├── server/ Fastify 5 API: TypeScript, Prisma, MySQL 8.4, Redis 7, Vitest, Dockerfile
32
+ ├── client/ Next.js 16 app: App Router, React 19, Tailwind v4, shadcn/ui, Vitest, Dockerfile
33
+ ├── .github/ CI on every push, a weekly dependency audit, Dependabot
34
+ ├── AGENTS.md rules for AI coding agents (one more in server/ and client/), CLAUDE.md imports them
35
+ └── .agents/ the security-audit skill the agents use before they finish a change
36
+ ```
37
+
38
+ How a request travels:
39
+
40
+ ```text
41
+ Browser
42
+ │ client/src/proxy.ts: a fresh CSP nonce per request, security headers,
43
+ │ signed-out visitors sent away from protected pages
44
+ ▼
45
+ Next.js client ── axios, httpOnly cookies ──▶ Fastify API /api/v1/...
46
+ one refresh per tab; a refresh race │ CORS allowlist + origin check, real visitor IP,
47
+ between tabs is replayed, not a sign-out │ IP blocks, per-route rate limits, Zod input checks
48
+ ▼
49
+ route → controller → service → repository → Prisma → MySQL
50
+ │ Redis: rate limits, lockout, IP blocks
51
+ └─ background jobs · Resend email · health probes
52
+ ```
53
+
54
+ ### Server
55
+
56
+ | Area | What is built |
16
57
  |---|---|
17
- | Framework | Next.js 16 (App Router, React 19) |
18
- | Styling | Tailwind CSS v4, shadcn/ui, OKLCH color system |
19
- | State | Redux Toolkit (auth), React Query v5 (server data) |
20
- | Forms | React Hook Form + Zod validation |
21
- | HTTP | Axios with httpOnly cookie auth + auto refresh |
22
- | Auth UI | Login, Register, Dashboard pages |
23
- | Components | Header, Footer, Loading, Error, Empty states |
24
- | Theme | Light/Dark mode with next-themes |
25
-
26
- ### Server (Fastify 5)
27
-
28
- | Feature | Technology |
58
+ | Accounts and sign-in | Register, sign in, sign out, sign out everywhere, the list of your sessions, forgot and reset password by email. Tokens live in httpOnly cookies (access 15 min, refresh 7 days by default); passwords are hashed with Argon2id. |
59
+ | Sessions | Every refresh rotates the token. When two tabs refresh at once, exactly one wins and the other keeps its session. Tokens are stored only as SHA-256 fingerprints. Signing out, a password reset, a ban or an admin revoke ends the access token at once, not 15 minutes later. |
60
+ | Abuse protection | Rate limits per route and per IP, tuned from env (`RATE_LIMIT_MULTIPLIER`, `RATE_LIMIT_OVERRIDES`). A login lockout per email and IP (the 15th failure locks for 15 min, the 30th for 1 h) that a stranger cannot use against the real user. An automatic IP block for repeat offenders, a manual block list, and a per-address cap on emails anyone can trigger. Every "slow down" answer says how long to wait. |
61
+ | Real visitor address | Verified behind Cloudflare and Coolify's Traefik before it is believed, so nobody can pick their own rate-limit key or get someone else blocked. Check it any time at `GET /api/v1/admin/client-ip`. |
62
+ | Input and errors | Zod validates every input. Wrong input always answers `422 VALIDATION_FAILED` with the list of fields (never the submitted values); an unexpected error answers a generic 500 and is logged in full on the server. |
63
+ | Users and files | Profile, password change, account deletion (30 days to change your mind, then purged). Avatars are judged by their bytes (JPEG, PNG, WebP, HEIC, AVIF), stored as WebP with location data stripped, capped at 10 MB and 50 megapixels. Private files are served only to their owner. |
64
+ | Admin API | Stats, the user list (search, role, status, deleted accounts), user detail, ban and unban, role change, restoring a deleted account, the session list and revoke, IP blocks. An admin cannot ban themselves and the last admin cannot delete their account. The first admin is promoted with `make-admin`. |
65
+ | Outbound requests | One shared HTTP client with timeouts and redacted logs, plus `safeHttpClient` for URLs a user supplied: it refuses internal addresses (localhost, private networks, cloud metadata) on every redirect hop. |
66
+ | Email | Resend, with a 10 s timeout and masked addresses in the logs. Optional email verification for new users. |
67
+ | Background jobs | Run inside the server process, no extra service: expired sessions and tokens hourly, deleted accounts past 30 days daily, Cloudflare's IP list daily. Each first runs about a minute after the server starts, so frequent deploys never postpone them. |
68
+ | Health and logs | `/api/v1/live`, `/ready` and `/health` for probes, and the full report for admins at `/api/v1/admin/health`. One log line per request (JSON fields in production, never the query string) with passwords, tokens, cookies and keys redacted. A crash exits 1; shutdown finishes in-flight requests within 8 s. |
69
+ | Database and Redis | MySQL 8.4 with Prisma 6. New projects ship their first migration; production applies migrations at start and refuses to start without one. Production also refuses to start without Redis, because the limits, the lockout and the IP blocks depend on it. |
70
+ | Local infrastructure | Docker Compose for MySQL and Redis, reachable from your machine only; phpMyAdmin and Redis Commander when you ask for them. Each project gets its own ports, so several can run side by side. |
71
+
72
+ ### Client
73
+
74
+ | Area | What is built |
29
75
  |---|---|
30
- | Framework | Fastify 5 with TypeScript (strict) |
31
- | Database | MySQL 8.0 + Prisma 6 ORM |
32
- | Cache | Redis 7 (ioredis) |
33
- | Auth | JWT (httpOnly cookies), session management |
34
- | Validation | Zod schemas on all inputs |
35
- | Security | Helmet, CORS, rate limiting, password hashing (Argon2) |
36
- | File uploads | Multipart + Sharp image optimization |
37
- | Logging | Pino with pretty dev output |
38
- | Testing | Vitest with 80% coverage thresholds |
39
- | Dev tools | Docker Compose (MySQL, phpMyAdmin, Redis, Redis Commander) |
76
+ | Framework | Next.js 16 (App Router, Server Components by default), React 19, TypeScript strict. |
77
+ | Security | `src/proxy.ts` (Next 16's name for middleware): a fresh CSP nonce per request with `strict-dynamic`, security headers, and a redirect to sign-in for protected pages. Tokens never reach JavaScript. |
78
+ | API client | Axios with httpOnly cookies. Parallel 401s share one refresh; a refresh race lost to another tab is replayed instead of signing out; a ban mid-session signs out at once; "slow down" answers show one toast with the wait time. |
79
+ | Sign-in wiring | `useAuth`, `useCurrentUser`, `AuthInitializer`, and the login, register and forgot-password form components: inline limit messages, the server's field errors under their fields, and a `?from=` redirect that only ever lands on your own site. Anonymous visitors make no API calls. |
80
+ | Admin wiring | Hooks and services for stats, users and sessions, ready for your own admin screens. |
81
+ | State | Redux Toolkit only for the signed-in user (one store per visitor), React Query for server data. |
82
+ | Design system | Tailwind CSS v4, shadcn/ui, OKLCH colour tokens with light and dark themes (next-themes). |
83
+ | Components | Header, footer, layouts, links with smooth navigation, a safe image, confirm dialog, empty state, pagination, loading states, error and not-found pages. |
84
+ | Testing | Vitest unit tests of the client's logic (session rules, the proxy, redirect safety, error parsing) with a coverage floor in CI. |
85
+
86
+ ### Pages are yours
87
+
88
+ Besides a welcome page and the `/healthz` health check, the client ships no pages, on purpose. Add yours at the
89
+ paths in `client/src/lib/constants/routes.ts`; the proxy, the API client and the emails already send people there:
40
90
 
41
- ### Codex Development
91
+ | Path | Your page | What to use |
92
+ |---|---|---|
93
+ | `/login` | sign in | `LoginForm` (reads `?from=`) |
94
+ | `/register` | sign up | `RegisterForm` |
95
+ | any path you like | forgot password | `ForgotPasswordForm` |
96
+ | `/reset-password?token=…` | new password, from the emailed link | `useResetPassword` |
97
+ | `/verify-account?token=…` | email verification (email module) | `useVerifyAccount`, `useSendVerification` |
98
+ | `/dashboard`, `/profile`, `/admin` and below | signed-in areas, protected by the proxy | `useCurrentUser`, the admin hooks |
42
99
 
43
- Includes concise `AGENTS.md` guidance at the project root and scoped guidance inside `client/` and `server/`, with matching `CLAUDE.md` files that import them so Claude Code reads the same rules. Generated projects also include Cloudflare's MIT-licensed `security-audit` repository skill (in `.agents/skills/` for Codex, with a thin pointer in `.claude/skills/` for Claude Code). Meaningful server changes must use its focused guidance and, before completion, scan the working-tree patch: `security-diff-scan` when the Codex Security plugin is installed, or `/security-review` in Claude Code.
100
+ The protected list lives next to the routes (`PROTECTED_PATHS`); add your own areas there.
44
101
 
45
- The security workflow falls back to the bundled skill when Codex Security is unavailable, while full or deep repository audits remain explicit operations rather than an automatic cost on every edit.
102
+ ### Built for AI agents
46
103
 
47
- ## Prerequisites
104
+ - `AGENTS.md` at the root and in `server/` and `client/`, with `CLAUDE.md` files that import them, so Codex and
105
+ Claude Code read the same rules: the architecture, the sources of truth, safe migrations, deployment and tests.
106
+ - Cloudflare's MIT-licensed `security-audit` skill (`.agents/skills/`, with a pointer in `.claude/skills/`). Before
107
+ finishing a meaningful change, the agent reviews the patch it is handing over (`git diff HEAD` plus new files):
108
+ with the Codex Security plugin's diff scan when it is installed, otherwise with this skill. Full audits stay an
109
+ explicit request.
110
+ - The code itself is the guide: one layout per module, one response and error shape, one rate-limit config, and a
111
+ route-contract test that fails when a new route has no test.
48
112
 
49
- - **Node.js** 22.12+
50
- - **Docker** (for MySQL and Redis)
113
+ ## Quick start
51
114
 
52
- ## After Scaffolding
115
+ Prerequisites:
116
+
117
+ - **Node.js 24+** with **npm 11.19+** for the generated apps (the CLI itself runs on Node 22.12+). Early Node 24
118
+ releases ship an older npm 11 whose lockfiles the Docker images reject: check `npm -v`, update with
119
+ `npm install -g npm@11`.
120
+ - **Docker**, for the local MySQL and Redis.
53
121
 
54
122
  ```bash
55
- # 1. Start infrastructure
56
- cd my-app/server
57
- docker compose up -d
123
+ npx create-tigra my-app
58
124
 
59
- # 2. Install server dependencies & set up database
60
- npm install
61
- cp .env.example .env
125
+ # Server: infrastructure, database, API
126
+ cd my-app/server
127
+ npm ci # installs the shipped lockfile exactly
128
+ npm run docker:up # MySQL and Redis for this project
62
129
  npm run prisma:generate
63
- npm run prisma:migrate:dev -- --name init
64
-
65
- # 3. Start the server
66
- npm run dev
130
+ npm run prisma:migrate:dev # creates the tables from the shipped first migration
131
+ npm run dev # http://localhost:8000
67
132
 
68
- # 4. In a new terminal, set up the client
133
+ # Client, in a second terminal
69
134
  cd my-app/client
70
- npm install
71
- cp .env.example .env
72
- npm run dev
135
+ npm ci
136
+ npm run dev # http://localhost:3000
73
137
  ```
74
138
 
75
- - Server: http://localhost:8000
76
- - Client: http://localhost:3000
77
- - phpMyAdmin: http://localhost:8080 (optional — see below)
78
- - Redis Commander: http://localhost:8081 (optional — see below)
139
+ The CLI already wrote `server/.env` and `client/.env` with fresh secrets. Do not copy `.env.example` over them: the
140
+ server refuses the example's placeholder secret.
141
+
142
+ The database admin tools are off by default. `npm run docker:tools` starts phpMyAdmin and Redis Commander on the
143
+ ports the CLI printed (also in `server/docker-compose.yml`); `npm run docker:down` stops everything.
144
+
145
+ ## Everyday commands
79
146
 
80
- The admin UIs (phpMyAdmin, Redis Commander) are behind the docker-compose `tools` profile and do **not** start with plain `docker compose up -d`. Start them with:
147
+ | In `server/` | What it does |
148
+ |---|---|
149
+ | `npm run dev` | API with reload on save |
150
+ | `npm test` / `npm run test:coverage` | unit tests (no database); with the coverage floor |
151
+ | `npm run test:integration` | every route against a real MySQL and Redis |
152
+ | `npm run lint` / `npm run typecheck` | ESLint / TypeScript |
153
+ | `npm run build` / `npm start` | production build / run it |
154
+ | `npm run prisma:migrate:dev` | create and apply a migration after a schema change |
155
+ | `npm run prisma:studio` | browse the database |
156
+ | `npm run make-admin -- you@example.com` | promote an existing account to admin |
157
+ | `npm run docker:up` / `docker:tools` / `docker:down` | local MySQL and Redis / plus the admin UIs / stop |
158
+
159
+ | In `client/` | What it does |
160
+ |---|---|
161
+ | `npm run dev` | the app with fast refresh |
162
+ | `npm test` / `npm run test:coverage` | unit tests / with the coverage floor |
163
+ | `npm run lint` / `npm run typecheck` | ESLint / TypeScript |
164
+ | `npm run build` / `npm start` | production build / run it locally (the Docker image runs the standalone `server.js`) |
165
+
166
+ ## Testing and CI
81
167
 
82
168
  ```bash
83
169
  cd my-app/server
84
- docker compose --profile tools up -d
170
+ npm test # unit tests: no database, no Docker
171
+ npm run test:coverage # the same, failing below the coverage floor
172
+ npm run test:integration # every route against a real MySQL + Redis
173
+
174
+ cd ../client
175
+ npm test # the client's logic: session rules, proxy, redirects, error parsing
176
+ npm run test:coverage
177
+ ```
178
+
179
+ The integration tests start a throwaway MySQL and Redis with Testcontainers (Docker must run). To use services you
180
+ already run instead, set `INTEGRATION_DATABASE_URL` (a database whose name ends in `_test`) and
181
+ `INTEGRATION_REDIS_URL` (a Redis database from 1 to 15): the suite empties both first. Every route has a contract
182
+ test (who may call it, wrong input, success), and that file fails when a new route is never called. Details:
183
+ `server/docs/testing.md`.
184
+
185
+ New projects ship GitHub workflows in `.github/`:
186
+
187
+ - `ci.yml`, on every push and pull request: typecheck, lint, unit tests with coverage and build for both apps, and
188
+ the server's integration tests (Testcontainers on GitHub's runners). It never deploys.
189
+ - `audit.yml`, weekly: `npm audit` of what production installs, red on a critical advisory. It does not block merges.
190
+ - `dependabot.yml`: security-update pull requests for npm packages and Actions (turn them on once in the
191
+ repository's Settings → Advanced Security → Dependabot security updates), and a monthly pull request that
192
+ refreshes the pinned `node:24-alpine` base image of both Dockerfiles (merge the two together).
193
+
194
+ ## Deploying to Coolify
195
+
196
+ Server and client deploy as two separate Coolify applications, each from its own Dockerfile (`server/Dockerfile`,
197
+ `client/Dockerfile`).
198
+
199
+ **Coolify checklist.** One Coolify project with two applications (from the same Git repository), a MySQL and a Redis:
200
+
201
+ | Setting | Server application | Client application |
202
+ |---|---|---|
203
+ | Build Pack | Dockerfile | Dockerfile |
204
+ | Base Directory | `/server` | `/client` |
205
+ | Ports Exposes | `8000` | `3000` |
206
+ | Domain | your API domain, e.g. `https://api.example.com` | your site, e.g. `https://example.com` |
207
+ | Health check | nothing to set: Coolify uses the Dockerfile's (`/api/v1/live`) | nothing to set: the Dockerfile's (`/healthz`) |
208
+ | Environment variables | from `server/.env.example.production`, runtime only: never tick "Available at Buildtime" | `NEXT_PUBLIC_API_BASE_URL` and `NEXT_PUBLIC_APP_NAME` with "Available at Buildtime" ticked: the build stops without the API address |
209
+ | Storage | a volume at `/app/uploads` (below) | none |
210
+
211
+ How the domains map to the variables:
212
+
213
+ ```text
214
+ NEXT_PUBLIC_API_BASE_URL (client) https://api.example.com/api/v1 the API domain + /api/v1
215
+ CORS_ORIGIN (server) https://example.com the site's origin exactly: no path, no trailing slash
216
+ CLIENT_URL (server) https://example.com used in the links of emails
217
+ COOKIE_DOMAIN (server) .example.com when site and API are sibling subdomains; unset on one host
218
+ DATABASE_URL (server) mysql://…internal…/app?connection_limit=5
219
+ REDIS_URL (server) redis://…internal… the internal URLs from Coolify's MySQL and Redis pages
220
+ ```
221
+
222
+ A wrong database URL fails the deploy at its migration step, and production refuses to start when it cannot reach
223
+ Redis within 10 s. Either way the old container keeps serving.
224
+
225
+ Deploy the server first (it applies the migrations), then the client. Afterwards sign in as an admin and open
226
+ `/api/v1/admin/health`: every check should be up. Coolify switches traffic to a new container only once its Dockerfile
227
+ health check passes, so a container that cannot start keeps the old one serving. Migrations run while the old
228
+ container still serves; before one that drops or renames anything, read `server/docs/deployment.md` (in this repo:
229
+ [template/server/docs/deployment.md](template/server/docs/deployment.md)), which also explains why a build without
230
+ Docker's cache takes about 6 to 7 minutes longer (it compiles libvips).
231
+
232
+ **The server needs a persistent volume for uploads.** Avatars and other uploaded files are written to `/app/uploads`
233
+ inside the container, and every deploy starts a fresh container, so without a volume they are lost on each redeploy.
234
+ In the server application: **Storages → Add Volume Mount**, leave *Source Path* empty (Coolify manages the volume),
235
+ *Destination Path* `/app/uploads`. The server warns at boot (`[STORAGE] … is not on a mounted volume`) when it runs in
236
+ production without one.
237
+
238
+ **First admin.** Sign up in the app with the account that should be the admin (verify its email if the email module
239
+ is on). Then open the server application's **Terminal** in Coolify and run:
240
+
241
+ ```bash
242
+ node dist/scripts/make-admin.js you@example.com
85
243
  ```
86
244
 
87
- ## Security and Migration Notes
245
+ It only changes that account's role and marks its email verified: no password is asked for or printed. Locally:
246
+ `npm run make-admin -- you@example.com` in `server/`. The same command recovers a project whose last admin was
247
+ demoted or banned by mistake.
248
+
249
+ **Background jobs** run inside the server process, so no extra Coolify service is needed, and with more than one
250
+ server replica each runs them too, which is safe.
251
+
252
+ ## Adding a module later
253
+
254
+ Modules add a feature to an existing project. Today there is one:
255
+
256
+ ```bash
257
+ cd my-app # the folder that holds server/ and client/
258
+ npx create-tigra add email-verification
259
+ ```
260
+
261
+ It adds the verification routes (`POST /auth/send-verification`, `POST /auth/verify-account`), their integration
262
+ tests, the client's `useVerifyAccount` / `useSendVerification` hooks and service, and sets `REQUIRE_USER_VERIFICATION=true` in `server/.env`.
263
+ Then set `RESEND_API_KEY` in `server/.env` and restart the server. Answering "yes" to the email question when you
264
+ create a project does the same. Run it on projects made with 4.x: it copies tests that use the 4.x test helpers.
265
+
266
+ ## Documentation
267
+
268
+ In every generated project:
269
+
270
+ | File | What it explains |
271
+ |---|---|
272
+ | `README.md`, `server/README.md`, `client/README.md` | what is where, how to run it |
273
+ | `server/docs/deployment.md` | what a deploy does, safe migrations (expand, deploy, contract), rollback, build time |
274
+ | `server/docs/rate-limits.md` | every limit, the login lockout, IP blocks, email caps, env overrides, Redis outages |
275
+ | `server/docs/testing.md` | unit and integration tests, writing new ones, CI, coverage |
276
+ | `server/docs/logging.md` | request logs, redaction, health checks |
277
+ | `server/.env.example`, `server/.env.example.production`, `client/.env.example*` | every setting, with notes |
278
+ | `AGENTS.md`, `server/AGENTS.md`, `client/AGENTS.md` | the rules agents (and people) follow when changing the code |
279
+
280
+ In this repository:
281
+
282
+ - [CHANGELOG.md](CHANGELOG.md): what changed in each release.
283
+ - [Client IP behind proxies and Cloudflare](docs/client-ip-behind-proxies.md): how the visitor address is verified,
284
+ and how to port it to an older project.
285
+ - [Account ban vs email verification](docs/account-ban-vs-email-verification.md) and
286
+ [Account deactivation and login](docs/account-deactivation-login-reactivation.md): two account-state fixes, with
287
+ porting steps.
288
+ - [Rate limits](template/server/docs/rate-limits.md), [deployment](template/server/docs/deployment.md),
289
+ [testing](template/server/docs/testing.md) and [logging](template/server/docs/logging.md): the same guides a
290
+ generated project ships.
291
+
292
+ ## Upgrading from 3.x
88
293
 
89
- - [Account deactivation login reactivation: issue, fix, and existing-project migration](docs/account-deactivation-login-reactivation.md)
294
+ A generated project never updates itself: it is your code from the moment it is created. 4.0 changed most of the
295
+ template (sessions, rate limits, uploads, the admin API, jobs, health checks, tests, the Docker images, the agent
296
+ rules and the client). [CHANGELOG.md](CHANGELOG.md) lists every change by area; the guides in `docs/` show how to port
297
+ the ones that need care. New projects need Node 24 and npm 11.19+ (the 3.3.0 images ran Node 20).
90
298
 
91
299
  ## License
92
300