@odvi/create-dtt-framework 0.1.3 → 0.1.5

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 (111) hide show
  1. package/dist/commands/create.d.ts.map +1 -1
  2. package/dist/commands/create.js +16 -13
  3. package/dist/commands/create.js.map +1 -1
  4. package/package.json +3 -2
  5. package/template/.env.example +103 -0
  6. package/template/components.json +22 -0
  7. package/template/docs/framework/01-overview.md +289 -0
  8. package/template/docs/framework/02-techstack.md +503 -0
  9. package/template/docs/framework/api-layer.md +681 -0
  10. package/template/docs/framework/clerk-authentication.md +649 -0
  11. package/template/docs/framework/cli-installation.md +564 -0
  12. package/template/docs/framework/deployment/ci-cd.md +907 -0
  13. package/template/docs/framework/deployment/digitalocean.md +991 -0
  14. package/template/docs/framework/deployment/domain-setup.md +972 -0
  15. package/template/docs/framework/deployment/environment-variables.md +863 -0
  16. package/template/docs/framework/deployment/monitoring.md +927 -0
  17. package/template/docs/framework/deployment/production-checklist.md +649 -0
  18. package/template/docs/framework/deployment/vercel.md +791 -0
  19. package/template/docs/framework/environment-variables.md +658 -0
  20. package/template/docs/framework/health-check-system.md +582 -0
  21. package/template/docs/framework/implementation.md +559 -0
  22. package/template/docs/framework/snowflake-integration.md +591 -0
  23. package/template/docs/framework/state-management.md +615 -0
  24. package/template/docs/framework/supabase-integration.md +581 -0
  25. package/template/docs/framework/testing-guide.md +544 -0
  26. package/template/docs/framework/what-did-i-miss.md +526 -0
  27. package/template/drizzle.config.ts +12 -0
  28. package/template/next.config.js +21 -0
  29. package/template/postcss.config.js +5 -0
  30. package/template/prettier.config.js +4 -0
  31. package/template/public/favicon.ico +0 -0
  32. package/template/src/app/(auth)/layout.tsx +4 -0
  33. package/template/src/app/(auth)/sign-in/[[...sign-in]]/page.tsx +10 -0
  34. package/template/src/app/(auth)/sign-up/[[...sign-up]]/page.tsx +10 -0
  35. package/template/src/app/(dashboard)/dashboard/page.tsx +8 -0
  36. package/template/src/app/(dashboard)/health/page.tsx +16 -0
  37. package/template/src/app/(dashboard)/layout.tsx +17 -0
  38. package/template/src/app/api/[[...route]]/route.ts +11 -0
  39. package/template/src/app/api/debug-files/route.ts +33 -0
  40. package/template/src/app/api/webhooks/clerk/route.ts +112 -0
  41. package/template/src/app/layout.tsx +28 -0
  42. package/template/src/app/page.tsx +12 -0
  43. package/template/src/app/providers.tsx +20 -0
  44. package/template/src/components/layouts/navbar.tsx +14 -0
  45. package/template/src/components/shared/loading-spinner.tsx +6 -0
  46. package/template/src/components/ui/badge.tsx +46 -0
  47. package/template/src/components/ui/button.tsx +62 -0
  48. package/template/src/components/ui/card.tsx +92 -0
  49. package/template/src/components/ui/collapsible.tsx +33 -0
  50. package/template/src/components/ui/scroll-area.tsx +58 -0
  51. package/template/src/components/ui/sheet.tsx +139 -0
  52. package/template/src/config/__tests__/env.test.ts +166 -0
  53. package/template/src/config/__tests__/site.test.ts +46 -0
  54. package/template/src/config/env.ts +36 -0
  55. package/template/src/config/site.ts +10 -0
  56. package/template/src/env.js +44 -0
  57. package/template/src/features/__tests__/health-check-config.test.ts +142 -0
  58. package/template/src/features/__tests__/health-check-types.test.ts +201 -0
  59. package/template/src/features/documentation/components/doc-sidebar.tsx +109 -0
  60. package/template/src/features/documentation/components/doc-viewer.tsx +70 -0
  61. package/template/src/features/documentation/index.tsx +92 -0
  62. package/template/src/features/documentation/utils/doc-loader.ts +177 -0
  63. package/template/src/features/health-check/components/health-dashboard.tsx +363 -0
  64. package/template/src/features/health-check/config.ts +72 -0
  65. package/template/src/features/health-check/index.ts +4 -0
  66. package/template/src/features/health-check/stores/health-store.ts +14 -0
  67. package/template/src/features/health-check/types.ts +18 -0
  68. package/template/src/hooks/__tests__/use-debounce.test.tsx +28 -0
  69. package/template/src/hooks/queries/use-health-checks.ts +16 -0
  70. package/template/src/hooks/utils/use-debounce.ts +20 -0
  71. package/template/src/lib/__tests__/utils.test.ts +52 -0
  72. package/template/src/lib/__tests__/validators.test.ts +114 -0
  73. package/template/src/lib/nextbank/client.ts +37 -0
  74. package/template/src/lib/snowflake/client.ts +53 -0
  75. package/template/src/lib/supabase/admin.ts +7 -0
  76. package/template/src/lib/supabase/client.ts +7 -0
  77. package/template/src/lib/supabase/server.ts +23 -0
  78. package/template/src/lib/utils.ts +6 -0
  79. package/template/src/lib/validators.ts +9 -0
  80. package/template/src/middleware.ts +22 -0
  81. package/template/src/server/api/index.ts +22 -0
  82. package/template/src/server/api/middleware/auth.ts +19 -0
  83. package/template/src/server/api/middleware/logger.ts +4 -0
  84. package/template/src/server/api/routes/health/clerk.ts +214 -0
  85. package/template/src/server/api/routes/health/database.ts +117 -0
  86. package/template/src/server/api/routes/health/edge-functions.ts +75 -0
  87. package/template/src/server/api/routes/health/framework.ts +45 -0
  88. package/template/src/server/api/routes/health/index.ts +102 -0
  89. package/template/src/server/api/routes/health/nextbank.ts +67 -0
  90. package/template/src/server/api/routes/health/snowflake.ts +83 -0
  91. package/template/src/server/api/routes/health/storage.ts +163 -0
  92. package/template/src/server/api/routes/users.ts +95 -0
  93. package/template/src/server/db/index.ts +17 -0
  94. package/template/src/server/db/queries/users.ts +8 -0
  95. package/template/src/server/db/schema/__tests__/health-checks.test.ts +31 -0
  96. package/template/src/server/db/schema/__tests__/users.test.ts +46 -0
  97. package/template/src/server/db/schema/health-checks.ts +11 -0
  98. package/template/src/server/db/schema/index.ts +2 -0
  99. package/template/src/server/db/schema/users.ts +16 -0
  100. package/template/src/server/db/schema.ts +26 -0
  101. package/template/src/stores/__tests__/ui-store.test.ts +87 -0
  102. package/template/src/stores/ui-store.ts +14 -0
  103. package/template/src/styles/globals.css +129 -0
  104. package/template/src/test/mocks/clerk.ts +35 -0
  105. package/template/src/test/mocks/snowflake.ts +28 -0
  106. package/template/src/test/mocks/supabase.ts +37 -0
  107. package/template/src/test/setup.ts +69 -0
  108. package/template/src/test/utils/test-helpers.ts +158 -0
  109. package/template/src/types/index.ts +14 -0
  110. package/template/tsconfig.json +43 -0
  111. package/template/vitest.config.ts +44 -0
