@mevdragon/vidfarm-devcli 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.env.example +11 -4
  2. package/PLATFORM_SPEC.md +142 -2
  3. package/README.md +165 -16
  4. package/SKILL.developer.md +577 -0
  5. package/dist/infra/cdk/bin/vidfarm-prod.js +59 -0
  6. package/dist/infra/cdk/lib/vidfarm-prod-stack.js +212 -0
  7. package/dist/src/account-pages.js +578 -0
  8. package/dist/src/app.js +887 -66
  9. package/dist/src/cli.js +284 -5
  10. package/dist/src/config.js +24 -4
  11. package/dist/src/db.js +427 -18
  12. package/dist/src/dev-app.js +59 -12
  13. package/dist/src/homepage.js +441 -0
  14. package/dist/src/index.js +12 -7
  15. package/dist/src/lib/crypto.js +14 -0
  16. package/dist/src/lib/template-dna.js +542 -0
  17. package/dist/src/lib/template-style-options.js +49 -0
  18. package/dist/src/registry.js +54 -7
  19. package/dist/src/runtime.js +3 -1
  20. package/dist/src/services/auth.js +69 -5
  21. package/dist/src/services/jobs.js +23 -4
  22. package/dist/src/services/providers.js +74 -12
  23. package/dist/src/services/storage.js +52 -18
  24. package/dist/src/services/template-certification.js +160 -0
  25. package/dist/src/services/template-loader.js +37 -0
  26. package/dist/src/services/template-sources.js +135 -0
  27. package/dist/src/worker.js +19 -7
  28. package/dist/templates/template_0000/src/lib/images.js +242 -0
  29. package/dist/templates/template_0000/src/remotion/Root.js +33 -0
  30. package/dist/templates/template_0000/src/sdk.js +3 -0
  31. package/dist/templates/template_0000/src/style-options.js +51 -0
  32. package/dist/templates/template_0000/src/template-dna.js +9 -0
  33. package/dist/templates/template_0000/src/template.js +1217 -0
  34. package/package.json +9 -1
  35. package/templates/template_0000/README.md +121 -0
  36. package/templates/template_0000/SKILL.md +193 -0
  37. package/templates/template_0000/assets/Abel-Regular.ttf +0 -0
  38. package/templates/template_0000/assets/DMSerifDisplay-Regular.ttf +0 -0
  39. package/templates/template_0000/assets/Montserrat[wght].ttf +0 -0
  40. package/templates/template_0000/assets/SourceCodePro[wght].ttf +0 -0
  41. package/templates/template_0000/assets/TikTokSans-SemiBold.ttf +0 -0
  42. package/templates/template_0000/assets/Yesteryear-Regular.ttf +0 -0
  43. package/templates/template_0000/composition.json +11 -0
  44. package/templates/template_0000/package-lock.json +5137 -0
  45. package/templates/template_0000/package.json +30 -0
  46. package/templates/template_0000/research/preview/.gitkeep +1 -0
  47. package/templates/template_0000/research/source_notes.md +7 -0
  48. package/templates/template_0000/scripts/create-site.mjs +27 -0
  49. package/templates/template_0000/scripts/render-cloud.mjs +72 -0
  50. package/templates/template_0000/src/lib/images.ts +284 -0
  51. package/templates/template_0000/src/remotion/Root.js +33 -0
  52. package/templates/template_0000/src/remotion/Root.tsx +75 -0
  53. package/templates/template_0000/src/remotion/index.tsx +4 -0
  54. package/templates/template_0000/src/sdk.ts +122 -0
  55. package/templates/template_0000/src/style-options.js +51 -0
  56. package/templates/template_0000/src/style-options.ts +60 -0
  57. package/templates/template_0000/src/template-dna.ts +15 -0
  58. package/templates/template_0000/src/template.ts +1747 -0
  59. package/templates/template_0000/template.config.json +26 -0
  60. package/templates/template_0000/tsconfig.json +19 -0
  61. package/dist/templates/template_0000/demo-template.js +0 -196
  62. package/dist/templates/template_0000/remotion/Root.js +0 -66
  63. /package/dist/templates/template_0000/{remotion → src/remotion}/index.js +0 -0
