Skip to content

slackerkids/reelka

Repository files navigation

Reelka

AI-powered short‑form video generator. Write a script, generate a voiceover, captions, images, and render a 9:16 video via Remotion Lambda. Auth, data, and quotas are managed with Supabase; subscriptions with Polar; analytics with PostHog.

Tech stack

  • Frontend: Next.js 15 (App Router), React 19, TypeScript, Tailwind CSS v4, shadcn/ui
  • Auth & DB: Supabase (Auth, Postgres, Storage)
  • Video: Remotion 4 + AWS Lambda, S3 for outputs
  • AI: ElevenLabs (TTS), DeepInfra (LLM), Whisper/ASR pipeline
  • Billing: Polar (Checkout + Customer Portal)
  • Analytics: PostHog (client + server)
  • Moderation: AWS Rekognition (image content safety)

Getting started

Prerequisites

  • Node.js 20+
  • AWS account + IAM user with S3/Lambda permissions (for Remotion Lambda)
  • Supabase project (URL + anon key + service role key)
  • Polar account (access token + webhook secret)
  • ElevenLabs API key
  • DeepInfra API key
  • PostHog project key

1) Install dependencies

npm install

2) Configure environment

Create a .env.local at the repo root (values are examples/placeholders):

# App
NEXT_PUBLIC_APP_URL=http://localhost:3000
NEXT_PUBLIC_SITE_URL=http://localhost:3000

# Supabase
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key

# Analytics (PostHog)
NEXT_PUBLIC_POSTHOG_KEY=phc_your_key

# Billing (Polar)
POLAR_ACCESS_TOKEN=your_polar_access_token
POLAR_SERVER=sandbox # or production
POLAR_SUCCESS_URL=http://localhost:3000/dashboard/confirmation
POLAR_WEBHOOK_SECRET=whsec_...

# AI
ELEVENLABS_API_KEY=your_elevenlabs_key
DEEPINFRA_API_KEY=your_deepinfra_key
# Optional, used by openai image helper
OPENAI_API_KEY=sk-...

# Remotion Lambda / AWS
# Either set REMOTION_* or standard AWS_* keys
REMOTION_AWS_ACCESS_KEY_ID=AKIA...
REMOTION_AWS_SECRET_ACCESS_KEY=...
# Optional (used by deploy script as fallback)
AWS_ACCESS_KEY_ID=AKIA...
AWS_SECRET_ACCESS_KEY=...

# Cron (for subscription maintenance)
CRON_SECRET=super-secure-random-string

# Optional
FACEBOOK_DOMAIN_VERIFICATION=

Notes:

  • Do not commit secrets. .gitignore already excludes env files.
  • NEXT_PUBLIC_APP_URL is used by server actions that call internal API routes for Lambda rendering.

3) Database setup

Use the SQL in supabase/migrations/001_initial_schema.sql to create tables and functions (scripts, videos, subscriptions, usage helpers). You can paste it in the Supabase SQL editor or run it with your preferred tooling.

4) Run the app

npm run dev

Visit http://localhost:3000.


Remotion Lambda (cloud rendering)

Rendering is done on AWS Lambda via Remotion. Update scripts/config.mjs if needed:

export const REGION = "us-west-1";
export const BUCKET_NAME = "your-remotion-bucket";
export const SITE_NAME = "reelka"; // deployment/site name
export const RAM = 2048;
export const DISK = 2048;
export const TIMEOUT = 800;

Then deploy the Lambda function and S3 site:

npm run deploy