@@ -0,0 +1,791 @@
1
+ # DTT Framework - Vercel Deployment Guide
2
+
3
+ ## Overview
4
+
5
+ This guide provides comprehensive instructions for deploying the DTT Framework to Vercel. Vercel is the recommended deployment platform for Next.js applications, offering seamless integration, automatic scaling, and excellent developer experience.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ 1. [Prerequisites](#prerequisites)
12
+ 2. [Pre-Deployment Setup](#pre-deployment-setup)
13
+ 3. [Deployment via Vercel CLI](#deployment-via-vercel-cli)
14
+ 4. [Deployment via Vercel Dashboard](#deployment-via-vercel-dashboard)
15
+ 5. [Environment Variables Setup](#environment-variables-setup)
16
+ 6. [Database Migrations Setup](#database-migrations-setup)
17
+ 7. [Clerk Webhook Configuration](#clerk-webhook-configuration)
18
+ 8. [Monitoring and Logs](#monitoring-and-logs)
19
+ 9. [Rollback Procedures](#rollback-procedures)
20
+ 10. [Troubleshooting Common Issues](#troubleshooting-common-issues)
21
+
22
+ ---
23
+
24
+ ## Prerequisites
25
+
26
+ Before deploying to Vercel, ensure you have the following:
27
+
28
+ ### Required Accounts
29
+
30
+ - **Vercel Account**: Sign up at [vercel.com](https://vercel.com)
31
+ - **Git Repository**: Your code should be hosted on GitHub, GitLab, or Bitbucket
32
+ - **Supabase Account**: For database, storage, and edge functions
33
+ - **Clerk Account**: For authentication
34
+
35
+ ### Required Tools
36
+
37
+ - **Node.js**: Version 20 or higher
38
+ - **pnpm**: Version 10 or higher (package manager)
39
+ - **Git**: For version control
40
+
41
+ ### Required Services
42
+
43
+ - **Supabase Project**: Configured with PostgreSQL database
44
+ - **Clerk Application**: Configured with authentication
45
+ - **Snowflake Account**: (Optional) For data warehouse integration
46
+
47
+ ---
48
+
49
+ ## Pre-Deployment Setup
50
+
51
+ ### 1. Verify Local Configuration
52
+
53
+ Ensure your local environment is properly configured:
54
+
55
+ ```bash
56
+ # Check Node.js version
57
+ node --version # Should be 20+
58
+
59
+ # Check pnpm version
60
+ pnpm --version # Should be 10+
61
+
62
+ # Verify .env file exists
63
+ ls -la .env
64
+
65
+ # Verify dependencies are installed
66
+ pnpm install
67
+ ```
68
+
69
+ ### 2. Test Local Build
70
+
71
+ Before deploying, verify the build works locally:
72
+
73
+ ```bash
74
+ # Build the application
75
+ pnpm build
76
+
77
+ # Run production build locally
78
+ pnpm start
79
+ ```
80
+
81
+ ### 3. Verify Database Connection
82
+
83
+ Ensure your database connection works:
84
+
85
+ ```bash
86
+ # Push schema to database
87
+ pnpm db:push
88
+
89
+ # Or run migrations
90
+ pnpm db:migrate
91
+ ```
92
+
93
+ ### 4. Configure Build Settings
94
+
95
+ Verify your `next.config.js` is properly configured:
96
+
97
+ ```javascript
98
+ /** @type {import('next').NextConfig} */
99
+ const nextConfig = {
100
+ // Vercel-specific optimizations
101
+ output: 'standalone',
102
+
103
+ // Environment variables for client
104
+ env: {
105
+ NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL,
106
+ },
107
+ }
108
+
109
+ export default nextConfig
110
+ ```
111
+
112
+ ### 5. Prepare Git Repository
113
+
114
+ Ensure your repository is ready for deployment:
115
+
116
+ ```bash
117
+ # Initialize git if not already done
118
+ git init
119
+
120
+ # Add all files
121
+ git add .
122
+
123
+ # Commit changes
124
+ git commit -m "Initial commit"
125
+
126
+ # Push to remote repository
127
+ git remote add origin https://github.com/your-username/your-repo.git
128
+ git push -u origin main
129
+ ```
130
+
131
+ ---
132
+
133
+ ## Deployment via Vercel CLI
134
+
135
+ ### Install Vercel CLI
136
+
137
+ ```bash
138
+ # Install Vercel CLI globally
139
+ pnpm add -g vercel
140
+
141
+ # Verify installation
142
+ vercel --version
143
+ ```
144
+
145
+ ### Login to Vercel
146
+
147
+ ```bash
148
+ # Login to your Vercel account
149
+ vercel login
150
+ ```
151
+
152
+ This will open a browser window for authentication.
153
+
154
+ ### Deploy Your Application
155
+
156
+ ```bash
157
+ # Deploy to preview environment
158
+ vercel
159
+
160
+ # Deploy to production
161
+ vercel --prod
162
+ ```
163
+
164
+ ### Configure Project Settings
165
+
166
+ During the first deployment, Vercel will ask for configuration:
167
+
168
+ ```bash
169
+ ? Set up and deploy "~/your-project"? [Y/n] Y
170
+ ? Which scope do you want to deploy to? Your Username
171
+ ? Link to existing project? [y/N] N
172
+ ? What's your project's name? dtt-framework
173
+ ? In which directory is your code located? ./
174
+ ? Want to override the settings? [y/N] N
175
+ ```
176
+
177
+ ### Set Environment Variables via CLI
178
+
179
+ ```bash
180
+ # Add environment variables
181
+ vercel env add DATABASE_URL production
182
+ vercel env add CLERK_SECRET_KEY production
183
+ vercel env add CLERK_WEBHOOK_SECRET production
184
+ vercel env add SUPABASE_SERVICE_ROLE_KEY production
185
+
186
+ # Pull environment variables locally
187
+ vercel env pull .env.production
188
+ ```
189
+
190
+ ### Deploy with Environment Variables
191
+
192
+ ```bash
193
+ # Deploy to production with all environment variables
194
+ vercel --prod
195
+ ```
196
+
197
+ ---
198
+
199
+ ## Deployment via Vercel Dashboard
200
+
201
+ ### Step 1: Import Project
202
+
203
+ 1. Go to [vercel.com/dashboard](https://vercel.com/dashboard)
204
+ 2. Click **"Add New..."** → **"Project"**
205
+ 3. Import your Git repository
206
+
207
+ ### Step 2: Configure Project Settings
208
+
209
+ ![Import Project](../images/deployment/vercel-import-project.png)
210
+
211
+ Configure the following settings:
212
+
213
+ | Setting | Value | Description |
214
+ |---------|-------|-------------|
215
+ | **Framework Preset** | Next.js | Automatically detected |
216
+ | **Root Directory** | `./` | Leave as default |
217
+ | **Build Command** | `pnpm build` | Build command |
218
+ | **Output Directory** | `.next` | Default for Next.js |
219
+ | **Install Command** | `pnpm install` | Package installation |
220
+
221
+ ### Step 3: Configure Environment Variables
222
+
223
+ In the project settings, add the following environment variables:
224
+
225
+ #### Required Variables
226
+
227
+ ```bash
228
+ # Application
229
+ NEXT_PUBLIC_APP_URL=https://your-app.vercel.app
230
+
231
+ # Clerk Authentication
232
+ NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_xxx
233
+ CLERK_SECRET_KEY=sk_live_xxx
234
+ CLERK_WEBHOOK_SECRET=whsec_xxx
235
+ NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
236
+ NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
237
+ NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/health
238
+ NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/health
239
+
240
+ # Supabase
241
+ NEXT_PUBLIC_SUPABASE_URL=https://xxx.supabase.co
242
+ NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJxxx
243
+ SUPABASE_SERVICE_ROLE_KEY=eyJxxx
244
+ DATABASE_URL=postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres
245
+
246
+ # Snowflake (Optional)
247
+ SNOWFLAKE_ACCOUNT=xxx.us-east-1
248
+ SNOWFLAKE_USERNAME=xxx
249
+ SNOWFLAKE_PASSWORD=xxx
250
+ SNOWFLAKE_WAREHOUSE=COMPUTE_WH
251
+ SNOWFLAKE_DATABASE=ANALYTICS
252
+ SNOWFLAKE_SCHEMA=PUBLIC
253
+ SNOWFLAKE_ROLE=ANALYST
254
+ ```
255
+
256
+ #### Environment-Specific Variables
257
+
258
+ Create separate sets for each environment:
259
+
260
+ | Environment | Prefix |
261
+ |-------------|--------|
262
+ | **Production** | No prefix (default) |
263
+ | **Preview** | `PREVIEW_` |
264
+ | **Development** | `DEV_` |
265
+
266
+ ### Step 4: Deploy
267
+
268
+ Click **"Deploy"** to start the deployment process. Vercel will:
269
+
270
+ 1. Clone your repository
271
+ 2. Install dependencies using `pnpm install`
272
+ 3. Build the application using `pnpm build`
273
+ 4. Deploy to Vercel's Edge Network
274
+
275
+ ### Step 5: Verify Deployment
276
+
277
+ Once deployment is complete:
278
+
279
+ 1. Visit your production URL: `https://your-app.vercel.app`
280
+ 2. Check the deployment logs for any errors
281
+ 3. Verify all features are working correctly
282
+
283
+ ---
284
+
285
+ ## Environment Variables Setup
286
+
287
+ ### Understanding Vercel Environment Variables
288
+
289
+ Vercel supports multiple environments:
290
+
291
+ | Environment | Use Case | Branch |
292
+ |-------------|----------|--------|
293
+ | **Production** | Live application | `main` or `master` |
294
+ | **Preview** | Pull request deployments | Pull request branches |
295
+ | **Development** | Testing environment | `dev` branch |
296
+
297
+ ### Setting Variables in Dashboard
298
+
299
+ 1. Go to **Settings** → **Environment Variables**
300
+ 2. Click **"Add New"**
301
+ 3. Enter variable name and value
302
+ 4. Select environments (Production, Preview, Development)
303
+ 5. Click **"Save"**
304
+
305
+ ### Setting Variables via CLI
306
+
307
+ ```bash
308
+ # Add variable to specific environment
309
+ vercel env add VARIABLE_NAME production
310
+
311
+ # List all variables
312
+ vercel env ls
313
+
314
+ # Remove variable
315
+ vercel env rm VARIABLE_NAME production
316
+ ```
317
+
318
+ ### Variable Scope
319
+
320
+ Variables can be scoped to:
321
+
322
+ - **All Environments**: Available in production, preview, and development
323
+ - **Specific Environments**: Only available in selected environments
324
+ - **Branch-Specific**: Only available for specific Git branches
325
+
326
+ ### Sensitive Variables
327
+
328
+ For sensitive variables, Vercel provides:
329
+
330
+ - **Encrypted Storage**: All variables are encrypted at rest
331
+ - **Access Control**: Only team members with appropriate permissions can view
332
+ - **Audit Logs**: Track who accessed or modified variables
333
+
334
+ ---
335
+
336
+ ## Database Migrations Setup
337
+
338
+ ### Option 1: Automatic Migrations on Deploy
339
+
340
+ Create a deployment script to run migrations:
341
+
342
+ ```json
343
+ // package.json
344
+ {
345
+ "scripts": {
346
+ "postinstall": "pnpm db:push"
347
+ }
348
+ }
349
+ ```
350
+
351
+ This will automatically push schema changes after each deployment.
352
+
353
+ ### Option 2: Manual Migrations
354
+
355
+ For production, run migrations manually:
356
+
357
+ ```bash
358
+ # Generate migration
359
+ pnpm db:generate
360
+
361
+ # Push to database
362
+ pnpm db:push
363
+
364
+ # Or run specific migration
365
+ pnpm db:migrate
366
+ ```
367
+
368
+ ### Option 3: Vercel Cron Jobs
369
+
370
+ Set up scheduled migrations using Vercel Cron Jobs:
371
+
372
+ ```javascript
373
+ // vercel.json
374
+ {
375
+ "crons": [
376
+ {
377
+ "path": "/api/cron/migrate",
378
+ "schedule": "0 2 * * *"
379
+ }
380
+ ]
381
+ }
382
+ ```
383
+
384
+ ### Database Migration Best Practices
385
+
386
+ 1. **Test Locally First**: Always test migrations locally
387
+ 2. **Backup Before Migrate**: Create database backups before production migrations
388
+ 3. **Use Transactions**: Wrap migrations in transactions for rollback capability
389
+ 4. **Monitor Performance**: Track migration performance in production
390
+ 5. **Document Changes**: Keep a changelog of schema changes
391
+
392
+ ---
393
+
394
+ ## Clerk Webhook Configuration
395
+
396
+ ### Step 1: Get Your Deployment URL
397
+
398
+ Your Vercel deployment URL will be:
399
+ ```
400
+ https://your-project.vercel.app
401
+ ```
402
+
403
+ Or your custom domain:
404
+ ```
405
+ https://your-app.com
406
+ ```
407
+
408
+ ### Step 2: Configure Clerk Webhook
409
+
410
+ 1. Go to [Clerk Dashboard](https://dashboard.clerk.com)
411
+ 2. Navigate to **Your App** → **Webhooks**
412
+ 3. Click **"Add Endpoint"**
413
+ 4. Enter your webhook URL:
414
+ ```
415
+ https://your-app.vercel.app/api/webhooks/clerk
416
+ ```
417
+ 5. Select events to listen for:
418
+ - `user.created`
419
+ - `user.updated`
420
+ - `user.deleted`
421
+ - `session.created`
422
+ - `session.ended`
423
+ 6. Click **"Create"**
424
+
425
+ ### Step 3: Copy Webhook Secret
426
+
427
+ After creating the webhook:
428
+
429
+ 1. Click on the webhook endpoint
430
+ 2. Copy the **Signing Secret** (starts with `whsec_`)
431
+ 3. Add it to Vercel environment variables:
432
+ ```bash
433
+ CLERK_WEBHOOK_SECRET=whsec_xxx
434
+ ```
435
+
436
+ ### Step 4: Test Webhook
437
+
438
+ 1. In Clerk Dashboard, go to **Webhooks** → **Your Webhook**
439
+ 2. Click **"Send test event"**
440
+ 3. Select an event type
441
+ 4. Click **"Send"`
442
+ 5. Check Vercel logs for successful delivery
443
+
444
+ ### Step 5: Verify Webhook Delivery
445
+
446
+ Check Vercel logs:
447
+
448
+ ```bash
449
+ # View deployment logs
450
+ vercel logs
451
+
452
+ # View real-time logs
453
+ vercel logs --follow
454
+ ```
455
+
456
+ ---
457
+
458
+ ## Monitoring and Logs
459
+
460
+ ### Vercel Analytics
461
+
462
+ Enable Vercel Analytics for performance insights:
463
+
464
+ ```bash
465
+ # Install Vercel Analytics
466
+ pnpm add @vercel/analytics
467
+ ```
468
+
469
+ Add to your app:
470
+
471
+ ```typescript
472
+ // src/app/layout.tsx
473
+ import { Analytics } from '@vercel/analytics/react'
474
+
475
+ export default function RootLayout({ children }) {
476
+ return (
477
+ <html>
478
+ <body>
479
+ {children}
480
+ <Analytics />
481
+ </body>
482
+ </html>
483
+ )
484
+ }
485
+ ```
486
+
487
+ ### Viewing Logs
488
+
489
+ #### Via Dashboard
490
+
491
+ 1. Go to **Deployments** → **Your Deployment**
492
+ 2. Click **"View Function Logs"**
493
+ 3. Filter by function or time range
494
+
495
+ #### Via CLI
496
+
497
+ ```bash
498
+ # View recent logs
499
+ vercel logs
500
+
501
+ # View logs for specific deployment
502
+ vercel logs <deployment-url>
503
+
504
+ # Follow logs in real-time
505
+ vercel logs --follow
506
+
507
+ # View logs for specific function
508
+ vercel logs --filter="api/health"
509
+ ```
510
+
511
+ ### Log Types
512
+
513
+ | Log Type | Description | Use Case |
514
+ |----------|-------------|----------|
515
+ | **Build Logs** | Build process output | Debugging build failures |
516
+ | **Function Logs** | Serverless function execution | Debugging runtime errors |
517
+ | **Edge Function Logs** | Edge function execution | Debugging edge-specific issues |
518
+ | **Deployment Logs** | Deployment process | Tracking deployment status |
519
+
520
+ ### Setting Up Alerts
521
+
522
+ Configure alerts for:
523
+
524
+ 1. **Build Failures**: Get notified when builds fail
525
+ 2. **Deployment Errors**: Get notified for deployment issues
526
+ 3. **Function Errors**: Get notified for runtime errors
527
+ 4. **Performance Issues**: Get notified for slow responses
528
+
529
+ ---
530
+
531
+ ## Rollback Procedures
532
+
533
+ ### Automatic Rollback
534
+
535
+ Vercel provides automatic rollback on deployment failure:
536
+
537
+ 1. If a deployment fails, Vercel automatically reverts to the previous successful deployment
538
+ 2. Your application remains available during rollback
539
+ 3. No manual intervention required
540
+
541
+ ### Manual Rollback via Dashboard
542
+
543
+ 1. Go to **Deployments** → **Your Project**
544
+ 2. Find the previous successful deployment
545
+ 3. Click **"..."** → **"Promote to Production"**
546
+ 4. Confirm the rollback
547
+
548
+ ### Manual Rollback via CLI
549
+
550
+ ```bash
551
+ # List all deployments
552
+ vercel list
553
+
554
+ # Rollback to specific deployment
555
+ vercel rollback <deployment-url>
556
+
557
+ # Rollback to previous deployment
558
+ vercel rollback
559
+ ```
560
+
561
+ ### Rollback Best Practices
562
+
563
+ 1. **Test Before Deploy**: Always test preview deployments
564
+ 2. **Monitor After Deploy**: Watch logs after deployment
565
+ 3. **Have Rollback Plan**: Know which deployment to rollback to
566
+ 4. **Document Rollbacks**: Keep a record of rollbacks and reasons
567
+ 5. **Investigate Failures**: Understand why rollback was needed
568
+
569
+ ---
570
+
571
+ ## Troubleshooting Common Issues
572
+
573
+ ### Issue: Build Fails
574
+
575
+ **Symptoms:**
576
+ - Deployment fails during build
577
+ - Error messages in build logs
578
+
579
+ **Solutions:**
580
+
581
+ ```bash
582
+ # Test build locally
583
+ pnpm build
584
+
585
+ # Check for missing dependencies
586
+ pnpm install
587
+
588
+ # Verify environment variables
589
+ vercel env ls
590
+
591
+ # Clear Vercel cache
592
+ vercel build --force
593
+ ```
594
+
595
+ ### Issue: Environment Variables Not Available
596
+
597
+ **Symptoms:**
598
+ - Application can't access environment variables
599
+ - `undefined` values for environment variables
600
+
601
+ **Solutions:**
602
+
603
+ ```bash
604
+ # Verify variables are set
605
+ vercel env ls
606
+
607
+ # Redeploy to apply changes
608
+ vercel --prod
609
+
610
+ # Check variable names match exactly (case-sensitive)
611
+ ```
612
+
613
+ ### Issue: Database Connection Failed
614
+
615
+ **Symptoms:**
616
+ - Database connection errors in logs
617
+ - Application can't connect to Supabase
618
+
619
+ **Solutions:**
620
+
621
+ ```bash
622
+ # Verify DATABASE_URL format
623
+ # Should use Transaction mode for Vercel:
624
+ DATABASE_URL=postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres
625
+
626
+ # Test connection locally
627
+ psql $DATABASE_URL
628
+
629
+ # Check Supabase project status
630
+ # Ensure project is not paused
631
+ ```
632
+
633
+ ### Issue: Clerk Webhook Not Working
634
+
635
+ **Symptoms:**
636
+ - Webhook events not being received
637
+ - User data not syncing to database
638
+
639
+ **Solutions:**
640
+
641
+ ```bash
642
+ # Verify webhook secret is correct
643
+ vercel env ls CLERK_WEBHOOK_SECRET
644
+
645
+ # Check webhook URL is correct
646
+ # Should be: https://your-app.vercel.app/api/webhooks/clerk
647
+
648
+ # Test webhook from Clerk Dashboard
649
+ # Send test event and check Vercel logs
650
+ ```
651
+
652
+ ### Issue: Slow Performance
653
+
654
+ **Symptoms:**
655
+ - Slow page load times
656
+ - High response times
657
+
658
+ **Solutions:**
659
+
660
+ ```bash
661
+ # Enable Vercel Analytics
662
+ pnpm add @vercel/analytics
663
+
664
+ # Check Vercel Analytics dashboard
665
+ # Identify slow pages and functions
666
+
667
+ # Optimize images
668
+ # Use next/image for all images
669
+
670
+ # Enable caching
671
+ # Add appropriate cache headers
672
+ ```
673
+
674
+ ### Issue: Edge Function Errors
675
+
676
+ **Symptoms:**
677
+ - Edge function failures
678
+ - Timeouts or errors
679
+
680
+ **Solutions:**
681
+
682
+ ```bash
683
+ # Check edge function logs
684
+ vercel logs --filter="edge"
685
+
686
+ # Increase timeout if needed
687
+ # In next.config.js:
688
+ experimental: {
689
+ serverActions: {
690
+ bodySizeLimit: '2mb',
691
+ },
692
+ }
693
+
694
+ # Optimize edge function code
695
+ # Reduce bundle size
696
+ ```
697
+
698
+ ### Issue: Deployment Stuck
699
+
700
+ **Symptoms:**
701
+ - Deployment hangs indefinitely
702
+ - No progress in deployment logs
703
+
704
+ **Solutions:**
705
+
706
+ ```bash
707
+ # Cancel current deployment
708
+ # In Vercel Dashboard: Click "Cancel Deployment"
709
+
710
+ # Retry deployment
711
+ vercel --prod
712
+
713
+ # Check Vercel status
714
+ # https://www.vercel-status.com/
715
+ ```
716
+
717
+ ---
718
+
719
+ ## Best Practices
720
+
721
+ ### 1. Use Preview Deployments
722
+
723
+ Always use preview deployments for testing:
724
+
725
+ ```bash
726
+ # Create a pull request
727
+ git checkout -b feature/new-feature
728
+ git push origin feature/new-feature
729
+
730
+ # Vercel automatically creates preview deployment
731
+ ```
732
+
733
+ ### 2. Monitor Deployments
734
+
735
+ Keep an eye on your deployments:
736
+
737
+ - Check deployment status after each push
738
+ - Review logs for any warnings or errors
739
+ - Set up alerts for critical issues
740
+
741
+ ### 3. Optimize Build Time
742
+
743
+ Reduce build time:
744
+
745
+ ```bash
746
+ # Use pnpm for faster installs
747
+ # Cache dependencies in .vercelignore
748
+
749
+ # .vercelignore
750
+ node_modules
751
+ .next
752
+ ```
753
+
754
+ ### 4. Use Environment-Specific Configs
755
+
756
+ Separate configurations for different environments:
757
+
758
+ ```javascript
759
+ // next.config.js
760
+ const isProd = process.env.NODE_ENV === 'production'
761
+
762
+ const nextConfig = {
763
+ // Production-specific settings
764
+ ...(isProd && {
765
+ compress: true,
766
+ swcMinify: true,
767
+ }),
768
+ }
769
+ ```
770
+
771
+ ### 5. Implement Health Checks
772
+
773
+ Set up health check endpoints:
774
+
775
+ ```typescript
776
+ // src/app/api/health/route.ts
777
+ export async function GET() {
778
+ return Response.json({ status: 'ok', timestamp: Date.now() })
779
+ }
780
+ ```
781
+
782
+ ---
783
+
784
+ ## Related Documentation
785
+
786
+ - [Domain Setup](./domain-setup.md) - Custom domain configuration
787
+ - [Environment Variables](./environment-variables.md) - Complete variable reference
788
+ - [CI/CD Setup](./ci-cd.md) - Automated deployments
789
+ - [Production Checklist](./production-checklist.md) - Pre-deployment checklist
790
+ - [Monitoring](./monitoring.md) - Monitoring and alerting setup
791
+ - [DigitalOcean Deployment](./digitalocean.md) - Alternative deployment platform