From 2b3ac756b84b3a4a8b9dc26d8fb84fa2eeb532eb Mon Sep 17 00:00:00 2001 From: herbygitea Date: Mon, 20 Apr 2026 16:36:44 +0000 Subject: [PATCH] Update pbs-membership-loe1-recipe-saving.md via n8n --- .../pbs-membership-loe1-recipe-saving.md | 57 +++++-------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/PBS/Tech/Projects/pbs-membership-loe1-recipe-saving.md b/PBS/Tech/Projects/pbs-membership-loe1-recipe-saving.md index a24fb89..1c2a5ad 100644 --- a/PBS/Tech/Projects/pbs-membership-loe1-recipe-saving.md +++ b/PBS/Tech/Projects/pbs-membership-loe1-recipe-saving.md @@ -1,3 +1,4 @@ + --- project: pbs-membership-loe1-recipe-saving type: project-plan @@ -13,8 +14,6 @@ created: 2026-04-06 updated: 2026-04-06 path: PBS/Tech/Projects/ --- - - # PBS Membership Platform — LOE 1: Recipe Saving ## Vision @@ -27,9 +26,7 @@ app, and a custom LLM trained on plant-based cooking knowledge. Recipe Saving is LOE 1 — the foundational project that establishes the membership infrastructure all other LOEs build on. - --- - ## LOE 1 Phases Overview - **Phase 0** — Ultimate Member setup (registration, login, user roles, @@ -40,9 +37,7 @@ endpoints) ← THIS DOC - **Phase 3** — Saved recipes page in pbs-hub (frontend UI) - **Phase 4** — Collections (named groups, organize saved recipes) - **Phase 5** — Polish (mobile optimization, loading states, error handling) - --- - ## All 4 Lines of Effort | LOE | Project | Status | @@ -51,9 +46,7 @@ endpoints) ← THIS DOC | 2 | Weekly Meal Plan Viewer | Queued | | 3 | Whole Food Diversity Tracker | Queued | | 4 | User Profiles & Preferences | Queued | - --- - ## Phase 1: Backend Foundation ### Goal @@ -63,12 +56,10 @@ frontend — just a working API testable via curl and verifiable in phpMyAdmin. ### Estimated Time: 4-6 hours - --- - ### Architecture -``` + Sunnie browser → WordPress cookie (set by Ultimate Member login) → Request to pbs-hub API @@ -76,13 +67,11 @@ Sunnie browser → API endpoint processes request → Writes to pbs_hub database → Returns JSON response -``` + **Key principle:** WordPress owns identity. pbs-hub owns membership features. The only bridge is the session cookie and read-only MySQL access. - --- - ### Database Design #### New database: pbs_hub @@ -90,7 +79,7 @@ features. The only bridge is the session cookie and read-only MySQL access. **user_interactions** — generic table for all post-related user actions (save, like, cooked, planned, rated). Serves LOE 1 now and LOEs 2-4 later. -```sql +sql CREATE DATABASE pbs_hub; CREATE TABLE pbs_hub.user_interactions ( @@ -102,12 +91,12 @@ CREATE TABLE pbs_hub.user_interactions ( created_at DATETIME DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY unique_action (wp_user_id, wp_post_id, action) ); -``` + **user_preferences** — key-value store for platform-specific user settings (LOE 4, but created now for completeness). -```sql +sql CREATE TABLE pbs_hub.user_preferences ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, wp_user_id INT UNSIGNED NOT NULL, @@ -117,11 +106,11 @@ CREATE TABLE pbs_hub.user_preferences ( CURRENT_TIMESTAMP, UNIQUE KEY unique_pref (wp_user_id, pref_key) ); -``` + #### MySQL user (scoped permissions) -```sql +sql CREATE USER 'pbshub_app'@'%' IDENTIFIED BY 'strong_password_here'; -- Read-only on WordPress (auth + recipe display) @@ -133,13 +122,11 @@ GRANT SELECT ON wordpress.wp_posts TO 'pbshub_app'@'%'; GRANT ALL ON pbs_hub.* TO 'pbshub_app'@'%'; FLUSH PRIVILEGES; -``` + **Note:** Also audit existing MySQL users (pbs-api, n8n) and scope their permissions. Stop using root for application access. - --- - ### API Endpoints | Method | Path | Description | Auth | Tier | @@ -153,16 +140,16 @@ type | Required | Free | interaction exists | Required | Free | **Request body (POST):** -```json +json { "post_id": 123, "action": "save", "metadata": null } -``` + **Response (GET list):** -```json +json { "interactions": [ { @@ -174,15 +161,13 @@ interaction exists | Required | Free | } ] } -``` + **Note:** The GET list endpoint joins pbs_hub.user_interactions with wordpress.wp_posts to return recipe title and slug. Query filters on `post_status = 'publish'` and `post_type IN ('post', 'wprm_recipe')` to exclude revisions, drafts, and other post types. - --- - ### Auth Middleware Flask `before_request` middleware that: @@ -201,26 +186,22 @@ Flask `before_request` middleware that: - Read-only MySQL user for WordPress tables - CSRF protection via Flask-WTF (for future form submissions) - Cookie is httponly and secure (WordPress default) - --- - ### Tier Authorization (Future-Proofed) Not needed for Phase 1 (everything is free), but the pattern is established: -```python +python TIER_PERMISSIONS = { "free": ["save", "like"], "basic": ["save", "like", "planned", "cooked"], "premium": ["save", "like", "planned", "cooked", "collections", "ai_suggest"], } -``` + Adding paid tiers later is a code change, not a schema change. - --- - ### Phase 1 Checklist - [ ] Create pbs_hub database on staging MySQL @@ -237,9 +218,7 @@ Adding paid tiers later is a code change, not a schema change. - [ ] Test all endpoints via curl - [ ] Verify data in phpMyAdmin - [ ] Error handling and logging - --- - ### Key Decisions Made | Decision | Choice | Rationale | @@ -264,9 +243,7 @@ dictionary gates actions in the API layer. Database doesn't know tiers exist. | | MySQL user | Scoped pbshub_app | Read-only on WordPress tables, full access on pbs_hub. No more root for applications. | - --- - ### Open Questions - **WordPress cookie hash suffix:** Need to check wp-config.php for the @@ -276,12 +253,8 @@ site URL) post type or as regular 'post' with recipe metadata - **pbs-hub deployment:** Does this extend the existing pbs-hub container or is Phase 1 a standalone Flask app for testing? - --- - *Next Step: Create pbs_hub database and tables on staging, then build the auth middleware* - --- ...sent from Jenny & Travis \ No newline at end of file