Five Engineering Rules for Reliable AI-Assisted Component Development
AI coding tools can generate UI components quickly, but generated code often fails to fit real project constraints. This article presents five engineering rule categories for AI-assisted component development: requirement clarification before coding, component contracts, runtime and dependency boundaries, design-system reuse, and verification as a delivery condition. It also explains how to load rules in AI tools, separate rule guidance from automated checks, and revise rules based on real rework.
1. The Problem Is Not Code Generation but Whether the Output Fits the Project
AI coding tools often deliver an obvious initial productivity gain for UI work. Describe a list, a form, or a modal, and a complete component implementation appears quickly. The real problems emerge when the task enters a real project.
Some components have no clear input types. Some treat all data as an arbitrary type to bypass checks. Some expand browser-side execution without analyzing the runtime environment. Others ignore existing design variables and hard-code colors, spacing, and z-index values.
These implementations may not fail immediately, but they steadily increase maintenance cost. Developers have to explain the same directory conventions, state rules, and style standards again and again. A problem corrected in one conversation may reappear in the next task.
What needs to be codified, therefore, is not a stronger prompt but a set of engineering rules that can be retrieved, executed, and checked.
The approach can be divided into five rule categories:
- Clarify requirements and implementation boundaries before development.
- Constrain data and interactions with component contracts.
- Control runtime boundaries, state ownership, and directory dependencies.
- Reuse design specifications and prevent visual implementation drift.
- Close the loop with verification and delivery notes.
One caveat should be stated first: a rule file is not a compiler, and it is not a security sandbox. It can improve consistency in generated results, but it cannot guarantee that an AI tool will always comply. A reliable approach should combine rule guidance, automated checks, and human review. Textual requirements should not be treated as an enforcement mechanism.
2. Rule One: Clarify Requirements Before Coding
1. Do not turn incomplete requirements directly into code
“Add a search list” looks simple, but it hides many implementation decisions:
- Is search performed as local filtering, or does it request remote data?
- Should search run immediately after input, or after a delay?
- Should pagination reset when search conditions change?
- Should “no data” and “no matching results” use different messages?
- How should a failed request be retried?
- If the user changes conditions quickly, can an older request overwrite newer results?
- Should filter conditions be preserved in the page URL?
If these questions are not clarified, the AI tool will choose for itself. The problem is not that it cannot design at all. The problem is that its choices may not match business expectations and existing project constraints.
2. Write the clarification process as executable steps
A planning rule can use the following structure:
Applicability:New pages, new business flows, changes to core interactions, or cross-module changes.Steps:1. Read relevant directories, existing components, and data-access implementations.2. Summarize confirmed facts, open questions, and external dependencies.3. Clarify issues that affect architecture, data, or acceptance first.4. Propose a minimal-change plan, affected files, and verification methods.5. For high-impact changes, obtain confirmation before modifying code.Prohibitions:Do not treat unconfirmed business assumptions as established requirements.Do not build complex frameworks for requirements that have not yet been raised.
The key point is not that every task must trigger a full questioning process. The key is to distinguish the importance of issues.
Changing button copy usually does not require a complete design process. Features involving permissions, data writes, and cross-page state should clarify key boundaries first. For low-risk details, the AI tool can state the default assumptions it adopts, so that planning does not become a new efficiency bottleneck.
3. Planning results must be acceptable
“Improve the interaction experience” is not a valid plan. A better plan should describe observable behavior, for example:
- Do not execute search when the input is empty.
- Return to the first page after filter conditions change.
- Allow only the latest query to update the result area.
- Keep query conditions when a request fails and show a retry entry point.
- Prevent duplicate submission during loading.
Such a plan can guide implementation and can also be converted directly into test scenarios.
3. Rule Two: Define Component Contracts Before Internal Logic
1. Clear inputs matter more than adding types afterward
A component contract is more than parameter types. It should include input meaning, optional conditions, callback behavior, and state constraints.
For a selector component, for example, the contract should answer at least:
- Is the selected value controlled by the parent, or maintained inside the component?
- What representation is used when nothing is selected?
- Are option identifiers stable and unique?
- Are callbacks allowed when the component is disabled?
- How should an existing value be displayed when the option no longer exists?
If these semantics are not defined, the component may still pass type checking while remaining behaviorally ambiguous.
A neutral contract description can look like this:
Component: single selectorInputs:- Current value: nullable unique identifier- Option collection: contains unique identifiers and display text- Disabled: boolean- Value-change notification: receives a new unique identifier or an empty valueConstraints:- Do not mutate the input collection directly- Do not emit value-change notifications when disabled- When the current value is not in the options, display it according to the agreed fallback strategy
2. Do not replace data modeling with bypassing checks
Common shortcuts in AI-generated code include widening type ranges, using repeated type assertions, and treating nullable data as a valid object.
Engineering rules should require:
- Validate external input at system boundaries.
- Narrow unknown data before it enters business logic.
- Define required and optional fields according to real business semantics.
- Do not add unsupported default values just to silence errors.
- When static checks must be bypassed, explain the reason, scope, and risk.
It is especially important to distinguish static constraints from runtime validation. The former helps find problems during development; the latter handles the data actually received. Declaring a return shape does not guarantee that remote data will always match that shape.
3. Use state models to reduce impossible states
Multiple independent booleans easily create conflicts, such as “loading” and “failed” appearing at the same time. For mutually exclusive states, explicit modeling is more appropriate:
Query state:- Not started- Loading- Success: carries result- Failure: carries error information
Note that UI state may also include “keep old results while refreshing.” In that case, the four states should not be applied mechanically. The implementation should distinguish first load, background refresh, and refresh failure according to the actual interaction. The goal of the rule is to express real semantics, not to pursue formal uniformity.
4. Rule Three: Define Runtime Boundaries and Keep Dependencies Clear
1. Do not assume all code runs in the browser
In projects that support both server-side and browser-side rendering, not every component needs to maintain interactive state in the browser.
Rules should require the AI tool to determine first:
- Does the component read browser-only capabilities?
- Does it need immediate interaction and local state?
- Does it contain data that should not be sent to the client?
- Can static display and interactive areas be split?
- Does it incorrectly import server-side dependencies into browser-side code?
The basic principle is to enable browser interaction only at boundaries where it is truly needed, rather than expanding the execution scope of the entire component tree for convenience.
This does not mean that less browser-side code is always better. A reasonable boundary should be based on interaction complexity, data-fetching approach, and maintenance cost. No single rendering strategy should be treated as the universal answer for every page.
2. Directory ownership should follow business responsibility
Directory rules can be described by responsibility rather than tied to a specific framework convention:
Page entry layer:Handles route parameters, page composition, and entry-level processing.Business feature layer:Contains components, state, and business rules for specific business scenarios.Shared UI layer:Contains data display and interaction components independent of specific business domains.Data access layer:Handles requests, response transformation, and external data boundary processing.
In real projects, existing structures should be followed first. The directory should not be rebuilt merely because an AI tool is more familiar with another organization style.
Dependency relationships should also be explicit: the shared UI layer should not depend in reverse on a business page; page entries should not accumulate large amounts of reusable business logic; components should not cross established boundaries to access internal data implementations directly.
3. Put state where it is actually needed
Not all state deserves to be lifted into a shared layer.
Short-lived interaction state, such as whether an input is expanded or whether a hint is visible, can usually be maintained locally. State that needs cross-component coordination can be lifted to the nearest common owner. Filter conditions that need to be shared, restored after refresh, or preserved during back navigation can be evaluated for URL state.
Rules should require the AI tool to explain the basis for state ownership, rather than introducing a global sharing mechanism immediately after seeing multiple components use the same data.
5. Rule Four: Reuse the Design System and Do Not Let Styles Become a Second Language
1. What should be prohibited is unsupported visual decision-making
“Do not write magic values” should not be interpreted as “no fixed values may ever appear.” Borders, icon sizes, and special layouts may all require specific numbers.
A more accurate requirement is:
- Prefer existing color, spacing, radius, and z-index variables in the project.
- Prefer composing existing base components.
- Do not create visual specifications that duplicate the design system.
- When adding special values, explain why and decide whether they should become shared variables.
- Do not mix multiple styling approaches merely for implementation convenience.
For projects with existing tool-based styling conventions, AI-generated code should follow those conventions. For projects using centralized style files or component-local styles, consistency should be maintained with the existing approach. There is no context-free answer here.
2. Design consistency must include interaction states
A button has more than a normal state. It may also include:
- Mouse hover.
- Keyboard focus.
- Disabled state.
- Submitting state.
- Destructive action warning.
Lists and forms also need to consider loading, empty, error, overly long text, and small-screen layouts.
If rules only require “correct colors,” the generated UI may still be visually close but unreliable in use. Accessibility should be included in style acceptance: focus should be visible, form labels should be explicit, errors should not be communicated by color alone, and key actions should be completable by keyboard.
6. Rule Five: Make Verification a Delivery Condition, Not a Closing Suggestion
1. Generated does not mean done
Delivery rules should require the AI tool to check whether changes meet the following conditions:
- Static checks pass.
- Component inputs and callbacks match the contract.
- Main interactions and exception paths are covered.
- Unrelated files are not modified by mistake.
- Unnecessary dependencies are not added.
- Existing directory boundaries are not broken.
- Sensitive data or unnecessary debug output is not included.
Checks should match risk. Purely presentational components should focus on rendering and accessibility. Components involving asynchronous queries should cover races. Features involving data modification should focus on duplicate submission, failure recovery, and permission handling.
2. Tests should focus on behavior, not copy the implementation
For a search list, the following acceptance scenarios can be selected:
- The correct state is displayed on first entry.
- Input changes trigger queries according to the agreed behavior.
- An earlier request returning later does not overwrite the latest result.
- Empty results and request failures use different messages.
- Clicking retry executes the query again.
- After leaving the page, expired UI updates are not triggered.
These tests protect user behavior rather than the name of an internal variable, so they are more adaptable to later refactoring.
3. Delivery notes must distinguish “verified” from “not verified”
A reliable delivery record should include at least:
Completed:Which observable behaviors this change implements.Change scope:Which business modules are involved; whether shared components are affected.Verification results:Which checks were actually executed and what the results were.Not yet verified:Verification that was not completed due to environment, data, or permission limits.Remaining risks:Which external conditions are still required; recommended follow-up review.
A check that was not actually executed cannot be written as “all passed.” If only static reading was performed, that should be stated explicitly. This kind of honest status report has more engineering value than a complete-looking but untraceable summary.
7. How to Put the Five Rule Categories into Practice
1. Confirm whether the tool supports rule loading
Different AI coding tools may have different requirements for rule file location, format, and loading timing. Some support selecting rules per task, some require explicit references, and some only read fixed entry files.
Therefore, it should not be assumed that “placing the document in a directory will make it take effect automatically.” Confirm the current tool’s capabilities first, then choose the loading method. If there is no automatic mechanism, the task template can explicitly require the relevant rules to be read.
2. Use a layered approach: common baseline plus scenario rules
Common rules should retain only requirements that apply to all tasks, such as not leaking sensitive information, not fabricating verification results, and not expanding the modification scope without authorization.
The five specialized rule categories can be loaded according to task needs, avoiding the injection of large amounts of irrelevant content every time. Each rule file should include:
- Applicable scope.
- Prerequisites for execution.
- Mandatory constraints.
- Conditions under which exceptions are allowed.
- Expected deliverables.
- An actionable checklist.
The handling of rule conflicts should also be explicit: base decisions on confirmed business requirements and valid project standards. When requirements cannot be satisfied at the same time, pause the relevant changes and explain the conflict rather than silently choosing one of them.
3. Divide work between rules and automated checks
Content that machines can judge reliably should be handled by deterministic checks as much as possible, such as syntax, types, formatting, and some dependency boundaries.
Content suitable for rule guidance and human review includes whether requirements are complete, whether abstraction is excessive, whether state ownership is reasonable, and whether interactions match business expectations.
The two cannot replace each other. Passing checks does not mean the solution is reasonable, and a reasonable-looking solution does not mean the implementation is error-free.
4. Revise rules continuously based on real rework
Rules should not be written once and then left unchanged for a long time. Repeated issues found in each review can be recorded and classified:
- No rule exists; add one.
- The rule is ambiguous; add examples.
- The rule is too broad; narrow its scope.
- The issue can be checked automatically; stop relying on human reminders.
- The rule is outdated; delete or update it.
When evaluating effectiveness, observe repeated violation counts, review rework rounds, the proportion of unrelated file modifications, and missed verification. However, do not claim a specific percentage efficiency improvement without actual records.
8. Conclusion: Make Standards a Workflow, Not Just a Prompt
The reliability of AI-assisted development does not depend on how forceful the prompt is. It depends on whether engineering constraints are clear, task boundaries are explicit, and results are verified.
The five rule categories form a complete path: first confirm what to do, then define component contracts; draw runtime and dependency boundaries, then unify visual implementation; finally, prove the result with tests, checks, and honest delivery records.
They cannot eliminate all errors, but they can expose many issues earlier in planning and implementation that would otherwise surface during code review and production feedback. The real goal is not to make AI tools generate more files in one pass, but to make every generation easier to understand, verify, and maintain.
