Enhanced User Profile System

User Profile System - Backend Persistence Implementation

Overview

Comprehensive user profile system with backend persistence to sync settings, profiles, preferences, and reviews across all devices and browsers.

Architecture

Domain Entities Created

1. UserProfile

  • Bio/description
  • Joined date (automatic)
  • Rentals offered count (cached statistics)
  • Avatar (predefined or uploaded)
  • Average rating & review count (cached)
  • Profile visibility
  • Display name
  • Location, website, languages

2. UserPreference

  • JSON storage for all user preferences
  • Syncs across all browsers/devices
  • Replaces localStorage approach

3. UserReview

  • Star rating (1-5)
  • Optional comment
  • Review date
  • Visibility toggle (moderation)
  • Verified status
  • Response capability
  • Prevents self-reviews
  • Unique constraint (one review per reviewer-reviewed pair)

Domain Events

  • UserProfileUpdatedEvent
  • UserAvatarChangedEvent
  • UserReviewReceivedEvent
  • UserReviewUpdatedEvent

Database Schema

UserProfiles (1:1 with Users)
├── UserId (FK, unique)
├── Bio
├── JoinedAt
├── RentalsOffered
├── AvatarType ('predefined' | 'uploaded')
├── AvatarValue
├── AverageRating (computed)
├── ReviewCount (computed)
├── IsPublicProfile
├── DisplayName
├── Location
├── Website
├── Languages (JSON)

UserPreferences (1:1 with Users)
├── UserId (FK, unique)
├── PreferencesJson (JSON column)

UserReviews (Many:Many Users)
├── Id
├── ReviewerId (FK)
├── ReviewedUserId (FK)
├── Rating (1-5)
├── Comment
├── ReviewDate
├── IsVisible
├── IsVerified
├── Response
├── ResponseDate
└── Unique Index: (ReviewerId, ReviewedUserId)

API Endpoints (To Be Created)

Profile Management

  • GET /api/users/me/profile - Get current user's profile
  • PUT /api/users/me/profile - Update profile
  • GET /api/users/{userId}/profile - Get public profile
  • POST /api/users/me/profile/avatar/predefined - Set predefined avatar
  • POST /api/users/me/profile/avatar/upload - Upload custom avatar

Preferences

  • GET /api/users/me/preferences - Get preferences
  • PUT /api/users/me/preferences - Update preferences

Reviews (Feature Flagged)

  • GET /api/users/{userId}/reviews - Get user's reviews
  • POST /api/users/{userId}/reviews - Create review
  • PUT /api/reviews/{reviewId} - Update review
  • DELETE /api/reviews/{reviewId} - Delete review
  • POST /api/reviews/{reviewId}/response - Add response
  • GET /api/users/{userId}/reviews/stats - Get review statistics

Feature Flag Configuration

{
  "FeatureFlags": {
    "Reviews": {
      "Enabled": false,
      "Description": "Enable user review system"
    }
  }
}

Benefits

  1. Cross-Device Sync: Settings and preferences available on all devices
  2. Persistent Avatars: User avatars stored and displayed consistently
  3. Profile Information: Rich user profiles with bio, location, stats
  4. Review System: Trust & reputation building (when enabled)
  5. Statistics Tracking: Automatic rental count tracking
  6. Performance: Cached ratings to avoid expensive calculations
  7. Moderation: Review visibility controls
  8. Data Integrity: Constraints prevent duplicate reviews

Implementation Status

✅ Completed

  • Domain entities (UserProfile, UserPreference, UserReview)
  • Domain events
  • DbContext configuration with relationships & indexes
  • DTOs/Contracts for all operations

🚧 In Progress

  • Application layer (Commands/Queries)
  • API endpoints with FastEndpoints
  • Feature flag implementation
  • Avatar upload with Azure Blob Storage
  • EF Core migration
  • Frontend integration

📋 Next Steps

  1. Create CQRS handlers (Commands/Queries)
  2. Implement API endpoints
  3. Add Azure App Configuration for feature flags
  4. Implement avatar upload to Azure Blob Storage
  5. Generate and apply EF Core migration
  6. Update frontend to call backend APIs
  7. Add validation and authorization
  8. Implement rate limiting for reviews
  9. Add review moderation endpoints

Security Considerations

  • Reviews can only be created by authenticated users
  • Users cannot review themselves
  • One review per user pair (enforced by DB constraint)
  • Profile visibility controls (public/private)
  • Avatar uploads should be validated (size, type)
  • Rate limiting on review creation
  • Moderation capabilities for admin

Performance Optimizations

  • Cached average rating in UserProfile
  • Cached review count
  • Indexed queries for reviews
  • JSON storage for preferences (flexible schema)
  • Lazy loading prevention with proper includes