package/.env.example CHANGED
@@ -9,13 +9,20 @@ API_KEY_SALT="replace-with-a-second-long-random-secret"
9
9
  WEBHOOK_SECRET="replace-with-a-third-long-random-secret"
10
10
 
11
11
  WORKER_POLL_MS="1500"
12
- WORKER_BATCH_SIZE="4"
12
+ WORKER_BATCH_SIZE="2"
13
+ WORKER_MAX_CONCURRENT_JOBS="1"
13
14
  DEFAULT_JOB_DELAY_SECONDS="20"
15
+ MAX_PENDING_JOBS_GLOBAL="0"
16
+ MAX_PENDING_JOBS_PER_CUSTOMER="0"
14
17
 
15
- PUBLIC_BASE_URL="http://localhost:3000"
18
+ PUBLIC_BASE_URL="https://vidfarm.cloud.zoomgtm.com"
19
+ VIDFARM_ADMIN_EMAILS="admin@example.com"
20
+ VIDFARM_DEVELOPER_EMAILS="developer@example.com"
21
+ TEMPLATE_SOURCE_ROOT="./data/template-sources"
16
22
  STORAGE_DRIVER="local"
17
23
  AWS_REGION="us-east-1"
18
24
  AWS_S3_BUCKET=""
25
+ AWS_S3_PUBLIC_READ="false"
19
26
  AWS_S3_ENDPOINT=""
20
27
  AWS_ACCESS_KEY_ID=""
21
28
  AWS_SECRET_ACCESS_KEY=""
@@ -31,9 +38,9 @@ PERPLEXITY_API_KEY=""
31
38
  REMOTION_FUNCTION_NAME=""
32
39
  REMOTION_REGION="us-east-1"
33
40
  REMOTION_BUCKET_NAME=""
34
- REMOTION_SITE_NAME="vidfarm-demo-template"
41
+ REMOTION_SITE_NAME="vidfarm-template-0000"
35
42
  REMOTION_SERVE_URL=""
36
- REMOTION_COMPOSITION_ID="demo-template"
43
+ REMOTION_COMPOSITION_ID="template-0000"
37
44
  REMOTION_AWS_ACCESS_KEY_ID=""
38
45
  REMOTION_AWS_SECRET_ACCESS_KEY=""
39
46
  REMOTION_MODE="auto"
package/PLATFORM_SPEC.md CHANGED
@@ -4,6 +4,8 @@ This document defines the initial platform architecture for Vidfarm running on a
4
4
 
5
5
  The goal is to let in-house developers build new video production templates quickly while the platform centrally owns auth, billing, job orchestration, customer state, and deployment.
6
6
 
7
+ For template code distribution in v1.1, the platform should support GitHub-backed in-house template sources, but production activation must still be manual, admin-approved, and pinned to a specific commit SHA.
8
+
7
9
  ## Goals
8
10
 
9
11
  1. Support multiple video production patterns behind one consistent API.
@@ -36,6 +38,38 @@ This gives us:
36
38
 
37
39
  Templates may still opt into isolated execution later when they have special requirements such as native binaries, unusually high memory use, or independent scaling needs.
38
40
 
41
+ ## Template Source Of Truth
42
+
43
+ Template code may live in GitHub, but the platform should not auto-pull floating branch heads into production.
44
+
45
+ Approved v1.1 release model:
46
+
47
+ 1. developer keeps template code in GitHub
48
+ 2. the default import branch is `production`
49
+ 3. admin manually reviews the repo and chooses when to import
50
+ 4. admin publishes the approved Remotion site bundle if the template needs Remotion
51
+ 5. platform resolves the chosen branch head to a commit SHA
52
+ 6. platform builds and certifies that exact commit
53
+ 7. platform activates a pinned release record for that commit
54
+ 8. admin rebuilds and redeploys the production Docker image with the approved release set
55
+
56
+ Live platform state should therefore point to:
57
+
58
+ - repo URL
59
+ - branch name
60
+ - exact commit SHA
61
+ - certification result
62
+ - active/inactive release state
63
+
64
+ It should not point only to a floating branch name.
65
+
66
+ Release authority should be centralized:
67
+
68
+ - developers can push source code to GitHub
69
+ - developers cannot directly publish to shared Remotion AWS
70
+ - developers cannot directly promote templates into production Docker
71
+ - shared AWS publish, activation, and production deployment are admin-only steps
72
+
39
73
  ## Initial Runtime Choice
