refactor: replace via framework with chi + templ + datastar #2

Merged
ryan merged 9 commits from refactor/remove-via into main 2026-03-03 00:47:20 +00:00
Owner

Summary

  • Replace the via meta-framework with direct dependencies: chi (routing), templ (HTML templates), datastar (SSE/reactivity), SCS (sessions), embedded NATS (pub/sub)
  • Adopt feature-sliced architecture (features/{auth,lobby,c4game,snakegame}/) with handler factory pattern (HandleX(deps) http.HandlerFunc)
  • Remove old ui/ package (gomponents-based views) and all via imports from go.mod

Details

The via framework wrapped chi, gomponents, datastar, SCS sessions, and embedded NATS into one opinionated package. This PR replaces all of those with direct dependencies, giving us full control over each layer.

New packages

  • features/common/layouts/ — base HTML layout with Datastar JS CDN
  • features/common/components/ — shared components (BackToLobby, NicknamePrompt, etc.)
  • features/auth/ — login/register pages and handlers
  • features/lobby/ — lobby page with tab switching (Connect 4 / Snake)
  • features/c4game/ — Connect 4 board, status, chat components and SSE handlers
  • features/snakegame/ — Snake board, status, chat components and SSE handlers (with 60fps drain pattern)
  • nats/ — embedded NATS server setup
  • sessions/ — SCS session manager setup
  • router/ — chi router wiring with hot-reload support in dev mode

Key migration decisions

  • c.Signal() → datastar data-signals/data-bind
  • c.Action() → dedicated POST endpoints with data-on:click
  • c.View() + c.Sync() → initial GET render + SSE PatchElementTempl fragments
  • c.Subscribe/Publish → NATS nc.ChanSubscribe/nc.Publish
  • Lobby tab switching is now pure client-side (data-show) instead of server round-trips
  • ChatMessage domain type moved from ui package to game package

Verified

  • go build ./... passes
  • go mod tidy clean
  • Application starts successfully (DB, sessions, NATS all initialize)
## Summary - Replace the `via` meta-framework with direct dependencies: chi (routing), templ (HTML templates), datastar (SSE/reactivity), SCS (sessions), embedded NATS (pub/sub) - Adopt feature-sliced architecture (`features/{auth,lobby,c4game,snakegame}/`) with handler factory pattern (`HandleX(deps) http.HandlerFunc`) - Remove old `ui/` package (gomponents-based views) and all `via` imports from `go.mod` ## Details The `via` framework wrapped chi, gomponents, datastar, SCS sessions, and embedded NATS into one opinionated package. This PR replaces all of those with direct dependencies, giving us full control over each layer. ### New packages - `features/common/layouts/` — base HTML layout with Datastar JS CDN - `features/common/components/` — shared components (BackToLobby, NicknamePrompt, etc.) - `features/auth/` — login/register pages and handlers - `features/lobby/` — lobby page with tab switching (Connect 4 / Snake) - `features/c4game/` — Connect 4 board, status, chat components and SSE handlers - `features/snakegame/` — Snake board, status, chat components and SSE handlers (with 60fps drain pattern) - `nats/` — embedded NATS server setup - `sessions/` — SCS session manager setup - `router/` — chi router wiring with hot-reload support in dev mode ### Key migration decisions - `c.Signal()` → datastar `data-signals`/`data-bind` - `c.Action()` → dedicated POST endpoints with `data-on:click` - `c.View()` + `c.Sync()` → initial GET render + SSE `PatchElementTempl` fragments - `c.Subscribe/Publish` → NATS `nc.ChanSubscribe`/`nc.Publish` - Lobby tab switching is now pure client-side (`data-show`) instead of server round-trips - `ChatMessage` domain type moved from `ui` package to `game` package ### Verified - `go build ./...` passes - `go mod tidy` clean - Application starts successfully (DB, sessions, NATS all initialize)
ryan added 2 commits 2026-03-02 22:17:06 +00:00
Add config package with build-tag-switched dev/prod environments,
structured logging via zerolog, Taskfile for dev workflow, golangci-lint
config, testutil package, and improved DB setup with proper SQLite
pragmas and cleanup. Rename sqlc output package from gen to repository.

