Skip to content

Commit 1fe1573

Browse files
committed
feat: create demo app
1 parent 5f844c2 commit 1fe1573

33 files changed

+2563
-61
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
dist
55
tmp
66
out-tsc
7+
.svelte-kit
78

89
# dependencies
910
node_modules

PHASE_0_FOUNDATION.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Phase 0: Foundation
2+
3+
**Branch:** `feat-demo-0-foundation`
4+
5+
**Goal:** Create fresh SvelteKit app, integrate with Nx and pnpm workspace, verify it builds successfully.
6+
7+
**Success Criteria:**
8+
-`apps/demo/` exists with SvelteKit app
9+
-`pnpm nx build demo` completes successfully
10+
-`pnpm nx dev demo` starts dev server
11+
- ✅ Dependencies installed via pnpm workspace
12+
- ✅ Cloudflare adapter configured
13+
- ✅ No build errors or warnings
14+
15+
---
16+
17+
## Tasks
18+
19+
### 1. Create Fresh SvelteKit App
20+
21+
```bash
22+
pnpm create svelte@latest apps/demo --template skeleton --types typescript
23+
```
24+
Select: TypeScript ✓, ESLint ✓, Prettier ✓, Skip testing tools
25+
26+
### 2. Configure Nx Integration
27+
28+
Create `apps/demo/project.json` with standard Nx configuration:
29+
- Define targets: `dev`, `build`, `preview`
30+
- Set executor to `nx:run-commands` for each
31+
- Point commands to Vite (e.g., `vite dev`, `vite build`)
32+
- Add build output path: `{projectRoot}/build`
33+
34+
### 3. Add Core Dependencies
35+
36+
```bash
37+
cd apps/demo
38+
39+
# Add Cloudflare adapter for deployment
40+
pnpm add -D @sveltejs/adapter-cloudflare
41+
42+
# Add Tailwind CSS for styling (automated setup)
43+
npx svelte-add@latest tailwindcss
44+
45+
# Add Supabase for backend
46+
pnpm add @supabase/supabase-js
47+
48+
# Install all dependencies
49+
pnpm install
50+
```
51+
52+
### 4. Update Package Configuration
53+
54+
Edit `apps/demo/package.json` to set the package name:
55+
- Change `"name"` to `"@pgflow/demo"`
56+
- Add `"private": true`
57+
58+
**Note:** `@pgflow/client`, `@xyflow/svelte`, and `shiki` will be added in later phases as needed.
59+
60+
### 5. Configure Cloudflare Adapter
61+
62+
Update `apps/demo/svelte.config.js`:
63+
- Import `@sveltejs/adapter-cloudflare` instead of adapter-auto
64+
- Set in config: `kit: { adapter: adapter() }`
65+
66+
### 6. Test Build
67+
68+
```bash
69+
# From monorepo root
70+
pnpm nx build demo
71+
72+
# Verify build output exists
73+
ls apps/demo/build
74+
```
75+
76+
### 7. Test Dev Server
77+
78+
```bash
79+
# From monorepo root
80+
pnpm nx dev demo
81+
82+
# Open http://localhost:5173/
83+
# Verify page loads without console errors
84+
```
85+
86+
---
87+
88+
## Validation Checklist
89+
90+
- [ ] `apps/demo/` exists with `project.json`
91+
- [ ] `package.json` name is `@pgflow/demo`
92+
- [ ] Cloudflare adapter configured in `svelte.config.js`
93+
- [ ] Tailwind CSS working (check for `app.css` with `@tailwind` directives)
94+
- [ ] `pnpm nx build demo` succeeds, creates `apps/demo/build/`
95+
- [ ] `pnpm nx dev demo` starts, http://localhost:5173/ loads
96+
- [ ] No TypeScript or console errors
97+
98+
---
99+
100+
## Troubleshooting
101+
102+
- **`pnpm create svelte` fails:** Check Node.js version (≥18), network connection
103+
- **`svelte-add tailwindcss` fails:** Run manually: `pnpm add -D tailwindcss postcss autoprefixer`
104+
- **Nx doesn't recognize demo:** Verify `apps/demo/project.json` exists, run `pnpm nx show projects`
105+
- **Build fails:** Check Cloudflare adapter installed: `pnpm list @sveltejs/adapter-cloudflare`
106+
- **Dev server won't start:** Check port 5173 available (`lsof -i :5173`), try `--port 5174`
107+
108+
---
109+
110+
## Next Phase
111+
112+
Proceed to **Phase 1: Vertical Slice** for end-to-end flow execution with minimal UI. Create branch `feat-demo-1-vertical-slice`.

PHASE_1_VERTICAL_SLICE.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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

Comments
 (0)