Knowledge > System Architecture
System Architecture Overview
Canonical reference for how ChurchWiseAI systems are structured, deployed, and connected. For day-to-day operational procedures, see Operations. For detailed schema, API, and infrastructure docs, see the children linked at the bottom.
ChurchWiseAI Portfolio Architecture
1. Portfolio Overview
Three active codebases deploy to Vercel. A fourth (legacy) exists for reference only.
| Codebase | What | Deploy | URL | Framework |
|---|---|---|---|---|
churchwiseai-web/ | AI products (voice + chatbot), admin dashboard, all APIs, marketing | main -> Vercel | churchwiseai.com | Next.js 16, React 19, Tailwind 4 |
pewsearch/web/ | Church directory (218K+ visible listings) + distribution channel | master -> Vercel | pewsearch.com | Next.js 16 |
sermon-illustrations/ | Sermon illustration library (327K content records) | master -> Vercel | illustratetheword.com | Next.js 16 |
ai-sermon-assistant/ | LEGACY -- read for reference only, never build here | NOT deployed | N/A | React / Nx monorepo |
Hostname Rewrites
churchwiseai-web/ also serves two additional brands via Vercel hostname rewrites:
| Domain | Rewrites To | Status |
|---|---|---|
| sermonwise.ai | churchwiseai-web/src/app/sermons/ | Live |
| sharewiseai.com | churchwiseai-web/src/app/social/ | Coming Soon (OAuth pending) |
2. How Systems Connect
USERS
|
+----------------+----------------+
| | |
churchwiseai.com pewsearch.com illustratetheword.com
(+ sermonwise.ai (directory) (illustrations)
+ sharewiseai.com)
| | |
v v v
+--------------------------------------------+
| Vercel (hosting) |
| 3 projects, serverless API routes |
+--------------------------------------------+
| | |
+--------+-------+--------+-------+
| |
v v
+-----------+ +-----------+
| Supabase | | Stripe |
| (ONE DB) | | (ONE acct)|
+-----------+ +-----------+
PHONE CALLS
|
v
+---------------+ +-------------------+
| Twilio/Telnyx | --> | LiveKit Cloud |
| (SIP) | | (Agents v1.5) |
+---------------+ +-------------------+
|
v
+-----------+
| Supabase |
| (same DB) |
+-----------+
Key points:
- All three web properties share ONE Supabase instance (no staging DB).
- All payments flow through ONE Stripe account (test + live modes).
- Voice calls route through Twilio/Telnyx SIP to LiveKit Cloud, then write back to the same Supabase DB.
- The chatbot API runs as a Vercel serverless function inside
churchwiseai-web/.
3. Shared Infrastructure
| Service | Instance | Notes |
|---|---|---|
| Supabase | Project wrwkszmobuhvcfjipasi | ONE instance for dev AND prod. No local DB, no staging. ~218K visible churches, ~327K content records. |
| Stripe | Account churchwiseai@gmail.com | ONE account, two modes (test + live). 24 active products in live mode (post 2026-05-04 VetWiseAI launch); test mode mirrors with a slightly different count due to consolidated annual products (see knowledge/data/pricing.yaml). |
| Vercel | Team churchwiseai-5386 | Hosts all 3 web properties. Serverless API routes for all backends. |
| LiveKit Cloud | Project cwa-voice-9x077mph | Voice agent runtime. Deploy via lk agent deploy --project cwa-voice --silent. |
| Twilio + Telnyx | SIP trunking | Routes inbound phone calls to LiveKit Cloud. Telnyx for new customers, Twilio for legacy numbers. |
| GitHub | Org JohnMoelker | All repos. main for churchwiseai-web, master for pewsearch + ITW. |
| MailerLite | REST API | Subscriber CRM, newsletter management. |
Environment Variables
Secrets are stored in Vercel env vars per project. Key variable names (values never stored in docs):
SUPABASE_URL,SUPABASE_SERVICE_ROLE_KEY-- database accessSTRIPE_SECRET_KEY,STRIPE_WEBHOOK_SECRET-- paymentsANTHROPIC_API_KEY-- chatbot primary LLM (Claude Haiku 4.5)OPENAI_API_KEY-- product/support chatbot LLMGOOGLE_GENERATIVE_AI_API_KEY-- voice agent primary LLMMAILERLITE_API_KEY-- subscriber CRM (newsletter management)
4. Product Ownership
Each product has a clear codebase owner. AI products never live in PewSearch or ITW.
| Product | Codebase | What It Sells | Price Range |
|---|---|---|---|
| ChurchWiseAI Voice Agent | churchwiseai-web/voice-agent-livekit/ | AI phone agent for churches | $39.95--99.95/mo |
| ChurchWiseAI Chatbot | churchwiseai-web/src/app/api/chatbot/ | AI chatbot widget + care pages | $14.95--59.95/mo |
| Pro Website | pewsearch/web/ | Hosted church website (directory-based) | $19.95/mo |
| Premium Page | pewsearch/web/ | Enhanced directory listing | $9.95/mo |
| ITW Premium | sermon-illustrations/ | Sermon illustration library access | $9.95/mo ($99.50/yr) |
| SermonWise Pro | churchwiseai-web/src/app/sermons/ | AI sermon preparation tools | $19.95/mo ($199.50/yr) |
| ShareWiseAI | churchwiseai-web/src/app/social/ | AI social media SaaS | Coming Soon |
Ownership Rule
A church can buy and use Voice Agent or Chatbot without ever visiting PewSearch. ChurchWiseAI is the standalone product brand. PewSearch is a distribution channel -- an optional integration, not a dependency.
5. Voice Agent Architecture
The voice agent runs on LiveKit Cloud using LiveKit Agents v1.5 (Python).
- Multi-tenant: ONE deployed agent serves ALL churches. No per-church deployments.
- Routing:
session.py:resolve_route()looks up the inbound phone number inPHONE_REGISTRYdict (with DB fallback tochurch_voice_agentstable) and builds a church-specific session with the right name, personality, and knowledge. - Agent structure: 2 agents per call:
- Coordinator Agent -- handles info requests, logistics, service times, directions, visitor capture, prayer requests, callbacks. Absorbed former Stewardship tools.
- Care Agent -- pastoral support, grief, crisis. Triggered by emotional/spiritual need detection.
- LLMs: Gemini 2.5 Flash (primary), Claude Haiku 4.5 (fallback; Care Agent uses Haiku as primary for better empathy).
- STT: Deepgram Nova-3 (LiveKit plugin).
- TTS: Cartesia Sonic (LiveKit plugin).
- Telephony: Telnyx for new customers (direct SIP to LiveKit, cheaper). Twilio for legacy numbers (SIP trunk to LiveKit).
- Deployment:
C:\dev\lk.exe agent deploy --project cwa-voice --silent - Code location:
churchwiseai-web/voice-agent-livekit/ - LiveKit project:
cwa-voice-9x077mph(project IDp_5u9xu5ysoly), agent IDCA_pX3Me4NK6qK8, regionus-east
6. Chatbot Architecture
The chatbot runs as a Vercel serverless function.
- Endpoint:
POST /api/chatbot/stream(single API route handles all conversations, Vercel AI SDK 6, streaming SSE). - UX surfaces: Three ways users interact with the chatbot:
/care/[slug]-- standalone pastoral care page/chat/[slug]-- standalone chat page- Embed widget -- JavaScript snippet churches place on their own site
- Agent structure: 4 agents with automatic routing:
- Coordinator -- general info, logistics, directions
- Care -- pastoral support, emotional/spiritual needs
- Stewardship -- giving, tithing, financial questions
- Discipleship -- Bible study, faith questions, theological guidance
- LLMs: Anthropic Claude Haiku 4.5 (primary, direct Anthropic SDK). OpenAI gpt-4o-mini used only for product/support chatbot.
- RAG pipeline: Queries
unified_rag_content(327K documents) plus church-specific knowledge base entries. Results are injected into the system prompt alongsideproduct_knowledgecontext. - Moderation: Content filtering applied to both input and output.
- Code location:
churchwiseai-web/src/app/api/chatbot/stream/route.ts
7. Data Flow Summary
Customer Signup
Pricing page (/pricing) -> "Get Started"
-> Onboard page (/onboard): church name, email, denomination, plan
-> Stripe Checkout (hosted)
-> Webhook: checkout.session.completed
1. Upsert premium_churches (status='active')
2. Store stripe_customer_id + stripe_subscription_id
3. provisionChatbot() -> creates organization_settings
4. Send welcome email with magic link
5. If voice plan -> send voice setup alert to admin
-> Admin Dashboard (/admin/[token]) -- church is live
Voice Call
Inbound call -> Twilio/Telnyx SIP -> LiveKit Cloud
-> session.py:resolve_route() routes by phone number
-> Coordinator or Care agent handles conversation
-> Tools write to Supabase:
- voice_prayer_requests (prayer submissions)
- voice_callback_requests (callback requests)
- voice_visitor_contacts (visitor info capture)
- voice_call_logs (transcript + recording)
Chat Message
User message -> POST /api/chatbot/stream
-> Agent routing (Coordinator / Care / Stewardship / Discipleship)
-> RAG retrieval from unified_rag_content + church KB
-> LLM generates response (Claude Haiku 4.5 primary)
-> Moderation check
-> Response streamed to client
-> Tools write to Supabase (same tables as voice: prayer, callback, visitor)
Knowledge System
knowledge/data/*.yaml (canonical source)
-> pnpm derive
-> pricing.ts (runtime constants)
-> product_knowledge table (chatbot + voice agent context)
-> Page verification (marketing copy accuracy)
-> PRICING.md (human-readable reference)
See Also
- Database Schema -- all tables, relationships, ownership
- API Catalog -- all endpoints across all codebases
- Infrastructure -- Vercel, Supabase, LiveKit, DNS, monitoring
- Operations Guide -- day-to-day operational procedures
- Strategy -- go-to-market and vertical expansion plans