Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .env.production.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copy to .env.production on the server and fill in. Never commit the real one.

# The database password. Anything long and random.
POSTGRES_PASSWORD=

# The two hostnames: the web app, and the NestJS API the browser talks to.
# Both get their own certificate from Let's Encrypt at ACME_EMAIL.
APP_HOST=content.yourcompany.com
API_HOST=api.content.yourcompany.com
ACME_EMAIL=you@yourcompany.com

# The session cookie has to be readable on BOTH hosts: the API sets it, the
# web app's proxy checks for it. A shared parent domain does that. Leave
# COOKIE_SAMESITE at lax while the two hosts share a site; set it to none
# only if they do not (then Secure is forced, and the domain must be set).
COOKIE_DOMAIN=.content.yourcompany.com
COOKIE_SAMESITE=lax

# Encrypts the API keys stored in the settings table.
#
# MOVE THE EXISTING VALUE from your local .env. A different secret does not
# fail loudly — it makes every key already saved unreadable, which reads as
# "the key vanished".
CONTENTOS_SECRET=

# How the model is reached on a server.
#
# Your laptop runs the `claude` CLI and bills your subscription. A server has
# no CLI and no login, so it needs a key; the app falls back to the API path
# when the command is missing. Set the brain to the matching model in
# Settings → Generation after the first sign-in.
ANTHROPIC_API_KEY=
29 changes: 29 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Typecheck, lint, tests, and a production build — the same four things
# `npm run check` and `npm run build:check` do on a laptop.
#
# No database and no model: nothing here talks to Postgres or spends a credit.
# The tests are the pure ones in tests/, and the build only has to compile.
name: check

on:
push:
branches: ["**"]
pull_request:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm ci --prefix api
- run: npm run check
# Into .next-check, so it can never be confused with a dev server's
# output — see next.config.ts.
- run: npm run build:check
# The API compiles on its own; the image is what a server runs.
- run: npm run build --prefix api
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ yarn-error.log*

# env files (can opt-in for committing if needed)
.env*
# …except the template a fresh clone copies from — DEPLOYING.md tells you to
# `cp` it, which needs it to be in the repo.
!.env.production.example

# vercel
.vercel
Expand All @@ -54,3 +57,7 @@ next-env.d.ts

# the real production secrets
.env.production

# the NestJS API has its own install and build output
api/node_modules
api/dist
14 changes: 4 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ FROM node:24-bookworm-slim AS build
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Read by the browser bundle, so it has to be known when the bundle is built.
ARG NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
# `output: "standalone"` in next.config.ts is what makes .next/standalone a
# server that can run without node_modules beside it.
RUN npm run build
Expand All @@ -21,20 +24,11 @@ WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3333

