customer_relation
A deterministic, domain-driven customer relationship and trust model for Dart.
This package helps you model customers, profiles, trust levels, and brand relationships with strict invariants, immutable identities, and fully controlled time.
If a rule can be violated, the API is considered broken.
Why this package exists
Most customer/loyalty systems fail because:
- Identity can be mutated accidentally
- Trust levels can be skipped or forged
- Business rules live in services instead of the domain
- Time (
DateTime.now()) makes logic untestable and non-replayable
customer_relation fixes this by enforcing rules inside the domain, not in documentation or developer discipline.
Core principles
-
Identity is sacred
Customer identity fields are immutable and validated. -
Trust is monotonic
Relationship levels can only move forward in a defined order. -
No hidden mutations
All state changes go through explicit intent-revealing methods. -
Time is injected, not magical
NoDateTime.now()leaks into the domain. -
Deterministic by design
Same input + same time = same output.
Features
- Immutable
CustomerId - Safe
CustomerProfilemutation - Brand relationship lifecycle
- Trust level progression
Identity → Habit → Legend - Relationship status management
- Clock / TimeProvider abstraction
- Fully testable & replayable domain logic
Installation
dart pub add customer_relation
Libraries
- customer_relation
- domain/entities/brand_relationship
- domain/entities/complaint
- domain/entities/customer
- domain/entities/customer_profile
- domain/enums/communication_preference
- domain/enums/feedback_source
- domain/enums/feedback_type
- domain/enums/relationship_level
- domain/enums/relationship_status
- domain/policies/relationship_progression_policy
- domain/policies/risk_evolution_policy
- domain/value_objects/customer_id
- domain/value_objects/feedback
- domain/value_objects/household_id
- domain/value_objects/phone_number
- infrastructure/system_clock
- ports/analytics_sink_port
- ports/clock
- ports/fraud_signal_ports
- ports/risk_signal_port
- services/customer_onboarding_services
- services/relationship_evolution_services