domain tier

domain-reviews

Ratings and reviews with multi-source support and cached aggregates

Ratings and reviews with multi-source support and cached aggregates

Tierdomain
Roleunclassified (baselined)
Pathcrates/domain/reviews
Edition2021
Targetsdomain_reviews
Public items79 across 6 modules
Tests14

What it is for

domain-reviews: Ratings and Reviews Library crate

A universal ratings and reviews system that can be attached to any entity via the EntityRef pattern. Supports multiple sources (Google, Yelp, etc.), cached aggregates with auto-refresh triggers, and AI sentiment analysis.

# Features

# Example

use domain_reviews::{Review, ReviewSource, EntityRef, Sentiment};
use rust_decimal_macros::dec;
use uuid::Uuid;

// Create a review for an organization
let entity = EntityRef::organization(Uuid::new_v4());
let review = Review::new(
tenant_id,
&entity,
ReviewSource::Google,
"google_review_123",
dec!(4.5),
)
.with_title("Great service!")
.with_text("They fixed my pipes quickly.")
.with_reviewer("John D.")
.as_verified()
.with_sentiment(Sentiment::Positive, Some(dec!(0.95)));

Capabilities

ReviewError

Review errors.

Item
pub enum ReviewError
ReviewError :: fn storage(msg : impl Into <String>) -> Self
ReviewError :: fn validation(msg : impl Into <String>) -> Self

ReviewEvent

Review domain events.

Item
pub enum ReviewEvent
ReviewEvent :: fn created(review_id : Uuid, tenant_id : Uuid, entity : & EntityRef, source : & ReviewSource, rating : Decimal,) -> Self
ReviewEvent :: fn updated(review_id : Uuid, tenant_id : Uuid, entity : & EntityRef, old_rating : Option <Decimal>, new_rating : Decimal,) -> Self
ReviewEvent :: fn deleted(review_id : Uuid, tenant_id : Uuid, entity : & EntityRef) -> Self
ReviewEvent :: fn sentiment_analyzed(review_id : Uuid, tenant_id : Uuid, sentiment : Sentiment, score : Option <Decimal>,) -> Self
ReviewEvent :: fn summary_refreshed(tenant_id : Uuid, entity : & EntityRef, review_count : i32, avg_rating : Option <Decimal>,) -> Self

jsonld (other)

schema.org/Review JSON-LD payload builder.

Item
fn build_jsonld_third_party_only(reviews : & Review, business_name : & str) -> Option <Value>

EntityRef

Core review models.

Item
pub struct EntityRef
EntityRef :: fn new(entity_type : impl Into <String>, entity_id : Uuid) -> Self
EntityRef :: fn organization(id : Uuid) -> Self
EntityRef :: fn catalog_item(id : Uuid) -> Self
EntityRef :: fn person(id : Uuid) -> Self

Review:Review

Core review models.

Item
pub struct Review

Review:as

Core review models.

Item
Review :: fn as_verified(mut self) -> Self
Review :: fn as_inactive(mut self) -> Self

Review:entity

Core review models.

Item
Review :: fn entity_ref(& self) -> EntityRef

Review:is

Core review models.

Item
Review :: fn is_positive(& self) -> bool
Review :: fn is_negative(& self) -> bool
Review :: fn is_third_party(& self) -> bool

Review:new

Core review models.

Item
Review :: fn new(tenant_id : Uuid, entity : & EntityRef, source : ReviewSource, source_id : impl Into <String>, rating : Decimal,) -> Self

Review:with

Core review models.

Item
Review :: fn with_source_url(mut self, url : impl Into <String>) -> Self
Review :: fn with_title(mut self, title : impl Into <String>) -> Self
Review :: fn with_text(mut self, text : impl Into <String>) -> Self
Review :: fn with_reviewer(mut self, name : impl Into <String>) -> Self
Review :: fn with_reviewer_id(mut self, id : impl Into <String>) -> Self
Review :: fn with_review_date(mut self, date : DateTime <Utc>) -> Self
Review :: fn with_sentiment(mut self, sentiment : Sentiment, score : Option <Decimal>) -> Self
Review :: fn with_body_short(mut self, short : impl Into <String>) -> Self
Review :: fn with_sequence(mut self, sequence : i32) -> Self

ReviewFilter

Core review models.