40
74
 
41
75
  ### Production Runtime
@@ -122,8 +156,11 @@ Even if a task could finish quickly, the platform should still prefer job creati
122
156
 
123
157
  ```txt
124
158
  GET /templates/:templateId
159
+ GET /templates/:templateId/about/*
160
+ GET /templates/:templateId/skill
125
161
  POST /templates/:templateId/config
126
162
  POST /templates/:templateId/operations/:operationName
163
+ GET /templates/:templateId/jobs
127
164
  GET /templates/:templateId/jobs/:jobId
128
165
  GET /templates/:templateId/jobs/:jobId/logs
129
166
  POST /templates/:templateId/jobs/:jobId/cancel
@@ -155,6 +192,62 @@ vidfarm-api-key: string
155
192
  }
156
193
  ```
157
194
 
195
+ ### Template Metadata Response Shape
196
+
197
+ ```json
198
+ {
199
+ "id": "4c7a7e1a-7f35-4f30-9f86-9c8a63c7f2db",
200
+ "slug_id": "template_0000",
201
+ "version": "1.0.0",
202
+ "title": "Template 0000",
203
+ "description": "Short-form slideshow pipeline",
204
+ "viral_dna": "Fast TikTok slideshow hooks with mobile-native pacing.",
205
+ "preview_media": [
206
+ "https://api.example.com/templates/4c7a7e1a-7f35-4f30-9f86-9c8a63c7f2db/about/preview-01.jpg"
207
+ ],
208
+ "link_to_original": "https://www.tiktok.com/@example/video/1234567890",
209
+ "skill_url": "https://api.example.com/templates/4c7a7e1a-7f35-4f30-9f86-9c8a63c7f2db/skill",
210
+ "operations": [
211
+ {
212
+ "name": "create_slideshow",
213
+ "description": "Generate slideshow frames.",
214
+ "providerHint": "openrouter"
215
+ }
216
+ ]
217
+ }
218
+ ```
219
+
220
+ `GET /templates/:templateId/about/*` should expose template metadata assets such as preview images or videos. In storage, these assets should use the stable logical prefix `templates/:templateId/about/*`, whether the backing store is local disk or S3.
221
+
222
+ Template definitions should expose `preview_media` as absolute HTTPS URLs. When the backing store is S3, those entries should point directly at the S3 object for assets stored under `templates/:templateId/about/*`.
223
+
224
+ ### Job List Filtering
225
+
226
+ `GET /templates/:templateId/jobs` should support:
227
+
228
+ - `tracer`
229
+ - `start_time`
230
+ - `end_time`
231
+ - `limit`
232
+
233
+ `GET /templates/:templateId/jobs/:jobId/logs` should use the same time window language:
234
+
235
+ - `start_time`
236
+ - `end_time`
237
+ - `limit`
238
+
239
+ `logs_from` is deprecated and should not be used in the standard.
240
+
241
+ `GET /templates/:templateId` is the template "about" response and must also return:
242
+
243
+ - `slug_id: string`
244
+ - `title: string`
245
+ - `viral_dna: string`
246
+ - `preview_media: string[]`
247
+ - `link_to_original: string`
248
+
249
+ In the template definition standard, this response `title` and `description` should be sourced from `template.about.title` and `template.about.description`, not top-level template fields.
250
+
158
251
  ## Template Model
159
252
 
160
253
  Templates are normal TypeScript packages with unrestricted internal structure and should live under a repo-level `templates/` directory, for example `templates/template_0000/*`.
@@ -178,9 +271,16 @@ Suggested shape:
178
271
 
