Backend authoritative runtime refactor

From curiositech/windags-skills · View interactive version

Backend authoritative runtime refactor is an AI agent skill from the GitHub repository curiositech/windags-skills. 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.

How to use this skill

Skill file

Backend-Authoritative Runtime Refactor

Refactor only after you can say exactly where execution truth lives and how the UI reads it.

When to Use

NOT for

Decision Points

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:

Working Method

1. Inventory the split brain

Find all places where the UI:

2. Freeze the contract

Define three classes only:

If a UI action cannot be expressed as one of these, the architecture is still muddy.

3. Normalize state ownership

Split stores into:

Do not let any store own both runtime truth and layout concerns.

4. Delete active compatibility seams

Prefer deletion over "supporting both for now."

Typical deletions:

5. Add evaluators before trusting the refactor

Every implementation node should have:

Failure Modes

Projection masquerading as authority

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.

Compatibility seam calcification

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.

Approval without inspectability

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.

Replay-hostile startup

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.

Shibboleth

If relaunching the app changes visible runtime state without any new backend event, authority is still split.

Worked Example

Tauri workflow editor with frontend-owned phase logic

Problem:

Refactor path:

  1. Inventory every place the UI invented execution truth.
  2. Collapse runtime interactions to commands, queries, and events.
  3. Move provider normalization and phase transitions behind backend commands.
  4. Delete starter-format unions from the active authoring path.
  5. Add evaluator gates so downstream work only proceeds from backend-validated outputs.

Success condition:

Fork Guidance

Fork when the work separates cleanly:

Keep final ownership decisions in the parent lane so one actor decides what the backend truly owns.

Quality Gates

Reference Map

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.