Skip to main content

Exhaustive 40 Schema Models Catalog

The platform defines 40 Mongoose models located under src/lib/db/models/. Every model includes TypeScript interface definitions, schema validation rules, compound and TTL indexes, and defensive compilation guards.

Below is the complete, exhaustive catalog organized across 10 functional domains.


Domain 1: Identity & Authentication​

1. User (src/lib/db/models/User.ts)​

  • Purpose: Central profile store for policyholders, affiliates, agency staff, and administrators.
  • TypeScript Interface: IUser
  • Schema Fields:
    • firstName (String, required, trim)
    • lastName (String, required, trim)
    • email (String, required, unique, lowercase, trim)
    • phone (String, optional, trim)
    • organization (String, optional, trim)
    • businessCategory (String, optional, trim)
    • password (String, required — bcrypt hash)
    • role (String, enum: ['super_admin', 'admin', 'user'], default: 'user')
    • referralCode (String, unique, sparse, uppercase, trim)
    • referredBy (String, optional, uppercase, trim)
    • emailVerified (Boolean, default: false)
    • phoneVerified (Boolean, default: false)
    • lastLogin (Date, default: null)
    • profilePictureUrl (String, default: null)
    • accountStatus (String, enum: ['active', 'inactive'], default: 'active')
    • timestamps: createdAt, updatedAt
  • Indexes: { email: 1 } (unique), { referralCode: 1 } (unique, sparse).

2. VerificationToken (src/lib/db/models/VerificationToken.ts)​

  • Purpose: Single-use cryptographically secure tokens for email activation and password resets.
  • TypeScript Interface: IVerificationToken
  • Schema Fields:
    • identifier (String, required, lowercase, trim — user email)
    • token (String, required, unique — hashed token string)
    • expires (Date, required — token expiration timestamp)
    • type (String, enum: ['email-verification', 'password-reset'], default: 'password-reset')
  • Indexes: { token: 1 } (unique), { identifier: 1, type: 1 }, { expires: 1 } (expireAfterSeconds: 0 TTL index).

Domain 2: Lead Ingestion & Downstream Processing​

3. Lead (src/lib/db/models/Lead.ts)​

  • Purpose: Direct web quote inquiries submitted via the homepage and 20 product landing pages. Supports two-step autosave and draft resumption.
  • TypeScript Interface: ILead
  • Schema Fields:
    • firstName (String, required)
    • lastName (String, optional)
    • email (String, optional on draft, required on complete)
    • phone (String, optional on draft, required on complete)
    • state (String, optional on draft, required on complete)
    • insuranceType (String, pre-selected product line slug)
    • additionalDetails (String, optional notes)
    • status (String, enum: ['draft', 'completed'], default: 'draft')
    • truckDetails (Object): { companyName: String, dot: String }
    • autoDetails (Object): { address1, address2, city, zipCode, referredBy, drivers: [DriverSchema], vehicles: [VehicleSchema], currentlyInsured, policyStartDate, residenceStatus, residenceType, propertyQuote, contactMethod, contactTime, contactDate, contactTimeOfDay }
    • homeDetails (Schema.Types.Mixed, placeholder for dwelling attributes)
    • timestamps: createdAt, updatedAt
  • Indexes: { email: 1, status: 1 }, { email: 1, createdAt: -1 }.