179
272
  ```ts
180
273
  export const myTemplate = defineTemplate({
181
- id: "ugc-voiceover-v1",
274
+ id: "123e4567-e89b-42d3-a456-426614174000",
275
+ slugId: "ugc_voiceover_v1",
182
276
  version: "1.0.0",
183
- description: "Short-form UGC voiceover pipeline",
277
+ about: {
278
+ title: "UGC Voiceover V1",
279
+ description: "Short-form UGC voiceover pipeline",
280
+ viral_dna: "Fast hooks, native pacing, and repeatable creator-style framing.",
281
+ preview_media: ["https://cdn.example.com/templates/ugc-voiceover-v1/about/preview-01.mp4"],
282
+ link_to_original: "https://www.tiktok.com/@example/video/1234567890"
283
+ },
184
284
  configSchema: z.object({
185
285
  defaultProvider: z.enum(["openai", "gemini", "openrouter", "perplexity"]).default("openai")
186
286
  }),
@@ -337,6 +437,8 @@ This is for:
337
437
  2. Template development.
338
438
  3. Dry-running internal workflows before deployment.
339
439
 
440
+ Template authors should also be able to run the same certification harness locally through the developer CLI before admin review.
441
+
340
442
  ### Production
341
443
 
342
444
  The platform must use customer-owned provider keys stored in the customer profile when the template requests external AI inference on behalf of that customer.
@@ -349,6 +451,20 @@ Platform-controlled keys may still exist for:
349
451
 
350
452
  But customer-billed workloads should default to customer-owned keys when available.
351
453
 
454
+ Admin-only template source import and activation are allowed in production. Developer template changes should not go live until an admin explicitly imports and activates a pinned release.
455
+
456
+ ## Developer And Admin Auth Model
457
+
458
+ The platform’s API auth remains customer-style `vidfarm-user-id` plus `vidfarm-api-key`, but the platform must also support an admin allowlist for template-source management endpoints.
459
+
460
+ Minimum v1.1 rule:
461
+
462
+ 1. all normal template execution uses standard platform auth
463
+ 2. template source registration, import, and activation endpoints are admin-only
464
+ 3. admin authorization may begin as an allowlist of trusted emails
465
+
466
+ This keeps v1 simple while still distinguishing runtime customers from internal release operators.
467
+
352
468
  ## Customer Profile Model
353
469
 
354
470
  Each customer profile should support:
@@ -768,6 +884,16 @@ Artifacts may include:
768
884
 
769
885
  This prefix is for template-generated outputs and intermediate artifacts. Keep it stable across storage backends so local development mirrors production object layout.
770
886
 
887
+ ### Template Metadata Convention
888
+
889
+ Suggested logical prefix:
890
+
891
+ ```txt
892
+ s3://bucket/templates/:templateId/about/...
893
+ ```
894
+
895
+ This prefix is for framework-owned template metadata assets such as preview images, preview videos, and other public "about" media referenced by `GET /templates/:templateId`.
896
+
771
897
  ## Remotion Integration
772
898
 
773
899
  Remotion should be treated as a specialized downstream execution path, not the center of the platform.
@@ -866,6 +992,8 @@ Responsibilities:
866
992
  3. Template code is trusted internal code in v1, not untrusted tenant code.
867
993
  4. Webhook signatures must be mandatory.
868
994
  5. Customer file access must always be scoped by customer identity.
995
+ 6. Template source imports must pin an exact commit SHA before activation.
996
+ 7. Templates must include a `SKILL.md` file so customer AI agents have a framework-owned usage contract.
869
997
 
870
998
  ## Operational Notes for v1
871
999
 
@@ -875,6 +1003,18 @@ Responsibilities:
875
1003
  4. Back up SQLite and treat it as transitional infrastructure.
876
1004
  5. Store all large artifacts in S3, not on container disk.
877
1005
  6. Assume template code is centrally reviewed before deployment.
1006
+ 7. Not every template requires Remotion. Remotion validation should only apply to templates that actually call the Remotion adapter.
1007
+
1008
+ ## Template Certification Minimum
1009
+
1010
+ A template must not be activatable unless all of the following pass:
1011
+
1012
+ 1. template metadata contract is valid
1013
+ 2. operation-to-workflow references are valid
1014
+ 3. a template-local `SKILL.md` file exists
1015
+ 4. every operation defines a smoke-test payload
1016
+ 5. the smoke-test harness passes
1017
+ 6. the release is associated with a pinned commit SHA
878
1018
 
879
1019
  ## Known Limits of v1
880
1020
 
package/README.md CHANGED
@@ -2,15 +2,20 @@
2
2
 
3
3
  Vidfarm is a single-container Node.js control plane for async video template pipelines. It follows the architecture in [video-pipeline-architecture-draft.md](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/video-pipeline-architecture-draft.md) and [PLATFORM_SPEC.md](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/PLATFORM_SPEC.md): Hono API, SQLite-backed jobs and provider-key leasing, S3-compatible storage, and an in-process worker suitable for Docker on EC2.
4
4
 
5
+ Production is now intended to run as one HTTPS host at `https://vidfarm.cloud.zoomgtm.com`, with the HTML console served from `/` and the API served under `/api/v1/...`.
6
+
5
7
  ## What Is Included
