Data Model

DynamoDB single-table design and entity relationships

Entity Relationship Diagram

Core entities and their relationships in MiFamilias.

erDiagram USER ||--o{ FAMILY_MEMBER : "belongs to" USER ||--o{ CONTENT : "creates" USER ||--o{ TIME_CAPSULE : "creates" USER ||--o{ NOTIFICATION : "receives" FAMILY ||--o{ FAMILY_MEMBER : "has" FAMILY ||--o{ CONTENT : "contains" FAMILY ||--o{ INVITE : "issues" CONTENT ||--o{ COMMENT : "has" CONTENT ||--o{ REACTION : "has" TIME_CAPSULE ||--|| CONTENT : "wraps" TIME_CAPSULE ||--o{ RECIPIENT : "targets" USER { string userId PK string email string givenName string familyName string profileImageUrl datetime createdAt boolean onboardingComplete } FAMILY { string familyId PK string name string adminUserId string inviteCode string trustLevel datetime createdAt } FAMILY_MEMBER { string familyId PK string userId SK string role datetime joinedAt string vouchScore } CONTENT { string contentId PK string userId string familyId string type string status string s3Key string thumbnailKey string transcription datetime createdAt } TIME_CAPSULE { string capsuleId PK string contentId string creatorId datetime unlockDate string status boolean notificationSent }

Single-Table Design

All entities stored in one DynamoDB table with composite keys.

flowchart TB subgraph Table["mifamilias-main"] subgraph Keys["Key Structure"] PK["PK (Partition Key)"] SK["SK (Sort Key)"] end subgraph Patterns["Access Patterns"] P1["USER#123 | PROFILE"] P2["USER#123 | FAMILY#abc"] P3["FAMILY#abc | META"] P4["FAMILY#abc | MEMBER#123"] P5["CONTENT#xyz | META"] P6["CAPSULE#456 | META"] end subgraph GSI1["GSI1 (Family Queries)"] G1PK["GSI1PK"] G1SK["GSI1SK"] G1Ex["FAMILY#abc | CONTENT#2024-01-15"] end subgraph GSI2["GSI2 (Unlock Queries)"] G2PK["GSI2PK"] G2SK["GSI2SK"] G2Ex["UNLOCK#2025-01-01 | CAPSULE#456"] end end

Content Lifecycle States

State machine for content from upload to delivery.

stateDiagram-v2 [*] --> Uploading: User starts upload Uploading --> Processing: Upload complete Processing --> Transcoding: Video received Transcoding --> Transcribing: Transcode done Transcribing --> Ready: Transcription done Ready --> Delivered: User views Processing --> Failed: Error Transcoding --> Failed: Error Transcribing --> Ready: Skip (no audio) Ready --> Archived: After 90 days Archived --> Ready: User requests Failed --> Processing: Retry

Time Capsule States

State machine for time-locked content.

stateDiagram-v2 [*] --> Draft: User creates Draft --> Scheduled: User confirms Scheduled --> Locked: Content uploaded Locked --> Unlocking: Unlock date reached Unlocking --> Available: Processing complete Available --> Viewed: Recipient opens Viewed --> Archived: After retention period Draft --> Cancelled: User cancels Scheduled --> Cancelled: User cancels Locked --> [*]: Cannot cancel after lock

Access Patterns

Pattern PK SK Index
Get user profile USER#<id> PROFILE Table
Get user's families USER#<id> FAMILY#* Table
Get family members FAMILY#<id> MEMBER#* Table
Get family feed FAMILY#<id> CONTENT#<date> GSI1
Get capsules to unlock UNLOCK#<date> CAPSULE#* GSI2

Entity Key Patterns

Entity PK SK GSI1PK GSI2PK
User USER#<userId> PROFILE - -
Family FAMILY#<familyId> META - -
Membership FAMILY#<familyId> MEMBER#<userId> USER#<userId> -
Content CONTENT#<contentId> META FAMILY#<familyId> -
Time Capsule CAPSULE#<capsuleId> META USER#<creatorId> UNLOCK#<date>