File size: 14,076 Bytes
d03d74d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# Vault - Project Overview

**Generated:** 2026-02-11  
**Project Type:** SaaS / Web Application  
**Domain:** E-Commerce / Creator Economy  
**Complexity:** Medium-High

---

## Executive Summary

Vault is an AI-powered e-commerce platform that transforms YouTube video archives into shoppable experiences. The platform automatically detects products featured in videos, matches them to marketplace listings (Amazon, eBay, Etsy), and creates passive revenue streams for content creators through affiliate marketing.

### Core Value Proposition

- **For Creators:** Monetize historical video content without manual tagging
- **For Viewers:** Discover and purchase products from trusted creators
- **For Marketplaces:** High-intent traffic from engaged audiences

---

## Business Goals

### Success Criteria

| Metric | Target |
|--------|--------|
| First affiliate revenue (video >12 months old) | Within 7 days of archive activation |
| Viewer product discovery | Under 3 clicks to find specific item |
| Creator passive revenue (Standard tier) | >$100/month average (12-month goal) |
| AI matching accuracy | >85% precision |
| Vault grid load time | <1.5 seconds on 4G |
| Archive processing | 1,000 videos within 48 hours |

### Innovation: "Lost Intent" Capture

Vault captures unmet demand for discontinued or out-of-stock items mentioned in historical media. When products are unavailable, viewers can click "I want this" to join a waitlist, creating valuable demand data for:
- Creators (sourcing opportunities)
- Resellers (market insights)
- Brands (demand signals)

---

## Architecture Overview

### High-Level Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        VAULT PLATFORM                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚   Vercel    β”‚    β”‚   Railway   β”‚    β”‚   Supabase  β”‚        β”‚
β”‚  β”‚  (Frontend) β”‚    β”‚  (Workers)  β”‚    β”‚  (Database) β”‚        β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚         β”‚                  β”‚                  β”‚                β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β”‚
β”‚                            β”‚                                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚                   Inngest                          β”‚        β”‚
β”‚  β”‚         (Durable Workflow Orchestration)           β”‚        β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚                            β”‚                                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚              External Integrations                 β”‚        β”‚
β”‚  β”‚  YouTube β”‚ Amazon β”‚ eBay β”‚ Etsy β”‚ Gemini β”‚ Redis  β”‚        β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Technology Decisions

| Decision | Choice | Rationale |
|----------|--------|-----------|
| Framework | Next.js 15 (App Router) | SSR for SEO, Server Actions for mutations |
| Database | Supabase Postgres | Managed Postgres with built-in auth options |
| ORM | Drizzle | Type-safe, lightweight, migration support |
| Background Jobs | Inngest | Durable workflows, automatic retries, observability |
| Caching | Upstash Redis | TTL-based caching, serverless-friendly |
| Auth | Better Auth | Next.js 15 App Router compatibility, YouTube OAuth |
| AI Vision | Gemini + HuggingFace | Multi-provider flexibility, cost optimization |
| Deployment | Vercel + Railway | Hybrid: Edge frontend + persistent workers |

---

## Feature Modules

### 1. Discovery Pipeline (`src/features/discovery/`)

**Purpose:** AI-powered video scanning and object detection

**Components:**
- YouTube OAuth integration
- Video archive scanning (Inngest workflow)
- Frame extraction (FFmpeg)
- AI vision analysis (Gemini/HuggingFace)
- Thumbnail storage (Supabase Storage)

**Key Files:**
- [`src/inngest/functions/scan-video-archive.ts`](../src/inngest/functions/scan-video-archive.ts) - Archive scanning workflow
- [`src/inngest/functions/detect-objects.ts`](../src/inngest/functions/detect-objects.ts) - Object detection workflow
- [`src/features/discovery/services/ai-vision.service.ts`](../src/features/discovery/services/ai-vision.service.ts) - Vision provider abstraction

### 2. Marketplace Integration (`src/features/marketplace/`)

**Purpose:** Product matching and affiliate link generation

**Supported Marketplaces:**
- Amazon (PA-API 5.0)
- eBay (Finding API)
- Etsy (Open API v3)

**Key Files:**
- [`src/features/marketplace/services/amazon.service.ts`](../src/features/marketplace/services/amazon.service.ts)
- [`src/features/marketplace/services/ebay.service.ts`](../src/features/marketplace/services/ebay.service.ts)
- [`src/features/marketplace/services/etsy.service.ts`](../src/features/marketplace/services/etsy.service.ts)
- [`src/inngest/functions/match-marketplace.ts`](../src/inngest/functions/match-marketplace.ts) - Matching workflow

### 3. Vault Experience (`src/features/vault/`)

**Purpose:** Public-facing product discovery interface

**Features:**
- Mobile-first responsive grid
- Category filtering
- Product search
- Affiliate redirect tracking
- Interest capture for out-of-stock items

**Key Files:**
- [`src/features/vault/services/vault.service.ts`](../src/features/vault/services/vault.service.ts) - Data fetching with caching
- [`src/features/vault/components/vault-grid.tsx`](../src/features/vault/components/vault-grid.tsx) - Main grid component
- [`src/features/vault/components/product-card.tsx`](../src/features/vault/components/product-card.tsx) - Product display