# The tools the Integrations page probes for. Without them the app still runs;
# source-video features report the binary as missing, which is the truth.
RUN apt-get update \
&& apt-get install -y --no-install-recommends ffmpeg python3 ca-certificates curl \
&& curl -fsSL https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp \
&& chmod a+rx /usr/local/bin/yt-dlp \
&& rm -rf /var/lib/apt/lists/*
# No ffmpeg or yt-dlp here any more: the ingest runs in the API's image.

COPY --from=build /app/public ./public
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
# Migrations run from the image on deploy, before the server takes traffic.
COPY --from=build /app/scripts ./scripts
COPY --from=build /app/lib/server/db ./lib/server/db

EXPOSE 3333
CMD ["node", "server.js"]
37 changes: 26 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ production dashboard where **topics** feed **packs**, packs run to produce

```bash
npm run db:up # Postgres in Docker, on 5437
./start.sh # dev server on http://localhost:3333
./start.sh prod # production build, then serve it on 3333
PORT=4000 ./start.sh # any other port
./start.sh # the NestJS API on :4000 and the Next dev server on :3333
./start.sh prod # production builds of both, then serve both
PORT=3400 ./start.sh # any other web port (API_PORT for the API's)
```

`./start.sh` brings the database up itself and says so if it cannot — every
Expand All @@ -29,7 +29,10 @@ which default to port 3000.

## Stack

Next.js 16 (App Router, Turbopack) · React 19 · TypeScript. No CSS framework:
**Frontend:** Next.js 16 (App Router, Turbopack) · React 19 · TypeScript.
**Backend:** NestJS 12 in `api/`, its own process on port 4000, sharing
`lib/server` (the repos, the run driver, the ingest) with the root. The
browser calls it directly at `NEXT_PUBLIC_API_URL`; there is no `app/api`. No CSS framework:
the design is expressed in inline styles, matching the source canvas one
declaration at a time, with shared fragments in [lib/theme.ts](lib/theme.ts).
Fonts are self-hosted through `next/font` (Inter, Inter Tight, JetBrains Mono,
Expand All @@ -45,11 +48,15 @@ and Noto Sans Bengali for the Bangla script screens).
| `/content/[topic]` | One document |
| `/packs` | Pack library — the shipped pack and anything written here |
| `/pack/[slug]` | One pack: its real sections, its rules, what it asks for |
| `/builder` | Writing a pack — saves to the database |
| `/builder` | Writing a new template — saving moves it to its own URL |
| `/builder/[slug]` | Editing that template |
| `/runs/[id]` | A run as it happens, section by section |
| `/login`, `/signup` | Sign in; claim the console (open only while it has no owner) |
| `/integrations` | What this machine can actually reach, probed live |
| `/tools`, `/settings` | Tools; preferences, keys and the account |
| `/tools` | This workspace's bench, grouped by category |
| `/tools/manage` | Every tool: category, on/off, which workspaces it stands in |
| `/tools/[tool]` | One tool — Content Research, or the video researcher |
| `/settings` | Preferences, keys, team and the account |

Three overlays render above any route: the **Run Pack** sheet, the **Add
Section** sheet, and the **command palette** (`⌘K` / `Ctrl+K`, `Esc` to close).
Expand All @@ -66,14 +73,20 @@ components/
views/ one component per screen
overlays/ run-setup, add-section, command palette
ui/ Hov (hover/press styles), Popover, Icons
tools/ the interactive pieces of a tool's screen (FramePicker)
lib/
data.ts what is left of the design's strings and numbers
store.tsx client state, hydrated from the API and written back
use-*.ts a screen's data logic as a hook (content list, run document)
slug.ts the one rule for turning a name into part of a URL
packs-client.ts the pack API, and the brief <-> runtime translation
packs-transfer.ts a template as a file: export, import, validation
runs-client.ts the run API
tools-client.ts the tool bench, uploads, and the researcher
theme.ts fonts, colors, repeated style fragments
config.ts advancedNav / runSpeed, the canvas's two props
server/ everything that touches the database (see below)
tests/ vitest, pure functions only — `npm run check`
design/ the imported source canvas, for reference
```

Expand All @@ -86,20 +99,22 @@ matters lives in React state any more.

```
docker-compose.yml Postgres 17 on 5437, one named volume
middleware.ts the lock on the front door
proxy.ts the front door: pages need a session cookie
api/src/main.ts the NestJS service: CORS, cookies, migrate + seed
api/src/common/ SessionGuard (global, closed by default), errors
api/src/<feature>/ one controller per feature, over lib/server
lib/server/db/schema.ts the schema, as an ordered list of migrations
lib/server/db/client.ts the pool, `q` / `one` / `tx`, and `ready()`
lib/server/auth.ts scrypt passwords, session rows, `requireUser`
lib/server/tools.ts what is installed, by running it
lib/server/brains.ts the four models, each over a CLI or an API
lib/server/repos/ rows in, objects out — workspaces, series, packs,
runs, sources, settings
lib/server/services/ the rules that are not the database's job,
including the yt-dlp / ffmpeg / whisper ingest
lib/server/services/ the rules that are not the database's job:
runs, the yt-dlp / ffmpeg / whisper ingest, the
researcher that reads frames
lib/packs/enbn-website.ts the shipped pack: rules, 12 sections, instructions
lib/server/prompt.ts system = voice + rules, user = source + inputs + deps
app/api/ auth, settings, integrations, sources, workspaces,
series, topics, packs, runs
```

### Signing in
Expand Down
48 changes: 48 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# The API, as a server runs it.
#
# Built from the REPO ROOT as context (`docker build -f api/Dockerfile .`),
# because the service shares lib/server with the web app: the repos, the run
# driver, the ingest. The image carries only what a request actually reaches —
# the compiled TypeScript and the binaries the ingest shells out to.
FROM node:24-bookworm-slim AS deps
WORKDIR /app/api
COPY api/package.json api/package-lock.json* ./
RUN npm ci

FROM node:24-bookworm-slim AS build
WORKDIR /app
COPY --from=deps /app/api/node_modules ./api/node_modules
# The shared code, and the root packages it imports (pg, the Anthropic SDK).
COPY package.json package-lock.json* ./
RUN npm ci --omit=dev
COPY lib ./lib
COPY api ./api
RUN cd api && npm run build

FROM node:24-bookworm-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=4000
# `@/lib/...` inside the compiled output points at dist, not at the sources.
ENV TS_NODE_BASEURL=./dist
# Downloads and frames live here; mount a volume on it.
ENV CONTENTOS_DATA_DIR=/app/.data

# The tools the ingest runs. Without them the API still starts; source-video
# features report the binary as missing, which is the truth.
RUN apt-get update \
&& apt-get install -y --no-install-recommends ffmpeg python3 ca-certificates curl \
&& curl -fsSL https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp \
&& chmod a+rx /usr/local/bin/yt-dlp \
&& rm -rf /var/lib/apt/lists/*

COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/api/node_modules ./api/node_modules
COPY --from=build /app/api/dist ./api/dist
COPY --from=build /app/api/package.json /app/api/tsconfig.json ./api/

WORKDIR /app/api
EXPOSE 4000
# tsconfig-paths resolves the `@/` imports inside the compiled output, the
# same way ts-node does in development.
CMD ["node", "-r", "tsconfig-paths/register", "dist/api/src/main.js"]
5 changes: 5 additions & 0 deletions api/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
Loading
Loading