FrameFlow is a photo-sharing platform for photography and event teams. An admin creates an event, adds team members, receives their uploads, selects the photos for delivery, and publishes a PIN-protected gallery for the customer.
Customers do not need an account. They receive a gallery link and a six-digit PIN, then view the published photos through the public gallery route.
Built for the TrizenAI full-stack internship challenge.
- Frontend: https://trizen-ai-frontend.vercel.app
- Backend health: https://trizen-ai.onrender.com/health
- API health: https://trizen-ai.onrender.com/api/v1/health
The frontend is deployed on Vercel. The backend is packaged as a Docker image and deployed as a Render web service.
- An admin registers and signs in through Clerk.
- The admin creates an event. New events start in
draftstatus. - The admin adds a team member from the Team page.
- The team member registers with the invited email and becomes a
TEAM_MEMBERin the admin's workspace. - The admin opens the event's Team tab and assigns an active team member from the workspace member selector.
- The team member sees the assigned event and uploads photos to it.
- The admin sees all event photos, selects the photos for delivery, and creates a gallery.
- The admin publishes the gallery and shares its URL and six-digit PIN.
- The customer opens the URL, enters the PIN, and browses the published gallery without signing in.
If Clerk production email delivery is not configured with a verified sending domain, the admin can create a pending member and share the registration URL manually. The member must use the exact email entered by the admin.
Admins can create, edit, delete, and change event status; manage workspace team members; assign members to events; view every photo in their workspace events; curate photos; create and publish galleries; set or regenerate gallery PINs; and share customer gallery URLs.
Event statuses are draft, active, and completed. Gallery status is
separate and uses draft and published.
Team members can sign in, view assigned events, upload photos, and view only their own uploaded photos in those events. They cannot manage users, assign members, view galleries, curate photos, create galleries, publish galleries, or delete photos.
Customers have no application account. They open a shared gallery URL, enter the six-digit PIN, browse published photos, and download individual photos.
| Layer | Technology | Responsibility |
|---|---|---|
| Frontend | Next.js 16, React 19, Tailwind CSS 4 | Dashboard, upload, gallery and customer UI |
| Authentication | Clerk | Sign-in, sign-up, sessions and invitations |
| Backend | Express 5, TypeScript, Node.js 24 | API, authorization, validation and business rules |
| Database | Supabase PostgreSQL | Users, workspaces, events, assignments and metadata |
| File storage | Appwrite Storage | Photo binaries only |
| Testing | Vitest, Supertest | API, authorization and workflow tests |
| Observability | Prometheus, Grafana, prom-client | Metrics, dashboards and alert examples (dev stack) |
| Monorepo | Turborepo, Bun | Workspace scripts, dependencies and builds |
| Frontend hosting | Vercel | Next.js production deployment |
| Backend hosting | Render | Dockerized Express production service |
Browser
|
| Clerk session token in Authorization header
v
Vercel - Next.js frontend
|
| HTTPS API requests
v
Render - Dockerized Express backend
|\
| \-- Clerk Backend SDK: identity and invitations
|\
| \- Supabase PostgreSQL: application metadata
|\
\---- Appwrite Storage: photo binaries
The browser never connects directly to PostgreSQL or Appwrite using server
credentials. Frontend requests go through
apps/frontend/src/lib/api/client.ts. The backend verifies the Clerk bearer
token and derives the user, role, and workspace from trusted server-side data.
- Clerk creates the browser session.
- The frontend obtains a Clerk session token.
- The token is sent as
Authorization: Bearer <token>. - Express verifies the token with
@clerk/backend. - The backend resolves the application user and role from PostgreSQL.
- Workspace and event membership checks run before protected operations.
GET /api/v1/public/galleries/:slug
POST /api/v1/public/galleries/:slug/unlock { pin }
GET /api/v1/public/galleries/:slug/photos/:photoId?st=<token>
The PIN is checked server-side. A successful unlock creates a short-lived, gallery-bound signed token. Photo bytes are proxied from Appwrite through the backend.
The schema is versioned under supabase/migrations/.
workspaces
|
+-- users
| |
| +-- invitations
| |
| +-- event_team_members -- events -- photos
| |
| +-- galleries -- gallery_photos -- photos
workspacesis the tenancy boundary.usersstores the verified Clerk ID, role, email, and workspace.invitationsstores pending workspace invitations and their status.eventsbelongs to one workspace and has a lifecycle status.event_team_membersis the relationship that grants event access.photosstores metadata only: event, uploader, filename, storage ID, MIME type, size, and timestamps.galleriesstores event-scoped gallery metadata, slug, PIN, and status.gallery_photosstores the admin's selected photo set.
PostgreSQL stores metadata only. Image files are stored in Appwrite.
All application routes are under /api/v1.
| Area | Routes | Access |
|---|---|---|
| Health | GET /health, GET /api/v1/health |
Public |
| Identity | GET /api/v1/me |
Authenticated |
| Dashboard | GET /api/v1/stats |
Authenticated, role-scoped |
| Workspace team | /team-members and related routes |
Admin |
| Events | /events CRUD |
Reads authenticated; writes admin |
| Event assignment | /events/:id/team-members |
Admin |
| Photos | /events/:id/photos, /photos/:id |
Assigned member upload/read-own; admin full access |
| Galleries | /events/:id/galleries, /galleries/:id/* |
Admin |
| Analytics | /analytics/* |
Admin, workspace-scoped |
| Public galleries | /public/galleries/:slug/* |
Public, PIN/token protected |
Errors use a consistent response shape:
{ "error": "A safe user-facing message" }Internal error details are logged server-side and are not returned to clients.
Photo lists are cursor-paginated — event collections and the public gallery surface never return unbounded arrays:
GET /api/v1/events/:eventId/photos?limit=50&cursor=<opaque>&order=newest|oldest
POST /api/v1/public/galleries/:slug/unlock?limit=50&cursor=<opaque> { pin }
GET /api/v1/public/galleries/:slug/photos?st=<token>&limit=50&cursor=<opaque>
limitis 1–100 (default 50); anything else is400.cursoris an opaque base64url token from the previous page'spagination.next_cursor; malformed cursors are400.- Every list responds
{ photos: [...], pagination: { limit, next_cursor, has_more } }. Follownext_cursorwhilehas_moreis true. - Event ordering is stable (
created_at,id); gallery ordering follows curation order (added_at,photo_id). Same-millisecond uploads cannot duplicate or skip rows across pages. - Authorization is unchanged: workspace/event gates run before pagination, and the public follow-up endpoint re-verifies the signed unlock token.
- The unlock response keeps its shape (
gallery,access_token,expires_at) and addspagination;gallery.photo_countis the total.
Uploads enqueue two thumbnail variants per photo (thumb_small 320w,
thumb_large 960w, WebP) and return 201 without waiting — a background
sweep processes them through QUEUED → PROCESSING → READY (FAILED after
3 attempts, with last_error kept on the row). Photo responses carry
processing_status plus per-variant status/url (URL only when READY);
grids render thumbnails with the original as fallback. The customer proxy
serves .../photos/:photoId?st=<token>&variant=thumb_small (409 while
not ready, 400 for unknown variants). Failures are retried explicitly:
POST /api/v1/photos/:photoId/derivatives/retry (admin, workspace-scoped)
Stuck PROCESSING rows (crashed worker) are re-queued automatically.
Originals are never modified; deleting a photo or event also removes its
derivative binaries (best-effort, like originals). Legacy photos uploaded
before this feature read as QUEUED until the retry endpoint enqueues them.
Thumbnail work runs in a separate worker process when Redis is configured:
docker compose up redis -d # local Redis on :6379
# apps/backend/.env.local: REDIS_URL=redis://localhost:6379
bun run dev --filter=backend # API (:4000)
cd apps/backend && bun run worker:thumbnails:watch # worker (separate terminal)Production runs the compiled worker as its own service
(node dist/workers/thumbnails.js) with REDIS_URL pointing at managed
Redis. Without REDIS_URL, everything still works: the API falls back to
the in-process sweep. Deployments that cannot run a separate worker (single
container, e.g. a free Render web service) but still want Redis for rate
limiting set DERIVATIVES_INLINE=true: the API then skips the queue and
keeps processing thumbnails in-process.
- Uploads publish one job per variant (
dv:<photoId>:<variant>) with 3 attempts, exponential backoff (5s base), a 120s processor timeout, and bounded worker concurrency (2). Replies never wait for jobs. - PostgreSQL stays authoritative: jobs that find a
READYrow or lose thePGclaim race are skips, so redelivery never duplicates derivatives. - Recovery without an outbox (deliberate): a repeatable reconciler job
(every 60s) re-queues crashed rows and republishes anything still
QUEUED/FAILED-with-budget — including photos created while Redis was down. A transactional outbox would narrow the already-small loss window (enqueue-then-publish crash) at the cost of a relay poller and new tables; the reconciler bounds that window to ~60s with visibleQUEUEDrows, so the outbox was deferred. Publish failures also trigger the in-process sweep immediately, and the admin retry endpoint always works. GET /api/v1/queues/derivatives(admin) reports BullMQ counts (configured: falsewithout Redis,503when Redis is unreachable). Worker logs are single-line JSON with no secrets;SIGTERM/SIGINTdrain active jobs before exit.
Customer interactions emit versioned events (GalleryViewed,
PhotoViewed, PhotoDownloaded, GalleryDownloaded, GalleryShared;
contract v1 in apps/backend/src/lib/analytics-events.ts):
docker compose up kafka -d # local Kafka on :9092
# apps/backend/.env.local: KAFKA_BROKERS=localhost:9092
cd apps/backend && bun run worker:analytics:watch # consumer (separate terminal)- Emission points today: successful gallery unlock (
GalleryViewed) and proxied photo serving (PhotoViewedinline,PhotoDownloadedfordl=1). Dashboard downloads use direct Appwrite URLs and are not observable server-side —PhotoDownloadedcurrently covers customer proxied downloads only. - Events carry ids, timestamps, a pseudonymous
visitorId, a per-unlockcorrelationId, and a normalized traffic source — never PINs, tokens, credentials, emails, IPs, or full URLs. The unlock response echoesvisitor_id/correlation_id; photo URLs carryv=/c=(img tags cannot set headers). The frontend mints the visitor id intolocalStorage(x-visitor-idheader); clearing site data resets it. Unique-visitor counts are therefore estimates, not identities. - Events also carry a transparent
clientClass(human/bot/suspicious) classified from the User-Agent. This is an analytics annotation only — it never blocks traffic — and legacy rows stay NULL, treated exactly likehumanfor eligibility. - Delivery honesty: producers fire-and-forget after the response with a
3s timeout — Kafka outages only log, galleries keep serving, and a crash
between serving and emitting loses that event (accepted: aggregates are
estimates). Consumers are at-least-once: one topic
(
frameflow.analytics.v1), partitioned with gallery-id keys, consumer groupframeflow-analytics-v1; offsets commit only after the validated event is stored, and redelivery dedupes on theevent_idprimary key. No transactional outbox: the loss window is small and loss-tolerant, so the extra relay was deferred (same reasoning as the thumbnail reconciler). - Raw events land in
analytics_event_log(no FK to galleries — analytics outlive deletions, workspace-scoped by a denormalized column). Phase 5 aggregates read from this table. - Production: hosted Kafka with an explicitly created topic (gallery-keyed partitions, 7-day retention to match local compose) plus a separate worker service. Vercel/Render provide no Kafka — this is external infrastructure with its own cost.
One view = one successful gallery unlock (one GalleryViewed event).
Re-entering the PIN counts as a new view; redelivery of the same event
(same eventId) never counts twice — the raw log's primary key plus
conditional aggregation enforce that. Initial page loads that 404, failed
PINs, and rate-limited attempts are not views.
Unique visitors are visitor-day estimates, not person counts: the
frontend sends a pseudonymous client-minted UUID (localStorage, reset by
clearing site data), stored as a SHA-256 hash in one row per
(gallery, UTC day, hash). Cookie deletion, multiple devices, shared links,
and missing ids (counted as views, never as uniques) all skew the number.
Range uniques are exact distinct-hash counts over the window — never summed
daily uniques.
Traffic sources are direct (no referrer), unknown (unparseable), or
a normalized hostname (www. stripped, length-capped, path/query dropped)
with optional UTM medium/campaign passthrough. Referrers are untrusted
input. All buckets are UTC days from the event's occurredAt.
GET /api/v1/analytics/overview?from=YYYY-MM-DD&to=YYYY-MM-DD (admin)
GET /api/v1/analytics/galleries/:galleryId?from=YYYY-MM-DD&to=YYYY-MM-DD (admin)
Both default to the trailing 30 days (max one year, 400 otherwise),
return zero-filled daily series plus per-source views/uniques, and are
workspace-scoped: team members get 403, foreign-workspace galleries
404 exactly like missing ones. Customer gallery endpoints are unchanged.
Every stored event counts exactly once (same eventId redelivery is a
no-op, including under concurrent consumers):
photo_views[photo]/photo_downloads[photo]—PhotoViewed/PhotoDownloadedcounts per photo and day. Served inline vsdl=1decides the classification server-side; clients cannot mislabel.- Gallery
photo_views/photo_downloads/shares— windowed sums;sharescountsGallerySharedclicks from the customer Share button (nativevsclipboardchannel). download_rate— DISTINCT download sessions / DISTINCT sessions over the window, ornullwhen there are no sessions. A session is one unlock correlation id, and every session renders the gallery, so every session is eligible — stated denominator, not a "CTR". Computed at read time from the raw log (exact distinct counts, UTC-bounded); counters come from the rollups. No per-photo uniques by design (counts only; uniques stay gallery-level).top_photos— top 10 by views (then downloads, then id) with filenames best-effort (nullafter a photo is deleted; counts survive).GalleryDownloadedis contracted but dormant: no bulk export exists, so nothing emits it yet. Share clicks send once per gesture with no retry — a failed report is dropped, never repeated, so retries can't inflate.- Event volume stays bounded: one event per unlock, photo serve, download, or share click — no scroll/hover tracking, no new visitor data beyond Phase 4's pseudonymous id.
GET /api/v1/analytics/popular-galleries?from=YYYY-MM-DD&to=YYYY-MM-DD
(or ?all=true for all-time; ?limit= 1–50, default 10; admin only,
workspace-scoped) ranks the workspace's galleries by eligible engagement:
- Order is total and deterministic: views, then exact window uniques,
then downloads, then gallery id ascending — same log, same window, same
ranking. Every number is a direct aggregate of
analytics_event_log(covered by a partial ranking index), never a cached score, so the result is reproducible and recomputable. - Eligible is the documented bot policy:
client_class = 'bot'events never count;human,suspicious(conservative — may be legitimate kiosks), andNULL(unclassified pre-Phase-7 rows) all count. - Views are eligible
GalleryViewedevents, uniques are exact distinct visitors over the whole window (not summed daily uniques), and downloads are eligiblePhotoDownloadedcounts. A gallery needs at least one eligible view to rank. - Draft galleries never rank — they are reported separately as
excluded_drafts(drafts that would have ranked). Published galleries with no activity are absent; deleted galleries drop out while their events stay in the log for history. - Windowed mode reuses the analytics range rules (trailing 30 days by
default, one-year cap).
?all=trueis deliberately unbounded: the all-time read scans the raw log end to end, the one query here whose cost grows with history (see Known limitations).
{
"range": { "from": "2026-05-01", "to": "2026-05-31" },
"rankings": [
{ "rank": 1, "gallery_id": "…", "name": "…", "slug": "…",
"views": 42, "unique_visitors": 17, "downloads": 9 }
],
"excluded_drafts": 2
}GET /api/v1/events/:eventId/photo-recommendations?limit= (1–50, default
24) helps admins curate an event's gallery. Admin picks are managed with
POST /api/v1/events/:eventId/photo-picks and
DELETE /api/v1/events/:eventId/photo-picks/:photoId (both idempotent,
both admin-only and workspace-scoped — a pick can never cross tenants).
The strategy is deterministic-baseline-v1: no ML, same photos plus the
same analytics log always produce the same ranking.
- Signal model, highest first: pinned admin picks → eligible popularity
(
views + 2 × downloadsover a trailing 30-day window, bot-classified events excluded, capped) → capture bursts (same uploader, photos within 120 s of each other, three or more in the cluster) → newest-first fallback. Reasons report which signals fired:admin_pick,popular,same_burst,recent. - Order is total and deterministic: score descending, then newest upload, then photo id ascending — repeated calls return the identical ranking. Pins are weighted so they always outrank any amount of popularity.
- Bounded: at most the 1,000 most recent photos of the event are
scored (
candidatesin the response), popularity is one aggregate query overanalytics_event_log, and bursts are computed in memory from upload metadata. - Admin surface only, photos only: the payload never contains gallery material (ids, slugs, PINs, publish status), so a curation read can never leak customer-facing data.
- Offline quality gate:
bun run eval:recoscores the strategy against a checked-in golden dataset (apps/backend/eval/reco-dataset.json) and exits non-zero if precision drops below the documented threshold — run it after touching scoring.
{
"strategy": "deterministic-baseline-v1",
"window_days": 30,
"candidates": 3,
"recommendations": [
{ "photo": { "id": "…" }, "score": 1000, "reasons": ["admin_pick"] },
{ "photo": { "id": "…" }, "score": 3, "reasons": ["popular"] },
{ "photo": { "id": "…" }, "score": 0, "reasons": ["recent"] }
]
}Distributed sliding-window limits guard every expensive or enumerable
surface. When REDIS_URL is configured the windows live in Redis (atomic
Lua scripts), so one budget is shared across all API instances — the
correct model behind a load balancer. Without Redis (local dev, tests) the
in-process window applies, and it is also the per-class degraded fallback
when Redis is unreachable. Blocked requests answer 429 with
Retry-After; bucket keys are SHA-256 hashes of the class and material, so
raw IPs and user ids never reach Redis, logs, or error messages.
| Class | Limit | Window | Key | Purpose |
|---|---|---|---|---|
pin-failure |
5 | 15 min | slug + IP | PIN brute force (failure window) |
pin-attempt |
30 | 15 min | slug + IP | unlock flood guard (all attempts) |
public-read |
600 | 1 min | IP | gallery metadata / photo floods |
upload |
30 | 10 min | user | upload floods |
admin |
300 | 10 min | user | admin API floods |
provision |
120 | 5 min | IP | signup/provision floods |
- PIN semantics: every unlock attempt draws from
pin-attempt; a wrong PIN additionally fills the 5-failurepin-failurewindow; a correct PIN clears it. Blocked requests never extend their own lockout, and buckets are scoped per slug — one attacked gallery cannot lock another. - Degradation is per class, deliberately: sensitive classes (PIN, upload,
admin) fall back to the in-process window, so protection never silently
drops; non-sensitive classes (
public-read,provision) fail OPEN — a Redis outage must not take the customer surface down. The outage is logged once (scope: "rate-limit") and a 15s cooldown keeps a dead Redis from adding latency to every request. - Client classification is reporting-only: the User-Agent is classified
(
human/bot/suspicious) and stamped onto analytics events (seeanalytics_event_log.client_class). It never blocks a request — the limiter applies equally to bots and humans — andbotevents are excluded from popularity-ranking inputs. - Redis being unset in production is a deployment gap, not a design choice: the in-memory fallback protects one instance only, which is why CI runs the limiter suite against real Redis.
Every process exports Prometheus metrics via prom-client. Collection is
in-process and failure-isolated: Prometheus or Grafana being down never
affects serving, and a worker whose metrics sidecar fails to bind logs the
error and keeps working.
| Surface | Endpoint | Notes |
|---|---|---|
| API | GET /metrics on port 4000 |
infra surface — no Clerk auth (see gate) |
| Thumbnail worker | http://localhost:9464/metrics |
sidecar; METRICS_PORT overrides |
| Analytics worker | http://localhost:9472/metrics |
sidecar; METRICS_PORT overrides |
Exposure policy: enabled by default only when NODE_ENV=development;
production opts in with METRICS_ENABLED=true. When METRICS_TOKEN is set,
the API route and the worker sidecars require Authorization: Bearer <token> (constant-time compare); without it, keep the ports off the public
internet.
What is exported: HTTP request counts (route pattern, method, status) and
latency histograms; PostgreSQL query latency by statement kind; BullMQ queue
depth, oldest-waiting age, worker concurrency, job completion/failure and
retries; derivative job outcomes and durations; Kafka consumer lag per
partition; analytics ingest outcomes (stored / duplicate / invalid) and
batch errors; Redis fallback errors; plus the default process metrics.
Labels are strictly bounded — route patterns (never raw URLs), fixed
outcome enums, topic/partition — so series count cannot grow with traffic;
requests that match no route collapse into route="unmatched".
Local stack:
docker compose up -d prometheus grafana # Grafana at http://localhost:3030 (admin/admin)Prometheus scrapes the host-run API and workers every 15s
(infra/prometheus/prometheus.yml) and loads example alert rules
(infra/prometheus/alerts.yml) that are validated with promtool. Grafana
comes provisioned with the datasource and the FrameFlow dashboard
(infra/grafana/): request rate/errors/latency, DB latency, queue health,
worker outcomes, consumer lag, and analytics ingest.
- Clerk is the only identity provider. Supabase Auth and custom JWTs are not used.
- The backend verifies every authenticated Clerk token.
- User IDs, uploader IDs, roles, and workspace IDs are never trusted from the browser.
- Roles are read from PostgreSQL, not from client state.
- Every workspace query is scoped to the authenticated user's workspace.
- Team members need an
event_team_membersrow to access an event. - Team-member photo reads are filtered by the authenticated uploader ID.
- Uploads accept JPEG, PNG, and WebP files with a 25 MB per-file limit.
- Gallery PIN attempts are rate-limited per gallery and IP address — distributed via Redis when configured, with per-class degraded fallbacks (see Rate limiting & abuse protection).
- Unpublished galleries are not exposed through the public API.
- Public gallery photos use signed, time-limited backend URLs.
- Secrets are validated at backend startup and are never committed to Git.
.
├── apps/
│ ├── frontend/ # Next.js application
│ └── backend/ # Express API and Dockerfile
├── packages/ # Shared workspace configuration
├── infra/ # Prometheus + Grafana provisioning (dev)
├── supabase/migrations/ # Versioned PostgreSQL migrations
├── .github/workflows/ci.yml # GitHub Actions checks
├── turbo.json
├── package.json
└── bun.lock
Requirements: Bun 1.x, Node.js 24+, PostgreSQL with the migrations applied, a Clerk development instance, and an Appwrite project with a storage bucket.
bun install
cp apps/frontend/.env.example apps/frontend/.env.local
cp apps/backend/.env.example apps/backend/.env.localApply the SQL migrations to the development database, then start the apps in separate terminals:
bun run dev --filter=frontend
bun run dev --filter=backendThe frontend runs on http://localhost:3000; the backend runs on
http://localhost:4000. docker compose up -d brings up the optional
local infrastructure: Redis, Kafka, and the Prometheus/Grafana
observability stack (see Observability).
Useful commands:
bun run lint
bun run check-types
bun run build
bun run testNEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...
NEXT_PUBLIC_API_URL=http://localhost:4000
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/login
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/register
NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL=/dashboard
NEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL=/dashboardNEXT_PUBLIC_* values are exposed to the browser. CLERK_SECRET_KEY is
server-only and is required by the Next.js Clerk proxy configuration.
DATABASE_URL=postgresql://user:password@host:port/database
DATABASE_SSL_CA=./prod-ca-2021.crt
CLERK_SECRET_KEY=sk_test_...
APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
APPWRITE_PROJECT_ID=your-project-id
APPWRITE_API_KEY=your-server-api-key
APPWRITE_BUCKET_ID=photos
GALLERY_TOKEN_SECRET=replace-with-a-long-random-secret
NODE_ENV=development
PORT=4000DATABASE_SSL_CA is required in production for a remote PostgreSQL database.
GALLERY_TOKEN_SECRET should be a separate random secret in production. Real
values must never be committed.
Optional observability variables (defaults suit local development — see
Observability): METRICS_ENABLED=true turns the endpoints on
(default: on only when NODE_ENV=development), METRICS_TOKEN gates them
behind Authorization: Bearer <token>, and METRICS_PORT overrides a
worker sidecar port.
- Create or select the production project.
- Apply every file in
supabase/migrations/in filename order. - Copy the transaction-pooler connection string into Render's
DATABASE_URL. - Keep the production Supabase CA certificate at
apps/backend/prod-ca-2021.crtso the Docker image can verify TLS.
Create the production project and image bucket, then create a server API key with only the storage permissions required by the backend. Add the endpoint, project ID, API key, and bucket ID to Render.
The Render service uses the repository root as the Docker build context:
Environment: Docker
Dockerfile path: apps/backend/Dockerfile
Docker build context: repository root (.)
Health check path: /health
Branch: main
Build locally with:
docker build -f apps/backend/Dockerfile -t frameflow-backend .Required Render variables:
NODE_ENV=production
CLERK_SECRET_KEY=sk_live_...
DATABASE_URL=your-production-supabase-connection-string
DATABASE_SSL_CA=./prod-ca-2021.crt
APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
APPWRITE_PROJECT_ID=your-production-project-id
APPWRITE_API_KEY=your-production-server-api-key
APPWRITE_BUCKET_ID=your-production-bucket-id
GALLERY_TOKEN_SECRET=your-long-random-production-secretThe application binds to 0.0.0.0 and uses Render's PORT value. Verify the
service after deployment:
curl https://trizen-ai.onrender.com/health
curl https://trizen-ai.onrender.com/api/v1/healthThe analytics pipeline runs unchanged against managed brokers that speak SASL over TLS. Set these on the API service and on the analytics worker:
KAFKA_BROKERS=<host>:<port> # Overview → Connection information (SASL tab)
KAFKA_TOPIC_ANALYTICS=frameflow.analytics.v1
KAFKA_SASL_USERNAME=avnadmin
KAFKA_SASL_PASSWORD=<secret>
KAFKA_SASL_MECHANISM=scram-sha-256 # Aiven default
KAFKA_SSL_CA=<inline PEM or ./ca.pem>- The credential pair switches the client to SASL_SSL; without it the client
dials plaintext (local compose).
KAFKA_SSL_CAaccepts an inline PEM value (convenient in the Render dashboard) or a file path (convenient locally) and enables full chain verification. - Create the topic before the first publish (console → Topics →
frameflow.analytics.v1), 2 partitions, keyed by gallery. Aiven's free tier caps retention (~3 days) and powers off idle services, losing topic data — treat it as a demo buffer, not durable storage. - The consumer is its own service (
node dist/workers/analytics.js, same repo and image as the API) with the sameDATABASE_*and Kafka variables. Render background workers have no free tier, so on a $0 budget the worker stays undeployed: the API keeps publishing, but no aggregates reach Postgres until a consumer runs somewhere.
Connect the repository to Vercel and deploy the apps/frontend Next.js app.
Set these Production variables:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_...
CLERK_SECRET_KEY=sk_live_...
NEXT_PUBLIC_API_URL=https://trizen-ai.onrender.com
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/login
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/register
NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL=/dashboard
NEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL=/dashboardRedeploy after changing any NEXT_PUBLIC_* value because those values are
embedded during the Next.js build.
- Use the Production Clerk instance for the Vercel deployment.
- Add the Vercel URL to Clerk's allowed origins and redirect URLs.
- Confirm
/login,/register,/dashboard, and the Clerk proxy path in production. - Configure a verified sending domain if production invitation emails are required.
Without a verified email domain, use the pending-member flow and share the
registration URL manually. Never put CLERK_SECRET_KEY in frontend code or a
NEXT_PUBLIC_* variable.
Vitest and Supertest cover authentication, role checks, workspace isolation, event assignment, assigned-event visibility, upload authorization, uploader attribution, file validation, gallery creation, publishing, PIN changes, rate limiting, signed public gallery access, popular-gallery ranking (order, windows, ties, bot filter, draft reporting, isolation), and the metrics surface (exposure gating, token enforcement, label-cardinality guard).
bun run lint
bun run check-types
bun run test
bun run buildThe database-backed integration suites require TEST_DATABASE_URL with the
migrations applied. The Redis-backend rate-limiter tests require
REDIS_TEST_URL (they skip themselves with a warning when it is unset).
GitHub Actions provisions PostgreSQL and Redis, applies migrations, and runs
the verification pipeline on pushes to main and pull requests.
- Production Clerk invitation emails require a verified sending domain; the manual pending-member flow is available without one.
- Gallery PINs are currently stored as plaintext in PostgreSQL.
- Rate limiting is Redis-backed when
REDIS_URLis set (shared across instances) and per-process otherwise; without Redis the fallback degrades per class — see Rate limiting & abuse protection. - Authenticated dashboard previews use Appwrite view URLs; public gallery photos use the signed backend proxy.
- Photo grids page through cursor-paginated APIs and prefer thumbnail URLs with full-size fallback.
- Popular-gallery all-time rankings aggregate the raw log directly; at large event volumes this is the first read whose cost grows with history (windowed rankings stay bounded, and a rollup optimization is the natural next step if volume demands it).
- Alert rules are dev examples (
infra/prometheus/alerts.yml); production alerting still needs an Alertmanager or Grafana contact-point setup. - Metrics endpoints are open unless
METRICS_TOKENis set — production must network-gate them or configure the token. - Bulk ZIP downloads, gallery expiry, and gallery unpublish are not included.
This repository was created as an internship challenge submission.