Kloyst Docs Index
Welcome to the documentation for the Kloyst Backend (kloyst-core).
Kloyst is an enterprise-grade, multi-tenant WhatsApp Business SaaS platform. This doc set covers the full backend architecture: contact ingestion, messaging pipeline, pricing engine, observability, security, and deployment.
π Documentation Mapβ
π Architectureβ
- System Design Overview β Service modes, request flow, module boundaries
π Databaseβ
- Prisma Schema Reference β All models, enums, indexes, relationships
- Database Design Decisions β Migration strategy, isolation model
π₯ Contact Ingestion Pipelineβ
- Upload Pipeline Flow β CSV/XLSX upload β scan β parse β validate β import
- Validation Engine Rules β Row-level validation, E.164, dedup logic
- Normalization & E.164 β libphonenumber, country codes, encryption
π¨ Messagingβ
- Queue System (BullMQ) β Job queues, concurrency, retry policy
- Outbox Pattern β DBβRedis relay with
FOR UPDATE SKIP LOCKED - Webhooks β Meta webhook handling, signature validation, event routing
π° Pricing Engineβ
- Pricing Engine β Rate cards, regional pricing, platform fees, quotation flow
π³ Billingβ
- Billing & Wallet β Credit system, transaction types, wallet debit on send
π Securityβ
- File Protection β ClamAV scan, SHA256, quarantine
- API Security β Helmet, CORS allowlist, throttling, JWT rotation
π Observability & Monitoringβ
- Metrics & Logging β Winston transports, log levels, rotation
- Monitoring Stack β Grafana + Loki + Promtail + Dozzle setup
π Resilienceβ
- Failure Handling β Dead letter queue, retry with backoff, outbox
π Sequences & Flowsβ
- Sequence Diagrams β Auth, campaign send, contact import
- Core Flows β Data flow through the system
π€ Integrationsβ
- Meta / WhatsApp Integration β WABA, phone numbers, template sync
- Shared WABA Dev Guide β How shared WABA accounts work
π§ͺ Upsert Strategyβ
- Contact Upsert Strategy β Merge strategies, conflict resolution
πΊ Deployment Architecture (Staging)β
GitHub (staging branch push)
β
Jenkins Pipeline
βββ rsync β /srv/apps/kloyst-core/
βββ docker build (on server, no registry)
βββ docker compose -f docker-compose.staging.yml up -d
β
βββ kloyst-staging-api-gateway β 127.0.0.1:3000
βββ kloyst-staging-webhook-worker β 127.0.0.1:3002
βββ kloyst-staging-worker-pool β (internal)
βββ kloyst-staging-outbox-relay β (internal)
βββ kloyst-staging-postgres β (internal)
βββ kloyst-staging-redis β (internal)
β
Nginx (SSL termination, basic auth)
βββ api.staging.kloyst.com/v1/* β :3000
βββ api.staging.kloyst.com/webhook/* β :3002
β
Monitoring Stack (/srv/apps/monitoring/)
βββ Grafana β 127.0.0.1:3003 β logs.staging.kloyst.com
βββ Loki β 127.0.0.1:3100 (internal)
βββ Promtail β (internal, tails Docker + log files)
βββ Dozzle β 127.0.0.1:8888 β dozzle.staging.kloyst.com
βοΈ Core Philosophyβ
- Never crash on partial errors β Invalid rows are rejected; valid ones continue.
- Tenant isolation is absolute β
vendorIdon every query. No exceptions. - Strict normalization β All phone numbers parsed with Google's
libphonenumberto E.164. - Auditability β Every import job, chunk, and contact change is logged immutably.
- Migration safety β
prisma migrate deployin all non-local environments. Neverdb push. - Secrets via Jenkins β Zero hardcoded credentials. All injected via secret file at deploy time.