Serenity Soother - Backend Architecture
``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ PREPROCESSING PHASE │ │ (One-time, before app deployment) │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌──────────────┐ ┌─────────────────┐ ┌──────────────────────┐ │ │ │ 3,344 Images │───────▶│ Python Script │───────▶│ Processed JSON │ │ │ │ (1792x1024) │ │ (Local/Cloud) │ │ + Clusters │ │ │ └──────────────┘ └────────┬────────┘ └──────────────────────┘ │ │ │ │ │ ▼ │ │ ┌──────────
Full Public Reader
Serenity Soother - Backend Architecture
Computation Flow Overview
┌─────────────────────────────────────────────────────────────────────────────────┐
│ PREPROCESSING PHASE │
│ (One-time, before app deployment) │
├─────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌─────────────────┐ ┌──────────────────────┐ │
│ │ 3,344 Images │───────▶│ Python Script │───────▶│ Processed JSON │ │
│ │ (1792x1024) │ │ (Local/Cloud) │ │ + Clusters │ │
│ └──────────────┘ └────────┬────────┘ └──────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ Google Gemini │ │
│ │ (Object Detect)│ │
│ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘
│
│ Bundle with app
▼
┌─────────────────────────────────────────────────────────────────────────────────┐
│ iOS APP RUNTIME │
├─────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌────────────────────────────────────────────────────────────────────────┐ │
│ │ ON-DEVICE PROCESSING │ │
│ │ ┌─────────────────┐ ┌──────────────────┐ ┌────────────────────┐ │ │
│ │ │ SwiftData DB │ │ NLEmbedding │ │ WorldGeneration │ │ │
│ │ │ (Local Store) │ │ (Semantic Search)│ │ Service │ │ │
│ │ └─────────────────┘ └──────────────────┘ └────────────────────┘ │ │
│ │ │ │ │ │ │
│ │ └─────────────────────┼──────────────────────┘ │ │
│ │ │ │ │
│ └────────────────────────────────┼────────────────────────────────────────┘ │
│ │ │
│ ┌────────────────────────────────┼────────────────────────────────────────┐ │
│ │ CLOUD API CALLS (On Demand) │ │
│ │ │ │ │
│ │ ┌───────────────────────────┼───────────────────────────────┐ │ │
│ │ │ ▼ │ │ │
│ │ │ ┌─────────────────┐ ┌─────────────────┐ ┌───────────┐ │ │ │
│ │ │ │ Vertex AI │ │ Cloud Vision │ │ Imagen │ │ │ │
│ │ │ │ (Gemini 1.5) │ │ (Labels/Safe) │ │ (Image │ │ │ │
│ │ │ │ │ │ │ │ Gen) │ │ │ │
│ │ │ │ • Script Gen │ │ • New images │ │ │ │ │ │
│ │ │ │ • Obj Detect │ │ • Validation │ │ Future │ │ │ │
│ │ │ │ • Chat/Prompt │ │ │ │ │ │ │ │
│ │ │ └─────────────────┘ └─────────────────┘ └───────────┘ │ │ │
│ │ │ │ │ │
│ │ │ GOOGLE CLOUD │ │ │
│ │ └──────────────────────────────────────────────────────────┘ │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘---
Phase 1: Preprocessing Pipeline
┌─────────────────────────────────────────────────────────────────────────────────┐
│ │
│ 1792x1024/ analyze_images_enhanced.py │
│ ├── image001.jpg ┌─────────────────────────┐ │
│ ├── image002.jpg ──────────▶│ For each image: │ │
│ ├── image003.jpg │ │ │
│ ├── ... │ 1. Load image │ │
│ └── image3344.jpg │ 2. Send to Gemini │──┐ │
│ │ 3. Parse response │ │ │
│ │ 4. Save JSON │ │ │
│ └─────────────────────────┘ │ │
│ │ │
│ ┌───────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────────────┐ │
│ │ GEMINI API REQUEST │ │
│ │ │ │
│ │ { │ │
│ │ "contents": [{ │ │
│ │ "parts": [ │ │
│ │ { "inline_data": { "mime_type": "image/jpeg", "data": "..." } }, │ │
│ │ { "text": "Analyze this image, detect objects..." } │ │
│ │ ] │ │
│ │ }], │ │
│ │ "generationConfig": { "temperature": 0.2 } │ │
│ │ } │ │
│ └──────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────────────┐ │
│ │ GEMINI API RESPONSE │ │
│ │ │ │
│ │ { │ │
│ │ "detected_objects": [ │ │
│ │ { │ │
│ │ "name": "ancient oak tree", │ │
│ │ "category": "tree", │ │
│ │ "bounding_box": { "x": 100, "y": 50, "width": 400, "height": 600}│ │
│ │ "confidence": 0.95, │ │
│ │ "therapeutic_associations": ["grounding", "calming"], │ │
│ │ "emotional_valence": 0.7, │ │
│ │ "calming_score": 0.8 │ │
│ │ }, │ │
│ │ { "name": "misty lake", "category": "water", ... }, │ │
│ │ { "name": "morning sun", "category": "sun", ... } │ │
│ │ ], │ │
│ │ "overall_mood": "peaceful", │ │
│ │ "therapeutic_value": { "anxiety_relief": 0.8, "grounding": 0.9 }, │ │
│ │ "suggested_realm_types": ["forest", "meadow"] │ │
│ │ } │ │
│ └──────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────────────┐ │
│ │ OUTPUT FILES │ │
│ │ │ │
│ │ Resources/ImageAnalyses/ │ │
│ │ ├── analyses/ │ │
│ │ │ ├── a1b2c3d4e5f6.json ◄── Per-image analysis │ │
│ │ │ ├── f7g8h9i0j1k2.json │ │
│ │ │ └── ... │ │
│ │ ├── clusters.json ◄── Object clusters by category │ │
│ │ └── realm_index.json ◄── Images mapped to realm types │ │
│ │ │ │
│ └──────────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘---
Phase 2: iOS App Runtime Architecture
┌─────────────────────────────────────────────────────────────────────────────────┐
│ USER INTERACTION │
│ │
│ ┌───────────────────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ "I want to create a universe focused on anxiety relief and sleep" │ │
│ │ │ │
│ │ Theme: [Serenity ▼] Goals: [✓ Anxiety] [✓ Sleep] [ Focus] │ │
│ │ │ │
│ │ Duration: [────●─────] 20 min Collaborative: [ ON ] │ │
│ │ │ │
│ │ [ Generate Universe ] │ │
│ │ │ │
│ └───────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
└─────────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────────┐
│ WORLD GENERATION SERVICE │
│ (On-Device Swift) │
│ │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │ Step 1: Create Universe Container │ │
│ │ │ │
│ │ let universe = TherapeuticUniverse( │ │
│ │ name: "Serene Sanctuary", │ │
│ │ theme: .serenity, │ │
│ │ creatorId: userId │ │
│ │ ) │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │ Step 2: Load Pre-analyzed Images (Bundled JSON) │ │
│ │ │ │
│ │ // Read from bundled resources │ │
│ │ let clusters = loadClusters("clusters.json") │ │
│ │ let realmIndex = loadRealmIndex("realm_index.json") │ │
│ │ │ │
│ │ // Filter for therapeutic goals │ │
│ │ let matchingImages = filterByTherapeuticValue( │ │
│ │ goals: [.anxiety, .sleep], │ │
│ │ clusters: clusters │ │
│ │ ) │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │ Step 3: Generate Realms from Clusters │ │
│ │ │ │
│ │ Cluster Analysis: │ │
│ │ ┌────────────────────────────────────────────────────────────────┐ │ │
│ │ │ Category │ Count │ Images │ Therapeutic Focus │ │ │
│ │ │────────────┼───────┼────────┼─────────────────────────────────│ │ │
│ │ │ water │ 487 │ 312 │ anxiety, sleep, stress │ │ │
│ │ │ tree │ 623 │ 445 │ grounding, healing │ │ │
│ │ │ moon │ 156 │ 142 │ sleep, anxiety │ ◄─────── Best match │
│ │ │ mountain │ 234 │ 198 │ confidence, grounding │ │ │
│ │ └────────────────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ Generated Realms: [Infinite Ocean, Aurora Realm, Enchanted Forest] │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │ Step 4: Populate Zones with Scenes │ │
│ │ │ │
│ │ For each Realm: │ │
│ │ ├── Create 3-5 Zones │ │
│ │ │ ├── Zone: "Coral Cove" (position: .center) │ │
│ │ │ │ ├── Select 2-4 matching images from cluster │ │
│ │ │ │ ├── Create WorldScene for each │ │
│ │ │ │ ├── Attach DetectedWorldObjects from JSON │ │
│ │ │ │ └── Add overlay effects (particles, fog) │ │
│ │ │ │ │ │
│ │ │ └── Zone: "Tide Pools" (position: .east) │ │
│ │ │ └── ... │ │
│ │ └── Connect zones (navigation graph) │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │ Step 5: Save to SwiftData │ │
│ │ │ │
│ │ modelContext.insert(universe) │ │
│ │ for realm in realms { modelContext.insert(realm) } │ │
│ │ try modelContext.save() │ │
│ │ │ │
│ │ Result: WorldGenerationResult( │ │
│ │ success: true, │ │
│ │ universeId: UUID(...), │ │
│ │ realmsCreated: 3, │ │
│ │ zonesCreated: 12, │ │
│ │ scenesIncorporated: 36, │ │
│ │ objectsDetected: 248 │ │
│ │ ) │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘---
Phase 3: Real-time API Calls (Dynamic Content)
┌─────────────────────────────────────────────────────────────────────────────────┐
│ DYNAMIC SCRIPT GENERATION │
│ │
│ User is in "Coral Cove" zone with detected objects: │
│ [coral reef] [gentle waves] [tropical fish] [sunlight rays] │
│ │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │ VertexAIService.generateScript() │ │
│ │ │ │
│ │ Request to Gemini: │ │
│ │ ┌─────────────────────────────────────────────────────────────────┐ │ │
│ │ │ "Generate a hypnotherapy script for anxiety relief. │ │ │
│ │ │ The user is viewing a scene with: coral reef, gentle waves, │ │ │
│ │ │ tropical fish, sunlight rays filtering through water. │ │ │
│ │ │ Duration: 15 minutes. Include breathing exercises." │ │ │
│ │ └─────────────────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ Response (streaming): │ │
│ │ ┌─────────────────────────────────────────────────────────────────┐ │ │
│ │ │ "Close your eyes and imagine yourself floating gently above │ │ │
│ │ │ a vibrant coral reef. Notice the soft turquoise light │ │ │
│ │ │ filtering down from the surface, dancing across the coral... │ │ │
│ │ │ │ │ │
│ │ │ Take a deep breath in... hold... and slowly release... │ │ │
│ │ │ │ │ │
│ │ │ Watch as a school of colorful fish glides peacefully by..." │ │ │
│ │ └─────────────────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────────┐
│ NEW IMAGE ANALYSIS (User Uploads) │
│ │
│ User adds their own image to a collaborative universe │
│ │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │ Real-time Gemini Analysis │ │
│ │ │ │
│ │ 1. Upload image to Cloud Storage (optional) │ │
│ │ 2. Call Gemini with object detection prompt │ │
│ │ 3. Parse response into DetectedWorldObject[] │ │
│ │ 4. Calculate therapeutic scores │ │
│ │ 5. Suggest best realm/zone placement │ │
│ │ 6. Save to user's universe │ │
│ │ │ │
│ │ ┌──────────────────────────────────────────────────────────────────┐ │ │
│ │ │ "Your image contains: misty mountains, pine forest, river │ │ │
│ │ │ Best fit: Mountain realm or Forest realm │ │ │
│ │ │ Therapeutic value: High grounding (0.9), moderate calm (0.6)" │ │ │
│ │ └──────────────────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘---
Data Flow Summary
┌─────────────────────────────────────────────────────────────────────────────────┐
│ │
│ ┌─────────────────────┐ │
│ │ RAW IMAGES │ │
│ │ (3,344 files) │ │
│ └──────────┬──────────┘ │
│ │ │
│ ┌───────────────┼───────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Object │ │ Therapeutic│ │ Color │ │
│ │ Detection │ │ Scoring │ │ Extraction │ │
│ │ (Gemini) │ │ (Gemini) │ │ (Vision) │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │ │
│ └───────────────┼───────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ STRUCTURED JSON │ │
│ │ (Bundled in App) │ │
│ └──────────┬──────────┘ │
│ │ │
│ ┌────────────────────────┼────────────────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌───────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ World Gen │ │ Scene Matching │ │ Script Gen │ │
│ │ (On-device) │ │ (NLEmbedding) │ │ (Gemini API) │ │
│ └───────┬───────┘ └────────┬────────┘ └────────┬────────┘ │
│ │ │ │ │
│ └───────────────────────┼────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ SwiftData │ │
│ │ (Local Storage) │ │
│ └──────────┬──────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ USER EXPERIENCE │ │
│ │ (Immersive Worlds) │ │
│ └─────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘---
Computation Location Summary
| Computation | Location | When | Cost |
|---|---|---|---|
| Image Object Detection | Google Cloud (Gemini) | Preprocessing | ~$0.001/image |
| Therapeutic Scoring | Google Cloud (Gemini) | Preprocessing | Included above |
| Cluster Building | Local (Python) | Preprocessing | Free |
| World Generation | On-device (Swift) | Runtime | Free |
| Semantic Search | On-device (NLEmbedding) | Runtime | Free |
| Script Generation | Google Cloud (Gemini) | Runtime | ~$0.01/script |
| New Image Analysis | Google Cloud (Gemini) | Runtime | ~$0.001/image |
| Data Persistence | On-device (SwiftData) | Runtime | Free |
---
Cost Estimation
One-time Preprocessing (3,344 images)
Gemini 1.5 Pro pricing: ~$0.00125/1K input tokens + $0.005/1K output tokens
Average per image: ~2K input + 1K output = ~$0.008
Total: 3,344 × $0.008 ≈ $27Per-User Runtime (Monthly)
Script generation: 30 scripts × $0.01 = $0.30
New image analysis: 5 images × $0.001 = $0.005
Total per user: ~$0.31/month---
Offline Capability
The app is designed to work mostly offline:
| Feature | Offline Support |
|---|---|
| World browsing | ✅ Full |
| Scene viewing | ✅ Full (bundled images) |
| World generation | ✅ Full (uses bundled JSON) |
| Semantic search | ✅ Full (NLEmbedding on-device) |
| Script generation | ❌ Requires internet |
| New image analysis | ❌ Requires internet |
| Collaborative sync | ❌ Requires internet |
---
Future: Server-Side Option
For scale, a backend server could handle:
┌────────────────────────────────────────────────────────────────┐
│ BACKEND SERVER (Optional) │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ FastAPI │ │ Redis │ │ PostgreSQL │ │
│ │ (Python) │◄──▶│ (Cache) │◄──▶│ (Users/DB) │ │
│ └──────┬──────┘ └─────────────┘ └─────────────┘ │
│ │ │
│ │ Handles: │
│ │ • User authentication │
│ │ • Collaborative world sync │
│ │ • Cached script generation │
│ │ • Usage analytics │
│ │ • Content moderation │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Google Cloud APIs │ │
│ │ (Gemini, Vision, Cloud Storage) │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────────┘This would reduce client-side API costs and enable real-time collaboration features.
---
Kindred Spirits: Affinity-Based Async Multiplayer
The Core Concept
"Similar souls build each other's worlds without knowing it"
┌─────────────────────────────────────────────────────────────────────────────────┐
│ │
│ USER A USER B │
│ ┌─────────┐ ┌─────────┐ │
│ │ Creates │ │ Returns │ │
│ │ a Zone │ │ to App │ │
│ └────┬────┘ └────┬────┘ │
│ │ │ │
│ ▼ │ │
│ ┌─────────────────┐ │ │
│ │ Affinity Check │◄──────────────────────────────┘ │
│ │ A ←→ B = 87% │ │
│ │ (Kindred Spirit)│ │
│ └────────┬────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Auto-share zone │────────▶│ Zone appears in │ │
│ │ to similar users│ │ B's universe! │ │
│ └─────────────────┘ └─────────────────┘ │
│ │
│ "A kindred spirit has left a path for you to discover..." │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘Affinity Score Calculation
Soul Affinity = (
Therapeutic Goals × 0.40 ← What you're healing
+ Realm Preferences × 0.25 ← Where you find peace
+ Object Interactions × 0.20 ← What resonates with you
+ Session Patterns × 0.10 ← How you practice
+ Emotional Valence × 0.05 ← Your emotional baseline
)
Examples:
• Both focus on anxiety + sleep, love ocean realms,
interact with water/moon objects = 92% (Kindred Spirit)
• Similar goals but different realms = 71% (Parallel Path)Connection Types
┌────────────────────────────────────────────────────────────────────┐
│ Connection Type │ Affinity │ Behavior │
├───────────────────────┼──────────┼────────────────────────────────┤
│ Soul Mirror │ 95-100% │ Extremely rare. Auto-share, │
│ │ │ instant integration │
├───────────────────────┼──────────┼────────────────────────────────┤
│ Kindred Spirit │ 85-95% │ Auto-share, appears as │
│ │ │ "discovered" content │
├───────────────────────┼──────────┼────────────────────────────────┤
│ Resonant Traveler │ 75-85% │ Pending approval, suggested │
├───────────────────────┼──────────┼────────────────────────────────┤
│ Parallel Path │ 70-75% │ Visible but not shared │
├───────────────────────┼──────────┼────────────────────────────────┤
│ Distant Echo │ <70% │ No connection │
└────────────────────────────────────────────────────────────────────┘The User Experience
┌─────────────────────────────────────────────────────────────────────────────────┐
│ │
│ DAY 1: User creates their universe │
│ ├── Focused on anxiety + sleep │
│ ├── Prefers ocean and aurora realms │
│ └── System calculates affinity profile │
│ │
│ DAY 2-7: User is away │
│ ├── Kindred spirits (87% match) create new zones │
│ ├── System auto-accepts high-affinity contributions │
│ ├── Background stories generated connecting new content │
│ └── "Peaceful Wanderer #4721 added 'Moonlit Cove'" │
│ │
│ DAY 8: User returns │
│ ├── "Welcome back! While you were away..." │
│ ├── 3 new zones discovered │
│ ├── 2 new stories to uncover │
│ └── Feels like the world grew organically │
│ │
│ ONGOING: Reciprocal building │
│ ├── User's creations flow to kindred spirits │
│ ├── Network of connected therapeutic universes │
│ └── Everyone benefits from collective healing journeys │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘Contribution Types
┌─────────────────────────────────────────────────────────────────────────────────┐
│ │
│ ZONE CONTRIBUTION │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ { │ │
│ │ "name": "Twilight Cove", │ │
│ │ "suggestedRealm": "ocean", │ │
│ │ "therapeuticValue": { "anxiety": 0.9, "sleep": 0.85 }, │ │
│ │ "scenes": 4, │ │
│ │ "overlayEffects": ["particles", "fog"] │ │
│ │ } │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ STORY CONTRIBUTION │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ { │ │
│ │ "title": "The Path Opens", │ │
│ │ "content": "A fellow traveler walked here before you...", │ │
│ │ "triggerZone": "twilight-cove-uuid", │ │
│ │ "narrativeType": "discovery" │ │
│ │ } │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘Privacy & Anonymity
┌─────────────────────────────────────────────────────────────────────────────────┐
│ │
│ USER IDENTITY │
│ ├── Real name: Never shared │
│ ├── Anonymous name: "Peaceful Wanderer #4721" │
│ │ └── Generated from: hash(userId) % adjectives × nouns │
│ ├── What's shared: Therapeutic patterns only (anonymized) │
│ └── What's NOT shared: Personal details, session content, journal entries │
│ │
│ CONTRIBUTION ATTRIBUTION │
│ ├── "A kindred spirit left this path..." │
│ ├── "Discovered through a fellow traveler's journey" │
│ └── Poetic, non-identifying language │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘Backend Requirements for Multiplayer
┌─────────────────────────────────────────────────────────────────────────────────┐
│ │
│ REQUIRED BACKEND (for full multiplayer) │
│ ├── User affinity profiles database │
│ ├── Contribution queue service │
│ ├── Affinity matching engine (can run periodically) │
│ └── Push notifications for new discoveries │
│ │
│ MINIMAL VIABLE APPROACH │
│ ├── CloudKit for user profile sync │
│ ├── Background App Refresh for checking gifts │
│ └── Local notification when gifts are waiting │
│ │
│ COST ESTIMATE │
│ ├── CloudKit: Free tier covers most needs │
│ ├── Affinity calculation: On-device (free) │
│ └── Story generation: ~$0.01 per returning user │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘Promotion Decision
Promote into a technical note or architecture paper with implementation anchors.
Source Anchor
Serenity Soother/SerenitySoother/Documentation/ARCHITECTURE.md
Detected Structure
Method · References · Code Anchors · Architecture