Customer Profiles
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Customer Profiles in the DRX system serve as a centralized repository for managing client-specific data, including contact information, purchase history, and credit parameters. This system is designed to support both "Guest" checkouts for rapid transactions and detailed "Profile" checkouts that enable tracking of preferences, repayment behaviors, and credit utilization. Profiles are essential for businesses that require robust customer relationship management (CRM) and AI-driven credit risk assessment.
The module facilitates regulatory compliance through optional features such as age verification, medical card tracking, and permanent PII (Personally Identifiable Information) masking via the Right to be Forgotten (RTBF) API. Data visibility within these profiles is strictly controlled by tenant-based isolation and configurable privacy presets.
Sources: scripts/help-center-data.ts:1145-1158, testsprite_tests/standard_prd.json:14-30
Data Architecture
The customer data model is structured to ensure per-business isolation and extensibility for specific industry needs, such as cannabis retail compliance.
Database Schema
The primary entity is the customers table, which maintains a foreign key relationship with the business_profile. This ensures that staff in one tenant cannot access customer data from another.
The diagram above illustrates the central role of the customer entity in linking sales, credit management, and internal notes.
Sources: db/migrations_combined.sql:85-112, supabase/migrations/20260121000000_ensure_alignment.sql:47-60
Field Specifications
| Field | Type | Constraint | Description |
|---|---|---|---|
first_name | VARCHAR(100) | NOT NULL | Required for all profile-based customers. |
phone_number | VARCHAR(20) | Optional* | Required if email is not provided. |
email | VARCHAR(255) | Optional* | Required if phone_number is not provided. |
total_purchases | DECIMAL(12,2) | Default 0 | Aggregate financial value of all completed sales. |
is_active | BOOLEAN | Default TRUE | Supports soft-disabling instead of deletion. |
med_card_number | VARCHAR(100) | Optional | Tracking for medical cannabis compliance. |
*Note: Validation logic requires at least one contact method (phone OR email) to successfully parse a customer record.
Sources: db/migrations_combined.sql:85-103, tests/customer-validation.unit.test.test.ts:121-144, app/(app)/help/page.tsx:103-111
Customer Lifecycle & Validation
The creation of a customer profile involves strict validation rules enforced via Zod schemas and database-level constraints.
Validation Logic
The system allows for "minimal" vs "full" profiles. A minimal profile requires only a first name and one contact method, while a full profile includes address data, aliases, and compliance fields.
The flowchart depicts the conditional validation path required to instantiate a customer record.
Sources: tests/customer-validation.unit.test.ts:121-160, app/(app)/help/page.tsx:103-111
CRM & Credit Integration
Customer profiles are the primary data source for the AI Credit Engine. This engine consumes customer metrics to calculate risk scores and recommend credit limits.
Analytics & Metrics
The UI displays real-time metrics derived from the v_credit_analytics view, including:
- Sales Windows: 30-day, 90-day, and all-time purchase totals.
- Repayment Behavior: On-time repayment ratio and late payment counts.
- Credit Utilization: Comparison of current balance against the assigned credit limit.
AI Feature Extraction
The system computes specific "features" from customer data to feed the risk model:
- Recency Score: Time elapsed since the last transaction.
- Frequency Score: Average transactions per week.
- Monetary Score: Average ticket size normalized against a $5000 threshold.
- Inventory Coverage: Ability of the business to support requested credit based on current stock value.
Sources: app/(app)/customers/[id]/page.tsx:84-110, lib/credit/aiEngine/features.ts:175-225
Privacy & Security
Customer data is subject to the project's core privacy principles, including masking and tenant isolation.
Privacy Presets
Visibility of sensitive customer fields (like full names or phone numbers) is determined by the business's privacy preset:
- Open: Full details visible to all staff.
- Private: Staff see Nickname/Alias only.
- Max Secure: Aggressive masking; even managers see restricted data.
Compliance Actions
- Soft Deletion: Profiles are marked
is_active = FALSErather than being permanently removed to maintain audit trails. - RTBF Deletion: A specialized API masks PII and removes tenant roles for permanent data privacy compliance.
Sources: scripts/help-center-data.ts:1175-1188, testsprite_tests/standard_prd.json:160-170
Summary
The Customer Profile system is a foundational module that balances operational speed with deep analytical capabilities. By enforcing strict validation for contact information and providing the data hooks necessary for AI-driven credit assessment, it enables businesses to scale their customer relationships while maintaining strict data privacy and regulatory compliance.