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
UserProfileUpdatedEventUserAvatarChangedEventUserReviewReceivedEventUserReviewUpdatedEvent
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 profilePUT /api/users/me/profile- Update profileGET /api/users/{userId}/profile- Get public profilePOST /api/users/me/profile/avatar/predefined- Set predefined avatarPOST /api/users/me/profile/avatar/upload- Upload custom avatar
Preferences
GET /api/users/me/preferences- Get preferencesPUT /api/users/me/preferences- Update preferences
Reviews (Feature Flagged)
GET /api/users/{userId}/reviews- Get user's reviewsPOST /api/users/{userId}/reviews- Create reviewPUT /api/reviews/{reviewId}- Update reviewDELETE /api/reviews/{reviewId}- Delete reviewPOST /api/reviews/{reviewId}/response- Add responseGET /api/users/{userId}/reviews/stats- Get review statistics
Feature Flag Configuration
{
"FeatureFlags": {
"Reviews": {
"Enabled": false,
"Description": "Enable user review system"
}
}
}
Benefits
- Cross-Device Sync: Settings and preferences available on all devices
- Persistent Avatars: User avatars stored and displayed consistently
- Profile Information: Rich user profiles with bio, location, stats
- Review System: Trust & reputation building (when enabled)
- Statistics Tracking: Automatic rental count tracking
- Performance: Cached ratings to avoid expensive calculations
- Moderation: Review visibility controls
- 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
- Create CQRS handlers (Commands/Queries)
- Implement API endpoints
- Add Azure App Configuration for feature flags
- Implement avatar upload to Azure Blob Storage
- Generate and apply EF Core migration
- Update frontend to call backend APIs
- Add validation and authorization
- Implement rate limiting for reviews
- 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