Skip to content

Commit a7f2161

Browse files
author
Rajat
committed
Add self-hosting, component packages, and demos
1 parent 25c1430 commit a7f2161

140 files changed

Lines changed: 4007 additions & 1467 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.dockerignore‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# VCS
2+
.git
3+
.gitignore
4+
5+
# Dependencies
6+
node_modules
7+
**/node_modules
8+
.pnpm-store
9+
10+
# Local environment and secrets
11+
.env
12+
.env.*
13+
**/.env
14+
**/.env.*
15+
!.env.example
16+
!**/.env.example
17+
18+
# Build outputs and caches
19+
dist
20+
**/dist
21+
.next
22+
**/.next
23+
out
24+
**/out
25+
coverage
26+
**/coverage
27+
.turbo
28+
**/.turbo
29+
.eslintcache
30+
*.tsbuildinfo
31+
**/*.tsbuildinfo
32+
33+
# Apps and packages not needed to build api / web / sites
34+
apps/docs
35+
36+
# Editor and OS noise
37+
.DS_Store
38+
*.log
39+
.idea
40+
.vscode

‎.env.example‎

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,76 @@
1-
# Secrets required by the self-hosted SendLit API in docker-compose.yml.
2-
# Generate each independently, for example: openssl rand -base64 48
1+
# Copy this file to .env before `docker compose up` (self-host stack).
2+
# Local `pnpm` development uses docker-compose.local.yml plus apps/*/.env
3+
# instead. Do not commit .env.
4+
# Generate secrets with: openssl rand -base64 48
5+
6+
# --- FrontLit ---------------------------------------------------------------
7+
# Required by frontlit-api. Must be at least 32 bytes.
8+
BETTER_AUTH_SECRET=
9+
# Required on X-Frontlit-Provisioning-Secret for POST /provisioning/teams.
10+
PROVISIONING_SECRET=
11+
12+
# Optional. Creates one administrator account + team + API key on first boot.
13+
# The key is printed once in `docker compose logs frontlit-api`.
14+
SUPER_ADMIN_EMAIL=admin@example.com
15+
16+
# Public origins. Keep these for local Compose. For a public deployment, use
17+
# the externally reachable HTTPS origins and set ENABLE_TRUST_PROXY=true.
18+
API_PUBLIC_URL=http://localhost:4000
19+
WEB_CLIENT=http://localhost:3000
20+
WEB_BASE_URL=http://localhost:3000
21+
SITES_BASE_URL=http://localhost:3002
22+
PLATFORM_SITE_DOMAIN=localhost
23+
ENABLE_TRUST_PROXY=false
24+
25+
# Optional published host ports.
26+
API_PORT=4000
27+
WEB_PORT=3000
28+
SITES_PORT=3002
29+
SENDLIT_API_PORT=3001
30+
31+
# Postgres is published on loopback only so `pnpm dev:api` can still use it.
32+
# POSTGRES_BIND=127.0.0.1
33+
# POSTGRES_PORT=5433
34+
# POSTGRES_USER=frontlit
35+
# POSTGRES_PASSWORD=frontlit
36+
# POSTGRES_DB=frontlit
37+
38+
# Optional platform SMTP (login OTPs). In development the OTP is logged.
39+
EMAIL_HOST=
40+
EMAIL_PORT=587
41+
EMAIL_USER=
42+
EMAIL_PASS=
43+
EMAIL_FROM=
44+
45+
# Optional integrations.
46+
MEDIALIT_APIKEY=
47+
MEDIALIT_SERVER=https://api.medialit.cloud
48+
REVALIDATE_WEBHOOK_SECRET=
49+
INTEGRATIONS_ENCRYPTION_KEY=
50+
GOOGLE_CLIENT_ID=
51+
GOOGLE_CLIENT_SECRET=
52+
AUTH_COOKIE_DOMAIN=
53+
54+
# --- SendLit (bundled email engine) ----------------------------------------
55+
# Generate each independently.
356
SENDLIT_BETTER_AUTH_SECRET=
457
SENDLIT_PIXEL_SIGNING_SECRET=
558
SENDLIT_ESP_CREDENTIALS_ENCRYPTION_KEY=
659
SENDLIT_SUPPRESSION_HASH_KEY=
760

8-
# On first boot, SendLit creates this administrator's default organization and
9-
# logs a one-time scoped organization API key. Put that key in FrontLit's
10-
# apps/api/.env as SENDLIT_ORGANIZATION_API_KEY.
61+
# On first boot, SendLit creates this administrator's default organization
62+
# and logs a one-time scoped organization API key. Paste it below.
1163
SENDLIT_SUPER_ADMIN_EMAIL=
1264

