Files
tiny-forge/plans/docker-watcher-core/phase-11-embed-sse.md
T
alexei.dolgolyov 0bb52f9ec6 chore: add feature planner setup for docker-watcher-core
Create structured plan files with 12 phases covering the full
implementation: scaffold, store, crypto, Docker/NPM clients,
registry poller, webhook, deployer, API layer, SvelteKit frontend,
embedding, and hardening.
2026-03-27 20:42:42 +03:00

56 lines
2.9 KiB
Markdown

# Phase 11: Frontend Embed & Real-Time Updates
**Status:** ⬜ Not Started
**Parent plan:** [PLAN.md](./PLAN.md)
**Domain:** fullstack
## Objective
Build SvelteKit to static files, embed into the Go binary with `go:embed`, serve from Go, and implement SSE for real-time deploy progress and instance status updates.
## Tasks
- [ ] Task 1: Configure SvelteKit static adapter to output to `web/build/`
- [ ] Task 2: Add `//go:embed web/build` directive in Go — serve static files
- [ ] Task 3: Create Go handler for serving embedded SPA — serve index.html for all non-API routes (SPA fallback)
- [ ] Task 4: Implement SSE endpoint for deploy logs — `GET /api/deploys/:id/logs` streams deploy progress in real-time
- [ ] Task 5: Implement SSE endpoint for instance status — `GET /api/events` streams instance status changes
- [ ] Task 6: Create event bus/broadcaster in Go — publish events from deployer, subscribe from SSE handlers
- [ ] Task 7: Frontend: connect to SSE for deploy progress — update deploy log view in real-time
- [ ] Task 8: Frontend: connect to SSE for instance status — update dashboard/project views without refresh
- [ ] Task 9: Handle SSE reconnection in frontend — auto-reconnect with backoff on disconnect
- [ ] Task 10: Build script/Makefile — `make build` builds frontend then Go binary
## Files to Modify/Create
- `web/svelte.config.js` — ensure static adapter outputs to `web/build/`
- `internal/api/static.go` — embedded static file server with SPA fallback
- `internal/api/sse.go` — SSE endpoints for deploy logs and instance events
- `internal/events/bus.go` — event bus for publishing/subscribing to events
- `web/src/lib/sse.ts` — SSE client helper with auto-reconnect
- `web/src/routes/+layout.svelte` — wire up global SSE connection for instance status
- `Makefile` — build frontend + backend
- `cmd/server/main.go` — wire embedded static serving and event bus
## Acceptance Criteria
- `make build` produces a single Go binary with embedded frontend
- Go binary serves the SvelteKit SPA on all non-API routes
- Deploy progress streams in real-time via SSE
- Instance status updates appear without page refresh
- SSE reconnects automatically after network hiccups
## Notes
- `go:embed` requires the embedded directory to be relative to the Go source file
- SPA fallback: any request that doesn't match `/api/*` gets `index.html`
- Event bus: simple pub/sub with channels — no external dependency needed
- SSE format: `data: {"type": "deploy_log", "payload": {...}}\n\n`
- Keep SSE connections lightweight — use context cancellation for cleanup
## Review Checklist
- [ ] All tasks completed
- [ ] Single binary serves both API and frontend
- [ ] SSE handles multiple concurrent clients
- [ ] No goroutine leaks on SSE disconnect
- [ ] Build process is reproducible (Makefile)
## Handoff to Next Phase
<!-- Filled in by the implementation agent after completing this phase. -->