4. HtiLead (src/lib/db/models/HtiLead.ts)​

  • Purpose: Ingests qualified personal and commercial trucking leads delivered via the HMAC-SHA256 authenticated Partner REST API (/api/leads/*).
  • TypeScript Interface: IHtiLead
  • Schema Fields:
    • leadType (String, required, enum: ['personal', 'commercial_trucking'], indexed)
    • externalLeadId (String, optional, sparse index — Falcon external identifier)
    • status (String, enum: ['received', 'reviewed', 'contacted', 'converted', 'archived'], default: 'received')
    • stage (String, indexed)
    • Normalized fields: firstName, lastName, email, phone, companyName, companyDBA, usDot, mcNumber, einNumber, state, city, zipCode, yearsInBusiness, insuranceLineType
    • Nested raw structures:
      • lead (Schema.Types.Mixed, required — 100% vendor data preserved)
      • user (Schema.Types.Mixed, optional)
      • rawPayload (Schema.Types.Mixed, full HTTP body)
    • timestamps: createdAt, updatedAt
  • Indexes: { leadType: 1 }, { externalLeadId: 1 }, { status: 1 }, { email: 1 }, { phone: 1 }, { companyName: 1 }, { usDot: 1 }, { createdAt: -1 }.

5. QuarantinedLead (src/lib/db/models/QuarantinedLead.ts)​

  • Purpose: Holds suspicious or bot-flagged submissions intercepted by reCAPTCHA v3 or honeypot filters.
  • TypeScript Interface: IQuarantinedLead
  • Schema Fields:
    • originalData (Schema.Types.Mixed, full submitted form payload)
    • score (Number, reCAPTCHA v3 assessment between 0.0 and 1.0)
    • reason (String, enum: ['LOW_SCORE', 'FAILED_VERIFICATION', 'SUSPICIOUS_PATTERN', 'MALICIOUS_CONTENT'])
    • formType (String, required — e.g. 'quote', 'contact', 'claims')
    • ipAddress (String, required client IP)
    • userAgent (String, optional)
    • action (String, optional reCAPTCHA action name)
    • processed (Boolean, default: false)
    • notes (String, optional admin review comments)
    • timestamps: createdAt, updatedAt
  • Indexes: { createdAt: -1 }, { processed: 1 }, { formType: 1 }, { score: 1 }.

6. CrmFailedLead (src/lib/db/models/CrmFailedLead.ts)​

  • Purpose: Captures outgoing leads that failed delivery to the downstream HTI CRM for admin manual retry.
  • TypeScript Interface: ICrmFailedLead
  • Schema Fields:
    • mongoLeadId (String, required reference to original Lead document)
    • insuranceType (String, required)
    • payload (Schema.Types.Mixed, exact JSON body dispatched to CRM)
    • errorMessage (String, HTTP error text or timeout diagnostic)
    • httpStatus (Number, HTTP status code returned by CRM)
    • resolved (Boolean, default: false)
    • retryCount (Number, default: 0)
    • lastRetryAt (Date, optional)
    • timestamps: createdAt, updatedAt
  • Indexes: { resolved: 1 }, { mongoLeadId: 1 }, { createdAt: -1 }.

7. MetaLead (src/lib/db/models/MetaLead.ts)​

  • Purpose: Stores Facebook & Instagram Lead Ads leads ingested via Meta Graph API v25.0 webhooks.
  • TypeScript Interface: IMetaLead
  • Schema Fields:
    • leadgenId (String, required, unique index — Meta lead identifier)
    • pageId (String, required Meta Page ID)
    • formId (String, required Meta Lead Form ID)
    • createdTime (Date, ad submission timestamp)
    • fieldData (Schema.Types.Mixed, normalized key-value user answers)
    • rawPayload (Schema.Types.Mixed, full Meta Graph API response)
    • status (String, enum: ['pending', 'synced', 'error'], default: 'pending')
    • errorMessage (String, optional)
    • timestamps: createdAt, updatedAt
  • Indexes: { leadgenId: 1 } (unique), { status: 1 }, { createdTime: -1 }.

8. MetaWebhookLog (src/lib/db/models/MetaWebhookLog.ts)​

  • Purpose: Raw immutable audit log of incoming HTTP POST webhook dispatches from Meta servers.
  • TypeScript Interface: IMetaWebhookLog
  • Schema Fields:
    • entryId (String)
    • time (Number)
    • rawPayload (Schema.Types.Mixed, unparsed webhook event body)
    • signature (String, X-Hub-Signature-256 header)
    • verified (Boolean, signature verification result)
    • processedAt (Date, default: Date.now)
  • Indexes: { processedAt: -1 }.

9. GoogleWebhookLog (src/lib/db/models/GoogleWebhookLog.ts)​

  • Purpose: Raw audit log of incoming Google Ads lead form webhooks.
  • TypeScript Interface: IGoogleWebhookLog
  • Schema Fields:
    • leadId (String, Google Ads lead identifier)
    • formId (String, Google campaign form identifier)
    • rawPayload (Schema.Types.Mixed, complete Google webhook payload)
    • processed (Boolean, default: false)
    • timestamps: createdAt, updatedAt
  • Indexes: { createdAt: -1 }.

Domain 3: Public Website Inquiries & Customer Forms​

10. CallLead (src/lib/db/models/CallLead.ts)​

  • Purpose: Requests for scheduled telephone consultations and callbacks.
  • TypeScript Interface: ICallLead
  • Schema Fields:
    • name (String, required, trim)
    • phoneNumber (String, required, trim)
    • preferredDate (String, required — YYYY-MM-DD)
    • preferredTimeSlot (String, required — e.g. '10:00 AM - 11:00 AM')
    • insuranceInterest (String, optional product line)
    • notes (String, optional)
    • status (String, enum: ['pending', 'completed', 'cancelled'], default: 'pending')
    • timestamps: createdAt, updatedAt
  • Indexes: { status: 1 }, { preferredDate: 1 }, { createdAt: -1 }.

11. ClaimsForm (src/lib/db/models/ClaimsForm.ts)​

  • Purpose: First Notice of Loss (FNOL) insurance incident reports.
  • TypeScript Interface: IClaimsForm
  • Schema Fields:
    • policyNumber (String, required, uppercase, trim)
    • policyHolderName (String, required, trim)
    • incidentDate (Date, required)
    • incidentLocation (String, required, trim)
    • description (String, required)
    • contactPhone (String, required, trim)
    • contactEmail (String, required, lowercase, trim)
    • vehicleOrPropertyDetails (String, optional)
    • supportingDocuments ([String], array of uploaded document/photo URLs)
    • status (String, enum: ['new', 'under_review', 'assigned', 'closed'], default: 'new')
    • timestamps: createdAt, updatedAt
  • Indexes: { policyNumber: 1 }, { status: 1 }, { contactEmail: 1 }, { createdAt: -1 }.

12. CareerForm (src/lib/db/models/CareerForm.ts)​

  • Purpose: Job applications submitted through the Careers portal with binary resumes.
  • TypeScript Interface: ICareerForm
  • Schema Fields:
    • fullName (String, required, trim)
    • email (String, required, lowercase, trim)
    • phone (String, required, trim)
    • positionAppliedFor (String, required, trim)
    • linkedinUrl (String, optional, trim)
    • portfolioUrl (String, optional, trim)
    • coverNote (String, optional)
    • resume: { fileName: String, contentType: String, fileData: Buffer, fileSize: Number }
    • status (String, enum: ['submitted', 'interviewing', 'rejected', 'hired'], default: 'submitted')
    • timestamps: createdAt, updatedAt
  • Indexes: { status: 1 }, { email: 1 }, { createdAt: -1 }.

13. ContactForm (src/lib/db/models/ContactForm.ts)​

  • Purpose: General support inquiries submitted from the Contact page.
  • TypeScript Interface: IContactForm
  • Schema Fields:
    • name (String, required, trim)
    • email (String, required, lowercase, trim)
    • phone (String, optional, trim)
    • subject (String, required, trim)
    • message (String, required)
    • status (String, enum: ['unread', 'in_progress', 'resolved'], default: 'unread')
    • ipAddress (String, optional)
    • timestamps: createdAt, updatedAt
  • Indexes: { status: 1 }, { email: 1 }, { createdAt: -1 }.

14. NewsLetter (src/lib/db/models/NewsLetter.ts)​

  • Purpose: Marketing newsletter email subscribers registered via footer forms.
  • TypeScript Interface: INewsLetter
  • Schema Fields:
    • email (String, required, unique, lowercase, trim)
    • isActive (Boolean, default: true)
    • subscribedAt (Date, default: Date.now)
  • Indexes: { email: 1 } (unique).

15. AppWaitlist (src/lib/db/models/AppWaitlist.ts)​

  • Purpose: Early access waitlist registrations for the upcoming HiTech mobile apps.
  • TypeScript Interface: IAppWaitlist
  • Schema Fields:
    • email (String, required, lowercase, trim)
    • platform (String, required, enum: ['ios', 'android'])
    • createdAt (Date, default: Date.now)
  • Indexes: { email: 1, platform: 1 } (unique compound index).

16. PrivacyIntakeForm (src/lib/db/models/PrivacyIntakeForm.ts)​

  • Purpose: Formal data privacy requests complying with California CCPA/CPRA, Texas TDPSA, and GLBA.
  • TypeScript Interface: IPrivacyIntakeForm
  • Schema Fields:
    • requestType (String, required, enum: ['know', 'delete', 'opt_out', 'correct'])
    • consumerType (String, required, enum: ['consumer', 'employee', 'business_contact'])
    • firstName (String, required, trim)
    • lastName (String, required, trim)
    • email (String, required, lowercase, trim)
    • phone (String, required, trim)
    • address (String, optional)
    • stateOfResidence (String, required — e.g. 'CA', 'TX')
    • authorizedAgent (Boolean, default: false)
    • agentDocumentationUrl (String, optional)
    • verificationStatus (String, enum: ['unverified', 'verified', 'rejected'], default: 'unverified')
    • status (String, enum: ['received', 'verifying', 'fulfilled', 'denied'], default: 'received')
    • timestamps: createdAt, updatedAt
  • Indexes: { email: 1 }, { status: 1 }, { createdAt: -1 }.

17. PrivacyAppealForm (src/lib/db/models/PrivacyAppealForm.ts)​

  • Purpose: Consumer appeals against denied or partially fulfilled privacy requests.
  • TypeScript Interface: IPrivacyAppealForm
  • Schema Fields:
    • originalRequestId (String, required reference to PrivacyIntakeForm._id)
    • consumerName (String, required, trim)
    • email (String, required, lowercase, trim)
    • appealReason (String, required)
    • additionalEvidence (String, optional)
    • status (String, enum: ['pending', 'under_review', 'resolved'], default: 'pending')
    • timestamps: createdAt, updatedAt
  • Indexes: { originalRequestId: 1 }, { status: 1 }, { createdAt: -1 }.

Domain 4: Referral & Affiliate Program​

18. Referral (src/lib/db/models/Referral.ts)​

  • Purpose: Client referrals submitted by registered policyholders.
  • TypeScript Interface: IReferral
  • Schema Fields:
    • referrer (Schema.Types.ObjectId, ref: 'User', required, indexed)
    • referredName (String, required, trim)
    • referredEmail (String, required, lowercase, trim)
    • referredPhone (String, required, trim)
    • insuranceType (String, required)
    • status (String, enum: ['submitted', 'contacted', 'quoted', 'bound', 'paid'], default: 'submitted')
    • rewardAmount (Number, default: 0)
    • payoutStatus (String, enum: ['pending', 'approved', 'disbursed'], default: 'pending')
    • notes (String, optional)
    • timestamps: createdAt, updatedAt
  • Indexes: { referrer: 1, status: 1 }, { referredEmail: 1 }, { createdAt: -1 }.

19. ReferForm (src/lib/db/models/ReferForm.ts)​

  • Purpose: Public guest referral submissions prior to account registration.
  • TypeScript Interface: IReferForm
  • Schema Fields:
    • referrerName (String, required, trim)
    • referrerContact (String, required, trim)
    • friendName (String, required, trim)
    • friendContact (String, required, trim)
    • notes (String, optional)
    • convertedToUserId (Schema.Types.ObjectId, ref: 'User', optional)
    • timestamps: createdAt, updatedAt
  • Indexes: { createdAt: -1 }.

Domain 5: Field Marketing & QR Event Campaigns​

20. EventCampaign (src/lib/db/models/EventCampaign.ts)​

  • Purpose: Provisioning field marketing campaigns (conventions, truck expos) with dynamic form schemas and QR short links.
  • TypeScript Interface: IEventCampaign
  • Schema Fields:
    • title (String, required, trim)
    • slug (String, required, unique index — powers /e/:slug)
    • description (String, optional)
    • eventType (String, enum: ['insurance', 'general'], default: 'insurance')
    • insuranceType (String, optional)
    • location (String, optional)
    • boothNumber (String, optional)
    • bannerUrl (String, optional)
    • agentPhone (String, optional)
    • agentId (String, optional)
    • agentName (String, optional)
    • organization (String, required, trim)
    • creatorId (String, required)
    • creatorEmail (String, required)
    • status (String, enum: ['active', 'draft', 'completed', 'archived'], default: 'active')
    • startDate / endDate (Date, optional)
    • fields ([EventFormFieldSchema]): { id, label, type, placeholder, required, options, defaultValue, order }
    • theme: { primaryColor, bannerText }
    • metrics: { scansCount: Number, submissionsCount: Number }
    • timestamps: createdAt, updatedAt
  • Indexes: { slug: 1 } (unique), { status: 1 }, { organization: 1 }.

21. EventAgent (src/lib/db/models/EventAgent.ts)​

  • Purpose: Licensed field agents assigned to marketing campaigns for attendee lead attribution.
  • TypeScript Interface: IEventAgent
  • Schema Fields:
    • eventId (String, required, indexed)
    • agentName (String, required, trim)
    • agentCode (String, required, uppercase, trim)
    • agentEmail (String, required, lowercase, trim)
    • totalLeadsCaptured (Number, default: 0)
    • timestamps: createdAt, updatedAt
  • Indexes: { eventId: 1, agentCode: 1 } (unique compound index).

22. EventLead (src/lib/db/models/EventLead.ts)​

  • Purpose: In-person leads captured by field agents via dynamic attendee forms during active events.
  • TypeScript Interface: IEventLead
  • Schema Fields:
    • eventId (String, required, indexed)
    • eventSlug (String, required, indexed)
    • eventTitle (String, required)
    • organization (String, required)
    • primaryContact: { name, phone, email, preferredLanguage, bestTimeToCall }
    • responses (Schema.Types.Mixed, dynamic key-value answers matching campaign fields)
    • status (String, enum: ['new', 'contacted', 'qualified', 'closed', 'lost'], default: 'new')
    • notes (String, optional)
    • metadata: { ipAddress, userAgent, submittedAt, crmSynced, crmSyncedAt }
    • timestamps: createdAt, updatedAt
  • Indexes: { eventId: 1 }, { eventSlug: 1 }, { "primaryContact.phone": 1 }, { "primaryContact.email": 1 }.

Domain 6: Content Management System (CMS)​

23. Blog (src/lib/db/models/Blog.ts)​

  • Purpose: Full editorial storage for educational insurance articles authored in Tiptap WYSIWYG.
  • TypeScript Interface: IBlog
  • Schema Fields:
    • title (String, required, trim)
    • slug (String, required, unique index)
    • excerpt (String, required, trim)
    • content (String, required — HTML output compiled by Tiptap)
    • coverImage (String, required image URL)
    • authorName (String, required)
    • authorAvatar (String, optional)
    • category (String, required)
    • tags ([String], default: [])
    • readTimeMinutes (Number, default: 3)
    • isPublished (Boolean, default: false)
    • publishedAt (Date, optional)
    • seoTitle / seoDescription / seoKeywords (String, optional)
    • timestamps: createdAt, updatedAt
  • Indexes: { slug: 1 } (unique), { isPublished: 1, publishedAt: -1 }, { category: 1 }.

24. BlogVisit (src/lib/db/models/BlogVisit.ts)​

  • Purpose: Anonymous readership engagement metrics recorded per blog article.
  • TypeScript Interface: IBlogVisit
  • Schema Fields:
    • blogSlug (String, required, indexed)
    • ipHash (String, anonymized hash)
    • userAgent (String)
    • referrer (String)
    • country (String)
    • state (String)
    • visitedAt (Date, default: Date.now)
  • Indexes: { blogSlug: 1, visitedAt: -1 }.

25. Faq (src/lib/db/models/Faq.ts)​

  • Purpose: Dynamic bilingual Frequently Asked Questions rendered on homepage and product views.
  • TypeScript Interface: IFaq
  • Schema Fields:
    • questionEn / answerEn (String, required English question and markdown answer)
    • questionEs / answerEs (String, required Spanish translation)
    • category (String, required, enum: ['general', 'auto', 'commercial', 'claims', 'billing'], default: 'general')
    • displayOrder (Number, default: 0)
    • isActive (Boolean, default: true)
    • timestamps: createdAt, updatedAt
  • Indexes: { category: 1, isActive: 1, displayOrder: 1 }.

Domain 7: Telemetry, Geolocation & Analytics​

26. ActiveVisitor (src/lib/db/models/ActiveVisitor.ts)​

  • Purpose: Real-time presence heartbeat tracker recording concurrent active visitors.
  • TypeScript Interface: IActiveVisitor
  • Schema Fields:
    • visitorId (String, required, unique index)
    • ipHash (String)
    • currentPath (String, required)
    • userAgent (String)
    • country / city (String)
    • lastHeartbeat (Date, required — TTL index expires after 300s = 5 minutes)
  • Indexes: { visitorId: 1 } (unique), { lastHeartbeat: 1 } (expireAfterSeconds: 300 TTL index).

27. DailyVisit (src/lib/db/models/DailyVisit.ts)​

  • Purpose: Pre-aggregated daily platform traffic metrics for instantaneous dashboard rendering.
  • TypeScript Interface: IDailyVisit
  • Schema Fields:
    • date (String, required, unique index — format YYYY-MM-DD)
    • totalPageViews (Number, default: 0)
    • uniqueVisitors (Number, default: 0)
    • bounceCount (Number, default: 0)
    • desktopCount (Number, default: 0)
    • mobileCount (Number, default: 0)
    • tabletCount (Number, default: 0)
  • Indexes: { date: 1 } (unique).

28. VisitLog (src/lib/db/models/VisitLog.ts)​

  • Purpose: Detailed individual visit records capturing device attributes and marketing attribution.
  • TypeScript Interface: IVisitLog
  • Schema Fields:
    • path (String, required)
    • referrer (String)
    • ipHash (String)
    • userAgent / browser / os / deviceType (String)
    • country / state / city (String)
    • utmSource / utmMedium / utmCampaign (String)
    • timestamp (Date, default: Date.now)
  • Indexes: { timestamp: -1 }, { path: 1 }, { country: 1 }, { state: 1 }.

29. VisitorJourney (src/lib/db/models/VisitorJourney.ts)​

  • Purpose: Multi-step conversion funnels tracking page navigation sequences up to quote or contact actions.
  • TypeScript Interface: IVisitorJourney
  • Schema Fields:
    • sessionId (String, required, unique index)
    • visitorId (String, required, indexed)
    • userEmail / userName (String, optional identified user)
    • userRole (String, enum: ['visitor', 'lead', 'client', 'admin'], default: 'visitor')
    • geo: { countryCode, countryName, stateCode, stateName, city, ip }
    • device: { browser, os, deviceType }
    • acquisition: { initialReferrer, landingPage, utmSource, utmMedium, utmCampaign }
    • pageViewCount (Number, default: 1)
    • formSubmitCount (Number, default: 0)
    • startedAt / lastActiveAt (Date)
    • durationSeconds (Number, default: 0)
    • journey: [{ type: JourneyEventType, path, title, target, status, metadata, timestamp }]
  • Indexes: { sessionId: 1 } (unique), { visitorId: 1 }, { startedAt: -1 }.

30. CountryVisit (src/lib/db/models/CountryVisit.ts)​

  • Purpose: Cumulative international geolocation traffic metrics.
  • TypeScript Interface: ICountryVisit
  • Schema Fields:
    • countryCode (String, required, unique index — ISO 3166-1 alpha-2)
    • countryName (String, required)
    • totalVisits (Number, default: 0)
    • lastVisitAt (Date, default: Date.now)
  • Indexes: { countryCode: 1 } (unique).

31. UsStateVisit (src/lib/db/models/UsStateVisit.ts)​

  • Purpose: State-by-state domestic distribution traffic metrics within the United States.
  • TypeScript Interface: IUsStateVisit
  • Schema Fields:
    • stateCode (String, required, unique index — two-letter code)
    • stateName (String, required)
    • totalVisits (Number, default: 0)
    • lastVisitAt (Date, default: Date.now)
  • Indexes: { stateCode: 1 } (unique).

Domain 8: System Infrastructure & Security​

32. RateLimit (src/lib/db/models/RateLimit.ts)​

  • Purpose: Distributed atomic sliding-window rate limit store.
  • TypeScript Interface: IRateLimit
  • Schema Fields:
    • key (String, required, unique index — format ratelimit:<category>:<idType>:<idValue>:<customKey>)
    • count (Number, required, default: 1)
    • resetAt (Date, required — TTL index expires immediately on window elapse)
  • Indexes: { key: 1 } (unique), { resetAt: 1 } (expireAfterSeconds: 0 TTL index).

33. AdminAuditLog (src/lib/db/models/AdminAuditLog.ts)​

  • Purpose: Immutable administrative action log for security compliance and transparency.
  • TypeScript Interface: IAdminAuditLog
  • Schema Fields:
    • adminId (String, required)
    • adminEmail (String, required, lowercase)
    • actionType (String, required — e.g. 'update_lead', 'delete_user', 'publish_blog', 'bulk_email_dispatch')
    • targetResource (String, required)
    • targetId (String, optional)
    • ipAddress (String)
    • userAgent (String)
    • metadataBefore (Schema.Types.Mixed, optional state snapshot before mutation)
    • metadataAfter (Schema.Types.Mixed, optional state snapshot after mutation)
    • timestamp (Date, default: Date.now)
  • Indexes: { timestamp: -1 }, { adminEmail: 1 }, { actionType: 1 }.

34. Counter (src/lib/db/models/Counter.ts)​

  • Purpose: Atomic sequence counter generating human-readable sequential identifiers (inquiry numbers, policy references).
  • TypeScript Interface: ICounter
  • Schema Fields:
    • sequenceName (String, required, unique index)
    • sequenceValue (Number, required, default: 0)
  • Indexes: { sequenceName: 1 } (unique).

Domain 9: Email Communications & Digital Signatures​

35. Signature (src/lib/db/models/Signature.ts)​

  • Purpose: Persistent database storage for custom administrative email signatures and inline template images. Completely eliminates serverless read-only filesystem errors (EROFS).
  • TypeScript Interface: ISignature
  • Schema Fields:
    • name (String, required, trim, maxlength: 60)
    • imageData (String, required base64 data URI)
    • contentType (String, required, default: 'image/png')
    • isSystemDefault (Boolean, default: false)
    • createdBy (String, optional admin email)
    • timestamps: createdAt, updatedAt
  • Public Streaming Route: Streamed over HTTPS via /api/signatures/[id] with Cache-Control: public, max-age=31536000, immutable.

36. EmailTemplate (src/lib/db/models/EmailTemplate.ts)​

  • Purpose: Reusable rich email templates authored in Tiptap for mass campaign broadcasts.
  • TypeScript Interface: IEmailTemplate
  • Schema Fields:
    • name (String, required, trim, maxlength: 100)
    • description (String, maxlength: 300, default: "")
    • category (String, trim, default: 'General')
    • subject (String, required, trim, maxlength: 200)
    • bodyHtml (String, required HTML compiled by Tiptap)
    • signatureText (String, optional)
    • signatureImageUrl (String, optional database signature URL)
    • attachments ([EmailTemplateAttachmentSchema]): { name, contentType, contentInBase64, size }
    • tags ([String], default: [])
    • createdBy (String, optional)
    • timestamps: createdAt, updatedAt
  • Indexes: { name: 1 }, { category: 1 }, { createdAt: -1 }.

37. RecipientList (src/lib/db/models/RecipientList.ts)​

  • Purpose: Curated audience lists for marketing campaigns created via manual input or CSV uploads.
  • TypeScript Interface: IRecipientList
  • Schema Fields:
    • name (String, required, trim, maxlength: 100)
    • description (String, maxlength: 300, default: "")
    • emails ([String], required array of validated email addresses)
    • tags ([String], default: [])
    • createdBy (String, optional)
    • timestamps: createdAt, updatedAt
  • Indexes: { name: 1 }, { createdAt: -1 }.

38. BulkEmailHistory (src/lib/db/models/BulkEmailHistory.ts)​

  • Purpose: Comprehensive campaign dispatch audit log recording metrics, sender, and status.
  • TypeScript Interface: IBulkEmailHistory
  • Schema Fields:
    • type (String, enum: ['bulk', 'test'], default: 'bulk')
    • sender (String, required)
    • senderEmail (String, required, lowercase)
    • subject (String, required)
    • bodyHtml (String, required)
    • snippet (String, optional)
    • totalRecipients (Number, required)
    • processedCount / sentCount / failedCount (Number, default: 0)
    • isDryRun (Boolean, default: false)
    • status (String, enum: ['queued', 'processing', 'paused', 'completed', 'partial', 'failed'], default: 'queued')
    • sampleRecipients / failedRecipients ([EmailRecipientStatusSchema]): { email, status, error }
    • attachments ([EmailHistoryAttachmentSchema]): { name, contentType, contentInBase64, size }
    • sentBy (String, admin identifier)
    • sentAt (Date)
    • timestamps: createdAt, updatedAt
  • Indexes: { status: 1 }, { sentAt: -1 }.

39. BulkEmailRecipientChunk (src/lib/db/models/BulkEmailRecipientChunk.ts)​

  • Purpose: Segmented recipient partitions for large broadcasts to avoid the 16 MB BSON document limit.
  • TypeScript Interface: IBulkEmailRecipientChunk
  • Schema Fields:
    • campaignId (Schema.Types.ObjectId, ref: 'BulkEmailHistory', required, indexed)
    • chunkIndex (Number, required, indexed)
    • recipients: [{ email: String, status: 'pending'|'sent'|'failed', error: String }]
    • timestamps: createdAt, updatedAt
  • Indexes: { campaignId: 1, chunkIndex: 1 } (unique compound index).

Domain 10: Social Portal Configuration​

40. SocialSiteConfig (src/lib/db/models/SocialSiteConfig.ts)​

  • Purpose: Dynamic configuration store powering social.hitechinsurance.ai.
  • TypeScript Interface: ISocialSiteConfig
  • Schema Fields:
    • quickActions: [{ id, name, icon, href, target, isActive, order }]
    • socialGrid: [{ id, name, url, icon, handle, color, isActive, order }]
    • highlights: [{ icon, label: { en, es }, desc: { en, es } }]
    • tipsReels: [{ id, tipNumber, category: { en, es }, categoryKey, headline: { en, es }, fullCaption: { en, es }, body: { en, es }, videoUrl, posterUrl, thumbnailUrl, instagramUrl }]
    • seo: { metaTitle: { en, es }, metaDescription: { en, es }, ogImage }
    • timestamps: createdAt, updatedAt
  • Indexes: Dynamic single document configuration store.