6
8
 
7
- - Async template API under `/templates/:templateId/*`
9
+ - Unified frontend and backend on one host
10
+ - Async template API under `/api/v1/templates/:templateId/*`
11
+ - User auth/profile/provider-key routes under `/api/v1/user/*`
8
12
  - Email OTP login with API key issuance
13
+ - `is_developer` user flag, assigned from allowlisted emails, required for template source submission
9
14
  - Customer-scoped provider key vault with encryption at rest
10
15
  - SQLite-backed job queue and provider-key lease coordination
11
16
  - Structured job logs, artifacts, billing events, and webhook delivery queue
12
17
  - Local storage mode plus S3-compatible mode for AWS
13
- - Remotion adapter seam and a sample `demo-template` slideshow pipeline
18
+ - Remotion adapter seam and a sample `template_0000` slideshow pipeline
14
19
 
15
20
  ## Quick Start
16
21
 
@@ -28,7 +33,7 @@ For local template development, use the bundled CLI instead of manually wiring a
28
33
 
29
34
  ```bash
30
35
  npm install
31
- npx @officexapp/vidfarm-devcli dev --port 3310 --reset
36
+ npx @mevdragon/vidfarm-devcli dev --port 3310 --reset
32
37
  ```
33
38
 
34
39
  What it does:
@@ -44,14 +49,26 @@ What it does:
44
49
  Useful commands:
45
50
 
46
51
  ```bash
47
- npx @officexapp/vidfarm-devcli dev --port 3310 --reset
48
- npx @officexapp/vidfarm-devcli session
52
+ npx @mevdragon/vidfarm-devcli dev --port 3310 --reset
53
+ npx @mevdragon/vidfarm-devcli session
54
+ npx @mevdragon/vidfarm-devcli validate-template --template-id template_0000
55
+ npx @mevdragon/vidfarm-devcli generate-template --slug-id template_0001 --template-dir ./templates/template_0001
56
+ npx @mevdragon/vidfarm-devcli analyze-viral-dna --template-dir ./templates/template_0001
57
+ npx @mevdragon/vidfarm-devcli analyze-visual-dna --template-dir ./templates/template_0001
49
58
  ```
50
59
 
51
60
  After install, the package also exposes `vidfarm` and `vidfarm-devcli` as local binaries.
52
61
 
53
62
  `vidfarm session` prints reusable auth headers and a sample `curl` request for the local REST API.
54
63
 
64
+ `generate-template` now scaffolds a standard `research/` area for new templates:
65
+
66
+ - `research/source_notes.md` for original-format notes
67
+ - `research/preview/` for source screenshots or video
68
+ - `src/template-dna.ts` as the checked-in metadata module that feeds `about.viral_dna`, `about.visual_dna`, and `about.link_to_original`
69
+
70
+ If preview media is already present, or if you pass `--source-preview-dir`, scaffold generation will run both DNA analyzers automatically unless `--skip-dna-analysis` is set.
71
+
55
72
  ## Environment
56
73
 
57
74
  Primary variables:
@@ -59,15 +76,22 @@ Primary variables:
59
76
  - `PORT`
60
77
  - `VIDFARM_DB_PATH`