Item
pub struct ReviewFilter
ReviewFilter :: fn new() -> Self
ReviewFilter :: fn source(mut self, source : ReviewSource) -> Self
ReviewFilter :: fn min_rating(mut self, rating : Decimal) -> Self
ReviewFilter :: fn max_rating(mut self, rating : Decimal) -> Self
ReviewFilter :: fn sentiment(mut self, sentiment : Sentiment) -> Self
ReviewFilter :: fn verified_only(mut self) -> Self
ReviewFilter :: fn active_only(mut self) -> Self
ReviewFilter :: fn with_text_only(mut self) -> Self
ReviewFilter :: fn date_range(mut self, from : DateTime <Utc>, to : DateTime <Utc>) -> Self
ReviewFilter :: fn paginate(mut self, limit : i64, offset : i64) -> Self

ReviewSource

Core review models.

Item
pub enum ReviewSource
ReviewSource :: fn as_str(& self) -> & str
ReviewSource :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result
ReviewSource :: fn from_str(s : & str) -> Result <Self, Self::Err>

ReviewSummary

Core review models.

Item
pub struct ReviewSummary
ReviewSummary :: fn entity_ref(& self) -> EntityRef
ReviewSummary :: fn five_star_percentage(& self) -> f64
ReviewSummary :: fn positive_percentage(& self) -> f64
ReviewSummary :: fn rating_tier(& self) -> & 'static str

Sentiment

Core review models.

Item
pub enum Sentiment
Sentiment :: fn as_str(& self) -> & 'static str
Sentiment :: fn from_str(s : & str) -> Result <Self, Self::Err>

BulkResult

Review repository trait.

Item
pub struct BulkResult
BulkResult :: fn new() -> Self
BulkResult :: fn total(& self) -> i64
BulkResult :: fn all_succeeded(& self) -> bool

ReviewRepository

Review repository trait.

Item
pub trait ReviewRepository

ReviewResult

Review repository trait.

Item
pub type ReviewResult<T>: Result <T, ReviewError>

ReviewService

Review service implementation.

Item
pub struct ReviewService<R : ReviewRepository>

ReviewService<R>:bulk

Review service implementation.

Item
ReviewService<R> :: async fn bulk_upsert_reviews(& self, reviews : Vec <Review>) -> ReviewResult <BulkResult>

ReviewService<R>:clone

Review service implementation.

Item
ReviewService<R> :: fn clone(& self) -> Self

ReviewService<R>:count

Review service implementation.

Item
ReviewService<R> :: async fn count_reviews(& self, tenant_id : Uuid, entity : & EntityRef, filter : & ReviewFilter,) -> ReviewResult <i64>

ReviewService<R>:create

Review service implementation.

Item
ReviewService<R> :: async fn create_review(& self, review : Review) -> ReviewResult <(Review, ReviewEvent)>

ReviewService<R>:delete

Review service implementation.

Item
ReviewService<R> :: async fn delete_review(& self, id : Uuid) -> ReviewResult <Option <ReviewEvent>>
ReviewService<R> :: async fn delete_entity_reviews(& self, tenant_id : Uuid, entity : & EntityRef,) -> ReviewResult <i64>

ReviewService<R>:get

Review service implementation.

Item
ReviewService<R> :: async fn get_review(& self, id : Uuid) -> ReviewResult <Option <Review>>
ReviewService<R> :: async fn get_review_or_error(& self, id : Uuid) -> ReviewResult <Review>
ReviewService<R> :: async fn get_summary(& self, tenant_id : Uuid, entity : & EntityRef, source : Option <& ReviewSource>,) -> ReviewResult <Option <ReviewSummary>>
ReviewService<R> :: async fn get_summary_or_error(& self, tenant_id : Uuid, entity : & EntityRef, source : Option <& ReviewSource>,) -> ReviewResult <ReviewSummary>

ReviewService<R>:list

Review service implementation.

Item
ReviewService<R> :: async fn list_reviews(& self, tenant_id : Uuid, entity : & EntityRef, filter : & ReviewFilter,) -> ReviewResult <Vec <Review>>

ReviewService<R>:new

Review service implementation.

Item
ReviewService<R> :: fn new(repository : Arc <R>) -> Self

ReviewService<R>:refresh

Review service implementation.

Item
ReviewService<R> :: async fn refresh_summary(& self, tenant_id : Uuid, entity : & EntityRef,) -> ReviewResult <(ReviewSummary, ReviewEvent)>
ReviewService<R> :: async fn refresh_all_summaries(& self) -> ReviewResult <i64>

ReviewService<R>:update

Review service implementation.

