Skip to main content

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.

CodebaseWhatDeployURLFramework
churchwiseai-web/AI products (voice + chatbot), admin dashboard, all APIs, marketingmain -> Vercelchurchwiseai.comNext.js 16, React 19, Tailwind 4
pewsearch/web/Church directory (218K+ visible listings) + distribution channelmaster -> Vercelpewsearch.comNext.js 16
sermon-illustrations/Sermon illustration library (327K content records)master -> Vercelillustratetheword.comNext.js 16
ai-sermon-assistant/LEGACY -- read for reference only, never build hereNOT deployedN/AReact / Nx monorepo

Hostname Rewrites

churchwiseai-web/ also serves two additional brands via Vercel hostname rewrites:

DomainRewrites ToStatus
sermonwise.aichurchwiseai-web/src/app/sermons/Live
sharewiseai.comchurchwiseai-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

ServiceInstanceNotes
SupabaseProject wrwkszmobuhvcfjipasiONE instance for dev AND prod. No local DB, no staging. ~218K visible churches, ~327K content records.
StripeAccount churchwiseai@gmail.comONE 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).
VercelTeam churchwiseai-5386Hosts all 3 web properties. Serverless API routes for all backends.
LiveKit CloudProject cwa-voice-9x077mphVoice agent runtime. Deploy via lk agent deploy --project cwa-voice --silent.
Twilio + TelnyxSIP trunkingRoutes inbound phone calls to LiveKit Cloud. Telnyx for new customers, Twilio for legacy numbers.
GitHubOrg JohnMoelkerAll repos. main for churchwiseai-web, master for pewsearch + ITW.
MailerLiteREST APISubscriber 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 access
  • STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET -- payments
  • ANTHROPIC_API_KEY -- chatbot primary LLM (Claude Haiku 4.5)
  • OPENAI_API_KEY -- product/support chatbot LLM
  • GOOGLE_GENERATIVE_AI_API_KEY -- voice agent primary LLM
  • MAILERLITE_API_KEY -- subscriber CRM (newsletter management)

4. Product Ownership

Each product has a clear codebase owner. AI products never live in PewSearch or ITW.

ProductCodebaseWhat It SellsPrice Range
ChurchWiseAI Voice Agentchurchwiseai-web/voice-agent-livekit/AI phone agent for churches$39.95--99.95/mo
ChurchWiseAI Chatbotchurchwiseai-web/src/app/api/chatbot/AI chatbot widget + care pages$14.95--59.95/mo
Pro Websitepewsearch/web/Hosted church website (directory-based)$19.95/mo
Premium Pagepewsearch/web/Enhanced directory listing$9.95/mo
ITW Premiumsermon-illustrations/Sermon illustration library access$9.95/mo ($99.50/yr)
SermonWise Prochurchwiseai-web/src/app/sermons/AI sermon preparation tools$19.95/mo ($199.50/yr)
ShareWiseAIchurchwiseai-web/src/app/social/AI social media SaaSComing 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 in PHONE_REGISTRY dict (with DB fallback to church_voice_agents table) 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 ID p_5u9xu5ysoly), agent ID CA_pX3Me4NK6qK8, region us-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 alongside product_knowledge context.
  • 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