audience
Declarative, rule-based audience segmentation. Segments are defined in
code with the defaudience macro or persisted dynamically in the
database, then evaluated against your user base through a hybrid SQL
predicate pipeline.
Key namespaces
| Namespace | Purpose |
|---|---|
|
In-process segment definition registry and the |
|
Pure: built-in filter types and the |
|
Pure: compile segments into SQL + predicate execution plans |
|
Pure: AND/OR/NOT composition of segment result sets |
|
Pure: Hiccup UI components for segments |
|
Protocols: |
|
Service orchestrating resolution, caching, and persistence |
|
|
|
|
|
REST + web endpoints (CRUD, preview, evaluate, members) |
Built-in filter types
| Filter | Matches on |
|---|---|
|
Age, gender, and other profile attributes |
|
Country, region, city |
|
Assigned user roles |
|
Time since account creation |
|
Recency of last activity |
|
Recorded user events / actions |
|
Use of specific product features |
Each filter is resolved through the filter→sql and
filter→predicate multimethods. SQL-eligible filters are pushed to the
database; the rest run as Clojure predicates over the candidate set.
Define new methods on both multimethods to add custom filter types.
Composition
Segments compose with AND / OR / NOT. A composition tree is checked before it is evaluated: circular, unknown or invalid references are rejected then.
Dynamic segments
Segments can also be stored in the database as JSON and loaded at runtime. Incoming JSON is schema-validated, and fn-typed values are rejected so persisted definitions stay data-only.
Caching
Membership results are cached in an audience_memberships table with a
configurable per-segment TTL, served through the IAudienceCache
component.
Builder UI
A segment builder is served over HTMX, with Replicant widget mount points for the filter panel and the composition builder.
Endpoints
| Endpoint group | Purpose |
|---|---|
CRUD |
Create, read, update, delete segments |
Preview |
Count + sample of matching members |
Evaluate |
Run evaluation and cache the result |
Members |
List cached members of a segment |