### 4. Moderation System (`src/features/moderation/`)

**Purpose:** Creator review and curation of AI detections

**Features:**
- Approval/rejection workflow
- Bulk operations
- Detection editing (name, category, links)
- Manual product addition
- Admin moderation for high-ambiguity items

**Key Files:**
- [`src/features/moderation/services/moderation.service.ts`](../src/features/moderation/services/moderation.service.ts)
- [`src/features/moderation/components/moderation-queue.tsx`](../src/features/moderation/components/moderation-queue.tsx)

### 5. Interest Capture (`src/features/interest/`)

**Purpose:** "Lost Intent" demand capture

**Features:**
- Email waitlist for unavailable items
- GDPR/CCPA compliant consent
- Duplicate prevention (email hashing)
- Notification system

**Key Files:**
- [`src/features/interest/components/interest-capture-modal.tsx`](../src/features/interest/components/interest-capture-modal.tsx)

### 6. Analytics (`src/features/analytics/`)

**Purpose:** Creator insights and metrics

**Features:**
- Click tracking
- Interest pledge counts
- Revenue attribution
- Key metrics dashboard

**Key Files:**
- [`src/features/analytics/components/key-metrics-row.tsx`](../src/features/analytics/components/key-metrics-row.tsx)

---

## User Roles

| Role | Description | Key Permissions |
|------|-------------|-----------------|
| **Anonymous Viewer** | Public visitor | Browse vaults, search products, click affiliate links |
| **Registered Creator** | Content creator | Connect YouTube, moderate detections, view analytics |
| **Admin** | Platform operator | All creator permissions + admin moderation, user management |

---

## Data Flow

### Video Processing Pipeline

```
YouTube Video
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Scan      β”‚ ◄── Inngest: scan-video-archive
β”‚   Archive   β”‚
β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Extract   β”‚ ◄── FFmpeg frame extraction
β”‚   Frames    β”‚
β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Detect    β”‚ ◄── Inngest: detect-objects
β”‚   Objects   β”‚     (Gemini/HuggingFace)
β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Match     β”‚ ◄── Inngest: match-marketplace
β”‚  Products   β”‚     (Amazon/eBay/Etsy)
β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Moderate   β”‚ ◄── Creator review
β”‚   Queue     β”‚
β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Public    β”‚ ◄── Vault grid display
β”‚   Vault     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## Security & Compliance

### Authentication
- Google OAuth with YouTube readonly scope
- Better Auth session management
- Secure cookie handling (production)

### Data Protection
- PII encryption (emails) at rest
- AES-256 encrypted email storage
- SHA-256 hashing for deduplication
- Unsubscribe tokens for GDPR compliance

### API Security
- YouTube API ToS compliance
- Marketplace API rate limit handling
- Sentry error tracking
- Input validation on all server actions

---

## Performance Targets

| Metric | Target | Strategy |
|--------|--------|----------|
| LTI (Load-to-Interactivity) | <1.5s on 4G | SSR + ISR + Edge caching |
| Search latency | <300ms | Redis caching, indexed queries |
| Traffic spike handling | 10x surge <10% degradation | CDN, connection pooling |
| Uptime | 99.9% | Multi-region deployment, health checks |

---

## Deployment Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      PRODUCTION                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚     Vercel       β”‚         β”‚     Railway      β”‚         β”‚
β”‚  β”‚   (Edge/Server)  β”‚         β”‚   (Background)   β”‚         β”‚
β”‚  β”‚                  β”‚         β”‚                  β”‚         β”‚
β”‚  β”‚  β€’ Next.js App   β”‚         β”‚  β€’ Inngest       β”‚         β”‚
β”‚  β”‚  β€’ SSR/ISR       β”‚         β”‚    Functions     β”‚         β”‚
β”‚  β”‚  β€’ API Routes    β”‚         β”‚  β€’ FFmpeg        β”‚         β”‚
β”‚  β”‚  β€’ Server        β”‚         β”‚    Processing    β”‚         β”‚
β”‚  β”‚    Actions       β”‚         β”‚                  β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚           β”‚                            β”‚                    β”‚
β”‚           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚
β”‚                        β”‚                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
β”‚  β”‚              External Services              β”‚             β”‚
β”‚  β”‚                                             β”‚             β”‚
β”‚  β”‚  β€’ Supabase (Postgres + Storage)           β”‚             β”‚
β”‚  β”‚  β€’ Upstash Redis (Caching)                 β”‚             β”‚
β”‚  β”‚  β€’ Inngest Cloud (Workflow orchestration)  β”‚             β”‚
β”‚  β”‚  β€’ Sentry (Error monitoring)               β”‚             β”‚
β”‚  β”‚  β€’ Google Cloud (YouTube API, Gemini)      β”‚             β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚
β”‚                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## Related Documentation

- [Source Tree](./source-tree.md) - Detailed directory structure
- [Data Models](./data-models.md) - Database schema and relationships
- [API Contracts](./api-contracts.md) - Endpoints and server actions
- [Inngest Workflows](./inngest-workflows.md) - Background job documentation
- [Development Guide](./development-guide.md) - Setup and deployment