Item
ReviewService<R> :: async fn update_review(& self, review : Review, old_rating : Option <rust_decimal::Decimal>,) -> ReviewResult <(Review, ReviewEvent)>
ReviewService<R> :: async fn update_sentiment(& self, id : Uuid, sentiment : Sentiment, score : Option <rust_decimal::Decimal>,) -> ReviewResult <(Review, ReviewEvent)>

ReviewService<R>:upsert

Review service implementation.

Item
ReviewService<R> :: async fn upsert_review(& self, review : Review) -> ReviewResult <(Review, ReviewEvent)>

How to use it

From this crate's own rustdoc:

use domain_reviews::{Review, ReviewSource, EntityRef, Sentiment};
use rust_decimal_macros::dec;
use uuid::Uuid;

// Create a review for an organization
let entity = EntityRef::organization(Uuid::new_v4());
let review = Review::new(
    tenant_id,
    &entity,
    ReviewSource::Google,
    "google_review_123",
    dec!(4.5),
)
.with_title("Great service!")
.with_text("They fixed my pipes quickly.")
.with_reviewer("John D.")
.as_verified()
.with_sentiment(Sentiment::Positive, Some(dec!(0.95)));

Module structure

domain_reviews

flowchart TD
  n_domain_reviews["domain_reviews"]
  n_domain_reviews --> n_errors["errors"]
  n_domain_reviews --> n_events["events"]
  n_domain_reviews --> n_jsonld["jsonld"]
  n_domain_reviews --> n_models["models"]
  n_domain_reviews --> n_repository["repository"]
  n_domain_reviews --> n_service["service"]

Public surface

`errors`

ItemWhat it is
pub enum ReviewErrorErrors that can occur in the reviews domain.
ReviewError :: fn storage(msg : impl Into <String>) -> Self
ReviewError :: fn validation(msg : impl Into <String>) -> Self

`events`

ItemWhat it is
pub enum ReviewEventEvents emitted by the reviews domain.
ReviewEvent :: fn created(review_id : Uuid, tenant_id : Uuid, entity : & EntityRef, source : & ReviewSource, rating : Decimal,) -> SelfCreate a ReviewCreated event.
ReviewEvent :: fn updated(review_id : Uuid, tenant_id : Uuid, entity : & EntityRef, old_rating : Option <Decimal>, new_rating : Decimal,) -> SelfCreate a ReviewUpdated event.
ReviewEvent :: fn deleted(review_id : Uuid, tenant_id : Uuid, entity : & EntityRef) -> SelfCreate a ReviewDeleted event.
ReviewEvent :: fn sentiment_analyzed(review_id : Uuid, tenant_id : Uuid, sentiment : Sentiment, score : Option <Decimal>,) -> SelfCreate a SentimentAnalyzed event.
ReviewEvent :: fn summary_refreshed(tenant_id : Uuid, entity : & EntityRef, review_count : i32, avg_rating : Option <Decimal>,) -> SelfCreate a SummaryRefreshed event.

`jsonld`

ItemWhat it is
fn build_jsonld_third_party_only(reviews : & Review, business_name : & str) -> Option <Value>Build a schema.org Organization JSON-LD payload with embedded review array — but ONLY from third-party rows

`models`

