Recommendation

src/Recommendation/ generates music recommendations using multiple algorithms and stores them for retrieval. It does not own the entities it recommends (artists, genres) — those live in Catalog. This context is purely about computing, persisting, and serving recommendation scores.

Domain Models

Aggregate Root: Recommendation

Property Description
score Numeric relevance score from the source algorithm
sourceType Type of entity that generated the recommendation
sourceId ID of the source entity
targetUser User who receives the recommendation
recommendationType Which algorithm produced this recommendation

Value Objects

Type Kind Description
RecommendationType Enum Classifies the originating algorithm (collaborative, content-based, genre, database relation)

Domain Services

Each domain service implements one recommendation algorithm:

Service Algorithm Description
CollaborativeFilteringCalculator User-based collaborative filtering Finds users with similar taste and recommends what they liked
ContentSimilarityCalculator Content-based similarity Matches entities with overlapping attributes
DatabaseRelationCalculator Relationship-based Uses existing database relations (e.g., same artist, same genre)
GenreSimilarityCalculator Genre overlap scoring Scores entities by shared genre membership

Commands & Handlers

Command Handler Purpose
SaveRecommendationCommand SaveRecommendationHandler Persist a single computed recommendation
DeleteRecommendationCommand DeleteRecommendationHandler Remove one recommendation by UUID
DeleteRecommendationsBySourceCommand DeleteRecommendationsBySourceHandler Remove all recommendations originating from a source entity

Queries & Query Handlers

Query Purpose
GetRecommendationQuery Fetch a single recommendation by UUID
GetRecommendationsForUserQuery All recommendations for the authenticated user
GetRecommendationsBySourceQuery Recommendations generated by a specific source entity
GetTargetingRecommendationsQuery Recommendations targeting a specific entity type and ID

Ports

This context has no port interfaces. Controllers dispatch commands and queries directly.

API Endpoints

All endpoints live under RecommendationController with the /api/recommendations prefix.

Method Path Purpose
GET /api/recommendations List recommendations for the current user (cursor-paginated)
GET /api/recommendations/source/{sourceType}/{sourceId} Recommendations by source entity
GET /api/recommendations/targeting/{targetType}/{targetId} Recommendations targeting a specific entity
POST /api/recommendations Create a recommendation
DELETE /api/recommendations/{uuid} Delete a single recommendation
DELETE /api/recommendations/source/{sourceType}/{sourceId} Delete all recommendations for a source

Cross-Context Relationships

Direction Context Details
Depends on Shared Uuid, PublicId
Depends on Catalog Artist and genre references (read-only)
Depended on by No contexts depend on Recommendation directly

Infrastructure

Component Type Purpose
RecommendationEntity Doctrine entity ORM entity mapped to the recommendations table
RecommendationRepository Doctrine repository Implements the domain repository interface