61
78
  - `VIDFARM_DATA_DIR`
79
+ - `VIDFARM_ADMIN_EMAILS`
80
+ - `TEMPLATE_SOURCE_ROOT`
62
81
  - `ENCRYPTION_SECRET`
63
82
  - `API_KEY_SALT`
64
83
  - `STORAGE_DRIVER=local|s3`
65
84
  - `AWS_REGION`
66
85
  - `AWS_S3_BUCKET`
86
+ - `AWS_S3_PUBLIC_READ=true|false`
67
87
  - `PUBLIC_BASE_URL`
68
88
  - `RESEND_API_KEY`
69
89
  - `WEBHOOK_SECRET`
70
90
  - `MOCK_PROVIDER_RESPONSES=true|false`
91
+ - `VIDFARM_DEVELOPER_EMAILS`
92
+ - `WORKER_MAX_CONCURRENT_JOBS`
93
+ - `MAX_PENDING_JOBS_GLOBAL`
94
+ - `MAX_PENDING_JOBS_PER_CUSTOMER`
71
95
 
72
96
  Remotion-specific variables:
73
97
 
@@ -82,7 +106,7 @@ Remotion-specific variables:
82
106
 
83
107
  When `MOCK_PROVIDER_RESPONSES=true`, AI provider calls use the real key-leasing flow but return mocked content. This makes local end-to-end testing possible without burning customer API calls.
84
108
 
85
- When using `npx @officexapp/vidfarm-devcli dev`, the CLI automatically chooses local-friendly defaults:
109
+ When using `npx @mevdragon/vidfarm-devcli dev`, the CLI automatically chooses local-friendly defaults:
86
110
 
87
111
  - `STORAGE_DRIVER=local`
88
112
  - `REMOTION_MODE=local`
@@ -93,6 +117,14 @@ When using `npx @officexapp/vidfarm-devcli dev`, the CLI automatically chooses l
93
117
 
94
118
  For shared Remotion AWS infra, use [AWS_REMOTION_HANDOFF.md](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/AWS_REMOTION_HANDOFF.md) as the operating contract.
95
119
 
120
+ Shared Remotion AWS publish is an admin-only release step. Template developers may build and test locally, but they should not push directly to the shared production Remotion account. The intended promotion flow is:
121
+
122
+ 1. developer pushes template code to GitHub `production`
123
+ 2. admin reviews and pins a commit SHA
124
+ 3. admin publishes the approved Remotion site bundle
125
+ 4. admin activates the approved template release
126
+ 5. admin rebuilds and redeploys the production Docker image
127
+
96
128
  The key points verified on `2026-05-16` are:
97
129
 
98
130
  - region: `us-east-1`
@@ -122,13 +154,56 @@ If you wire real Lambda rendering into `src/services/remotion.ts`, preserve the
122
154
 
123
155
  ## API Flow
124
156
 