13-
# Public URLs used by SendLit when it runs behind a reverse proxy. The defaults
14-
# in docker-compose.yml are suitable for local development.
65+
# Inside Compose, FrontLit talks to SendLit on the Docker network. After the
66+
# first SendLit boot, set the one-time key from:
67+
# docker compose logs sendlit-api
68+
# then `docker compose up -d frontlit-api` so FrontLit picks it up.
69+
SENDLIT_API_URL=http://sendlit-api:3001
70+
SENDLIT_ORGANIZATION_API_KEY=
71+
72+
# Public URLs used by SendLit when it runs behind a reverse proxy. The
73+
# defaults in docker-compose.yml are suitable for local Compose.
1574
# SENDLIT_NODE_ENV=production
1675
# SENDLIT_API_PUBLIC_URL=https://sendlit-api.example.com
1776
# SENDLIT_WEB_CLIENT=https://sendlit.example.com

‎README.md‎

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,68 @@ Articles, documentation, and product updates share one content system and can be
88

99
API first. AI ready (MCP compatible).
1010

11+
## Local development
12+
13+
Start Postgres, Redis, and SendLit. Run FrontLit on the host:
14+
15+
```sh
16+
docker compose -f docker-compose.local.yml up
17+
```
18+
19+
In other terminals (or `pnpm dev` to run all three together):
20+
21+
```sh
22+
cp apps/api/.env.example apps/api/.env
23+
cp apps/web/.env.example apps/web/.env
24+
cp apps/sites/.env.example apps/sites/.env
25+
pnpm --filter @frontlit/api-contract build
26+
pnpm dev:api
27+
pnpm dev:web
28+
pnpm dev:sites
29+
```
30+
31+
Wait for `FrontLit migrations applied.` in the Compose logs before
32+
`pnpm dev:api`. Schema lives in Compose, not in the API process.
33+
34+
Do not use `pnpm dev:api && pnpm dev:web && pnpm dev:sites` — `&&` waits
35+
for each process to exit. Use separate terminals or `pnpm dev`.
36+
37+
On first SendLit boot, copy the one-time `organizationApiKey` into
38+
`apps/api/.env` as `SENDLIT_ORGANIZATION_API_KEY`:
39+
40+
```sh
41+
docker compose -f docker-compose.local.yml logs sendlit-api
42+
```
43+
44+
Postgres is on `127.0.0.1:5433`, SendLit on `http://localhost:3001`.
45+
See [`apps/docs/content/docs/getting-started/overview.mdx`](apps/docs/content/docs/getting-started/overview.mdx).
46+
47+
Do not run this at the same time as the self-host stack — both bind those
48+
ports.
49+
50+
## Self-hosting with Docker Compose
51+
52+
The root Compose file is the product: PostgreSQL (FrontLit + SendLit
53+
databases), Redis, SendLit, and FrontLit's API, dashboard, and public sites.
54+
55+
```sh
56+
cp .env.example .env
57+
# Set the required secrets (commands are included as comments there).
58+
docker compose up --build -d
59+
docker compose logs frontlit-api
60+
docker compose logs sendlit-api
61+
```
62+
63+
Set `SUPER_ADMIN_EMAIL` and `SENDLIT_SUPER_ADMIN_EMAIL` before the first
64+
start. Each process logs a one-time API key; save those. After SendLit prints
65+
`organizationApiKey`, put it in `.env` as `SENDLIT_ORGANIZATION_API_KEY` and
66+
run `docker compose up -d frontlit-api`.
67+
68+
Open the dashboard at `WEB_CLIENT` (`http://localhost:3000` by default), the
69+
API at `API_PUBLIC_URL` (`http://localhost:4000`), public sites at
70+
`SITES_BASE_URL` (`http://localhost:3002`), and SendLit at
71+
`http://localhost:3001`.
72+
1173
## Tech stack
1274

1375
- ts-rest (for API)
@@ -24,11 +86,11 @@ API first. AI ready (MCP compatible).
2486

2587
`/settings/esp` shows _“It’s provisioned automatically in the background…”_ when FrontLit has no stored SendLit team key (`integrations.provider = 'sendlit'`). That is not the same as SendLit being down.
2688

27-
1. Confirm Compose SendLit is up: `docker compose ps` and `curl -s http://localhost:3001/health`.
28-
2. Confirm `apps/api/.env` has `SENDLIT_API_URL` and `SENDLIT_ORGANIZATION_API_KEY`. The org key is printed **once** on first SendLit boot:
89+
1. Confirm SendLit is up: `curl -s http://localhost:3001/health`. Local: `docker compose -f docker-compose.local.yml ps`. Self-host: `docker compose ps`.
90+
2. Confirm `apps/api/.env` (local) or the root `.env` (self-host) has `SENDLIT_API_URL` and `SENDLIT_ORGANIZATION_API_KEY`. The org key is printed **once** on first SendLit boot:
2991

