Local development
This page gets ContentsVision running on your machine. There are two processes (a FastAPI backend and a Next.js frontend) plus FFmpeg on your PATH.
Prerequisites
- Python 3.11+
- Node.js 20+
- FFmpeg (
brew install ffmpegon macOS) - API keys: Anthropic / OpenRouter, Deepgram (transcription), and the AdjustSquare JWT secret for login
- Optional: a PostHog project key to enable product analytics locally. Leave it unset and analytics stays off.
Quick start: ./start.sh
From the repo root, one command brings up both processes for development:
./start.sh
It is idempotent. On the first run it creates backend/venv, installs the
backend and frontend dependencies, and copies backend/.env from
backend/.env.example (it never overwrites an existing .env). Then it starts:
- the backend on
http://localhost:8001(uvicorn--reload), and - the frontend on
http://localhost:3001(next dev).
Ctrl-C stops both cleanly. Useful flags:
--backend-only/--frontend-onlyrun just one side.--backend-port N/--frontend-port Nuse different ports (handy when the Dockerlocalstack already holds8001/3001). The frontend's/apiproxy follows the chosen backend port automatically (the script exportsNEXT_PUBLIC_API_URL). The live job progress stream does not: its route handler readsBACKEND_ORIGIN(defaulthttp://localhost:8001), so with a different backend port start it asBACKEND_ORIGIN=http://localhost:N ./start.sh --backend-port N.--skip-installskips the dependency checks for a faster restart.
After the first run, set the AI keys and ADJUSTSQUARE_JWT_SECRET in
backend/.env (see the configuration reference); the script
warns about any that are still empty. The sections below describe the same two
processes by hand, which is exactly what the script automates.
Backend
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
# Edit .env: set the AI keys and ADJUSTSQUARE_JWT_SECRET (see the configuration reference)
uvicorn app.main:app --host 127.0.0.1 --port 8001 --reload
The backend now serves on http://localhost:8001, with interactive API docs at http://localhost:8001/docs. On first start it creates storage/inventory.db and runs the schema setup and backfills automatically.
backend/.env is untracked and start.sh seeds a fresh one from .env.example with every secret blank, so a new checkout or git worktree starts with nothing filled in. For a credential that is the same across every checkout on your machine (the Mailgun sending key used to test the insured invitation email locally, for instance), put it in ~/.contentsvision/local.env instead and every checkout picks it up:
mkdir -p ~/.contentsvision && chmod 700 ~/.contentsvision
printf 'MAILGUN_API_KEY=%s\n' '<your sending key>' >> ~/.contentsvision/local.env
chmod 600 ~/.contentsvision/local.env
That file sits outside the repo so it can never be committed, and a real value in a checkout's own .env still overrides it. A blank one does not. See where a value comes from. Keep anything per-instance, like PUBLIC_APP_BASE_URL, in backend/.env: it has to match the port that instance is actually served on.
Frontend
cd frontend
npm install
npm run dev
The dev server runs on http://localhost:3001 (the dev script is next dev -p 3001).
How the dev proxy works
The frontend calls everything under a relative /api. In development, next.config.js rewrites /api/* to the backend:
// frontend/next.config.js (rewrites fallback)
destination: `${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8001'}/api/:path*`
So with the backend on 8001 and no NEXT_PUBLIC_API_URL set, the proxy just works. Next.js checks its own routes before applying the rewrite, which lets the local SSE route handler (app/api/jobs/[id]/stream/route.ts) own the streaming endpoint (the rewrite proxy buffers, which would freeze the progress bar) while every other /api/* path goes to the backend. That handler fetches the backend at BACKEND_ORIGIN, not NEXT_PUBLIC_API_URL, defaulting to http://localhost:8001.
Signing in locally
There are two ways to sign in locally.
Option 1: Local auth bypass (recommended)
When APP_ENV=local and LOCAL_AUTH_USER_EMAIL are set in your .env, the backend skips JWT validation and authenticates as that user directly from the database.
# In backend/.env
APP_ENV=local
If that user is not in the local database yet, the backend creates it on the first request, on an "Adjust Square (Local Dev)" team. This matters because every git worktree starts with its own empty SQLite database. LOCAL_AUTH_USER_EXTERNAL_ID (optional) is stamped on the auto-created user; set it to an id on admin_external_user_ids to get the admin pages locally. With the bypass on, /login sends you straight to the dashboard (GET /api/auth/config reports local_bypass: true), since Adjust Square sign-in cannot redirect back to localhost.
Set both once for the whole machine in ~/.contentsvision/local.env and every checkout and worktree is signed in automatically. A blank LOCAL_AUTH_USER_EMAIL= in a checkout's .env does not override it.
Option 2: JWT token
If APP_ENV is not local, login goes through AdjustSquare SSO and requires a valid token signed with your ADJUSTSQUARE_JWT_SECRET. See the test helper make_test_token in backend/app/core/security.py for the exact token shape.
Running with Docker (optional)
The dev docker-compose.yml builds both services and publishes the backend on 8000 and the frontend on 3000. It passes NEXT_PUBLIC_API_URL=http://backend:8000 as a build arg so the frontend's /api proxy targets the backend container:
cp backend/.env.example .env # add your keys
docker compose up --build
This file has no env_file: the backend only receives the handful of variables it lists (ANTHROPIC_API_KEY, the BILLING_* and POSTHOG_* keys, plus fixed DATABASE_URL and CORS_ORIGINS), interpolated from the root .env. OPENROUTER_API_KEY, DEEPGRAM_API_KEY, ADJUSTSQUARE_JWT_SECRET and the local auth bypass do not reach it, and the backend image never contains a .env (backend/.dockerignore excludes it). For a containerized stack with your full configuration, use docker-compose.local.yml below.
The frontend builds with output: 'standalone', and Next.js freezes the next.config.js rewrite destination into the routes manifest at build time. A runtime-only NEXT_PUBLIC_API_URL is ignored by the proxy (it bakes the local-dev fallback and every /api/* call 500s with ECONNREFUSED). The value must be present during npm run build, so the frontend Dockerfile declares ARG NEXT_PUBLIC_API_URL and the compose files pass it under build.args.
docker-compose.local.yml is the same stack on host ports 3001 (frontend) and 8001 (backend), and it loads the full root .env (repo root, not backend/.env) into the backend with env_file, overriding only DATABASE_URL and CORS_ORIGINS=http://localhost:3001:
docker compose -f docker-compose.local.yml up --build -d
# frontend → http://localhost:3001, backend → http://localhost:8001
docker compose -f docker-compose.local.yml logs -f # follow logs
docker compose -f docker-compose.local.yml down # stop and remove
Neither compose file sets BACKEND_ORIGIN for the frontend container, so the job progress stream route falls back to http://localhost:8001 inside the container, where no backend is listening. This is closer to production but slower to iterate than the two-process setup above. For day-to-day development, prefer running uvicorn and next dev directly.
After every change: run the tests
This repo has a hard rule: run the full test suite after any change, and keep it green. From the repo root:
./run_tests.sh # everything
./run_tests.sh -k audio # filter by name
./run_tests.sh -x # stop at first failure
The suite is offline and safe to run anytime. See testing for the details and the rationale.
Common gotchas
ffmpegnot found: the video and audio pipelines shell out to FFmpeg. Install it and make sure it is on your PATH.- 401 on every request: your
ADJUSTSQUARE_JWT_SECRETdoes not match the token you are sending. See troubleshooting. - Transcription does nothing: no
DEEPGRAM_API_KEYset. The pipeline logs a warning and produces a visual-only inventory. - Port mismatch: if you run the backend on a port other than 8001, set
NEXT_PUBLIC_API_URLso the proxy can find it, andBACKEND_ORIGINso the live progress stream can. - Backend exits at startup with
Extra inputs are not permitted: a non-blank key inbackend/.env(or~/.contentsvision/local.env) is not a setting inconfig.py. Delete the line or blank it. See troubleshooting.