125
- 1. `POST /auth/request-otp`
126
- 2. `POST /auth/verify-otp`
127
- 3. `POST /me/provider-keys`
128
- 4. `POST /templates/demo-template/config`
129
- 5. `POST /templates/demo-template/operations/generate`
130
- 6. Poll `GET /templates/demo-template/jobs/:jobId`
131
- 7. Stream timeline data from `GET /templates/demo-template/jobs/:jobId/logs`
157
+ 1. `POST /api/v1/user/request-otp`
158
+ 2. `POST /api/v1/user/verify-otp`
159
+ 3. `POST /api/v1/user/me/provider-keys`
160
+ 4. `GET /api/v1/templates/template_0000`
161
+ 5. `GET /api/v1/templates/template_0000/skill`
162
+ 6. `POST /api/v1/templates/template_0000/config`
163
+ 7. `POST /api/v1/templates/template_0000/operations/create_slideshow`
164
+ 8. Poll `GET /api/v1/templates/template_0000/jobs/:jobId`
165
+ 9. List or filter jobs with `GET /api/v1/templates/template_0000/jobs?tracer=...&start_time=...&end_time=...`
166
+ 10. Stream timeline data from `GET /api/v1/templates/template_0000/jobs/:jobId/logs?start_time=...&end_time=...`
167
+
168
+ ## Template Release Flow
169
+
170
+ Templates can still live in this repo, but the platform now supports a GitHub-backed release workflow for in-house templates:
171
+
172
+ 1. developer keeps template code in GitHub
173
+ 2. the approved branch convention is `production`
174
+ 3. admin registers the template source with repo URL, module path, build command, and `SKILL.md` path
175
+ 4. admin imports a specific commit, or the current `production` head
176
+ 5. platform builds the repo, loads the template module, and runs certification
177
+ 6. only certified releases can be activated
178
+ 7. activation pins the live template to a specific commit SHA, not a floating branch head
179
+
180
+ Template management endpoints:
181
+
182
+ - `GET /api/v1/templates/sources`
183
+ - `POST /api/v1/templates/sources`
184
+ - `GET /api/v1/templates/releases`
185
+ - `POST /api/v1/templates/sources/:sourceId/import`
186
+ - `POST /api/v1/templates/releases/:releaseId/activate`
187
+
188
+ `POST /api/v1/templates/sources` requires a user with `is_developer=true`. That flag is assigned from `VIDFARM_DEVELOPER_EMAILS` or `VIDFARM_ADMIN_EMAILS` during OTP verification. Registration now requires a self-issued UUIDv4 `template_id` plus a human-readable `slug_id`, and the platform rejects reused `template_id` values with an explicit conflict error. Import and activation remain admin-only via `VIDFARM_ADMIN_EMAILS`.
189
+
190
+ ## Template Certification
191
+
192
+ Every template must have:
193
+
194
+ - a `SKILL.md` file for customer AI agents
195
+ - both `about.viral_dna` and `about.visual_dna`
196
+ - at least one operation
197
+ - valid workflow references
198
+ - a `smokeTestPayload` for each operation
199
+
200
+ Use the CLI locally before import/activation:
201
+
202
+ ```bash
203
+ npx @mevdragon/vidfarm-devcli validate-template --template-id template_0000
204
+ ```
205
+
206
+ Not every template needs Remotion. Certification only requires Remotion behavior if the template itself calls `ctx.remotion`.
132
207
 
133
208
  ## Docker
134
209
 
@@ -136,16 +211,90 @@ If you wire real Lambda rendering into `src/services/remotion.ts`, preserve the
136
211
  docker compose up --build
137
212
  ```
138
213
 
139
- For AWS/EC2, mount `/app/data` onto durable storage if SQLite is local, or switch artifacts to S3 with:
214
+ For local Docker, `docker-compose.yml` already mounts `./data:/app/data`, which keeps SQLite across container restarts and rebuilds on the same machine.
215
+
216
+ For production on EC2, the CDK stack mounts a dedicated EBS volume at `/var/lib/vidfarm` on the instance and binds it into the container as `/app/data`. That means the following survive shutdowns, reboots, and container updates:
217
+
218
+ - `vidfarm.sqlite`
219
+ - SQLite WAL/SHM files
220
+ - imported template source checkouts
221
+ - any local fallback runtime data under `/app/data`
222
+
223
+ Artifacts and workspace objects should still live in S3 in production:
140
224
 
141
225
  ```env
142
226
  STORAGE_DRIVER=s3
143
227
  AWS_REGION=us-east-1
144
228
  AWS_S3_BUCKET=your-vidfarm-bucket
