// architecture reference
Architecture Reference
// key design decisions
Date-based state (no reset job)
Store greeted_{waba}: "YYYY-MM-DD" per contact. No daily reset needed — date comparison handles deduplication automatically.
Independent WABA tracking
Each contact × WABA pair is tracked separately. Messaging WABA A doesn't affect WABA B greeting state.
Firestore named database
Isolated from other projects in the same GCP account. Schema-free — adding new WABAs requires zero migration.
Monthly PDPA cleanup
Contacts inactive for 30+ days are purged. Keeps storage lean and compliant with data minimisation principles.
// key design decisions
S3 blocks all public access
Content served exclusively via CloudFront with OAC. Eliminates direct bucket exposure — no public S3 URL is possible.
Lambda Function URL (no API Gateway)
Reduces cost and latency for a single-function visitor counter. No API Gateway overhead needed at this scale.
DevSecOps pipeline as the gate
Every commit triggers Snyk SCA/SAST and Selenium smoke tests. Deployment only proceeds on full pass.
Cost governance built-in
AWS Budgets sends proactive alerts before thresholds are breached — keeping this workload predictably lean.
// key design decisions
Rubric-based scoring (not black-box AI)
Lead score + confidence signal + rules engine. Qualification decisions are auditable and reduce LLM misclassification risk.
Confidence-gated human review
Low-confidence cases queue for sales ops review. Review outcomes feed back into rubric refinement, improving accuracy over time.
Consent-first handoff
Agent captures consent and packages a summarised conversation + intent before escalating — improving consultant efficiency and user trust.
Idempotent integration
Webhook validated via IP allowlist and idempotency check on session ID + phone number. Retry-safe by design.
// key design decisions
Retry-safe webhook ingestion
4xx for invalid payloads (no retry). 5xx for transient failures (retry with backoff). Idempotency key on primary order ID prevents double-processing.
Explicit order event semantics
Order type (received/ready) classified at validation. One pipeline handles both — simplifying extension to future order states.
Async notifications as side effects
Notifications don't block the ingestion response to POS. Messaging failures can't cascade into order processing failures.
SMS fallback for degraded scenarios
KDS → SMS path ensures customer communication continues during provider outages. Clear operational fallback path.
// key design decisions
Ledger before retry
The intent and exact payload are written as PENDING before the first create. Every retry reuses the same UUID, so ambiguity is always traceable.
Read-only reconcile
A timeout triggers list and detail lookups matched on guest, dates and amount before any retry — the API has no idempotency key to lean on.
One retry, then a human
A two-minute quiet period, one retry maximum, then MANUAL_REVIEW with “do not honour until confirmed”.
Payment stays in the engine
No card data reaches the platform; amounts come from the confirm preview, not the conversation.
// key design decisions
Apex holds the key
The browser never calls the API. The key lives in a protected custom setting and the callout runs server-side.
Phone is the join key
A before-save flow copies MobilePhone into Phone and the card sends digits only — one canonical field between two systems.
Paginate, don’t poll
A bounded page of recent messages; no background polling and no callout loop.
Tests gate the deploy
Callouts are mocked with HttpCalloutMock; 9 of 9 tests pass and run on deploy.
// key design decisions
Ledger outranks balance
Balances are a projection. The ledger records the key, delta and resulting balances for every operation.
Idempotency is required
Every mutation carries a key; a replay returns the stored result with idempotent_replay: true and does not re-apply.
Two buckets, no cross-spend
Campaign and evergreen points have separate balances and separate catalogues.
Schema drift at runtime
Option ids and field names differ between workspaces; resolve them at runtime instead of hard-coding.
// key design decisions
Transport is a door, not a product
Browser upload and partner SFTP converge on one prefix. The parser never learns which door a file used, so validation, mapping and reporting exist once.
Discover the schema before mapping
There is no schema endpoint and users create fields, so discovery reads the live set — and counts fields with zero values as real.
Validate, then write
The row cap and header check run against the whole file before the first contact is created. A rejected file writes nothing.
Batch, isolate, resume
Calls carry 50 rows; a rejected batch is replayed row by row; progress commits every 100 rows so a crash resumes instead of restarting.