|
| 1 | +# Phase 1: Vertical Slice |
| 2 | + |
| 3 | +**Branch:** `feat-demo-1-vertical-slice` |
| 4 | + |
| 5 | +**Goal:** Implement minimal end-to-end flow execution - from UI button click through Edge Function to real-time status updates. Validates entire integration stack with **client-side auth only**. |
| 6 | + |
| 7 | +**Success Criteria:** |
| 8 | +- ✅ Supabase initialized in demo app |
| 9 | +- ✅ Client-side anonymous auth working |
| 10 | +- ✅ Edge Function with 1-step test flow executes |
| 11 | +- ✅ pgflow packages vendored correctly |
| 12 | +- ✅ pgflow client connects from UI |
| 13 | +- ✅ Button click starts flow |
| 14 | +- ✅ Status updates in real-time |
| 15 | +- ✅ No console errors |
| 16 | + |
| 17 | +**Philosophy:** Build the thinnest possible slice through the entire stack. UI will be ugly - that's fine. Goal is to prove integration works. **No server-side auth needed - demo is public!** |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Tasks |
| 22 | + |
| 23 | +### 1. Add pgflow Client Dependency |
| 24 | + |
| 25 | +Edit `apps/demo/package.json` - add `"@pgflow/client": "workspace:*"` to dependencies: |
| 26 | + |
| 27 | +```bash |
| 28 | +pnpm install |
| 29 | +``` |
| 30 | + |
| 31 | +### 2. Initialize Supabase |
| 32 | + |
| 33 | +```bash |
| 34 | +cd apps/demo && supabase init && cd ../.. |
| 35 | +``` |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +### 3. Configure Supabase for pgflow |
| 40 | + |
| 41 | +Edit `apps/demo/supabase/config.toml` - add `"pgflow"` to `[api]` schemas: |
| 42 | + |
| 43 | +```toml |
| 44 | +schemas = ["public", "pgflow"] |
| 45 | +``` |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +### 4. Copy Vendoring Script |
| 50 | + |
| 51 | +```bash |
| 52 | +mkdir -p apps/demo/scripts |
| 53 | +cp examples/playground/scripts/sync-edge-deps.sh apps/demo/scripts/ |
| 54 | +chmod +x apps/demo/scripts/sync-edge-deps.sh |
| 55 | +``` |
| 56 | + |
| 57 | +### 5. Update Vendoring Script Paths |
| 58 | + |
| 59 | +Edit `apps/demo/scripts/sync-edge-deps.sh` - replace `PLAYGROUND_DIR` with `DEMO_DIR`: |
| 60 | + |
| 61 | +```bash |
| 62 | +DEMO_DIR="$(dirname "$SCRIPT_DIR")" |
| 63 | +VENDOR_DIR="$DEMO_DIR/supabase/functions/_vendor" |
| 64 | +``` |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +### 6. Add Nx Target for Vendoring |
| 69 | + |
| 70 | +Edit `apps/demo/project.json` - add `sync-edge-deps` target: |
| 71 | + |
| 72 | +```json |
| 73 | +"sync-edge-deps": { |
| 74 | + "executor": "nx:run-commands", |
| 75 | + "dependsOn": ["core:build", "dsl:build"], |
| 76 | + "options": { "command": "./scripts/sync-edge-deps.sh", "cwd": "apps/demo" } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +### 7. Build Dependencies and Vendor |
| 81 | + |
| 82 | +```bash |
| 83 | +pnpm nx build core dsl |
| 84 | +pnpm nx sync-edge-deps demo # Verify: ls apps/demo/supabase/functions/_vendor/@pgflow/ |
| 85 | +``` |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +### 8. Create Test Flow Definition |
| 90 | + |
| 91 | +Create `apps/demo/supabase/functions/_flows/test-flow.ts`: |
| 92 | +- Import Flow from `@pgflow/dsl` |
| 93 | +- Create simple 1-step flow with slug 'test-flow' |
| 94 | +- Handler returns: `Hello, ${input.run.message}!` |
| 95 | +- Note: Access run input via `input.run.*` pattern |
| 96 | + |
| 97 | +### 9. Create Edge Function Worker |
| 98 | + |
| 99 | +Create `apps/demo/supabase/functions/demo-worker/index.ts`: |
| 100 | +```typescript |
| 101 | +import { EdgeWorker } from '@pgflow/edge-worker'; |
| 102 | +import TestFlow from '../_flows/test-flow.ts'; |
| 103 | + |
| 104 | +EdgeWorker.start(TestFlow); |
| 105 | +``` |
| 106 | +**This 3-line pattern is critical - it's how all pgflow workers are set up!** |
| 107 | + |
| 108 | +### 10. Test Edge Function Locally |
| 109 | + |
| 110 | +```bash |
| 111 | +cd apps/demo |
| 112 | +supabase start # Then in another terminal: |
| 113 | +supabase functions serve demo-worker |
| 114 | +``` |
| 115 | + |
| 116 | +### 11. Create Client-Side Supabase Configuration |
| 117 | + |
| 118 | +Create `apps/demo/src/lib/supabase.ts`: |
| 119 | +- Create Supabase client with URL and anon key (use env vars or local defaults) |
| 120 | +- Create PgflowClient wrapping the Supabase client |
| 121 | +- Export both for use in components |
| 122 | +- **Key point:** Pure client-side - no server hooks, no cookies! |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +### 12. Create Minimal Test UI |
| 127 | + |
| 128 | +Replace `apps/demo/src/routes/+page.svelte` with basic test interface. |
| 129 | + |
| 130 | +**Key patterns to implement:** |
| 131 | +- Anonymous auth: `await supabase.auth.signInAnonymously()` in onMount |
| 132 | +- Start flow: `pgflow.startFlow('test-flow', { message: 'World' })` |
| 133 | +- Listen to events: `run.on('*', (event) => { ... })` |
| 134 | +- Svelte 5 state: `let status = $state<string>('idle')` |
| 135 | +- Display status updates and output |
| 136 | + |
| 137 | +**Remember:** Use `onclick={handler}` not `on:click` (Svelte 5 syntax) |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | +### 13. Start Dev Server |
| 142 | + |
| 143 | +```bash |
| 144 | +pnpm nx dev demo # Ensure supabase start running |
| 145 | +``` |
| 146 | + |
| 147 | +### 14. Test End-to-End |
| 148 | + |
| 149 | +Open http://localhost:5173/, click button, verify: |
| 150 | +- Status: `idle` → `starting...` → `running` → `completed` |
| 151 | +- Output shows `"Hello, World!"` |
| 152 | +- Console shows event stream |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +## Validation Checklist |
| 157 | + |
| 158 | +- [ ] Supabase initialized, pgflow packages vendored |
| 159 | +- [ ] Test flow + worker created |
| 160 | +- [ ] Anonymous auth working (check Network tab for auth.signInAnonymously) |
| 161 | +- [ ] `supabase start` and `functions serve demo-worker` running |
| 162 | +- [ ] Dev server starts, button click starts flow |
| 163 | +- [ ] Status updates real-time, output appears, no console errors |
| 164 | + |
| 165 | +--- |
| 166 | + |
| 167 | +## Troubleshooting |
| 168 | + |
| 169 | +- **Vendoring fails:** Check `ls pkgs/core/dist`, rebuild with `pnpm nx build core dsl` |
| 170 | +- **Edge Function won't start:** Check `supabase status`, verify vendored files exist |
| 171 | +- **Anonymous auth fails:** Check browser console, ensure Supabase anon key is valid |
| 172 | +- **Flow doesn't start:** Check browser console - Supabase connection, pgflow schema in config.toml, flow slug matches |
| 173 | +- **No real-time updates:** Check Realtime enabled, Edge Function logs, Svelte `$state` reactivity |
| 174 | +- **TypeScript errors:** Verify Svelte 5 syntax (`$state`, `onclick`) |
| 175 | +- **Auth issues:** Remember - this is all client-side! No server hooks needed |
| 176 | + |
| 177 | +**Rollback:** Mock pgflow client to debug Edge Function separately |
| 178 | + |
| 179 | +**Common issues:** |
| 180 | +- `workspace:*` not resolving → `pnpm install --force` |
| 181 | +- Port in use → `lsof -i :54321`, kill process |
| 182 | +- Import paths wrong → Re-run `pnpm nx sync-edge-deps demo` |
| 183 | + |
| 184 | +--- |
| 185 | + |
| 186 | +## Next Phase |
| 187 | + |
| 188 | +Proceed to **Phase 2: Article Flow** for 4-step flow and state management. Create branch `feat-demo-2-article-flow`. |
0 commit comments