State Management & End-to-End Data Flow
This document details how data flows through veridex-hitech-web-application, from user interaction and client-side form state through Server Actions, rate limiting, validation, MongoDB persistence, and external service synchronization.
1. State Management Architecture
Rather than relying on heavyweight global state libraries (such as Redux or MobX), the platform adopts a modern, lightweight state architecture aligned with React 19 and Next.js 15:
1.1 State Categories
- Server-Rendered Page State: Handled via Server Components. Initial data (e.g. blog posts, dynamic FAQs) is passed directly down component trees as typed props.
- Form Mutation State: Managed via React 19's
useActionStatehook. TracksisPending, validation errors, and server return values without requiring manualtry/catchor intermediate loading state variables. - Authentication State: Provided by
<AuthProvider>(SessionProviderwrapper) allowing client components to access user credentials, role, and referral code viauseSession(). - Transient Client State: Managed by
useStatefor UI concerns such as step progression in the 16-step auto questionnaire, image cropping zoom levels, and modal visibility.
2. Inbound Lead Data Flow & Draft Autosave Pipeline
To minimize drop-off on complex commercial and personal insurance applications, the platform implements an atomic two-step draft-and-complete data flow:
3. Telemetry & Visitor Journey Data Flow
Visitor engagement and conversion telemetry execute non-blocking, privacy-preserving tracking without third-party tracking cookies:
4. Bulk Email Broadcast Data Flow
The mass communication pipeline processes campaigns through managed micro-batches to guarantee high deliverability:
- Composition & Asset Offloading: The administrator composes the email in Tiptap. Uploaded images are offloaded via
uploadInlineEmailImageActioninto theSignaturecollection, substituting/api/signatures/[id]URLs to maintain lightweight template documents. - Recipient Chunking: Recipients from manual inputs or CSV uploads are divided into chunks and stored in
BulkEmailRecipientChunk({ campaignId, chunkIndex }), mitigating the 16 MB BSON document limit. - Controlled Micro-Batch Dispatch:
- Emails are dispatched in batches of 5 (
BATCH_SIZE = 5). - An artificial delay of 250ms (
BATCH_DELAY_MS = 250) is enforced between batches. - Individual recipient success/failure is recorded in real time.
- Emails are dispatched in batches of 5 (
- Audit Trail Logging: Once complete, an immutable summary record is logged in
AdminAuditLogrecording the administrator identity, subject line, recipient count, and timestamp.