Requirements:

  • REMOTION_AWS_ACCESS_KEY_ID and REMOTION_AWS_SECRET_ACCESS_KEY (or standard AWS vars) must be set.
  • NEXT_PUBLIC_APP_URL must point to your running app domain (used by server to call /api/lambda/*).

Local preview with Remotion Studio:

npm run remotion

Manual render (CLI):

npm run render -- Composition

Billing & quotas

  • Subscriptions are handled via Polar checkout and customer portal
    • Checkout route: GET /api/checkout
    • Portal route: GET /api/portal?customerId=...
  • Webhook handler: POST /api/webhook/polar (set POLAR_WEBHOOK_SECRET)
  • Quota/usage tracking stored in subscriptions table. Helpers and reset logic are in the SQL migration.

Scheduled quota maintenance:

  • GET /api/cron/subscription-check expects header Authorization: Bearer ${CRON_SECRET}
  • Cancels expired subscriptions and resets monthly quotas when needed

AI pipeline

From the editor (/dashboard/videos/editor/[scriptId]):

  1. Text‑to‑Speech (ElevenLabs): /api/video/generate-audio
  2. Captions (ASR): /api/video/generate-captions
  3. Prompt generation (DeepInfra LLM): /api/video/generate-prompts
  4. Image generation (Stable diffusion/Flux via DeepInfra): /api/video/generate-images
  5. Image moderation (AWS Rekognition) before render
  6. Render via Remotion Lambda: /api/lambda/render, progress /api/lambda/progress, cleanup /api/lambda/delete

Uploads

  • Direct, signed S3 uploads for user-provided images: POST /api/upload/presigned-url

Analytics

  • PostHog is initialized on client and server.
  • Set NEXT_PUBLIC_POSTHOG_KEY (and optional NEXT_PUBLIC_POSTHOG_HOST).
  • Feature flags: keep usage minimal and centralized; validate flag values.

Project structure (high level)

app/                  # Next.js routes (App Router)
  api/                # API routes (checkout/portal, video generation, lambda, cron)
  dashboard/          # Authenticated app (scripts, videos, billing)
  remotion/           # Remotion Root + Composition
components/           # UI components (shadcn UI, dashboard, editor)
hooks/                # React hooks (local storage, generation pipeline)
scripts/              # Lambda/S3 deploy helpers & config
supabase/             # SQL migrations
types/                # Shared TypeScript types
utils/                # AI, AWS, Supabase, Remotion, PostHog helpers

Key files

  • app/remotion/Composition.tsx: 9:16 composition, captioning, Ken Burns images
  • app/api/video/*: asset generation endpoints (audio, captions, prompts, images)
  • app/api/lambda/*: Remotion Lambda render/progress/delete
  • app/api/webhook/polar/route.ts: Polar webhooks
  • utils/supabase/*: client/server/admin clients, billing helpers, storage
  • utils/aws/*: S3 client + Rekognition moderation

Useful scripts

npm run dev        # Start Next.js (with Turbopack)
npm run build      # Production build
npm run start      # Run production server
npm run remotion   # Open Remotion Studio locally
npm run render     # Render via Remotion CLI (local render)
npm run deploy     # Deploy Remotion Lambda function & site (AWS)

Environment variables reference

  • App: NEXT_PUBLIC_APP_URL, NEXT_PUBLIC_SITE_URL
  • Supabase: NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY
  • PostHog: NEXT_PUBLIC_POSTHOG_KEY, NEXT_PUBLIC_POSTHOG_HOST
  • Polar: POLAR_ACCESS_TOKEN, POLAR_SERVER, POLAR_SUCCESS_URL, POLAR_WEBHOOK_SECRET
  • AI: ELEVENLABS_API_KEY, DEEPINFRA_API_KEY, optional OPENAI_API_KEY
  • AWS / Remotion: REMOTION_AWS_ACCESS_KEY_ID, REMOTION_AWS_SECRET_ACCESS_KEY (or AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  • Cron: CRON_SECRET
  • Optional: FACEBOOK_DOMAIN_VERIFICATION

Never hardcode or commit secrets. Use .env.local and platform secret managers.


Development notes

  • UI: Uses Tailwind v4 and shadcn/ui. To add components:
    npx shadcn@latest add <component>
  • Styling: Inter typography, rounded buttons, light/dark themes are preconfigured in app/globals.css.
  • Images: Next Image allows specific remote hosts (see next.config.ts).
  • Feature flags and custom properties for analytics: keep names consistent and centralized.

Deployment

  • Frontend/API: Deploy on platforms like Vercel. Ensure all env vars are set, especially NEXT_PUBLIC_APP_URL.
  • Rendering: Deploy Remotion Lambda (npm run deploy), confirm the region/bucket/site in scripts/config.mjs and AWS permissions.
  • Webhooks: Expose POST /api/webhook/polar and set POLAR_WEBHOOK_SECRET.

Troubleshooting

  • Missing credentials errors in Lambda endpoints: ensure AWS/Remotion env vars are present on the server.
  • Polar webhooks failing: verify POLAR_WEBHOOK_SECRET and that your endpoint is reachable.
  • Supabase auth issues: confirm URL/keys and that cookies are allowed in your domain.
  • Image generation fails: check DEEPINFRA_API_KEY and logs. Rekognition rejections will surface as content policy violation errors.
  • Video stuck in processing: check /api/lambda/progress logs and AWS CloudWatch for the Lambda.

License

MIT — see LICENSE.

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors