@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,991 @@
1
+ # DTT Framework - DigitalOcean Deployment Guide
2
+
3
+ ## Overview
4
+
5
+ This guide provides comprehensive instructions for deploying the DTT Framework to DigitalOcean. DigitalOcean offers two main deployment options: App Platform (PaaS) and Droplets (VPS). This guide covers both approaches.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ 1. [Prerequisites](#prerequisites)
12
+ 2. [Option A: App Platform Deployment](#option-a-app-platform-deployment)
13
+ 3. [Option B: Droplet Deployment](#option-b-droplet-deployment)
14
+ 4. [Database Setup](#database-setup)
15
+ 5. [Monitoring and Logs](#monitoring-and-logs)
16
+ 6. [Troubleshooting Common Issues](#troubleshooting-common-issues)
17
+
18
+ ---
19
+
20
+ ## Prerequisites
21
+
22
+ Before deploying to DigitalOcean, ensure you have the following:
23
+
24
+ ### Required Accounts
25
+
26
+ - **DigitalOcean Account**: Sign up at [digitalocean.com](https://digitalocean.com)
27
+ - **Git Repository**: Your code should be hosted on GitHub, GitLab, or Bitbucket
28
+ - **Supabase Account**: For database, storage, and edge functions
29
+ - **Clerk Account**: For authentication
30
+ - **Domain Name**: (Optional) For custom domain
31
+
32
+ ### Required Tools
33
+
34
+ - **Node.js**: Version 20 or higher
35
+ - **pnpm**: Version 10 or higher
36
+ - **Git**: For version control
37
+ - **SSH Client**: For Droplet access (Option B)
38
+
39
+ ### Required Services
40
+
41
+ - **Supabase Project**: Configured with PostgreSQL database
42
+ - **Clerk Application**: Configured with authentication
43
+ - **Snowflake Account**: (Optional) For data warehouse integration
44
+
45
+ ---
46
+
47
+ ## Option A: App Platform Deployment
48
+
49
+ DigitalOcean App Platform is a Platform-as-a-Service (PaaS) solution that automatically builds and deploys your application from a Git repository.
50
+
51
+ ### Step 1: Create a New App
52
+
53
+ 1. Log in to [DigitalOcean Dashboard](https://cloud.digitalocean.com/apps)
54
+ 2. Click **"Create App"**
55
+ 3. Select your Git provider (GitHub, GitLab, or Bitbucket)
56
+ 4. Authorize DigitalOcean to access your repository
57
+ 5. Select your repository and branch
58
+
59
+ ### Step 2: Configure App Settings
60
+
61
+ ![App Platform Configuration](../images/deployment/do-app-config.png)
62
+
63
+ Configure the following settings:
64
+
65
+ | Setting | Value | Description |
66
+ |---------|-------|-------------|
67
+ | **App Name** | `dtt-framework` | Your app name |
68
+ | **Region** | `New York` | Choose nearest region |
69
+ | **Instance Size** | `Basic XXS` | For development/testing |
70
+ | **Instance Count** | `1` | Number of instances |
71
+
72
+ ### Step 3: Configure Build Settings
73
+
74
+ ```yaml
75
+ # .do/app.yaml (optional)
76
+ name: dtt-framework
77
+ services:
78
+ - name: web
79
+ source_dir: /
80
+ github:
81
+ repo: your-username/your-repo
82
+ branch: main
83
+ run_command: pnpm start
84
+ environment_slug: node-js
85
+ instance_count: 1
86
+ instance_size_slug: basic-xxs
87
+ envs:
88
+ - key: NODE_ENV
89
+ value: production
90
+ - key: NEXT_PUBLIC_APP_URL
91
+ value: ${APP_URL}
92
+ ```
93
+
94
+ #### Build Configuration
95
+
96
+ | Setting | Value |
97
+ |---------|-------|
98
+ | **Build Command** | `pnpm build` |
99
+ | **Run Command** | `pnpm start` |
100
+ | **Output Directory** | `.next` |
101
+ | **Install Command** | `pnpm install` |
102
+
103
+ ### Step 4: Set Environment Variables
104
+
105
+ In the App Platform settings, add the following environment variables:
106
+
107
+ #### Required Variables
108
+
109
+ ```bash
110
+ # Application
111
+ NODE_ENV=production
112
+ NEXT_PUBLIC_APP_URL=https://your-app.ondigitalocean.app
113
+
114
+ # Clerk Authentication
115
+ NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_xxx
116
+ CLERK_SECRET_KEY=sk_live_xxx
117
+ CLERK_WEBHOOK_SECRET=whsec_xxx
118
+ NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
119
+ NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
120
+ NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/health
121
+ NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/health
122
+
123
+ # Supabase
124
+ NEXT_PUBLIC_SUPABASE_URL=https://xxx.supabase.co
125
+ NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJxxx
126
+ SUPABASE_SERVICE_ROLE_KEY=eyJxxx
127
+ DATABASE_URL=postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres
128
+
129
+ # Snowflake (Optional)
130
+ SNOWFLAKE_ACCOUNT=xxx.us-east-1
131
+ SNOWFLAKE_USERNAME=xxx
132
+ SNOWFLAKE_PASSWORD=xxx
133
+ SNOWFLAKE_WAREHOUSE=COMPUTE_WH
134
+ SNOWFLAKE_DATABASE=ANALYTICS
135
+ SNOWFLAKE_SCHEMA=PUBLIC
136
+ SNOWFLAKE_ROLE=ANALYST
137
+ ```
138
+
139
+ ### Step 5: Deploy
140
+
141
+ Click **"Create App"** to start the deployment. DigitalOcean will:
142
+
143
+ 1. Clone your repository
144
+ 2. Install dependencies using `pnpm install`
145
+ 3. Build the application using `pnpm build`
146
+ 4. Deploy to the App Platform
147
+
148
+ ### Step 6: Verify Deployment
149
+
150
+ Once deployment is complete:
151
+
152
+ 1. Visit your app URL: `https://your-app.ondigitalocean.app`
153
+ 2. Check the deployment logs for any errors
154
+ 3. Verify all features are working correctly
155
+
156
+ ### Step 7: Configure Health Checks
157
+
158
+ Enable health checks for your app:
159
+
160
+ ```yaml
161
+ # In App Platform settings
162
+ health_check:
163
+ http_path: /api/health
164
+ initial_delay_seconds: 60
165
+ period_seconds: 30
166
+ timeout_seconds: 5
167
+ success_threshold: 1
168
+ failure_threshold: 3
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Option B: Droplet Deployment
174
+
175
+ DigitalOcean Droplets provide full control over your server environment. This approach requires manual setup but offers maximum flexibility.
176
+
177
+ ### Step 1: Provision a Droplet
178
+
179
+ 1. Go to [DigitalOcean Dashboard](https://cloud.digitalocean.com/droplets)
180
+ 2. Click **"Create Droplet"**
181
+ 3. Choose an image:
182
+ - **Ubuntu 22.04 LTS** (Recommended)
183
+ - **Ubuntu 24.04 LTS**
184
+ 4. Choose a plan:
185
+ - **Basic**: For development/testing
186
+ - **General Purpose**: For production
187
+ 5. Choose a region (nearest to your users)
188
+ 6. Add SSH keys (recommended) or choose password authentication
189
+ 7. Click **"Create Droplet"**
190
+
191
+ ### Step 2: Connect to Your Droplet
192
+
193
+ #### Using SSH Keys (Recommended)
194
+
195
+ ```bash
196
+ # Add your SSH key to DigitalOcean
197
+ # Settings → Security → Add SSH Key
198
+
199
+ # Connect to your droplet
200
+ ssh root@your-droplet-ip
201
+ ```
202
+
203
+ #### Using Password
204
+
205
+ ```bash
206
+ # Connect to your droplet
207
+ ssh root@your-droplet-ip
208
+ # Enter your password when prompted
209
+ ```
210
+
211
+ ### Step 3: Update System Packages
212
+
213
+ ```bash
214
+ # Update package list
215
+ apt update
216
+
217
+ # Upgrade installed packages
218
+ apt upgrade -y
219
+
220
+ # Install essential tools
221
+ apt install -y curl wget git vim ufw
222
+ ```
223
+
224
+ ### Step 4: Install Node.js
225
+
226
+ ```bash
227
+ # Install Node.js 20.x using NodeSource
228
+ curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
229
+ apt install -y nodejs
230
+
231
+ # Verify installation
232
+ node --version # Should be 20.x.x
233
+ npm --version # Should be 10.x.x
234
+ ```
235
+
236
+ ### Step 5: Install pnpm
237
+
238
+ ```bash
239
+ # Install pnpm globally
240
+ npm install -g pnpm
241
+
242
+ # Verify installation
243
+ pnpm --version # Should be 10.x.x
244
+ ```
245
+
246
+ ### Step 6: Install Nginx
247
+
248
+ ```bash
249
+ # Install Nginx
250
+ apt install -y nginx
251
+
252
+ # Start Nginx
253
+ systemctl start nginx
254
+
255
+ # Enable Nginx to start on boot
256
+ systemctl enable nginx
257
+
258
+ # Verify Nginx is running
259
+ systemctl status nginx
260
+ ```
261
+
262
+ ### Step 7: Configure Firewall
263
+
264
+ ```bash
265
+ # Allow SSH
266
+ ufw allow OpenSSH
267
+
268
+ # Allow HTTP
269
+ ufw allow 80
270
+
271
+ # Allow HTTPS
272
+ ufw allow 443
273
+
274
+ # Enable firewall
275
+ ufw enable
276
+
277
+ # Check firewall status
278
+ ufw status
279
+ ```
280
+
281
+ ### Step 8: Clone Your Repository
282
+
283
+ ```bash
284
+ # Create application directory
285
+ mkdir -p /var/www/dtt-framework
286
+ cd /var/www/dtt-framework
287
+
288
+ # Clone your repository
289
+ git clone https://github.com/your-username/your-repo.git .
290
+
291
+ # Or use SSH
292
+ git clone git@github.com:your-username/your-repo.git .
293
+ ```
294
+
295
+ ### Step 9: Install Dependencies
296
+
297
+ ```bash
298
+ # Install dependencies
299
+ pnpm install
300
+
301
+ # Build the application
302
+ pnpm build
303
+ ```
304
+
305
+ ### Step 10: Configure Environment Variables
306
+
307
+ ```bash
308
+ # Create .env file
309
+ nano /var/www/dtt-framework/.env
310
+ ```
311
+
312
+ Add the following environment variables:
313
+
314
+ ```bash
315
+ # Application
316
+ NODE_ENV=production
317
+ NEXT_PUBLIC_APP_URL=https://your-domain.com
318
+
319
+ # Clerk Authentication
320
+ NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_xxx
321
+ CLERK_SECRET_KEY=sk_live_xxx
322
+ CLERK_WEBHOOK_SECRET=whsec_xxx
323
+ NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
324
+ NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
325
+ NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/health
326
+ NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/health
327
+
328
+ # Supabase
329
+ NEXT_PUBLIC_SUPABASE_URL=https://xxx.supabase.co
330
+ NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJxxx
331
+ SUPABASE_SERVICE_ROLE_KEY=eyJxxx
332
+ DATABASE_URL=postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres
333
+
334
+ # Snowflake (Optional)
335
+ SNOWFLAKE_ACCOUNT=xxx.us-east-1
336
+ SNOWFLAKE_USERNAME=xxx
337
+ SNOWFLAKE_PASSWORD=xxx
338
+ SNOWFLAKE_WAREHOUSE=COMPUTE_WH
339
+ SNOWFLAKE_DATABASE=ANALYTICS
340
+ SNOWFLAKE_SCHEMA=PUBLIC
341
+ SNOWFLAKE_ROLE=ANALYST
342
+ ```
343
+
344
+ Save and exit (Ctrl+X, Y, Enter).
345
+
346
+ ### Step 11: Run Database Migrations
347
+
348
+ ```bash
349
+ # Push schema to database
350
+ pnpm db:push
351
+
352
+ # Or run migrations
353
+ pnpm db:migrate
354
+ ```
355
+
356
+ ### Step 12: Install PM2 for Process Management
357
+
358
+ ```bash
359
+ # Install PM2 globally
360
+ npm install -g pm2
361
+
362
+ # Start the application with PM2
363
+ pm2 start pnpm --name "dtt-framework" -- start
364
+
365
+ # Save PM2 process list
366
+ pm2 save
367
+
368
+ # Setup PM2 to start on boot
369
+ pm2 startup
370
+ # Copy and run the command shown
371
+ ```
372
+
373
+ ### Step 13: Configure Nginx as Reverse Proxy
374
+
375
+ ```bash
376
+ # Create Nginx configuration
377
+ nano /etc/nginx/sites-available/dtt-framework
378
+ ```
379
+
380
+ Add the following configuration:
381
+
382
+ ```nginx
383
+ upstream dtt-framework {
384
+ server localhost:3000;
385
+ }
386
+
387
+ server {
388
+ listen 80;
389
+ server_name your-domain.com www.your-domain.com;
390
+
391
+ # Redirect HTTP to HTTPS (after SSL is configured)
392
+ # return 301 https://$server_name$request_uri;
393
+
394
+ location / {
395
+ proxy_pass http://dtt-framework;
396
+ proxy_http_version 1.1;
397
+ proxy_set_header Upgrade $http_upgrade;
398
+ proxy_set_header Connection 'upgrade';
399
+ proxy_set_header Host $host;
400
+ proxy_set_header X-Real-IP $remote_addr;
401
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
402
+ proxy_set_header X-Forwarded-Proto $scheme;
403
+ proxy_cache_bypass $http_upgrade;
404
+ }
405
+
406
+ # Health check endpoint
407
+ location /api/health {
408
+ proxy_pass http://dtt-framework;
409
+ access_log off;
410
+ }
411
+ }
412
+ ```
413
+
414
+ Save and exit.
415
+
416
+ ### Step 14: Enable Nginx Configuration
417
+
418
+ ```bash
419
+ # Create symbolic link
420
+ ln -s /etc/nginx/sites-available/dtt-framework /etc/nginx/sites-enabled/
421
+
422
+ # Test Nginx configuration
423
+ nginx -t
424
+
425
+ # Reload Nginx
426
+ systemctl reload nginx
427
+ ```
428
+
429
+ ### Step 15: Configure SSL with Let's Encrypt
430
+
431
+ ```bash
432
+ # Install Certbot
433
+ apt install -y certbot python3-certbot-nginx
434
+
435
+ # Obtain SSL certificate
436
+ certbot --nginx -d your-domain.com -d www.your-domain.com
437
+
438
+ # Follow the prompts to:
439
+ # - Enter email for renewal notifications
440
+ # - Agree to terms of service
441
+ # - Choose whether to redirect HTTP to HTTPS
442
+
443
+ # Verify SSL certificate
444
+ certbot certificates
445
+ ```
446
+
447
+ Certbot will automatically configure Nginx with SSL and set up auto-renewal.
448
+
449
+ ### Step 16: Verify SSL Auto-Renewal
450
+
451
+ ```bash
452
+ # Test renewal process
453
+ certbot renew --dry-run
454
+
455
+ # Check renewal timer
456
+ systemctl list-timers | grep certbot
457
+ ```
458
+
459
+ ### Step 17: Configure PM2 Monitoring
460
+
461
+ ```bash
462
+ # Install PM2 Plus (optional)
463
+ pm2 plus
464
+
465
+ # Monitor application
466
+ pm2 monit
467
+
468
+ # View logs
469
+ pm2 logs
470
+
471
+ # View process information
472
+ pm2 info dtt-framework
473
+ ```
474
+
475
+ ### Step 18: Set Up Log Rotation
476
+
477
+ ```bash
478
+ # Create PM2 log rotation configuration
479
+ pm2 install pm2-logrotate
480
+
481
+ # Configure log rotation
482
+ pm2 set pm2-logrotate:max_size 10M
483
+ pm2 set pm2-logrotate:retain 7
484
+ pm2 set pm2-logrotate:compress true
485
+ ```
486
+
487
+ ### Step 19: Configure Automatic Updates
488
+
489
+ ```bash
490
+ # Create update script
491
+ nano /usr/local/bin/update-dtt-framework.sh
492
+ ```
493
+
494
+ Add the following:
495
+
496
+ ```bash
497
+ #!/bin/bash
498
+
499
+ # Navigate to application directory
500
+ cd /var/www/dtt-framework
501
+
502
+ # Pull latest changes
503
+ git pull origin main
504
+
505
+ # Install dependencies
506
+ pnpm install
507
+
508
+ # Build application
509
+ pnpm build
510
+
511
+ # Run migrations
512
+ pnpm db:push
513
+
514
+ # Restart PM2
515
+ pm2 restart dtt-framework
516
+
517
+ echo "Update completed successfully"
518
+ ```
519
+
520
+ Make it executable:
521
+
522
+ ```bash
523
+ chmod +x /usr/local/bin/update-dtt-framework.sh
524
+ ```
525
+
526
+ ### Step 20: Set Up Cron Job for Updates
527
+
528
+ ```bash
529
+ # Edit crontab
530
+ crontab -e
531
+ ```
532
+
533
+ Add the following to run updates daily at 2 AM:
534
+
535
+ ```cron
536
+ 0 2 * * * /usr/local/bin/update-dtt-framework.sh >> /var/log/dtt-framework-update.log 2>&1
537
+ ```
538
+
539
+ ---
540
+
541
+ ## Database Setup
542
+
543
+ ### Option 1: Use Supabase (External)
544
+
545
+ The framework is designed to work with Supabase as the primary database. This is the recommended approach for DigitalOcean deployments.
546
+
547
+ #### Configure Supabase Connection
548
+
549
+ ```bash
550
+ # In your .env file
551
+ DATABASE_URL=postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres
552
+ ```
553
+
554
+ #### Enable Supabase Connection Pooling
555
+
556
+ For DigitalOcean deployments, use Supabase's Transaction mode:
557
+
558
+ - **Port**: 6543
559
+ - **Host**: `.pooler.supabase.com`
560
+ - **Mode**: Transaction mode
561
+
562
+ ### Option 2: Use DigitalOcean Managed Database
563
+
564
+ If you prefer to use DigitalOcean's managed PostgreSQL:
565
+
566
+ #### Create a Managed Database
567
+
568
+ 1. Go to [DigitalOcean Databases](https://cloud.digitalocean.com/databases)
569
+ 2. Click **"Create Database Cluster"**
570
+ 3. Choose **PostgreSQL**
571
+ 4. Select plan and configuration
572
+ 5. Create database
573
+
574
+ #### Configure Connection
575
+
576
+ ```bash
577
+ # In your .env file
578
+ DATABASE_URL=postgresql://doadmin:[password]@db-postgresql-[region].do-user-[id].db.ondigitalocean.com:25060/defaultdb?sslmode=require
579
+ ```
580
+
581
+ #### Run Migrations
582
+
583
+ ```bash
584
+ # On your droplet
585
+ cd /var/www/dtt-framework
586
+
587
+ # Push schema to database
588
+ pnpm db:push
589
+ ```
590
+
591
+ ### Database Backup Strategy
592
+
593
+ #### Automated Backups
594
+
595
+ For Supabase:
596
+ - Enable daily backups in Supabase Dashboard
597
+ - Configure point-in-time recovery
598
+
599
+ For DigitalOcean Managed Database:
600
+ - Enable automated backups (daily, weekly)
601
+ - Configure backup retention period
602
+
603
+ #### Manual Backups
604
+
605
+ ```bash
606
+ # Backup database
607
+ pg_dump $DATABASE_URL > backup_$(date +%Y%m%d).sql
608
+
609
+ # Restore database
610
+ psql $DATABASE_URL < backup_20231201.sql
611
+ ```
612
+
613
+ ---
614
+
615
+ ## Monitoring and Logs
616
+
617
+ ### App Platform Monitoring
618
+
619
+ #### Built-in Metrics
620
+
621
+ DigitalOcean App Platform provides:
622
+
623
+ - **CPU Usage**: Monitor CPU utilization
624
+ - **Memory Usage**: Track memory consumption
625
+ - **Response Time**: Measure request latency
626
+ - **Request Count**: Track request volume
627
+ - **Error Rate**: Monitor application errors
628
+
629
+ #### Access Logs
630
+
631
+ 1. Go to **App Platform** → **Your App**
632
+ 2. Click **"Deployments"** → **Your Deployment**
633
+ 3. Click **"View Logs"**
634
+
635
+ #### Component Logs
636
+
637
+ 1. Go to **App Platform** → **Your App**
638
+ 2. Click **"Components"** → **Your Component**
639
+ 3. Click **"View Logs"**
640
+
641
+ ### Droplet Monitoring
642
+
643
+ #### System Monitoring
644
+
645
+ ```bash
646
+ # Check CPU usage
647
+ top
648
+
649
+ # Check memory usage
650
+ free -h
651
+
652
+ # Check disk usage
653
+ df -h
654
+
655
+ # Check process list
656
+ ps aux
657
+ ```
658
+
659
+ #### PM2 Monitoring
660
+
661
+ ```bash
662
+ # Monitor all processes
663
+ pm2 monit
664
+
665
+ # View logs
666
+ pm2 logs
667
+
668
+ # View specific process logs
669
+ pm2 logs dtt-framework
670
+
671
+ # View process info
672
+ pm2 info dtt-framework
673
+ ```
674
+
675
+ #### Nginx Access Logs
676
+
677
+ ```bash
678
+ # View access logs
679
+ tail -f /var/log/nginx/access.log
680
+
681
+ # View error logs
682
+ tail -f /var/log/nginx/error.log
683
+ ```
684
+
685
+ #### Application Logs
686
+
687
+ ```bash
688
+ # View PM2 logs
689
+ pm2 logs dtt-framework --lines 100
690
+
691
+ # View error logs only
692
+ pm2 logs dtt-framework --err --lines 100
693
+ ```
694
+
695
+ ### Setting Up External Monitoring
696
+
697
+ #### Uptime Monitoring
698
+
699
+ Use services like:
700
+ - **UptimeRobot**: Free uptime monitoring
701
+ - **Pingdom**: Advanced monitoring
702
+ - **StatusCake**: Website monitoring
703
+
704
+ Configure health check endpoint:
705
+ ```
706
+ https://your-domain.com/api/health
707
+ ```
708
+
709
+ #### Error Tracking
710
+
711
+ Integrate error tracking:
712
+ - **Sentry**: Error and performance monitoring
713
+ - **LogRocket**: Session replay and error tracking
714
+ - **Bugsnag**: Error monitoring and reporting
715
+
716
+ ---
717
+
718
+ ## Troubleshooting Common Issues
719
+
720
+ ### Issue: App Platform Build Fails
721
+
722
+ **Symptoms:**
723
+ - Deployment fails during build
724
+ - Error messages in build logs
725
+
726
+ **Solutions:**
727
+
728
+ ```bash
729
+ # Test build locally
730
+ pnpm build
731
+
732
+ # Check for missing dependencies
733
+ pnpm install
734
+
735
+ # Verify .do/app.yaml configuration
736
+ # Ensure build command is correct
737
+ ```
738
+
739
+ ### Issue: Droplet Application Won't Start
740
+
741
+ **Symptoms:**
742
+ - PM2 shows application as stopped
743
+ - Application crashes on startup
744
+
745
+ **Solutions:**
746
+
747
+ ```bash
748
+ # Check PM2 status
749
+ pm2 status
750
+
751
+ # View PM2 logs
752
+ pm2 logs dtt-framework
753
+
754
+ # Restart application
755
+ pm2 restart dtt-framework
756
+
757
+ # Check environment variables
758
+ cat /var/www/dtt-framework/.env
759
+
760
+ # Test application manually
761
+ cd /var/www/dtt-framework
762
+ pnpm start
763
+ ```
764
+
765
+ ### Issue: Nginx 502 Bad Gateway
766
+
767
+ **Symptoms:**
768
+ - Nginx returns 502 error
769
+ - Application not accessible
770
+
771
+ **Solutions:**
772
+
773
+ ```bash
774
+ # Check if application is running
775
+ pm2 status
776
+
777
+ # Check Nginx configuration
778
+ nginx -t
779
+
780
+ # Check Nginx error logs
781
+ tail -f /var/log/nginx/error.log
782
+
783
+ # Restart Nginx
784
+ systemctl restart nginx
785
+
786
+ # Restart application
787
+ pm2 restart dtt-framework
788
+ ```
789
+
790
+ ### Issue: SSL Certificate Not Renewing
791
+
792
+ **Symptoms:**
793
+ - SSL certificate expired
794
+ - HTTPS not working
795
+
796
+ **Solutions:**
797
+
798
+ ```bash
799
+ # Test renewal
800
+ certbot renew --dry-run
801
+
802
+ # Manually renew
803
+ certbot renew
804
+
805
+ # Check certificate status
806
+ certbot certificates
807
+
808
+ # Reload Nginx
809
+ systemctl reload nginx
810
+ ```
811
+
812
+ ### Issue: Database Connection Failed
813
+
814
+ **Symptoms:**
815
+ - Database connection errors
816
+ - Application can't connect to database
817
+
818
+ **Solutions:**
819
+
820
+ ```bash
821
+ # Test database connection
822
+ psql $DATABASE_URL
823
+
824
+ # Check DATABASE_URL format
825
+ # For Supabase, use Transaction mode:
826
+ # postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres
827
+
828
+ # Check firewall rules
829
+ ufw status
830
+
831
+ # Ensure database allows connections from your IP
832
+ ```
833
+
834
+ ### Issue: Out of Memory
835
+
836
+ **Symptoms:**
837
+ - Application crashes
838
+ - System becomes unresponsive
839
+
840
+ **Solutions:**
841
+
842
+ ```bash
843
+ # Check memory usage
844
+ free -h
845
+
846
+ # Check PM2 memory usage
847
+ pm2 monit
848
+
849
+ # Increase swap space
850
+ fallocate -l 2G /swapfile
851
+ chmod 600 /swapfile
852
+ mkswap /swapfile
853
+ swapon /swapfile
854
+
855
+ # Add to /etc/fstab for persistence
856
+ echo '/swapfile none swap sw 0 0' >> /etc/fstab
857
+ ```
858
+
859
+ ### Issue: Disk Space Full
860
+
861
+ **Symptoms:**
862
+ - Application can't write files
863
+ - Logs not being written
864
+
865
+ **Solutions:**
866
+
867
+ ```bash
868
+ # Check disk usage
869
+ df -h
870
+
871
+ # Find large files
872
+ du -h /var/log | sort -n | tail -20
873
+
874
+ # Clean old logs
875
+ pm2 flush
876
+
877
+ # Clean package cache
878
+ pnpm store prune
879
+
880
+ # Clean old PM2 logs
881
+ pm2 install pm2-logrotate
882
+ pm2 set pm2-logrotate:retain 7
883
+ ```
884
+
885
+ ### Issue: High CPU Usage
886
+
887
+ **Symptoms:**
888
+ - Slow application performance
889
+ - High CPU utilization
890
+
891
+ **Solutions:**
892
+
893
+ ```bash
894
+ # Check CPU usage
895
+ top
896
+
897
+ # Find CPU-intensive processes
898
+ ps aux --sort=-%cpu | head -20
899
+
900
+ # Check PM2 process stats
901
+ pm2 show dtt-framework
902
+
903
+ # Optimize application code
904
+ # - Use caching
905
+ # - Optimize database queries
906
+ # - Implement rate limiting
907
+ ```
908
+
909
+ ---
910
+
911
+ ## Best Practices
912
+
913
+ ### 1. Security
914
+
915
+ ```bash
916
+ # Keep system updated
917
+ apt update && apt upgrade -y
918
+
919
+ # Use SSH keys instead of passwords
920
+ # Disable root login
921
+ nano /etc/ssh/sshd_config
922
+ # Set: PermitRootLogin no
923
+
924
+ # Configure firewall
925
+ ufw enable
926
+ ufw allow OpenSSH
927
+ ufw allow 80
928
+ ufw allow 443
929
+ ```
930
+
931
+ ### 2. Backup Strategy
932
+
933
+ ```bash
934
+ # Regular database backups
935
+ # Add to crontab:
936
+ 0 3 * * * pg_dump $DATABASE_URL > /backups/db_$(date +\%Y\%m\%d).sql
937
+
938
+ # Backup application files
939
+ 0 4 * * * tar -czf /backups/app_$(date +\%Y\%m\%d).tar.gz /var/www/dtt-framework
940
+ ```
941
+
942
+ ### 3. Monitoring
943
+
944
+ ```bash
945
+ # Set up monitoring alerts
946
+ # Use DigitalOcean Monitoring
947
+ # Configure UptimeRobot for uptime monitoring
948
+ # Set up Sentry for error tracking
949
+ ```
950
+
951
+ ### 4. Performance Optimization
952
+
953
+ ```bash
954
+ # Enable Nginx caching
955
+ # Configure gzip compression
956
+ # Use CDN for static assets
957
+ # Optimize images
958
+ ```
959
+
960
+ ### 5. Documentation
961
+
962
+ ```bash
963
+ # Document your setup
964
+ # Keep track of configurations
965
+ # Maintain change logs
966
+ # Document troubleshooting steps
967
+ ```
968
+
969
+ ---
970
+
971
+ ## Comparison: App Platform vs Droplet
972
+
973
+ | Feature | App Platform | Droplet |
974
+ |---------|--------------|---------|
975
+ | **Ease of Use** | High | Medium |
976
+ | **Setup Time** | Minutes | Hours |
977
+ | **Control** | Limited | Full |
978
+ | **Scalability** | Auto-scaling | Manual |
979
+ | **Cost** | Higher | Lower |
980
+ | **Best For** | Quick deployment | Custom configurations |
981
+
982
+ ---
983
+
984
+ ## Related Documentation
985
+
986
+ - [Domain Setup](./domain-setup.md) - Custom domain configuration
987
+ - [Environment Variables](./environment-variables.md) - Complete variable reference
988
+ - [CI/CD Setup](./ci-cd.md) - Automated deployments
989
+ - [Production Checklist](./production-checklist.md) - Pre-deployment checklist
990
+ - [Monitoring](./monitoring.md) - Monitoring and alerting setup
991
+ - [Vercel Deployment](./vercel.md) - Alternative deployment platform