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.
- package/CHANGELOG.md +151 -0
- package/README.md +264 -56
- package/bin/create-tigra.js +497 -472
- package/lib/patchers/email-verification.patcher.js +72 -10
- package/modules/email-verification/client/hooks/useVerification.ts +4 -1
- package/modules/email-verification/server/__tests__/verification.integration.test.ts +115 -0
- package/modules/email-verification/server/verification.controller.ts +3 -1
- package/modules/email-verification/server/verification.service.ts +44 -13
- package/package.json +5 -3
- package/template/.github/dependabot.yml +47 -0
- package/template/.github/workflows/audit.yml +36 -0
- package/template/.github/workflows/ci.yml +79 -0
- package/template/AGENTS.md +18 -9
- package/template/README.md +79 -0
- package/template/client/.dockerignore +1 -0
- package/template/client/.env.example.production +13 -2
- package/template/client/AGENTS.md +13 -5
- package/template/client/Dockerfile +186 -14
- package/template/client/README.md +92 -21
- package/template/client/next.config.ts +1 -1
- package/template/client/package-lock.json +15983 -14181
- package/template/client/package.json +56 -48
- package/template/client/scripts/check-sharp.mjs +53 -0
- package/template/client/scripts/next-dev.cjs +5 -1
- package/template/client/src/__tests__/proxy.test.ts +92 -0
- package/template/client/src/app/healthz/route.ts +16 -0
- package/template/client/src/app/layout.tsx +9 -3
- package/template/client/src/app/page.tsx +2 -2
- package/template/client/src/app/providers.tsx +23 -4
- package/template/client/src/components/layout/Header.tsx +7 -3
- package/template/client/src/features/admin/hooks/useAdminSessions.ts +2 -1
- package/template/client/src/features/admin/hooks/useAdminUsers.ts +3 -1
- package/template/client/src/features/admin/types/admin.types.ts +2 -3
- package/template/client/src/features/auth/components/AuthInitializer.tsx +35 -18
- package/template/client/src/features/auth/components/ForgotPasswordForm.tsx +107 -0
- package/template/client/src/features/auth/components/LimitNotice.tsx +28 -0
- package/template/client/src/features/auth/components/LoginForm.tsx +13 -2
- package/template/client/src/features/auth/components/RegisterForm.tsx +23 -7
- package/template/client/src/features/auth/hooks/useAuth.ts +11 -1
- package/template/client/src/features/auth/hooks/usePasswordReset.ts +7 -1
- package/template/client/src/features/auth/services/auth.service.ts +8 -3
- package/template/client/src/features/auth/store/authSlice.ts +7 -2
- package/template/client/src/lib/api/__tests__/axios.config.test.ts +183 -0
- package/template/client/src/lib/api/api.types.ts +14 -0
- package/template/client/src/lib/api/axios.config.ts +101 -15
- package/template/client/src/lib/api/hard-redirect.ts +8 -0
- package/template/client/src/lib/api/session-events.ts +29 -0
- package/template/client/src/lib/constants/routes.ts +12 -0
- package/template/client/src/lib/observability/sentry-scrub.ts +1 -1
- package/template/client/src/lib/utils/__tests__/error.test.ts +119 -0
- package/template/client/src/lib/utils/__tests__/form.test.ts +42 -0
- package/template/client/src/lib/utils/__tests__/paths.test.ts +43 -0
- package/template/client/src/lib/utils/__tests__/security.test.ts +40 -0
- package/template/client/src/lib/utils/__tests__/session-marker.test.ts +27 -0
- package/template/client/src/lib/utils/error.ts +81 -0
- package/template/client/src/lib/utils/form.ts +31 -0
- package/template/client/src/lib/utils/paths.ts +18 -0
- package/template/client/src/lib/utils/session-marker.ts +24 -0
- package/template/client/src/{middleware.ts → proxy.ts} +25 -11
- package/template/client/src/store/__tests__/store.test.ts +44 -0
- package/template/client/src/store/index.ts +26 -8
- package/template/client/vitest.config.mts +48 -0
- package/template/server/.env.example +280 -270
- package/template/server/.env.example.production +283 -242
- package/template/server/AGENTS.md +13 -4
- package/template/server/Dockerfile +176 -14
- package/template/server/README.md +108 -0
- package/template/server/docker-compose.yml +4 -2
- package/template/server/docs/deployment.md +63 -0
- package/template/server/docs/logging.md +66 -4
- package/template/server/docs/rate-limits.md +153 -0
- package/template/server/docs/testing.md +81 -0
- package/template/server/eslint.config.mjs +19 -0
- package/template/server/package-lock.json +8784 -8743
- package/template/server/package.json +79 -75
- package/template/server/prisma/migrations/0_init/migration.sql +82 -0
- package/template/server/prisma/migrations/migration_lock.toml +3 -0
- package/template/server/prisma/schema.prisma +0 -3
- package/template/server/scripts/check-heic.mjs +40 -0
- package/template/server/scripts/check-sharp.mjs +53 -0
- package/template/server/src/__tests__/routes.integration.test.ts +280 -0
- package/template/server/src/app.ts +248 -346
- package/template/server/src/config/__tests__/env.test.ts +219 -0
- package/template/server/src/config/__tests__/rate-limit.config.test.ts +158 -0
- package/template/server/src/config/env.ts +326 -182
- package/template/server/src/config/rate-limit.config.ts +157 -106
- package/template/server/src/jobs/__tests__/cleanup-deleted-accounts.job.test.ts +60 -8
- package/template/server/src/jobs/__tests__/cleanup-expired-auth.job.test.ts +44 -0
- package/template/server/src/jobs/__tests__/jobs.integration.test.ts +88 -0
- package/template/server/src/jobs/__tests__/schedule.test.ts +92 -0
- package/template/server/src/jobs/cleanup-deleted-accounts.job.ts +38 -36
- package/template/server/src/jobs/cleanup-expired-auth.job.ts +32 -24
- package/template/server/src/jobs/index.ts +12 -2
- package/template/server/src/jobs/refresh-cloudflare-ranges.job.ts +28 -0
- package/template/server/src/jobs/schedule.ts +50 -0
- package/template/server/src/libs/__tests__/auth.test.ts +98 -7
- package/template/server/src/libs/__tests__/client-ip.test.ts +257 -121
- package/template/server/src/libs/__tests__/cloudflare-ranges.test.ts +79 -0
- package/template/server/src/libs/__tests__/cookies.test.ts +53 -2
- package/template/server/src/libs/__tests__/email-quota.test.ts +81 -0
- package/template/server/src/libs/__tests__/email.test.ts +68 -0
- package/template/server/src/libs/__tests__/error-handler.test.ts +162 -0
- package/template/server/src/libs/__tests__/health-db-down.integration.test.ts +37 -0
- package/template/server/src/libs/__tests__/health-redis-down.integration.test.ts +45 -0
- package/template/server/src/libs/__tests__/health-routes.test.ts +83 -0
- package/template/server/src/libs/__tests__/health.integration.test.ts +118 -0
- package/template/server/src/libs/__tests__/http.test.ts +74 -2
- package/template/server/src/libs/__tests__/ip-block.test.ts +179 -62
- package/template/server/src/libs/__tests__/logger.test.ts +50 -0
- package/template/server/src/libs/__tests__/monitoring.test.ts +185 -0
- package/template/server/src/libs/__tests__/outbound.integration.test.ts +48 -0
- package/template/server/src/libs/__tests__/prisma-client.test.ts +28 -0
- package/template/server/src/libs/__tests__/query-counter.integration.test.ts +53 -0
- package/template/server/src/libs/__tests__/rate-limiting.test.ts +146 -0
- package/template/server/src/libs/__tests__/rate-limits.integration.test.ts +53 -0
- package/template/server/src/libs/__tests__/redis-required.test.ts +30 -0
- package/template/server/src/libs/__tests__/redis.test.ts +38 -2
- package/template/server/src/libs/__tests__/request-id.test.ts +25 -0
- package/template/server/src/libs/__tests__/requestLogger.test.ts +126 -0
- package/template/server/src/libs/__tests__/safe-http.test.ts +138 -0
- package/template/server/src/libs/__tests__/sentry-scrub.test.ts +82 -80
- package/template/server/src/libs/__tests__/shutdown.test.ts +89 -0
- package/template/server/src/libs/__tests__/url-safety.test.ts +130 -80
- package/template/server/src/libs/auth.ts +39 -10
- package/template/server/src/libs/client-ip.ts +158 -77
- package/template/server/src/libs/cloudflare-ranges.ts +132 -0
- package/template/server/src/libs/cookies.ts +53 -14
- package/template/server/src/libs/email-quota.ts +74 -0
- package/template/server/src/libs/email.ts +46 -9
- package/template/server/src/libs/error-handler.ts +111 -0
- package/template/server/src/libs/health-routes.ts +53 -0
- package/template/server/src/libs/http.ts +139 -47
- package/template/server/src/libs/ip-address.ts +37 -0
- package/template/server/src/libs/ip-block.ts +284 -221
- package/template/server/src/libs/logger.ts +41 -12
- package/template/server/src/libs/monitoring.ts +127 -41
- package/template/server/src/libs/observability/sentry.ts +1 -1
- package/template/server/src/libs/origin-check.ts +9 -7
- package/template/server/src/libs/prisma.ts +47 -4
- package/template/server/src/libs/query-counter.ts +71 -59
- package/template/server/src/libs/rate-limiting.ts +110 -0
- package/template/server/src/libs/redis-required.ts +28 -0
- package/template/server/src/libs/redis.ts +27 -1
- package/template/server/src/libs/request-id.ts +18 -0
- package/template/server/src/libs/requestLogger.ts +112 -17
- package/template/server/src/libs/safe-http.ts +101 -0
- package/template/server/src/libs/shutdown.ts +87 -0
- package/template/server/src/libs/storage/__tests__/fixtures/tiny-heic.ts +13 -0
- package/template/server/src/libs/storage/__tests__/image-optimizer.test.ts +59 -0
- package/template/server/src/libs/storage/__tests__/multipart-limits.test.ts +91 -0
- package/template/server/src/libs/storage/__tests__/upload-persistence.test.ts +52 -0
- package/template/server/src/libs/storage/file-storage.service.ts +94 -84
- package/template/server/src/libs/storage/file-validator.ts +48 -46
- package/template/server/src/libs/storage/image-optimizer.service.ts +16 -5
- package/template/server/src/libs/token-hash.ts +18 -0
- package/template/server/src/libs/url-safety.ts +127 -121
- package/template/server/src/libs/validation-errors.ts +86 -0
- package/template/server/src/modules/admin/__tests__/admin-actions.integration.test.ts +255 -0
- package/template/server/src/modules/admin/__tests__/admin.health.test.ts +82 -0
- package/template/server/src/modules/admin/__tests__/admin.repo.test.ts +55 -0
- package/template/server/src/modules/admin/__tests__/admin.schemas.test.ts +38 -0
- package/template/server/src/modules/admin/__tests__/admin.service.test.ts +162 -0
- package/template/server/src/modules/admin/admin.controller.ts +66 -49
- package/template/server/src/modules/admin/admin.repo.ts +49 -10
- package/template/server/src/modules/admin/admin.routes.ts +48 -2
- package/template/server/src/modules/admin/admin.schemas.ts +18 -6
- package/template/server/src/modules/admin/admin.service.ts +66 -4
- package/template/server/src/modules/auth/__tests__/auth.controller.test.ts +39 -0
- package/template/server/src/modules/auth/__tests__/auth.integration.test.ts +9 -3
- package/template/server/src/modules/auth/__tests__/auth.service.dummy-hash.test.ts +34 -0
- package/template/server/src/modules/auth/__tests__/auth.service.test.ts +197 -37
- package/template/server/src/modules/auth/__tests__/session-cleanup.test.ts +39 -0
- package/template/server/src/modules/auth/__tests__/sessions.integration.test.ts +246 -0
- package/template/server/src/modules/auth/__tests__/token-fingerprints.test.ts +119 -0
- package/template/server/src/modules/auth/auth.controller.ts +133 -128
- package/template/server/src/modules/auth/auth.repo.ts +44 -44
- package/template/server/src/modules/auth/auth.schemas.ts +4 -2
- package/template/server/src/modules/auth/auth.service.ts +167 -96
- package/template/server/src/modules/auth/session.repo.ts +12 -0
- package/template/server/src/modules/files/__tests__/files.integration.test.ts +5 -5
- package/template/server/src/modules/users/__tests__/avatar-upload.test.ts +120 -0
- package/template/server/src/modules/users/__tests__/name-rules.test.ts +46 -0
- package/template/server/src/modules/users/__tests__/users.integration.test.ts +295 -0
- package/template/server/src/modules/users/__tests__/users.repo.test.ts +37 -0
- package/template/server/src/modules/users/__tests__/users.service.test.ts +129 -0
- package/template/server/src/modules/users/users.controller.ts +9 -38
- package/template/server/src/modules/users/users.repo.ts +23 -7
- package/template/server/src/modules/users/users.routes.ts +3 -22
- package/template/server/src/modules/users/users.schemas.ts +15 -9
- package/template/server/src/modules/users/users.service.ts +105 -93
- package/template/server/src/scripts/make-admin.ts +48 -0
- package/template/server/src/server.ts +48 -26
- package/template/server/src/shared/errors/AppError.ts +27 -1
- package/template/server/src/shared/errors/errors.ts +42 -5
- package/template/server/src/shared/responses/successResponse.ts +22 -3
- package/template/server/src/shared/types/index.ts +7 -0
- package/template/server/src/test/__tests__/integration-services.test.ts +66 -0
- package/template/server/src/test/integration-helpers.ts +343 -0
- package/template/server/src/test/integration-services.ts +74 -0
- package/template/server/src/test/integration.global-setup.ts +144 -0
- package/template/server/src/test/integration.setup.ts +35 -158
- package/template/server/src/test/setup.ts +3 -10
- package/template/server/tsconfig.build.json +1 -1
- package/template/server/tsconfig.json +1 -0
- package/template/server/vitest.config.ts +17 -4
- package/template/server/vitest.integration.config.ts +18 -13
- package/template/server/src/libs/storage/filename-sanitizer.ts +0 -71
|
@@ -1,242 +1,283 @@
|
|
|
1
|
-
# ===================================================================
|
|
2
|
-
# PRODUCTION ENVIRONMENT CONFIGURATION
|
|
3
|
-
# ===================================================================
|
|
4
|
-
# This file contains production-optimized settings for high-traffic
|
|
5
|
-
# deployments (10K-100K users/day). Copy to .env and customize.
|
|
6
|
-
#
|
|
7
|
-
# COOLIFY DEPLOYMENT NOTE:
|
|
8
|
-
# When adding environment variables in Coolify, do NOT check
|
|
9
|
-
# "Available at Buildtime" for any variable unless explicitly noted.
|
|
10
|
-
# The server Dockerfile handles build-time config internally.
|
|
11
|
-
# Secrets (DATABASE_URL, JWT_SECRET, COOKIE_SECRET, REDIS_URL) must
|
|
12
|
-
# NEVER be available at buildtime — they get baked into the image layer.
|
|
13
|
-
#
|
|
14
|
-
# ===================================================================
|
|
15
|
-
|
|
16
|
-
# ===================================================================
|
|
17
|
-
# APPLICATION
|
|
18
|
-
# ===================================================================
|
|
19
|
-
|
|
20
|
-
# COOLIFY: Do NOT check "Available at Buildtime" — the Dockerfile
|
|
21
|
-
# sets NODE_ENV=development during build to ensure devDependencies install.
|
|
22
|
-
NODE_ENV=production
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
#
|
|
45
|
-
# COOLIFY: Runtime only. Do NOT check "Available at Buildtime".
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
|
|
58
|
-
#
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
#
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
# ===================================================================
|
|
68
|
-
|
|
69
|
-
#
|
|
70
|
-
|
|
71
|
-
#
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
#
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
|
|
86
|
-
#
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
#
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
#
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
#
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
#
|
|
115
|
-
#
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
#
|
|
119
|
-
#
|
|
120
|
-
#
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
#
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
#
|
|
131
|
-
#
|
|
132
|
-
#
|
|
133
|
-
|
|
134
|
-
#
|
|
135
|
-
#
|
|
136
|
-
#
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
#
|
|
140
|
-
|
|
141
|
-
# ===================================================================
|
|
142
|
-
|
|
143
|
-
#
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
#
|
|
147
|
-
#
|
|
148
|
-
#
|
|
149
|
-
#
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
#
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
#
|
|
157
|
-
#
|
|
158
|
-
#
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
#
|
|
162
|
-
#
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
#
|
|
166
|
-
#
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
#
|
|
170
|
-
#
|
|
171
|
-
#
|
|
172
|
-
#
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
#
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
#
|
|
180
|
-
#
|
|
181
|
-
#
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
#
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
#
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
#
|
|
196
|
-
|
|
197
|
-
#
|
|
198
|
-
#
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
#
|
|
202
|
-
#
|
|
203
|
-
#
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
#
|
|
207
|
-
#
|
|
208
|
-
#
|
|
209
|
-
|
|
210
|
-
#
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
#
|
|
215
|
-
|
|
216
|
-
#
|
|
217
|
-
#
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
#
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
#
|
|
227
|
-
#
|
|
228
|
-
|
|
229
|
-
#
|
|
230
|
-
#
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
#
|
|
234
|
-
#
|
|
235
|
-
#
|
|
236
|
-
|
|
237
|
-
#
|
|
238
|
-
#
|
|
239
|
-
#
|
|
240
|
-
#
|
|
241
|
-
#
|
|
242
|
-
#
|
|
1
|
+
# ===================================================================
|
|
2
|
+
# PRODUCTION ENVIRONMENT CONFIGURATION
|
|
3
|
+
# ===================================================================
|
|
4
|
+
# This file contains production-optimized settings for high-traffic
|
|
5
|
+
# deployments (10K-100K users/day). Copy to .env and customize.
|
|
6
|
+
#
|
|
7
|
+
# COOLIFY DEPLOYMENT NOTE:
|
|
8
|
+
# When adding environment variables in Coolify, do NOT check
|
|
9
|
+
# "Available at Buildtime" for any variable unless explicitly noted.
|
|
10
|
+
# The server Dockerfile handles build-time config internally.
|
|
11
|
+
# Secrets (DATABASE_URL, JWT_SECRET, COOKIE_SECRET, REDIS_URL) must
|
|
12
|
+
# NEVER be available at buildtime — they get baked into the image layer.
|
|
13
|
+
#
|
|
14
|
+
# ===================================================================
|
|
15
|
+
|
|
16
|
+
# ===================================================================
|
|
17
|
+
# APPLICATION
|
|
18
|
+
# ===================================================================
|
|
19
|
+
|
|
20
|
+
# COOLIFY: Do NOT check "Available at Buildtime" — the Dockerfile
|
|
21
|
+
# sets NODE_ENV=development during build to ensure devDependencies install.
|
|
22
|
+
NODE_ENV=production
|
|
23
|
+
# Keep 8000: the Dockerfile EXPOSEs it, its HEALTHCHECK and Coolify's port setting use it.
|
|
24
|
+
PORT=8000
|
|
25
|
+
HOST=0.0.0.0
|
|
26
|
+
|
|
27
|
+
# ===================================================================
|
|
28
|
+
# SERVER TIMEOUTS
|
|
29
|
+
# ===================================================================
|
|
30
|
+
|
|
31
|
+
# Fastify request timeout in milliseconds (default: 30000 = 30s)
|
|
32
|
+
# Long-running routes (LLM calls, big exports) may need 180000+ (180s).
|
|
33
|
+
# CRITICAL: the reverse proxy (Nginx/Coolify) timeout must be raised to
|
|
34
|
+
# match, or the proxy cuts the connection before the server does.
|
|
35
|
+
REQUEST_TIMEOUT_MS=30000
|
|
36
|
+
|
|
37
|
+
# Fastify connection timeout in milliseconds (default: 60000 = 60s)
|
|
38
|
+
CONNECTION_TIMEOUT_MS=60000
|
|
39
|
+
|
|
40
|
+
# ===================================================================
|
|
41
|
+
# DATABASE (MySQL 8.4 LTS; 8.0+ works)
|
|
42
|
+
# ===================================================================
|
|
43
|
+
|
|
44
|
+
# Production database connection.
|
|
45
|
+
# COOLIFY: Runtime only. Do NOT check "Available at Buildtime".
|
|
46
|
+
# A MySQL on Coolify's own network: use its internal host name (shown on the
|
|
47
|
+
# database's page in Coolify), a dedicated user and password. That network is
|
|
48
|
+
# private, so no TLS parameter is needed. A wrong URL fails the deploy: the
|
|
49
|
+
# container runs `prisma migrate deploy` before the server starts.
|
|
50
|
+
DATABASE_URL="mysql://app_user:CHANGE_ME_password@mysql-internal-host:3306/app_db?connection_limit=5"
|
|
51
|
+
|
|
52
|
+
# A MySQL OUTSIDE Coolify's network (another server, a managed database):
|
|
53
|
+
# require TLS with Prisma's sslaccept argument (and sslcert=<path> when the
|
|
54
|
+
# server uses its own CA). `?ssl=true` is not a Prisma argument and does
|
|
55
|
+
# nothing. For example:
|
|
56
|
+
# DATABASE_URL="mysql://app_user:CHANGE_ME_password@db.example.com:3306/app_db?connection_limit=5&sslaccept=strict"
|
|
57
|
+
|
|
58
|
+
# Connection pool: sized INSIDE DATABASE_URL (Prisma 6 has no separate pool
|
|
59
|
+
# variables): ?connection_limit=N&pool_timeout=S. Without connection_limit
|
|
60
|
+
# Prisma opens (physical CPU cores x 2) + 1 connections per server process, so
|
|
61
|
+
# a few apps on one shared MySQL can exhaust its max_connections; 5 is plenty
|
|
62
|
+
# for one app's typical load. Keep the total of all processes below the
|
|
63
|
+
# database's max_connections.
|
|
64
|
+
|
|
65
|
+
# ===================================================================
|
|
66
|
+
# REDIS
|
|
67
|
+
# ===================================================================
|
|
68
|
+
|
|
69
|
+
# Production Redis instance. REQUIRED: the server refuses to start in production
|
|
70
|
+
# without it (rate limits, login lockout and IP blocks all live in Redis), and
|
|
71
|
+
# also when it cannot reach it within 10 s at boot (a wrong host or password
|
|
72
|
+
# fails the deploy instead of running with those protections off; on Coolify
|
|
73
|
+
# the old container keeps serving). Outages after boot are not fatal.
|
|
74
|
+
# CRITICAL: Use authentication and private network
|
|
75
|
+
# COOLIFY: Runtime only. Do NOT check "Available at Buildtime".
|
|
76
|
+
REDIS_URL="redis://:REDIS_PASSWORD@redis.internal:6379"
|
|
77
|
+
|
|
78
|
+
# Production retry settings
|
|
79
|
+
REDIS_MAX_RETRIES=5
|
|
80
|
+
REDIS_CONNECT_TIMEOUT=5000
|
|
81
|
+
|
|
82
|
+
# ===================================================================
|
|
83
|
+
# RATE LIMITING
|
|
84
|
+
# ===================================================================
|
|
85
|
+
|
|
86
|
+
# Always enabled in production. On/off switches accept only true or false.
|
|
87
|
+
RATE_LIMIT_ENABLED=true
|
|
88
|
+
|
|
89
|
+
# Production: keep at 1 (default limits are tuned for production)
|
|
90
|
+
RATE_LIMIT_MULTIPLIER=1
|
|
91
|
+
|
|
92
|
+
# Change any single limit: NAME=MAX/WINDOW, comma-separated, WINDOW like 30s, 15m, 1h.
|
|
93
|
+
# NAME = a key of RATE_LIMITS in src/config/rate-limit.config.ts, DEFAULT (every
|
|
94
|
+
# route without its own limit, 200/1m) or EMAIL_PER_ADDRESS (emails to one address,
|
|
95
|
+
# 3/1h). A typo stops the server at boot. The multiplier still applies on top.
|
|
96
|
+
# All limits, the lockout, the email cap and the auto-block: docs/rate-limits.md
|
|
97
|
+
# Example: RATE_LIMIT_OVERRIDES=AUTH_LOGIN=200/15m,DEFAULT=300/1m
|
|
98
|
+
RATE_LIMIT_OVERRIDES=
|
|
99
|
+
|
|
100
|
+
# Client IP: nothing to configure. The server trusts only its own proxy (Coolify's
|
|
101
|
+
# Traefik) and recognises Cloudflare by its published edge ranges, so rate limits and
|
|
102
|
+
# IP blocks see the real visitor both behind Cloudflare and without it. A leftover
|
|
103
|
+
# TRUST_CLOUDFLARE variable is ignored. See docs/client-ip-behind-proxies.md.
|
|
104
|
+
#
|
|
105
|
+
# Recommended behind Cloudflare: prove requests came through YOUR zone. Add a
|
|
106
|
+
# Cloudflare Transform Rule (Rules > Transform Rules > Modify Request Header) that
|
|
107
|
+
# sets the static header X-Origin-Verify to this value for the app's hostname. Then
|
|
108
|
+
# Cloudflare's visitor header is believed only on requests that carry it, so another
|
|
109
|
+
# Cloudflare customer's Worker cannot forge visitor addresses. Generate:
|
|
110
|
+
# openssl rand -hex 32
|
|
111
|
+
# COOLIFY: Runtime only. Do NOT check "Available at Buildtime". Leave empty if unused.
|
|
112
|
+
CLOUDFLARE_ORIGIN_SECRET=
|
|
113
|
+
|
|
114
|
+
# ===================================================================
|
|
115
|
+
# IP AUTO-BLOCK
|
|
116
|
+
# ===================================================================
|
|
117
|
+
|
|
118
|
+
# Rate-limit violations before an IP is auto-blocked for every route.
|
|
119
|
+
# Keep HIGH enough that a retry-looping legitimate client or a NAT'd
|
|
120
|
+
# office sharing one egress IP cannot self-ban (sustained abuse only).
|
|
121
|
+
# See src/config/rate-limit.config.ts before lowering.
|
|
122
|
+
IP_AUTO_BLOCK_THRESHOLD=20
|
|
123
|
+
|
|
124
|
+
# Sliding window for counting violations, in seconds (5 minutes)
|
|
125
|
+
IP_AUTO_BLOCK_WINDOW_SECONDS=300
|
|
126
|
+
|
|
127
|
+
# How long an auto-blocked IP stays blocked, in seconds (1 hour)
|
|
128
|
+
IP_AUTO_BLOCK_DURATION_SECONDS=3600
|
|
129
|
+
|
|
130
|
+
# ===================================================================
|
|
131
|
+
# ACCOUNT ACTIVATION
|
|
132
|
+
# ===================================================================
|
|
133
|
+
|
|
134
|
+
# Require email verification before users can sign in. true only with the
|
|
135
|
+
# email-verification module (it switches this to true when added): without it
|
|
136
|
+
# there is no verify route and nobody could sign in. Needs RESEND_API_KEY.
|
|
137
|
+
REQUIRE_USER_VERIFICATION=false
|
|
138
|
+
|
|
139
|
+
# ===================================================================
|
|
140
|
+
# FILE UPLOAD
|
|
141
|
+
# ===================================================================
|
|
142
|
+
|
|
143
|
+
# Maximum file upload size in MB
|
|
144
|
+
MAX_FILE_SIZE_MB=10
|
|
145
|
+
|
|
146
|
+
# Two-tier upload storage. BOTH optional — defaults are <cwd>/uploads/public and
|
|
147
|
+
# <cwd>/uploads/private. Keep them UNDER /app/uploads (the Coolify volume below)
|
|
148
|
+
# so files survive redeploys.
|
|
149
|
+
# PUBLIC tier: static files at /uploads/ — viewable by ANYONE (e.g. avatars).
|
|
150
|
+
# PRIVATE tier: OUTSIDE the static root; served ONLY via the auth-gated,
|
|
151
|
+
# owner-scoped route GET /api/v1/files/:filename.
|
|
152
|
+
# UPLOAD_PUBLIC_DIR=/app/uploads/public
|
|
153
|
+
# UPLOAD_PRIVATE_DIR=/app/uploads/private
|
|
154
|
+
|
|
155
|
+
# COOLIFY PERSISTENT STORAGE (required for uploads to survive redeployments):
|
|
156
|
+
# Go to your service in Coolify → Storages → Add Volume Mount:
|
|
157
|
+
# Name: uploads (or <project-name>-uploads)
|
|
158
|
+
# Source Path: (leave empty — Coolify manages the Docker volume)
|
|
159
|
+
# Destination Path: /app/uploads
|
|
160
|
+
# Without this, all uploaded files are lost on every redeployment. The server
|
|
161
|
+
# logs a "[STORAGE] ... is not on a mounted volume" warning at boot when it
|
|
162
|
+
# runs in a production container without it.
|
|
163
|
+
|
|
164
|
+
# ===================================================================
|
|
165
|
+
# JWT AUTHENTICATION
|
|
166
|
+
# ===================================================================
|
|
167
|
+
|
|
168
|
+
# CRITICAL: Generate a cryptographically secure secret: openssl rand -hex 48
|
|
169
|
+
# The value below is EXAMPLE TEXT, not a real secret. Every committed example
|
|
170
|
+
# secret starts with CHANGE_ME, and the server refuses to boot with it
|
|
171
|
+
# (src/config/env.ts), so a forgotten placeholder fails loudly.
|
|
172
|
+
# COOLIFY: Runtime only. Do NOT check "Available at Buildtime" — this is a secret!
|
|
173
|
+
JWT_SECRET="CHANGE_ME_generate_with_openssl_rand_hex_48"
|
|
174
|
+
|
|
175
|
+
# Production token expiry (tighter security)
|
|
176
|
+
JWT_ACCESS_EXPIRY="15m"
|
|
177
|
+
JWT_REFRESH_EXPIRY="7d"
|
|
178
|
+
|
|
179
|
+
# Cookie signing secret (separate from JWT for defense-in-depth).
|
|
180
|
+
# EXAMPLE TEXT: generate a different value with openssl rand -hex 48.
|
|
181
|
+
# COOLIFY: Runtime only. Do NOT check "Available at Buildtime" — this is a secret!
|
|
182
|
+
COOKIE_SECRET="CHANGE_ME_generate_with_openssl_rand_hex_48"
|
|
183
|
+
|
|
184
|
+
# ===================================================================
|
|
185
|
+
# CORS
|
|
186
|
+
# ===================================================================
|
|
187
|
+
|
|
188
|
+
# REQUIRED in production - your frontend domain(s)
|
|
189
|
+
# Multiple origins separated by commas. Bare origins only (https://host,
|
|
190
|
+
# no path, no trailing slash, no *): the server refuses anything else at boot.
|
|
191
|
+
# Use https: the login cookies are Secure in production, and browsers drop them
|
|
192
|
+
# over plain http (the server warns at boot when it sees http:// here).
|
|
193
|
+
CORS_ORIGIN="https://yourdomain.com,https://app.yourdomain.com"
|
|
194
|
+
|
|
195
|
+
# Cookie domain when client and API run on sibling subdomains of one domain
|
|
196
|
+
# (the only split setup supported: the cookies stay SameSite Strict/Lax).
|
|
197
|
+
# REQUIRED when client and API are on different subdomains:
|
|
198
|
+
# Client: https://app.example.com | API: https://api.example.com
|
|
199
|
+
# → Set COOKIE_DOMAIN=".example.com" (leading dot = all subdomains)
|
|
200
|
+
# Only the non-secret auth_session indicator uses this domain, so the client's
|
|
201
|
+
# middleware can see a session exists. The access/refresh token cookies stay
|
|
202
|
+
# host-only on the API and are never sent to other subdomains.
|
|
203
|
+
# Without it, the client keeps redirecting signed-in users to /login.
|
|
204
|
+
COOKIE_DOMAIN=".yourdomain.com"
|
|
205
|
+
|
|
206
|
+
# ===================================================================
|
|
207
|
+
# EMAIL (Resend)
|
|
208
|
+
# ===================================================================
|
|
209
|
+
|
|
210
|
+
# Resend API key for transactional emails
|
|
211
|
+
# COOLIFY: Runtime only. Do NOT check "Available at Buildtime" — this is a secret!
|
|
212
|
+
RESEND_API_KEY="CHANGE_ME_your_resend_api_key"
|
|
213
|
+
|
|
214
|
+
# Sender email — must be from a verified domain in Resend
|
|
215
|
+
# With a Resend key set, the server refuses to start in production while the key
|
|
216
|
+
# or this sender is still the placeholder, and warns on Resend's test sender
|
|
217
|
+
# onboarding@resend.dev (it delivers only to your own Resend account's address).
|
|
218
|
+
RESEND_FROM_EMAIL="noreply@yourdomain.com"
|
|
219
|
+
|
|
220
|
+
# Frontend URL for email links (password reset, verification, etc.).
|
|
221
|
+
# Required in production when RESEND_API_KEY is set: the server refuses to start
|
|
222
|
+
# without it, since every email link would otherwise point at localhost.
|
|
223
|
+
CLIENT_URL="https://yourdomain.com"
|
|
224
|
+
|
|
225
|
+
# ===================================================================
|
|
226
|
+
# LOGGING
|
|
227
|
+
# ===================================================================
|
|
228
|
+
|
|
229
|
+
# Production: info or warn (reduces log volume)
|
|
230
|
+
# Use warn to reduce costs in high-traffic scenarios
|
|
231
|
+
LOG_LEVEL=info
|
|
232
|
+
|
|
233
|
+
# ===================================================================
|
|
234
|
+
# DATABASE SEEDING
|
|
235
|
+
# ===================================================================
|
|
236
|
+
|
|
237
|
+
# DO NOT SEED PRODUCTION. The seed script (npm run prisma:seed) creates
|
|
238
|
+
# well-known demo accounts (admin@example.com) and hard-refuses to run when
|
|
239
|
+
# NODE_ENV=production. These variables exist only to keep .env files in sync
|
|
240
|
+
# across environments — leave them commented out in production.
|
|
241
|
+
# SEED_ADMIN_PASSWORD=
|
|
242
|
+
# SEED_USER_PASSWORD=
|
|
243
|
+
|
|
244
|
+
# ===================================================================
|
|
245
|
+
# ERROR TRACKING
|
|
246
|
+
# ===================================================================
|
|
247
|
+
|
|
248
|
+
# Sentry for production error monitoring (leave unset to disable — fully inert)
|
|
249
|
+
# Get your DSN from: https://sentry.io/settings/projects/
|
|
250
|
+
SENTRY_DSN="https://YOUR_PUBLIC_KEY@o0.ingest.sentry.io/YOUR_PROJECT_ID"
|
|
251
|
+
|
|
252
|
+
# Fraction of transactions sampled for performance tracing (0.0–1.0, default 0.1).
|
|
253
|
+
SENTRY_TRACES_SAMPLE_RATE=0.1
|
|
254
|
+
|
|
255
|
+
# Environment tag on Sentry events (defaults to NODE_ENV when unset).
|
|
256
|
+
SENTRY_ENVIRONMENT=production
|
|
257
|
+
|
|
258
|
+
# ===================================================================
|
|
259
|
+
# DEPLOYMENT
|
|
260
|
+
# ===================================================================
|
|
261
|
+
|
|
262
|
+
# SOURCE_COMMIT: the deployed git commit, set by Coolify (a predefined
|
|
263
|
+
# variable). Do not set it yourself. Shown as "commit" in
|
|
264
|
+
# GET /api/v1/admin/health; null there when it is not set.
|
|
265
|
+
|
|
266
|
+
# ===================================================================
|
|
267
|
+
# PRODUCTION CHECKLIST
|
|
268
|
+
# ===================================================================
|
|
269
|
+
# [ ] DATABASE_URL uses a dedicated user, a strong password and connection_limit
|
|
270
|
+
# (TLS via sslaccept=strict when the database is outside Coolify's network)
|
|
271
|
+
# [ ] JWT_SECRET is a strong random string (openssl rand -hex 48), not the CHANGE_ME example
|
|
272
|
+
# [ ] COOKIE_SECRET is a different strong random string, not the CHANGE_ME example
|
|
273
|
+
# [ ] CORS_ORIGIN is set to your exact frontend URL(s)
|
|
274
|
+
# [ ] COOKIE_DOMAIN is set if client and API are on different subdomains
|
|
275
|
+
# [ ] REDIS_URL uses authentication if Redis is exposed
|
|
276
|
+
# [ ] LOG_LEVEL is set to info or warn
|
|
277
|
+
# [ ] SENTRY_DSN is configured for error tracking
|
|
278
|
+
# [ ] Database connection pool tested under load (all apps together stay below max_connections)
|
|
279
|
+
# [ ] All secrets are stored in environment variables, not in code
|
|
280
|
+
# [ ] SSL/TLS certificates are configured
|
|
281
|
+
# [ ] Firewall rules restrict access to database and Redis
|
|
282
|
+
# [ ] In Coolify: NO secrets have "Available at Buildtime" checked
|
|
283
|
+
# [ ] In Coolify: NODE_ENV does NOT have "Available at Buildtime" checked
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Server
|
|
1
|
+
# Server agent instructions
|
|
2
2
|
|
|
3
3
|
## Architecture and naming
|
|
4
4
|
|
|
@@ -6,23 +6,32 @@
|
|
|
6
6
|
- Domain modules live in `src/modules/<domain>/` with `<domain>.routes.ts`, `.controller.ts`, `.service.ts`, `.repo.ts`, and `.schemas.ts`.
|
|
7
7
|
- All API routes use the `/api/v1` prefix. Use the shared `successResponse`, `paginatedResponse`, and typed `AppError` contracts rather than custom response/error shapes.
|
|
8
8
|
- Use the shared logger and outbound HTTP client. Never add ad-hoc `console.log`, raw `fetch`, or per-call HTTP clients that bypass redaction, timeouts, and error mapping.
|
|
9
|
+
- Fetch a URL that came from a user (a link, webhook, import or avatar URL) only with `safeHttpClient` (`src/libs/safe-http.ts`), never `httpClient` or `fetch`: it refuses internal addresses on every hop.
|
|
10
|
+
- Recurring work (cleanups, syncs, reminders) goes through `startRecurringJob` (`src/jobs/schedule.ts`), registered in `src/jobs/index.ts`, never a bare `setInterval`: it first runs about a minute after every start, so frequent deploys never postpone it, and a run never overlaps the previous one.
|
|
9
11
|
|
|
10
12
|
## Sources of truth
|
|
11
13
|
|
|
12
|
-
- `prisma/schema.prisma` owns models, relations, indexes, and database naming. Change schema through reviewed Prisma migrations; production is forward-only with `prisma migrate deploy`.
|
|
14
|
+
- `prisma/schema.prisma` owns models, relations, indexes, and database naming. Change schema through reviewed Prisma migrations; production is forward-only with `prisma migrate deploy`. `prisma/migrations/0_init` (shipped with the template) creates the first tables; never edit or delete an applied migration, add a new one with `npm run prisma:migrate:dev`. Every deploy applies new migrations while the old version is still serving (`docs/deployment.md`): never drop, rename, retype or make a column required in the same deploy as the code that stops using it. Prisma writes a renamed field as drop + add, which loses the data; to rename only in the code, keep the database name with `@map` / `@@map`.
|
|
13
15
|
- `src/config/env.ts` owns runtime configuration validation. Keep `.env.example` and `.env.example.production` synchronized, but keep real secrets out of the repository and image.
|
|
14
16
|
- Zod route schemas own external input validation. Services own authorization and business invariants; repositories must not decide access policy.
|
|
17
|
+
- Wrong input has one answer: 422 `VALIDATION_FAILED` with `error.fields` (`src/libs/validation-errors.ts`, applied by `src/libs/error-handler.ts` to route schemas and `ZodError`). Validate inside a handler with `parseInput(schema, data)`, never a hand-made `ValidationError(issues[0].message)`. Messages describe the rule; never put a submitted value into one.
|
|
15
18
|
|
|
16
19
|
## Security and deployment
|
|
17
20
|
|
|
18
21
|
- Preserve httpOnly cookie auth, production CORS allowlists, state-changing request origin checks, rate limiting, safe client IP handling, generic 500 responses, and server-side-only diagnostic logging.
|
|
22
|
+
- Rate limits have one source, `src/config/rate-limit.config.ts` (`docs/rate-limits.md` explains all of them). A new route gets the 200/min default automatically; give it its own `RATE_LIMITS` entry only when it needs another number. Every "slow down" answer must be a `TooManyRequestsError` (or `IP_BLOCKED`) carrying `retryAfterSeconds`. Any new flow that sends email anyone can trigger calls `consumeEmailQuota(email)` before looking up the account (public counter); only flows that prove the owner (e.g. a correct password) may use their own counter.
|
|
19
23
|
- Use Prisma parameterization and explicit safe projections; never expose password hashes, tokens, internal errors, or secret-bearing upstream payloads.
|
|
20
24
|
- Keep public uploads under the static public root. Private uploads stay outside it and are served only through authenticated, owner-scoped routes; preserve filename/path validation.
|
|
21
|
-
- The production image runs non-root, applies `prisma migrate deploy` before `node dist/server.js`, and probes unauthenticated `GET /api/v1/live`. Preserve writable ownership for runtime storage and add explicit Alpine packages for new native runtime dependencies.
|
|
25
|
+
- The production image runs non-root, refuses to start without any migration, applies `prisma migrate deploy` before `node dist/server.js`, and probes unauthenticated `GET /api/v1/live`. In production the server also refuses to start when Redis is not reachable within 10 s (`src/server.ts`): keep that refusal, since rate limits, login lockout and IP blocks would otherwise be off. Preserve writable ownership for runtime storage and add explicit Alpine packages for new native runtime dependencies.
|
|
26
|
+
|
|
27
|
+
## Tests
|
|
28
|
+
|
|
29
|
+
- Integration tests run the real app against MySQL and Redis (see the root `AGENTS.md`, Verification, for what they need). Build them from `src/test/integration-helpers.ts` (`buildTestApp`, `call`, `registerUser`, `registerAdmin`, `startEmailStub`, …) instead of new setup code.
|
|
30
|
+
- Every API route needs its contract in `src/__tests__/routes.integration.test.ts`: who may call it (401 anonymous, 403 the wrong user or role), wrong input (422 `VALIDATION_FAILED`) and its success answer. Its last test fails, naming the route, when a registered route is never called there; a route that another file tests goes in its `COVERED_ELSEWHERE` list with that file's name.
|
|
22
31
|
|
|
23
32
|
## Mandatory security completion gate
|
|
24
33
|
|
|
25
|
-
- Follow the root `AGENTS.md` security workflow for every meaningful server change: use `security-audit` guidance during implementation
|
|
34
|
+
- Follow the root `AGENTS.md` security workflow for every meaningful server change: use `security-audit` guidance during implementation, then review the resulting patch (`git diff HEAD` plus untracked files) before completion, with `codex-security:security-diff-scan` in Codex or the bundled `security-audit` skill in Claude Code. Not `/security-review`: it reviews only commits since `origin/HEAD` and never sees uncommitted work.
|
|
26
35
|
- Review the concrete trust boundary, attacker-controlled input, affected principal/resource, authorization decision, validation point, and observable impact. Missing best practices without a reachable boundary failure are hardening notes, not confirmed vulnerabilities.
|
|
27
36
|
- Add or update focused regression coverage for changed authorization, validation, origin/CORS, cookie/session, upload/path, outbound-request, and data-isolation behavior. Never rely on client checks as security evidence.
|
|
28
37
|
- If a required security check cannot run, state the exact blocker and safe follow-up instead of reporting the server change as fully verified.
|