145
- PUBLIC_BASE_URL=https://your-domain.example
229
+ AWS_S3_PUBLIC_READ=false
230
+ PUBLIC_BASE_URL=https://vidfarm.cloud.zoomgtm.com
146
231
  ```
147
232
 
233
+ Queue protection for small EC2 instances is now SQLite-backed and built into the app:
234
+
235
+ - `WORKER_MAX_CONCURRENT_JOBS=1` by default
236
+ - `WORKER_BATCH_SIZE=2` by default
237
+ - `MAX_PENDING_JOBS_GLOBAL=0` by default
238
+ - `MAX_PENDING_JOBS_PER_CUSTOMER=0` by default
239
+
240
+ With the default `0` values, submissions are always accepted and persisted in SQLite. The worker simply drains the queue at the configured concurrency. Set either pending-job value above `0` only if you later decide you want a hard backlog cap.
241
+
242
+ ## AWS CDK Production
243
+
244
+ The production CDK app lives under `infra/cdk` and provisions:
245
+
246
+ - one S3 bucket for Vidfarm object storage
247
+ - one public ALB with HTTP to HTTPS redirect
248
+ - one ACM certificate for `vidfarm.cloud.zoomgtm.com`
249
+ - one EC2 instance running the Docker image
250
+ - one dedicated encrypted EBS data volume retained separately from the container
251
+ - Route53 `A` and `AAAA` alias records for the production hostname
252
+
253
+ Required shell variables before synth or deploy:
254
+
255
+ ```bash
256
+ export CDK_DEFAULT_ACCOUNT=123456789012
257
+ export CDK_DEFAULT_REGION=us-east-1
258
+ export VIDFARM_ZONE_NAME=cloud.zoomgtm.com
259
+ export VIDFARM_ZONE_ID=Z1234567890ABC
260
+ export VIDFARM_RECORD_NAME=vidfarm
261
+ export VIDFARM_PUBLIC_BASE_URL=https://vidfarm.cloud.zoomgtm.com
262
+ export VIDFARM_ADMIN_EMAILS=admin@zoomgtm.com
263
+ export VIDFARM_DEVELOPER_EMAILS=dev1@zoomgtm.com,dev2@zoomgtm.com
264
+ export VIDFARM_ENCRYPTION_SECRET='replace-with-a-long-random-secret'
265
+ export VIDFARM_API_KEY_SALT='replace-with-a-second-long-random-secret'
266
+ export VIDFARM_WEBHOOK_SECRET='replace-with-a-third-long-random-secret'
267
+ ```
268
+
269
+ Optional app env passthroughs are supported too, including:
270
+
271
+ - `VIDFARM_RESEND_API_KEY`
272
+ - `VIDFARM_RESEND_FROM_EMAIL`
273
+ - `VIDFARM_OPENAI_API_KEY`
274
+ - `VIDFARM_OPENROUTER_API_KEY`
275
+ - `VIDFARM_GEMINI_API_KEY`
276
+ - `VIDFARM_PERPLEXITY_API_KEY`
277
+ - `VIDFARM_REMOTION_*`
278
+ - `VIDFARM_INSTANCE_TYPE`
279
+ - `VIDFARM_DATA_VOLUME_SIZE_GIB`
280
+ - `VIDFARM_WORKER_MAX_CONCURRENT_JOBS`
281
+ - `VIDFARM_MAX_PENDING_JOBS_GLOBAL`
282
+ - `VIDFARM_MAX_PENDING_JOBS_PER_CUSTOMER`
283
+
284
+ If you do not set `VIDFARM_INSTANCE_TYPE`, the CDK app now defaults to `t3.small`.
285
+
286
+ Deploy flow:
287
+
288
+ ```bash
289
+ npm install
290
+ npm run cdk:synth
291
+ npx aws-cdk bootstrap aws://$CDK_DEFAULT_ACCOUNT/$CDK_DEFAULT_REGION
292
+ npm run cdk:deploy
293
+ ```
294
+
295
+ The stack builds the Docker image locally, pushes it to an asset ECR repository, installs Docker on the EC2 host, mounts the retained EBS volume, writes the production env file, and runs the container as a systemd service.
296
+
148
297
  ## Notes
149
298
 
150
- - `demo-template` is the canonical sample internal template. Add more templates by registering them in [src/registry.ts](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/src/registry.ts).
299
+ - `template_0000` is the canonical sample internal template slug. Its current sample `template_id` is `4c7a7e1a-7f35-4f30-9f86-9c8a63c7f2db`. Add more templates by registering them in [src/registry.ts](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/src/registry.ts).
151
300
  - Remotion is still stubbed behind [src/services/remotion.ts](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/src/services/remotion.ts). When upgrading it to real Lambda submission, follow [AWS_REMOTION_HANDOFF.md](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/AWS_REMOTION_HANDOFF.md) and use the Remotion-specific AWS credentials already available in local production env config.