app: the Church App's foundation; docs for Hub 2.26.1 and two years of devotionals

apps/app (not released; app@1.0.0 is built in slices, APP-1.0-PLAN §15):
- backend (Express, Prisma, pg-boss, as the Website): the Hub client
  (CCP-, product app, the active-member band in the heartbeat), links
  and church.changed, sign-in through Accounts (everyone a Member; 8 days
  renewed up to 90; every role only with 2FA; the first Owner from
  HUB_ADMIN_EMAIL), Accounts' user.updated/export/deleted, active members
  once a day, modules on and off, GET /api/v1/app. Migration init.
- frontend (Next.js 16): header, tab bar, footer, manifest and icons from
  the church profile, service worker, Add to home screen, Me, the admin's
  first dashboard.
- env.template.json, PM2 template, README, CHANGELOG, WHATS-NEW; 27 tests.

Docs: the Hub runs 2.26.1 with two years of Cross Code's devotionals; an
App gets 2 weeks, today included. HANDOVER lists the App's slices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 00:20:07 +02:00
co-authored by Claude Opus 5.5
parent 74dee881e4
commit bb36e06fa4
85 changed files with 4479 additions and 53 deletions
@@ -0,0 +1,109 @@
-- Church App 1.0.0: the foundation (docs/APP-1.0-PLAN.md §1, §2, §10, §12): members and roles,
-- sessions, links to the church's other products, the audit log and settings.
-- CreateSchema
CREATE SCHEMA IF NOT EXISTS "public";
-- CreateEnum
CREATE TYPE "AppRole" AS ENUM ('owner', 'church_admin', 'content_admin', 'devotional_writer', 'prayer_coordinator', 'pastoral_care');
-- CreateTable
CREATE TABLE "Member" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"email" TEXT NOT NULL,
"phone" TEXT,
"whatsappOptedOut" BOOLEAN NOT NULL DEFAULT false,
"roles" "AppRole"[] DEFAULT ARRAY[]::"AppRole"[],
"lastActiveAt" TIMESTAMP(3),
"lastSignInAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Member_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Session" (
"id" TEXT NOT NULL,
"tokenHash" TEXT NOT NULL,
"memberId" TEXT NOT NULL,
"sid" TEXT,
"mfa" BOOLEAN NOT NULL DEFAULT false,
"idToken" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"lastSeenAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"expiresAt" TIMESTAMP(3) NOT NULL,
"absoluteExpiresAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "ProductLink" (
"installId" TEXT NOT NULL,
"product" TEXT NOT NULL,
"url" TEXT NOT NULL,
"publicKey" TEXT NOT NULL,
"secret" TEXT NOT NULL,
"connectedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"connectedById" TEXT,
"showEvents" BOOLEAN NOT NULL DEFAULT true,
"lastSyncAt" TIMESTAMP(3),
"lastGoodAt" TIMESTAMP(3),
"lastSyncError" TEXT,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "ProductLink_pkey" PRIMARY KEY ("installId")
);
-- CreateTable
CREATE TABLE "LinkNonce" (
"nonce" TEXT NOT NULL,
"seenAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "LinkNonce_pkey" PRIMARY KEY ("nonce")
);
-- CreateTable
CREATE TABLE "AuditLog" (
"id" TEXT NOT NULL,
"actorId" TEXT,
"actorRole" TEXT NOT NULL,
"action" TEXT NOT NULL,
"targetType" TEXT NOT NULL,
"targetId" TEXT,
"metadata" JSONB,
"ip" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "AuditLog_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "AppSetting" (
"key" TEXT NOT NULL,
"value" TEXT NOT NULL,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "AppSetting_pkey" PRIMARY KEY ("key")
);
-- CreateIndex
CREATE INDEX "Member_lastActiveAt_idx" ON "Member"("lastActiveAt");
-- CreateIndex
CREATE UNIQUE INDEX "Session_tokenHash_key" ON "Session"("tokenHash");
-- CreateIndex
CREATE INDEX "Session_memberId_idx" ON "Session"("memberId");
-- CreateIndex
CREATE INDEX "Session_sid_idx" ON "Session"("sid");
-- CreateIndex
CREATE INDEX "AuditLog_createdAt_idx" ON "AuditLog"("createdAt");
-- AddForeignKey
ALTER TABLE "Session" ADD CONSTRAINT "Session_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"
+119
View File
@@ -0,0 +1,119 @@
// Church App 1.0.0 (docs/APP-1.0-PLAN.md). One database per church.
//
// The foundation (§1, §2, §10, §12): members and their roles, sessions, links to the church's other
// products, the audit log and settings. The modules' tables (House of Prayer, prayer requests,
// announcements, devotionals, events) come with each module. Shared facts (name, logo, colours,
// timezone, contact) are the church profile's, in Accounts (§9), and are never stored here.
generator client {
provider = "prisma-client"
// Its own output, so hoisted clients of other apps never overwrite it (EVENTS-2.2-PLAN §2).
output = "../src/generated/prisma"
moduleFormat = "esm"
importFileExtension = "js"
}
datasource db {
provider = "postgresql"
}
/// The App's roles above Member (§10). Held here, per product: an Events or Website role gives
/// nothing in the App. A person can have several; every one of them needs 2FA (§2, decision 7).
enum AppRole {
owner
church_admin
content_admin
devotional_writer
prayer_coordinator
pastoral_care
}
/// Someone who has signed in to the App: keyed by their account's `sub` from Accounts. Everyone
/// signed in is a Member; `roles` adds what the admin can do. A copy of the Accounts profile, kept
/// up to date by `user.updated`.
model Member {
id String @id
name String
email String
/// The verified number from Accounts (reminders by WhatsApp), or null.
phone String?
/// The person replied STOP to the church's WhatsApp number (decision 11): no WhatsApp of any kind.
whatsappOptedOut Boolean @default(false)
roles AppRole[] @default([])
/// The last day they used the App signed in (written at most once a day): active members (§10).
lastActiveAt DateTime?
lastSignInAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
sessions Session[]
@@index([lastActiveAt])
}
/// A sign-in (the `cca_session` cookie holds the token; only its SHA-256 is kept). It lasts 8 days,
/// renewed by each visit, and never past `absoluteExpiresAt`, 90 days from the sign-in (§2).
/// `sid` is Accounts' session id, so a back-channel logout ends the matching sessions.
model Session {
id String @id @default(uuid())
tokenHash String @unique
memberId String
member Member @relation(fields: [memberId], references: [id], onDelete: Cascade)
sid String?
/// Whether Accounts did a second step for this sign-in (`amr` has `mfa`): needed for any role.
mfa Boolean @default(false)
/// The ID token (encrypted), for "Sign out" at Accounts (`id_token_hint`).
idToken String?
createdAt DateTime @default(now())
lastSeenAt DateTime @default(now())
expiresAt DateTime
absoluteExpiresAt DateTime
@@index([memberId])
@@index([sid])
}
/// A link to another of the church's products (`crosscode.link/1`): Accounts, for signing in and
/// the shared email and WhatsApp settings, and Events / the Website for the event feed (§7, §8).
/// The secret is encrypted.
model ProductLink {
installId String @id
product String
url String
publicKey String
secret String
connectedAt DateTime @default(now())
connectedById String?
/// Show this sibling's events in the App (the event feed, §7). Accounts has none.
showEvents Boolean @default(true)
lastSyncAt DateTime?
lastGoodAt DateTime?
lastSyncError String?
updatedAt DateTime @updatedAt
}
/// Nonces of link messages seen in the last hour (replays are refused).
model LinkNonce {
nonce String @id
seenAt DateTime @default(now())
}
/// Who changed what in the admin (§10, Audit log).
model AuditLog {
id String @id @default(uuid())
actorId String?
actorRole String
action String
targetType String
targetId String?
metadata Json?
ip String?
createdAt DateTime @default(now())
@@index([createdAt])
}
model AppSetting {
key String @id
value String
updatedAt DateTime @updatedAt
}