Frontend Architecture: Features and State Ownership
Use Vaastu's frontend architecture skill to organize features, components, state, forms, and data fetching with an AI agent. Verify the affected interactions.
Choose the frontend problem to solve
Use Vaastu when a frontend workflow has unclear ownership, duplicated state, tangled imports, or a change that crosses feature boundaries. Describe the actual user outcome and preserve the existing design system, routes, and framework conventions.
This walkthrough uses a searchable record list as an illustrative example. Users filter records, open a detail view, edit an allowed field, and return to their results. The architecture should preserve the filter and navigation history while keeping edits and fetched data consistent. It is not a claim that this example has been implemented or tested.
Keep behavior with its feature
Let the records feature own the list, detail interaction, filter interpretation, and mutation behavior. The route composes that feature and adapts navigation parameters. Shared UI primitives can render inputs and dialogs without owning record-specific rules.
Extract a component or hook when it has a coherent responsibility, lifecycle, or real consumer. Do not move every component into a global folder or create a shared package merely because another page might use it someday. Public feature entry points should make supported dependencies clear.
Decide what survives navigation
For shareable web results, filters and sorting can belong in URL state. The established loader or query cache owns fetched records. The editing form owns unsaved values, while focus and dialog visibility stay near the interaction that controls them.
Define back/forward navigation and invalid filter behavior. A slow search response must not overwrite a newer query. Do not copy the result list into another global store just to make it accessible to unrelated components. If offline drafts are required, name their persistence, expiry, and account-change behavior explicitly.
Reconcile edits without losing the user's work
Keep client feedback separate from authoritative validation and permission enforcement. Preserve entered values after a recoverable rejection and associate recognized field errors with their inputs. Update or revalidate affected detail, list, and aggregate data through the existing data owner.
If a changed record no longer matches the active filter, decide whether it disappears from the current result and how the user learns that the save succeeded. For optimistic changes, define rollback and reconciliation. For an unknown result after a lost response, use the operation's recovery contract before submitting another mutation.
Organize frontend components and modules around features
For frontend project structure, keep a feature's components, form rules, and interaction logic close to the feature that owns them. Keep route files focused on routing and composition. A reusable visual primitive can live in the design system; a component coupled to one feature's permissions or data shape usually stays with that feature.
Before extracting a shared module, identify its consumers and intended public API. Check that shared code does not import application internals and that moving it will not create circular dependencies. This makes code organization an ownership decision with observable consequences instead of a folder naming exercise.
Ask your coding agent for a scoped frontend change
Use the installed skill and the actual record workflow in your project. This prompt focuses the agent on frontend architecture without requiring a backend rewrite.
Read the installed Vaastu SKILL.md and its frontend architecture guidance.
Inspect this repository's routing, UI components, data loading, and state conventions.
Implement [frontend workflow] using the existing stack and visual system.
Define the owners of URL state, fetched data, form values, and local interaction state.
Preserve navigation, permissions, current contracts, and unrelated behavior.
Acceptance criteria: [success, empty, loading, error, keyboard, and viewport behavior].
Check stale responses, mutation reconciliation, and account changes where affected.
State a brief plan, implement within scope, and report the verification evidence.Verify interaction and architecture together
Exercise loading, empty results, invalid filters, server field errors, background refresh, and successful edits. Check that navigation restores the intended result state and obsolete requests cannot replace current data. If identity changes, old results and drafts must not appear under the new account.
Inspect keyboard flow, focus recovery, labels, readable errors, narrow widths, and large text in the target runtime. Measure performance against the reported issue before adding memoization, virtualization, or another data library. Record browser/device checks separately from source inspection and mocked interaction tests.