Switch to allowlist .gitignore, Alpine+UPX+scratch Dockerfile, and
CI pipeline with test/lint gates before deploy.
refactor: replace via framework with chi + templ + datastar
Some checks failed
CI / Deploy / test (pull_request) Successful in 28s
CI / Deploy / lint (pull_request) Failing after 42s
CI / Deploy / deploy (pull_request) Has been skipped
8c3b3fc6ea
Migrate from the via meta-framework to direct dependencies:
- chi for routing, templ for HTML templates, datastar for SSE/reactivity
- Feature-sliced architecture (features/{auth,lobby,c4game,snakegame}/)
- Shared layouts and components (features/common/)
- Handler factory pattern (HandleX(deps) http.HandlerFunc)
- Embedded NATS server (nats/), SCS sessions (sessions/), chi router wiring (router/)
- Move ChatMessage domain type from ui package to game package
- Remove old ui/ package (gomponents-based via/h views)
- Remove via dependency from go.mod entirely
ryan added 1 commit 2026-03-02 22:30:41 +00:00
refactor: remove persister abstraction layer
Some checks failed
CI / Deploy / test (pull_request) Successful in 8s
CI / Deploy / lint (pull_request) Failing after 46s
CI / Deploy / deploy (pull_request) Has been skipped
2aa026b1d5
Inline persistence logic directly into game stores and handlers:
- game/persist.go: DB mapping methods on GameStore and GameInstance
- snake/persist.go: DB mapping methods on SnakeStore and SnakeGameInstance
- Chat persistence inlined into c4game handlers
- Delete db/persister.go (GamePersister, SnakePersister, ChatPersister)
- Stores now take *repository.Queries directly instead of Persister interface
ryan added 1 commit 2026-03-02 22:38:26 +00:00
fix: resolve all linting errors and add SSE compression
Some checks failed
CI / Deploy / test (pull_request) Successful in 8s
CI / Deploy / lint (pull_request) Failing after 44s
CI / Deploy / deploy (pull_request) Has been skipped
afd8a3e9d0
- Add brotli compression (level 5) to long-lived SSE event streams
  (HandleGameEvents, HandleSnakeEvents) to reduce wire payload
- Fix all errcheck violations with nolint annotations for best-effort calls
- Fix goimports: separate stdlib, third-party, and local import groups
- Fix staticcheck: add package comments, use tagged switch
- Zero lint issues remaining
ryan added 1 commit 2026-03-02 22:40:03 +00:00
fix: suppress gosec G117 on auth form signal structs
All checks were successful
CI / Deploy / test (pull_request) Successful in 7s
CI / Deploy / lint (pull_request) Successful in 47s
CI / Deploy / deploy (pull_request) Has been skipped
67d4dba37f
ryan added 1 commit 2026-03-02 22:42:13 +00:00
fix: warn when .env file is missing instead of silently ignoring
All checks were successful
CI / Deploy / test (pull_request) Successful in 13s
CI / Deploy / lint (pull_request) Successful in 24s
CI / Deploy / deploy (pull_request) Has been skipped
fcc6b70e84
ryan added 1 commit 2026-03-02 23:19:46 +00:00
refactor: streamline routes to RESTful naming conventions
All checks were successful
CI / Deploy / test (pull_request) Successful in 13s
CI / Deploy / lint (pull_request) Successful in 23s
CI / Deploy / deploy (pull_request) Has been skipped
5120eef776
Remove /api/ prefix and consolidate route groups:
- /api/lobby/* -> /games, /snake, /logout (top-level)
- /game/{game_id} + /api/game/{game_id}/* -> /games/{id}/*
- /snake/{game_id} + /api/snake/{game_id}/* -> /snake/{id}/*
- /api/auth/* -> /auth/*
- Standardize snake join page to use return_url= (was return=)
ryan added 2 commits 2026-03-03 00:35:30 +00:00
Replace CDN-hosted datastar beta.11 with local v1.0.0-RC.7 to fix
client-side expression incompatibilities with the Go SDK. Also fix
quoted CSS class keys in data-class expressions, harden session cookie
settings (named cookie, Secure flag), simplify SetupRoutes to not
return an error, and regenerate templ output.
feat: add downloader binary for client-side dependencies
All checks were successful
CI / Deploy / test (pull_request) Successful in 14s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
303c45cab1
Replace the curl-based Taskfile download task with a Go binary that
concurrently fetches datastar.js, datastar.js.map, daisyui.mjs, and
daisyui-theme.mjs. Update vendored libs to latest versions.
ryan merged commit 021215ed94 into main 2026-03-03 00:47:20 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ryan/games#2