---
id: rating-system
name: Rating System
version: 1.0.0
summary: |
  Internal Reviews system that owns customer feedback, publishes rating
  changes to Catalog, and provides read-time feedback summaries for books.
scope: internal
containers:
  - id: rating-database
    version: 1.0.0
  - id: rating-cache
    version: 1.0.0
entities:
  - id: feedback
    version: 1.0.0
services:
  - id: rating-api
    version: 1.0.0
flows:
  - id: feedback-publication
    version: 1.0.0
relationships:
  - id: product-catalog-system
    version: 1.0.0
    label: updates the denormalized book rating summary through events
  - id: data-privacy
    version: 1.0.0
    label: detects and redacts PII in feedback summarization via Presidio
  - id: mcp-tools
    version: 1.0.0
    label: provides book details and review-analysis prompts to the Rating agent
  - id: identity-provider
    version: 1.0.0
    label: introspects access tokens for protected API requests
actors:
  - id: customer
    name: Customer
    label: submits and reads feedback
    direction: inbound
  - id: administrator
    name: Administrator
    label: can delete feedback
    direction: inbound
owners:
  - catalog-experience-team
repository:
  language: C#
  url: "https://github.com/foxminchan/BookWorm"
badges:
  - content: Internal
    backgroundColor: gray
    textColor: gray
    icon: LockClosedIcon
---

## System Purpose & Boundary

The Rating System owns individual customer [[entity|feedback]] records, moderation, and read-time review summarization within the [[domain|reviews]] domain. It serves **Customers** submitting ratings and requesting AI-assisted book summaries, and **Administrators** moderating or deleting feedback. Authoritative book metadata and derived catalog rating totals remain owned by [[system|product-catalog-system]] and are explicitly out of scope.

:::note
Rating System synchronizes rating deltas to [[system|product-catalog-system]] over Kafka. If a customer submits feedback for a book that does not exist in Catalog, Catalog emits [[event|BookUpdatedRatingFailedIntegrationEvent]] and Rating compensates by idempotently deleting the orphaned feedback.
:::

## Contained Capabilities

| Service / Agent         | Role in System                                                                                                    | Primary Data Store                                          | Interaction Style (Sync / Async)     |
| :---------------------- | :---------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------- | :----------------------------------- |
| [[service\|rating-api]] | Exposes versioned HTTP endpoints for feedback CRUD and summarization, hosts A2A gRPC, and publishes rating events | [[container\|rating-database]], [[container\|rating-cache]] | Sync (HTTP/A2A gRPC) & Async (Kafka) |
| [[agent\|rating-agent]] | Generates read-time review classifications and grounded summaries using catalog context and raw feedback          | None (Read-only)                                            | Sync (A2A gRPC / In-process)         |

## External Interactions & Trust Boundaries

- **Human actors via API Gateway:** Customers authenticate via [[system|identity-provider]] to submit feedback and request summaries; Administrators require the `admin` role to delete feedback.
- **Catalog event synchronization:** Publishes [[event|FeedbackCreatedIntegrationEvent]] and [[event|FeedbackDeletedIntegrationEvent]] to [[system|product-catalog-system]], and consumes [[event|BookUpdatedRatingFailedIntegrationEvent]] for compensation.
- **Conversational & tooling integrations:** [[system|chat-system]] invokes [[agent|rating-agent]] over authenticated A2A gRPC; [[agent|rating-agent]] retrieves book context and analysis prompts from [[system|mcp-tools]] and screens inputs/outputs fail-closed through [[system|data-privacy]].

<Accordion title="Consistency & Summarization Notes">
	- **Eventual projection consistency:** Catalog's average rating and review count update
	asynchronously, trading brief projection lag for decoupled availability. - **Read-time
	summarization:** Summaries are computed on demand without mutating stored feedback or persisting
	generated classifications.
</Accordion>

## System Visualizations

### System Context

<ContextDiagram />

### Reviews Context

<LikeC4View viewId="ratingContext" project="reviews" />

### Component Topology

<NodeGraph mode="full" search="false" legend="false" />

### Architecture Decisions

<ADRTable />

## Related Documentation

- [[flow|feedback-publication]] — End-to-end feedback creation, projection, and compensation flow.
- [[doc|domains/bookworm/subdomains/reviews/engineering/feedback-contracts-and-integration]] — Feedback contracts and integration boundaries.
- [[doc|domains/bookworm/subdomains/reviews/guides/feedback-lifecycle]] — Feedback lifecycle guide.
- [[doc|domains/bookworm/subdomains/reviews/runbooks/catalog-rating-projection-failure]] — Runbook for Catalog rating projection failures.