3092
```bash
31-
docker compose logs sendlit-api | grep organizationApiKey
93+
docker compose -f docker-compose.local.yml logs sendlit-api | grep organizationApiKey
3294
```
3395

3496
Recreating the SendLit database or container without updating this key produces `401 unauthorized` on `POST /provisioning/teams`.
@@ -42,7 +104,11 @@ API first. AI ready (MCP compatible).
42104
ORDER BY created_at DESC;
43105
```
44106

45-
After **8** failures the row is `failed` and the worker stops. Fix the key, then retry:
107+
After **8** failures a `provision_sendlit` row used to sit in `failed`
108+
forever (the banner on `/settings/esp`). The API now requeues those
109+
rows on boot and, unless `SENDLIT_PROVISION_RETRY_FOREVER=false`,
110+
keeps retrying provision jobs. Team admins can also click **Retry now**
111+
on `/settings/esp`. Older images still need the reset below:
46112

47113
```sql
48114
UPDATE outbox_jobs

‎apps/api/.env.example‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# Postgres connection string.
2-
DB_CONNECTION_STRING=postgres://frontlit:frontlit@localhost:5432/frontlit
1+
# Postgres connection string. docker-compose.local.yml publishes Postgres
2+
# on loopback port 5433 (the container still listens on 5432).
3+
DB_CONNECTION_STRING=postgres://frontlit:frontlit@localhost:5433/frontlit
34

45
# Port the API listens on.
56
PORT=4000
@@ -86,19 +87,23 @@ INTEGRATIONS_ENCRYPTION_KEY=
8687
# transactional email. Points at either the hosted SendLit instance or a
8788
# self-hosted one running alongside FrontLit (§10.4). Email/ticket
8889
# email features silently no-op if unset.
89-
SENDLIT_API_URL=
90-
# Scoped SendLit organization API key for POST /provisioning/teams. For the
91-
# self-hosted Compose stack, set SENDLIT_SUPER_ADMIN_EMAIL, then retrieve the
92-
# one-time `organizationApiKey` from `docker compose logs sendlit-api`.
90+
SENDLIT_API_URL=http://localhost:3001
91+
# Scoped SendLit organization API key for POST /provisioning/teams. For
92+
# local Compose, retrieve the one-time `organizationApiKey` from:
93+
# docker compose -f docker-compose.local.yml logs sendlit-api
94+
# For the self-host stack, use `docker compose logs sendlit-api`.
9395
SENDLIT_ORGANIZATION_API_KEY=
96+
# Keep retrying `provision_sendlit` outbox jobs after 8 failures (default true).
97+
# Set false to mark them `failed` like other outbox types.
98+
# SENDLIT_PROVISION_RETRY_FOREVER=true
9499

95100
# Base URL for apps/sites, used to build magic-link ticket thread URLs in
96101
# help-desk notification emails (architecture.md §11.2). Falls back to
97102
# http://localhost:3002.
98103
SITES_BASE_URL=http://localhost:3002
99104
# Base URL for apps/web (the dashboard), used to build "view in dashboard"
100-
# links in help-desk notification emails. Falls back to http://localhost:3001.
101-
WEB_BASE_URL=http://localhost:3001
105+
# links in help-desk notification emails. Falls back to http://localhost:3000.
106+
WEB_BASE_URL=http://localhost:3000
102107

103108
# Public-site hostname suffix. The API is the sole authority that classifies
104109
# `<slug>.<suffix>` hosts and resolves the slug against teams.subdomain.

‎apps/api/Dockerfile‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Multi-arch:
2+
# docker buildx build --platform linux/amd64,linux/arm64 \
3+
# -f apps/api/Dockerfile -t codelit/frontlit-api:k3s --push .
14
FROM node:24-alpine AS base
25
RUN corepack enable pnpm
36

@@ -11,12 +14,14 @@ COPY pnpm-workspace.yaml ./
1114
COPY apps/api ./apps/api
1215
COPY packages/api-contract ./packages/api-contract
1316

14-
RUN pnpm install --frozen-lockfile
17+
# better-auth declares next/react/drizzle-kit as optional peers. pnpm would
18+
# otherwise auto-install them (and @next/swc) into this Node API image.
19+
# Only install this package's workspace graph, not web/sites.
20+
RUN printf 'auto-install-peers=false\n' > .npmrc \
21+
&& pnpm install --filter=@frontlit/api... --no-frozen-lockfile
1522

