Self-hosting
Deploy Bellcast to Vercel with Supabase Postgres: schema, environment variables, cron and retention.
Create the database
- Create a project at supabase.com and wait for it to finish provisioning.
- Open SQL Editor → New query in the Supabase dashboard.
- Copy the schema below, paste it into the editor and run it once.
- Copy the project URL and the service role key from Project settings → API.
Database schema
The schema is idempotent — running it again is safe. It creates the messages table, its indexes, and the publish_message and list_topics functions. Row level security is enabled with no policies, and the anon / authenticated roles have their grants revoked, so only the service role can read or write. Bellcast never sends that key to a browser.
-- Bellcast schema (unchanged since v0.1).
-- Single-tenant: every topic belongs to the one instance owner.
-- Clients never touch Postgres directly; the API uses service_role.
create extension if not exists pgcrypto;
create table if not exists public.messages (
seq bigint generated always as identity primary key,
id uuid not null unique default gen_random_uuid(),
topic text not null
check (topic ~ '^[a-z0-9][a-z0-9_-]{0,63}$'),
title text,
body text not null,
priority smallint not null default 3
check (priority between 1 and 5),
tags text[] not null default '{}',
click_url text,
actions jsonb,
idempotency_key text not null default gen_random_uuid()::text,
created_at timestamptz not null default now(),
unique (topic, idempotency_key)
);
create index if not exists messages_topic_seq_idx
on public.messages (topic, seq desc);
create index if not exists messages_seq_idx
on public.messages (seq);
create index if not exists messages_created_idx
on public.messages (created_at);
alter table public.messages enable row level security;
-- No policies. Only service_role can read or write.
-- Defense in depth: remove the default grants Supabase gives to the API roles.
revoke all on public.messages from anon, authenticated;
revoke all on all sequences in schema public from anon, authenticated;
-- Atomic publish: idempotent per (topic, key), no separate topics table.
create or replace function public.publish_message(
p_topic text,
p_title text,
p_body text,
p_priority smallint,
p_tags text[],
p_click text,
p_actions jsonb,
p_idem text
) returns public.messages
language plpgsql
security definer
set search_path = public
as $$
declare
v_msg public.messages;
begin
insert into public.messages
(topic, title, body, priority, tags, click_url, actions, idempotency_key)
values
(p_topic, p_title, p_body, p_priority, coalesce(p_tags, '{}'),
p_click, p_actions, p_idem)
on conflict (topic, idempotency_key) do nothing
returning * into v_msg;
if v_msg.id is null then
select * into v_msg
from public.messages
where topic = p_topic
and idempotency_key = p_idem;
end if;
return v_msg;
end;
$$;
create or replace function public.list_topics()
returns table (
topic text,
last_seq bigint,
last_message_at timestamptz
)
language sql
stable
security definer
set search_path = public
as $$
select m.topic, max(m.seq), max(m.created_at)
from public.messages m
group by m.topic
order by max(m.seq) desc;
$$;
revoke all on function public.publish_message(text, text, text, smallint, text[], text, jsonb, text)
from anon, authenticated;
revoke all on function public.list_topics()
from anon, authenticated;Prefer a file? Download 20261025000000_init.sql from the repository instead.
Deploy the app
- Push the repository to GitHub.
- Import it into Vercel and set the project root to
apps/web. - Add the environment variables below for Production (and Preview if you want preview deployments to work).
- Deploy, then open the site and sign in with your API key.
The same app runs on any Node 20+ host with pnpm --filter web build and pnpm --filter web start, as long as the environment variables are present. Vercel is only required for the built-in cron.
Environment variables
| Variable | Required | Purpose |
|---|---|---|
| SUPABASE_URL | Yes | Project URL used by the server-side store. |
| SUPABASE_SERVICE_ROLE_KEY | Yes | Server-only key. Never expose it to the client. |
| BELLCAST_API_KEY | Yes | The single key for publishing and signing in. |
| CRON_SECRET | For pruning | Bearer secret required by the prune endpoint. |
| BELLCAST_RETENTION_DAYS | No | Message retention in days. Default 30. |
| BELLCAST_MAX_BODY_BYTES | No | Maximum publish body size. Default 65536. |
| BELLCAST_DEV_STORE | Local only | Use a JSON file instead of Supabase. |
Generate a strong key with openssl rand -hex 32. Treat it like a password: anyone with it can publish to every topic and read the inbox.
Retention cron
apps/web/vercel.json schedules /api/cron/prune once a day. The endpoint requires Authorization: Bearer $CRON_SECRET and deletes messages older than BELLCAST_RETENTION_DAYS. Vercel sends this header automatically when CRON_SECRET is set.
On another host, call the same endpoint from cron or systemd timers. If you do not want automatic cleanup, delete the crons entry from vercel.json and prune manually.
curl https://your-instance.example.com/api/cron/prune \
-H "Authorization: Bearer $CRON_SECRET"Updating
Pull the latest commit and redeploy. Run any new SQL migrations in order before the deploy that depends on them. Stored messages are never rewritten by an update.