Skip to main content

CommonWire Self-Hosting Guide

CommonWire is MIT-licensed. You can run it on your own infrastructure — for a single city or as a multi-city platform for a county, council of governments or state association.

1. What you need

ComponentPurposeOptions
Web appPublic site, staff console, server functionsNode 20+/Bun runtime, Docker, Cloudflare Workers, Vercel, Netlify
Database & authPostgres with row-level security, sign-inSupabase (cloud or self-hosted)
Email providerConfirmations and noticesSendGrid or Amazon SES (each city brings its own)
SMS providerText alertsTwilio (each city brings its own)
Domain + TLSe.g. news.yourcity.govAny DNS provider

Minimum server: 1 vCPU, 1 GB RAM. Supabase's free tier is enough for a pilot.

2. Get the code

git clone https://github.com/<your-org>/commonwire.git
cd commonwire
bun install        # or: npm install

3. Create the database

  1. Create a Supabase project (or run self-hosted Supabase with Docker: https://supabase.com/docs/guides/self-hosting/docker).
  2. Apply the migrations in order. They create every table, security policy, the archive fingerprint trigger and the Oakridge sample city:
for f in drizzle/migrations/*.sql; do psql "$DATABASE_URL" -f "$f"; done

Or run bunx drizzle-kit migrate with DATABASE_URL set. 3. Optional: delete the sample city when you're ready — delete from cities where slug = 'oakridge'; (everything belonging to it is removed with it).

4. Configure environment variables

Create .env (never commit it):

# Public (safe in the browser)
VITE_SUPABASE_URL=https://<project>.supabase.co
VITE_SUPABASE_PUBLISHABLE_KEY=<anon / publishable key>
VITE_SUPABASE_PROJECT_ID=<project ref>

# Server only
SUPABASE_URL=https://<project>.supabase.co
SUPABASE_PUBLISHABLE_KEY=<anon / publishable key>
SUPABASE_SERVICE_ROLE_KEY=<service role key>       # never expose to the browser
PROVIDER_CREDENTIALS_KEY=<64+ random characters>   # encrypts each city's email/SMS keys
DEMO_USER_PASSWORD=<40+ random characters>         # only needed if you keep the public demo

Generate random values with openssl rand -base64 48.

Important: if you lose or change PROVIDER_CREDENTIALS_KEY, saved provider keys can't be decrypted. Cities must re-enter them under Settings.

5. Configure sign-in

In Supabase → Authentication:

  • Email: enable, keep email confirmation on. Set Site URL to your domain and add https://<your-domain>/** to redirect URLs.
  • Microsoft (Entra ID): in Azure Portal → App registrations, create an app; redirect URI https://<project>.supabase.co/auth/v1/callback; create a client secret. In Supabase enable the Azure provider with the client ID, secret and tenant URL https://login.microsoftonline.com/<tenant-id>/v2.0. Limit to your tenant for staff-only sign-in.
  • The hosted version uses a managed Microsoft sign-in helper (src/integrations/lovable). When self-hosting, replace the lovable.auth.signInWithOAuth("microsoft", …) call in src/components/civic/StaffSignIn.tsx with supabase.auth.signInWithOAuth({ provider: "azure", options: { scopes: "email", redirectTo } }).

6. Build and run

Option A — Docker

docker build -t commonwire .
docker run -d --name commonwire -p 3000:3000 --env-file .env commonwire

Put a reverse proxy (Caddy, nginx, Traefik) in front for TLS. Caddy example:

news.yourcity.gov {
  reverse_proxy localhost:3000
}

Option B — Node / Bun on a VM

NITRO_PRESET=bun bun run build
PORT=3000 bun .output/server/index.mjs   # serves the built app

Run it under systemd or pm2 so it restarts automatically.

Option C — Vercel / Netlify / Cloudflare

Import the repository, set the environment variables from step 4, and use the framework defaults (TanStack Start). Build command bun run build.

7. Single-city vs multi-city

  • Multi-city (default): the home page lists cities and anyone signed in can register one at /register. Each city lives at /<slug>.
  • Single city: register your city, then remove the /register link from src/routes/index.tsx and change the home page to redirect to /<your-slug> (a one-line beforeLoad: () => { throw redirect({ to: "/$city", params: { city: "your-slug" } }) }). Optionally restrict who can register by editing registerCity in src/lib/city.functions.ts.
  • Edit src/city.config.ts to change the defaults new cities start with.

8. Connect delivery providers

Each city enters its own SendGrid/SES/Twilio credentials in Staff console → Settings. Credentials are encrypted with AES-GCM using PROVIDER_CREDENTIALS_KEY and only decrypted on the server at send time. See the User Manual, section 2.

9. Operations

  • Backups: enable Supabase point-in-time recovery or run nightly pg_dump. The archive is a public record — keep backups per your retention schedule.
  • Archive integrity: every archive row is fingerprinted by a database trigger (SHA-256 chain per city). Staff → Records shows whether the chain is intact. Never edit archive rows directly in SQL.
  • Updates: git pull, apply any new files in drizzle/migrations/ in order, rebuild, restart.
  • Monitoring: watch the server logs and each city's Delivery log for provider failures.
  • Security: keep the service role key and PROVIDER_CREDENTIALS_KEY only on the server; rotate them if exposed. Report vulnerabilities per SECURITY.md.

10. Accessibility responsibilities

CommonWire is built for WCAG 2.1 AA, but your content matters too: write alt text, keep reading level at grade 6–8, and caption videos. The DOJ ADA Title II rule requires compliance by April 26, 2027 (population 50,000+) or April 26, 2028 (smaller entities and special districts).

11. Troubleshooting

SymptomLikely cause
"permission denied for table"A migration didn't apply. Re-run them in order.
Staff see "No staff role yet"Add them in Settings → Staff (or insert into city_staff).
Provider keys stop working after redeployPROVIDER_CREDENTIALS_KEY changed. Restore it or re-enter keys.
Sign-in redirects to the wrong siteFix Site URL and redirect URLs in Supabase Auth.
Microsoft sign-in failsCheck the Azure redirect URI and tenant URL.