skills/backend-authoritative-runtime-refactor/SKILL.md
Refactor apps so backend owns runtime truth and UI only projects snapshots. Use when tools have split authority. NOT for cosmetic UI work or new features before drift is removed.
npx skillsauth add curiositech/windags-skills backend-authoritative-runtime-refactorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Refactor only after you can say exactly where execution truth lives and how the UI reads it.
flowchart TD
A[Workflow refactor request] --> B{Can the UI still invent runtime truth?}
B -->|No| C[Use a narrower domain or UI skill]
B -->|Yes| D[Inventory command, query, and event seams]
D --> E{Can every user action map to command, query, or event?}
E -->|No| F[Freeze the contract before feature work]
E -->|Yes| G[Split projection state from backend-owned state]
G --> H{Are legacy compat paths still active?}
H -->|Yes| I[Move them to migration edges or delete them]
H -->|No| J[Add evaluators, replay-safe startup queries, and event subscriptions]
I --> J
J --> K[Validate reconnection, approval, and downstream readiness]
Use this routing model first:
command -> backend transition -> query or event projection, the seam is still wrong.Find all places where the UI:
Define three classes only:
If a UI action cannot be expressed as one of these, the architecture is still muddy.
Split stores into:
Do not let any store own both runtime truth and layout concerns.
Prefer deletion over "supporting both for now."
Typical deletions:
Every implementation node should have:
Symptom: the UI looks "read only" but quietly assembles phase, graph, or provider truth locally.
Fix: move that logic into backend commands or queries and treat the frontend as a projector.
Symptom: "support both for now" remains in the hot path for weeks and becomes the real architecture.
Fix: push compatibility to one-way migration edges with an explicit deletion date or remove it now.
Symptom: a human can approve work they cannot inspect because the review payload is partial or frontend synthesized.
Fix: backend must emit the exact review payload; the UI only renders it.
Symptom: relaunching the app changes visible state or loses gate position because the frontend cached authority.
Fix: startup must be a query against backend truth plus event replay, not store reconstruction.
If relaunching the app changes visible runtime state without any new backend event, authority is still split.
Problem:
Refactor path:
Success condition:
Fork when the work separates cleanly:
Keep final ownership decisions in the parent lane so one actor decides what the backend truly owns.
references/architecture-patterns.md — backend-owned workflow contract patterns and state-ownership splits.references/windags-lessons.md — concrete lessons from a real split-authority runtime migration.data-ai
license: Apache-2.0 NOT for unrelated tasks outside this domain.
development
Use when designing caching strategies (cache-aside, write-through, write-behind), implementing distributed locks, building rate limiters, leaderboards, real-time streams (XADD/consumer groups), pub/sub, or tuning eviction policies. Triggers: thundering-herd on cache miss, dogpile on key expiry, Redlock vs SET-NX-PX choice, sliding-window rate limiter, hot-key on a single cluster slot, big-key blowup, MULTI/EXEC across slots, KEYS in production. NOT for Redis Cluster operations/admin (different domain), embedded KV (SQLite, leveldb), in-process LRU caches, or Memcached.
tools
Drawing the `'use client'` boundary correctly in React Server Components apps (Next.js App Router, RSC frameworks) — leaf-pushing, slot composition, serialization rules, and environment poisoning prevention. Grounded in react.dev and Next.js 16 docs.
development
Use when designing rate limiting for an API, choosing between token bucket / sliding window / leaky bucket / fixed window, implementing it in Redis, deciding edge (Cloudflare/Upstash) vs origin enforcement, sizing per-user vs per-IP vs per-endpoint quotas, returning the right 429 response with Retry-After, or fixing the boundary-burst bug in fixed-window limiters. Triggers: 429 too many requests, INCR + EXPIRE, ZADD + ZREMRANGEBYSCORE + ZCARD, X-RateLimit-Remaining header, Cloudflare WAF rate limiting rules, Upstash @upstash/ratelimit, leaky bucket shaping vs policing, distributed rate limiter consistency. NOT for DDoS mitigation specifically (different scale), CAPTCHA / bot management, full WAF design, or per-user quota billing.