ItemWhat it is
pub struct EntityRefReference to an entity that can be reviewed.
EntityRef :: fn new(entity_type : impl Into <String>, entity_id : Uuid) -> Self
EntityRef :: fn organization(id : Uuid) -> Self
EntityRef :: fn catalog_item(id : Uuid) -> Self
EntityRef :: fn person(id : Uuid) -> Self
pub enum ReviewSourceSource of a review.
ReviewSource :: fn as_str(& self) -> & str
ReviewSource :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result
ReviewSource :: fn from_str(s : & str) -> Result <Self, Self::Err>
pub enum SentimentSentiment classification for AI analysis.
Sentiment :: fn as_str(& self) -> & 'static str
Sentiment :: fn from_str(s : & str) -> Result <Self, Self::Err>
pub struct ReviewA review of an entity.
Review :: fn new(tenant_id : Uuid, entity : & EntityRef, source : ReviewSource, source_id : impl Into <String>, rating : Decimal,) -> SelfCreate a new review.
Review :: fn with_source_url(mut self, url : impl Into <String>) -> Self
Review :: fn with_title(mut self, title : impl Into <String>) -> Self
Review :: fn with_text(mut self, text : impl Into <String>) -> Self
Review :: fn with_reviewer(mut self, name : impl Into <String>) -> Self
Review :: fn with_reviewer_id(mut self, id : impl Into <String>) -> Self
Review :: fn as_verified(mut self) -> Self
Review :: fn with_review_date(mut self, date : DateTime <Utc>) -> Self
Review :: fn with_sentiment(mut self, sentiment : Sentiment, score : Option <Decimal>) -> Self
Review :: fn with_body_short(mut self, short : impl Into <String>) -> SelfSet the operator-controlled short form for widget cards.
Review :: fn with_sequence(mut self, sequence : i32) -> SelfSet the manual ordering sequence for widget rendering
Review :: fn as_inactive(mut self) -> SelfMark this review as inactive (hidden from public widgets but not soft-deleted)
Review :: fn entity_ref(& self) -> EntityRefGet the entity reference.
Review :: fn is_positive(& self) -> boolCheck if this is a positive review (4+ stars).
Review :: fn is_negative(& self) -> boolCheck if this is a negative review (< 3 stars).
Review :: fn is_third_party(& self) -> booltrue when this review's source indicates a third-party platform (Google, Yelp, BBB, Facebook, Trustpilot, etc.) — i.e
pub struct ReviewSummaryCached review statistics for an entity.
ReviewSummary :: fn entity_ref(& self) -> EntityRefGet the entity reference.
ReviewSummary :: fn five_star_percentage(& self) -> f64Calculate the percentage of 5-star reviews.
ReviewSummary :: fn positive_percentage(& self) -> f64Calculate the percentage of positive sentiment reviews.
ReviewSummary :: fn rating_tier(& self) -> & 'static strGet a simple rating tier.
pub struct ReviewFilterFilter options for querying reviews.
ReviewFilter :: fn new() -> Self
ReviewFilter :: fn source(mut self, source : ReviewSource) -> Self
ReviewFilter :: fn min_rating(mut self, rating : Decimal) -> Self
ReviewFilter :: fn max_rating(mut self, rating : Decimal) -> Self
ReviewFilter :: fn sentiment(mut self, sentiment : Sentiment) -> Self
ReviewFilter :: fn verified_only(mut self) -> Self
ReviewFilter :: fn active_only(mut self) -> SelfFilter to only active (published) reviews
ReviewFilter :: fn with_text_only(mut self) -> Self
ReviewFilter :: fn date_range(mut self, from : DateTime <Utc>, to : DateTime <Utc>) -> Self
ReviewFilter :: fn paginate(mut self, limit : i64, offset : i64) -> Self

`repository`

ItemWhat it is
pub type ReviewResult<T>: Result <T, ReviewError>Result type for review operations.
pub trait ReviewRepositoryRepository trait for review persistence.
pub struct BulkResultResult of a bulk operation.
BulkResult :: fn new() -> SelfCreate a new empty bulk result.
BulkResult :: fn total(& self) -> i64Total records processed.
BulkResult :: fn all_succeeded(& self) -> boolCheck if all records succeeded.

`service`

ItemWhat it is
pub struct ReviewService<R : ReviewRepository>Service for managing reviews and summaries.
ReviewService<R> :: fn new(repository : Arc <R>) -> SelfCreate a new review service.
ReviewService<R> :: async fn create_review(& self, review : Review) -> ReviewResult <(Review, ReviewEvent)>Create a new review.
ReviewService<R> :: async fn update_review(& self, review : Review, old_rating : Option <rust_decimal::Decimal>,) -> ReviewResult <(Review, ReviewEvent)>Update an existing review.
ReviewService<R> :: async fn upsert_review(& self, review : Review) -> ReviewResult <(Review, ReviewEvent)>Upsert a review (create or update based on source + source_id).
ReviewService<R> :: async fn get_review(& self, id : Uuid) -> ReviewResult <Option <Review>>Get a review by ID.
ReviewService<R> :: async fn get_review_or_error(& self, id : Uuid) -> ReviewResult <Review>Get a review by ID, returning error if not found.
ReviewService<R> :: async fn list_reviews(& self, tenant_id : Uuid, entity : & EntityRef, filter : & ReviewFilter,) -> ReviewResult <Vec <Review>>List reviews for an entity.
ReviewService<R> :: async fn count_reviews(& self, tenant_id : Uuid, entity : & EntityRef, filter : & ReviewFilter,) -> ReviewResult <i64>Count reviews for an entity.
ReviewService<R> :: async fn delete_review(& self, id : Uuid) -> ReviewResult <Option <ReviewEvent>>Delete a review.
ReviewService<R> :: async fn delete_entity_reviews(& self, tenant_id : Uuid, entity : & EntityRef,) -> ReviewResult <i64>Delete all reviews for an entity.
ReviewService<R> :: async fn get_summary(& self, tenant_id : Uuid, entity : & EntityRef, source : Option <& ReviewSource>,) -> ReviewResult <Option <ReviewSummary>>Get review summary for an entity.
ReviewService<R> :: async fn get_summary_or_error(& self, tenant_id : Uuid, entity : & EntityRef, source : Option <& ReviewSource>,) -> ReviewResult <ReviewSummary>Get review summary for an entity, returning error if not found.
ReviewService<R> :: async fn refresh_summary(& self, tenant_id : Uuid, entity : & EntityRef,) -> ReviewResult <(ReviewSummary, ReviewEvent)>Manually refresh review summary for an entity.
ReviewService<R> :: async fn refresh_all_summaries(& self) -> ReviewResult <i64>Refresh all review summaries.
ReviewService<R> :: async fn bulk_upsert_reviews(& self, reviews : Vec <Review>) -> ReviewResult <BulkResult>Bulk upsert reviews.
ReviewService<R> :: async fn update_sentiment(& self, id : Uuid, sentiment : Sentiment, score : Option <rust_decimal::Decimal>,) -> ReviewResult <(Review, ReviewEvent)>Update sentiment analysis for a review.
ReviewService<R> :: fn clone(& self) -> Self

