8.0 KiB
POWR Pack Implementation Document
Overview
This document outlines the implementation plan for creating a "POWR Pack" feature in the POWR fitness app. POWR Packs are shareable collections of workout templates and exercises that users can import into their app. This feature leverages the Nostr protocol (NIP-51 lists) to enable decentralized sharing of fitness content.
Key Concepts
- POWR Pack: A collection of workout templates and exercises stored as a NIP-51 list (kind 30004 "Curation set")
- Pack Sharing: Packs are shared via
naddr1
links that encode references to the collection - Selective Import: Users can select which templates/exercises to import from a pack
- Dependency Management: When selecting a template, all required exercises are automatically selected
Implementation Steps
1. Database Schema Extensions
Add new tables to track imported packs and their contents:
-- POWR Packs table
CREATE TABLE powr_packs (
id TEXT PRIMARY KEY,
title TEXT NOT NULL,
description TEXT,
author_pubkey TEXT,
nostr_event_id TEXT,
import_date INTEGER NOT NULL
);
-- POWR Pack items table
CREATE TABLE powr_pack_items (
pack_id TEXT NOT NULL,
item_id TEXT NOT NULL,
item_type TEXT NOT NULL,
item_order INTEGER,
PRIMARY KEY (pack_id, item_id),
FOREIGN KEY (pack_id) REFERENCES powr_packs(id) ON DELETE CASCADE
);
2. New Service: POWRPackService
Create a new service in lib/db/services/POWRPackService.ts
with these key methods:
fetchPackFromNaddr(naddr: string)
: Fetch a pack and its content from NostrimportPack(pack, templates, exercises, selectedIds)
: Import selected items to local databasegetImportedPacks()
: List all imported packs with metadatadeletePack(packId, keepItems)
: Remove a pack while optionally keeping its content
3. UI Components
Settings Integration
Add POWR Packs to the settings drawer:
- "Import POWR Pack" item
- "Manage POWR Packs" item
Import Flow
Create screen at app/(packs)/import.tsx
:
- Input field for naddr
- Pack details display
- Selectable list of templates
- Selectable list of exercises with auto-selection based on template dependencies
- Import button
Management Interface
Create screen at app/(packs)/manage.tsx
:
- List of imported packs
- Pack details (templates/exercises count, import date)
- Delete functionality
Social Discovery
Add a section to the social tab:
- Horizontal scrolling list of available packs
- Tap to view/import a pack
4. Routing
Configure routing in app/(packs)/_layout.tsx
:
- Import screen as modal
- Management screen as standard page
Technical Implementation Details
Data Flow
- Pack Creation: Exercise → Template → Pack (we've validated this flow works via NAK tests)
- Pack Import:
- Decode naddr
- Fetch pack event and referenced content
- Parse Nostr events to POWR model objects
- Save selected items to database
Dependency Management
When users select a workout template, the system will:
- Identify all exercises referenced by the template
- Automatically select these exercises (shown as "required")
- Prevent deselection of required exercises
Integration with Existing Services
- NostrWorkoutService: Use existing conversion methods between Nostr events and app models
- LibraryService: Update to query content from imported packs
- NDK: Use for fetching Nostr events and managing relay connections
Sharing UI Mockups
Import Screen
┌─────────────────────────────┐
│ Import POWR Pack │
├─────────────────────────────┤
│ ┌───────────────────────┐ │
│ │ naddr1... │ │
│ └───────────────────────┘ │
│ │
│ ┌─────────────┐ │
│ │ Fetch Pack │ │
│ └─────────────┘ │
│ │
│ Pack Name │
│ Description text here... │
│ │
│ Templates │
│ ┌─────────────────────────┐ │
│ │ ☑ Beginner Full Body │ │
│ │ Strength workout │ │
│ └─────────────────────────┘ │
│ │
│ Exercises │
│ ┌─────────────────────────┐ │
│ │ ☑ Squat │ │
│ │ Required by template │ │
│ └─────────────────────────┘ │
│ │
│ ┌───────────────────────┐ │
│ │ Import 3 items │ │
│ └───────────────────────┘ │
└─────────────────────────────┘
Management Screen
┌─────────────────────────────┐
│ Manage POWR Packs │
├─────────────────────────────┤
│ ┌─────────────────────────┐ │
│ │ POWR Test Pack [🗑]│ │
│ │ A test collection... │ │
│ │ │ │
│ │ 2 templates • 2 exercises│
│ │ Imported 2 days ago │ │
│ └─────────────────────────┘ │
│ │
│ ┌─────────────────────────┐ │
│ │ Beginner Pack [🗑]│ │
│ │ For new users... │ │
│ │ │ │
│ │ 3 templates • 5 exercises│
│ │ Imported 1 week ago │ │
│ └─────────────────────────┘ │
│ │
└─────────────────────────────┘
Social Discovery
┌─────────────────────────────┐
│ │
│ POWR Packs │
│ Discover workout collections│
│ │
│ ┌─────┐ ┌─────┐ ┌─────┐ │
│ │Pack1│ │Pack2│ │Pack3│ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ └─────┘ └─────┘ └─────┘ │
│ │
└─────────────────────────────┘
Testing and Validation
We've successfully tested the basic Nostr event publishing flow using NAK:
- Created exercise events (kind 33401)
- Created template events (kind 33402) that reference the exercises
- Created a pack event (kind 30004) that references both templates and exercises
- Verified that all events were published and can be fetched by ID
Implementation Timeline
- Database Schema Updates: Implement new tables
- POWRPackService: Create service for fetching and importing packs
- Settings Integration: Add menu items to settings drawer
- Import UI: Implement import screen with selection logic
- Management UI: Create pack management interface
- Social Discovery: Add pack discovery section to social tab
- Testing: Validate full import/management flow
Next Steps
- Implement the database schema changes
- Build POWRPackService
- Create the UI components
- Test the full feature flow
- Consider future enhancements (creating/publishing packs from within the app)