16-
FROM base AS builder
23+
FROM deps AS builder
1724
WORKDIR /app
18-
COPY --from=deps /app/ ./
19-
2025
RUN pnpm --filter=@frontlit/api-contract build
2126
RUN pnpm --filter=@frontlit/api build
2227

@@ -28,18 +33,19 @@ ENV NODE_ENV=production
2833
RUN addgroup --system --gid 1001 nodejs
2934
RUN adduser --system --uid 1001 nodeuser
3035

31-
COPY --chown=nodeuser:nodejs --from=builder /app/package.json ./
32-
COPY --chown=nodeuser:nodejs --from=builder /app/pnpm-lock.yaml ./
33-
COPY --chown=nodeuser:nodejs --from=builder /app/pnpm-workspace.yaml ./
34-
35-
COPY --chown=nodeuser:nodejs --from=builder /app/packages/api-contract/package.json ./packages/api-contract/package.json
36-
COPY --chown=nodeuser:nodejs --from=builder /app/packages/api-contract/dist ./packages/api-contract/dist
37-
38-
COPY --chown=nodeuser:nodejs --from=builder /app/apps/api/package.json ./apps/api/package.json
39-
COPY --chown=nodeuser:nodejs --from=builder /app/apps/api/dist ./apps/api/dist
40-
COPY --chown=nodeuser:nodejs --from=builder /app/apps/api/drizzle ./apps/api/drizzle
41-
42-
RUN pnpm install --prod --frozen-lockfile --ignore-scripts
36+
COPY package.json ./
37+
COPY pnpm-lock.yaml ./
38+
COPY pnpm-workspace.yaml ./
39+
COPY --from=builder /app/packages/api-contract/package.json ./packages/api-contract/package.json
40+
COPY --from=builder /app/packages/api-contract/dist ./packages/api-contract/dist
41+
COPY --from=builder /app/apps/api/package.json ./apps/api/package.json
42+
COPY --from=builder /app/apps/api/dist ./apps/api/dist
43+
COPY --from=builder /app/apps/api/drizzle ./apps/api/drizzle
44+
45+
RUN printf 'auto-install-peers=false\nstore-dir=/tmp/pnpm-store\n' > .npmrc \
46+
&& pnpm install --prod --filter=@frontlit/api... --no-frozen-lockfile --ignore-scripts \
47+
&& rm -rf /tmp/pnpm-store /root/.local /root/.cache \
48+
&& chown -R nodeuser:nodejs /app
4349

4450
USER nodeuser
4551

‎apps/api/docs/mcp-architecture.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ pnpm dev:api
412412
```
413413

414414
If the API crashes with `relation "auth_oauth_resource" does not exist`, the
415-
application was started before `0000_baseline` was applied. If token exchange
415+
application was started before `0000_baseline` was applied. Local Compose
416+
applies this via `frontlit-migrate` (`docker compose -f docker-compose.local.yml up`). If token exchange
416417
reports that `alg` does not exist in the JWKS Drizzle schema, reset the
417418
database and re-apply the baseline so the deployed application and schema
418419
match.

‎apps/api/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"description": "Better Auth protected REST API for building and serving pages — the FrontLit backend",
66
"license": "MIT",
77
"main": "dist/index.js",
8+
"files": [
9+
"dist",
10+
"drizzle"
11+
],
812
"scripts": {
913
"build": "tsc",
1014
"dev": "nodemon --exec 'node --env-file=.env --import tsx' src/index.ts",

‎apps/api/src/auth/operation-policy.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ export const REST_OPERATION_POLICIES = {
311311
"settings:write",
312312
MCP_SCOPES.settingsWrite,
313313
),
314+
"email.retryProvision": teamPermission(
315+
"settings:write",
316+
MCP_SCOPES.settingsWrite,
317+
),
314318
"email.listTemplates": teamPermission(
315319
"broadcasts:read",
316320
MCP_SCOPES.broadcastsRead,

‎apps/api/src/db/migrate.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import "dotenv/config";
2+
import path from "node:path";
23
import { migrate } from "drizzle-orm/node-postgres/migrator";
34
import { db, pool } from "./client";
45

56
async function main() {
67
await pool.query("CREATE EXTENSION IF NOT EXISTS vector;");
78
await migrate(db, {
8-
migrationsFolder: process.env.MIGRATIONS_FOLDER || "./drizzle",
9+
migrationsFolder:
10+
process.env.MIGRATIONS_FOLDER ||
11+
path.join(__dirname, "../../drizzle"),
912
});
1013
await pool.end();
1114
// CLI success output for operators running migrations manually.

0 commit comments

Comments
 (0)