Re-exports. Exported here, defined elsewhere.

ExportDefined in
ReviewErrorerrors::ReviewError
ReviewEventevents::ReviewEvent
ReviewServiceservice::ReviewService
build_jsonld_third_party_onlyjsonld::build_jsonld_third_party_only
{BulkResult,ReviewRepository,ReviewResult}repository::{BulkResult,ReviewRepository,ReviewResult}
{EntityRef,Review,ReviewFilter,ReviewSource,ReviewSummary,Sentiment}models::{EntityRef,Review,ReviewFilter,ReviewSource,ReviewSummary,Sentiment}

Boundary

Depends on no other workspace tier.

Shares tier domain with 41 other crates: domain-agreements, domain-ai-report, domain-billing, domain-catalog, domain-classify, domain-comments, domain-competitive-intel, domain-contact, … (41 total).

_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._

Where it sits

Tier (ontology)domain
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/domain/reviews
Vocabulary in force (lexicon)current

Dependencies

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
async-trait^0.1noalways
chrono^0.4serdenoalways
rust_decimal^1serdenoalways
serde^1derivenoalways
serde_json^1noalways
thiserror^1noalways
uuid^1v4, serdenoalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
rust_decimal_macros^1noalways
tokio^1rt-multi-thread, macrosnoalways

Build. None.

Depended on by. 4 workspace crates.

Signal flow — what reaches this crate, and what it reaches.

flowchart LR
  n_application_reviews["application-reviews"] -->|uses| SELF
  n_infrastructure_adapters_yelp["infrastructure-adapters-yelp"] -->|uses| SELF
  n_platform_customer_ui["platform-customer-ui"] -->|uses| SELF
  n_platform_privacy_scan_api["platform-privacy-scan-api"] -->|uses| SELF
  SELF["domain-reviews"]
  classDef self fill:#1f883d,stroke:#1f883d,color:#fff;
  class SELF self;

Feature flags

No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.

Targets

KindNameSource
libdomain_reviews`src/lib.rs`

Error model

Error typeNamed by
ReviewErrorReviewResult

Operational characteristics

PropertyEvidence
async public surfaceyes
async runtimenone detected
database accessnone detected
network I/Onone detected
unsafe codenone detected
environment variablesnone detected

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.

4 workspace crates depend on this one: application-reviews, infrastructure-adapters-yelp, platform-customer-ui, platform-privacy-scan-api.

Verification

KindCount
Unit tests14
Integration tests0
Examples0
Doctests1

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
errors101
events100
jsonld101
models609
repository300
service100

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc5079
Public modules with a //! block66
pie showData
    title Public items with rustdoc
    "Documented" : 50
    "No rustdoc detected" : 29

Metrics

MetricValue
Rust source files7
Source lines1451
Code lines1088
Public API items79
Public modules6
Tests14
Examples0
Cargo features0
Direct runtime dependencies7
Workspace reverse dependencies4
pie showData
    title Public API by kind
    "enum" : 4
    "function" : 1
    "method" : 66
    "struct" : 6
    "trait" : 1
    "type alias" : 1
pie showData
    title Rust source composition
    "Code" : 1088
    "Blank or comment" : 363

Generation

Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.

All domain · Manual