# HTMX + Go 1.22+ Reactive Patterns > Production-ready HTMX patterns for game backends without JavaScript frameworks. **Last Updated:** 2026-03-14 **Go Version:** 1.22+ **HTMX Version:** 1.9.x --- ## Purpose This example demonstrates building reactive game admin interfaces using **HTMX** with **Go 1.22+** without requiring JavaScript frameworks. Patterns include: - Component composition with Go `template/block` syntax - WebSocket-based real-time updates for game events - Progressive enhancement for accessibility - Systemic consistency for game state management - Server-driven UI patterns for game admin panels --- ## 2026 Best Practices ### HTMX Architecture Patterns | Pattern | Use Case | Implementation | |---------|----------|----------------| | **Boost Mode** | Full page transitions | `hx-boost="true"` on forms | | **Push URL** | Browser history sync | `hx-push-url="true"` for navigation | | **Polling** | Periodic state refresh | `hx-trigger="every 2s"` for metrics | | **WebSocket** | Real-time game events | `hx-ext="ws"` for event streaming | | **SSE** | One-way server updates | `hx-ext="sse"` for notifications | ### Go 1.22+ Template Features ```go // Block syntax for component composition {{block "player-card" .Player}}
{{.Player.Name}} - Level {{.Player.Level}}
{{end}} ``` ### Accessibility (A11Y) Requirements | Requirement | HTMX Pattern | WCAG Level | |-------------|--------------|------------| | **Focus Management** | `hx-focus="#element"` on updates | AA | | **ARIA Live Regions** | `aria-live="polite"` with `hx-trigger` | AA | | **Keyboard Navigation** | Standard `
` + ` {{end}} `) ``` ### Server-Driven Events ```go // game-admin-panel.go func (g *GameAdmin) broadcastEvent(w http.ResponseWriter, r *http.Request) { // Game event originates from server event := GameEvent{Type: "PLAYER_ACTION", Payload: action} g.mu.Lock() g.clients[wsID] <- event g.mu.Unlock() } ``` --- ## Guardrails Compliance | Rule | Implementation | |------|----------------| | **PRODUCTION FIRST** | Server code before template tests | | **SERVER AUTHORITY** | No client-side game logic | | **ACCESSIBILITY** | ARIA labels, keyboard nav, focus management | | **RATE LIMITING** | Per-session request limits | | **AUDIT LOGGING** | All state mutations logged | --- ## Related Documentation - [AGENT_GUARDRAILS.md](../../docs/AGENT_GUARDRAILS.md) - Core safety protocols - [TEST_PRODUCTION_SEPARATION.md](../../docs/standards/TEST_PRODUCTION_SEPARATION.md) - Separation standards - [WEB_UI_IMPLEMENTATION.md](../../docs/sprints/SPRINT_002_WEB_UI_IMPLEMENTATION.md) - Web UI patterns --- **Authored by:** Claude Code (Anthropic) **Document Owner:** Project Maintainers **Review Cycle:** Monthly