Building Interactive Web Applications with LLM Assistance: Requirement Decomposition and Implementation Validation

    Learn how to use large language models to develop interactive web applications more reliably by breaking requirements into interface, interaction, and business layers. This article covers draggable windows, glassmorphism styling, real-time and turn-based logic, optional automation assistants, prompt iteration, and a practical validation checklist.

    1. Why Requirements Should Be Decomposed First

    When a large language model is used to generate an interactive web application, three problems commonly arise: visual effects are difficult to describe precisely in text, interaction details are easily overlooked, and business rules may conflict with one another. If you submit only a broad requirement, the model may produce the appearance or the main workflow, but rarely both in a complete and consistent way.

    A more reliable approach is to divide the requirements into three layers:

    • Interface layer: Window containers, title bars, buttons, hierarchy, and transition animations.
    • Interaction layer: Mouse and touch events, drag movement, boundary constraints, focus, and z-index changes.
    • Business layer: Rules, state, and progression, such as resource production, research queues, and win conditions.

    Each layer should have its own acceptance criteria. This makes it easier to identify which layer has a problem during iteration, instead of rewriting the entire application each time.

    2. Key Considerations for Window Dragging

    Draggable windows are a basic capability of desktop-style web interfaces. Three points are especially important: windows must use absolute positioning, dragging must be constrained to the visible area, and clicking a window should bring it to the front.

    1. let topZ = 10;
    2. function makeDraggable(windowEl, handleEl) {
    3. let offsetX = 0;
    4. let offsetY = 0;
    5. let dragging = false;
    6. handleEl.addEventListener('mousedown', (e) => {
    7. dragging = true;
    8. const rect = windowEl.getBoundingClientRect();
    9. offsetX = e.clientX - rect.left;
    10. offsetY = e.clientY - rect.top;
    11. windowEl.style.zIndex = String(++topZ);
    12. e.preventDefault();
    13. });
    14. document.addEventListener('mousemove', (e) => {
    15. if (!dragging) return;
    16. const maxX = window.innerWidth - windowEl.offsetWidth;
    17. const maxY = window.innerHeight - windowEl.offsetHeight;
    18. const x = Math.min(Math.max(0, e.clientX - offsetX), maxX);
    19. const y = Math.min(Math.max(0, e.clientY - offsetY), maxY);
    20. windowEl.style.left = `${x}px`;
    21. windowEl.style.top = `${y}px`;
    22. });
    23. document.addEventListener('mouseup', () => {
    24. dragging = false;
    25. });
    26. }

    For touch-device support, the mousedown, mousemove, and mouseup events can be replaced with the corresponding pointer events. The underlying logic remains the same.

    3. Implementing and Validating a Semi-Transparent Visual Style

    A glass-like effect is typically created by combining background transparency, backdrop blur, a subtle border, and a shadow. The following CSS provides a common starting point:

    1. .window {
    2. position: absolute;
    3. background: rgba(255, 255, 255, 0.35);
    4. backdrop-filter: blur(12px);
    5. -webkit-backdrop-filter: blur(12px);
    6. border: 1px solid rgba(255, 255, 255, 0.5);
    7. border-radius: 8px;
    8. box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    9. }

    backdrop-filter is not fully supported in some older browsers, so a fallback style should be provided. For example, the application can use a more opaque solid-color background when the effect is unavailable.

    Visual validation should not rely only on screenshots. Check the interface in different browsers and viewport sizes, and verify that text maintains sufficient contrast.

    Three-dimensional window transitions are generally implemented with perspective transforms using properties such as perspective and rotateY. These animations can be performance-sensitive. Apply transformations to only a small number of windows, and use transform and opacity for transitions to avoid repeatedly triggering layout calculations.

    4. Distinguishing Real-Time and Turn-Based Logic

    For the same strategy game, the fundamental difference between real-time and turn-based modes is how time advances.

    • Turn-based mode: Time advances only when the player selects an “end turn” action. All calculations are completed during the transition between turns.
    • Real-time mode: Time advances continuously through a fixed-frequency loop. Resource production, construction, and research accumulate over time.

    A typical real-time loop looks like this:

    1. let lastTime = performance.now();
    2. function gameLoop(now) {
    3. const dt = (now - lastTime) / 1000;
    4. lastTime = now;
    5. update(dt); // Advance the state based on elapsed time
    6. render();
    7. requestAnimationFrame(gameLoop);
    8. }
    9. requestAnimationFrame(gameLoop);

    Fairness is essential in real-time mode. Both sides must use the same rules, unit speeds, and calculation interfaces. If an automated character has access to additional data or operates at a shorter interval, the match will no longer be fair. This should therefore be checked as a separate acceptance criterion.

    5. An Optional Automation Assistant Module

    A feature such as “automatically complete research” is an additional module built on top of the existing rules; it is not part of the original rules themselves. The design should follow these principles:

    1. Use an explicit switch to control whether the feature is enabled.
    2. Read only publicly available game state and do not directly modify internal data.
    3. Start an action only when sufficient resources are available, while following the same cost rules as the player.

    A simplified example is shown below:

    1. function assistantTick(state) {
    2. if (!state.assistantEnabled) return;
    3. if (state.research.current !== null) return;
    4. const next = state.research.queue.find(
    5. (tech) => state.resources.science >= tech.cost
    6. );
    7. if (next) {
    8. startResearch(state, next);
    9. }
    10. }

    This function runs during each time step. It first checks whether the assistant is enabled, then verifies that no research project is currently active, and finally selects the first affordable project from the queue. This structure is easy to test and can later be replaced with a more advanced prioritization strategy.

    6. Iterating on Prompts

    Prompt quality has a direct impact on the generated result. The following practices can significantly reduce the amount of rework:

    • Use explicit requirements: Write the requirements as numbered clauses that can each be validated independently, such as “The window can be dragged without leaving the viewport.”
    • Change one variable at a time: Modify only one requirement in each iteration so that improvements or regressions can be attributed to a specific change.
    • Preserve versions: Save each version separately for easier comparison.
    • Provide a reference structure: Specify the file organization, function naming conventions, or target runtime environment to reduce assumptions made by the model.

    Prompts should also define boundaries clearly. For example, stating “Do not introduce third-party dependencies” or “Use only native DOM APIs” can prevent the generated result from relying on libraries that are difficult to control.

    7. Validation Checklist

    After generation is complete, review the result against the following checklist:

    • Can each window be dragged, and do the boundary constraints work?
    • Does clicking a window correctly change its z-index?
    • Does the semi-transparent effect work in the target browsers?
    • Are the transition animations smooth, without noticeable frame drops?
    • In real-time mode, does time advance continuously without manual input?
    • When the assistant is disabled, does research stop completely?
    • When the assistant is enabled, does research start only when resources are sufficient?
    • Do both sides follow the same rules, with no hidden speed advantage?

    Online generation services may respond slowly or experience interruptions during peak usage. In practice, generation tasks should have timeout and retry handling, and completed intermediate results should be saved so that a single failure does not require starting over.

    8. Conclusion

    When using a large language model to develop an interactive web application, the key is to turn ambiguous requirements into verifiable clauses. Windows, visual styling, time progression, and automation modules should be treated as separate areas, allowing layered validation to locate problems quickly.

    The code examples in this article can serve as a starting point, but the final result still needs to be tested in a real environment. Functionality, visual quality, and gameplay fairness should all be reviewed individually to confirm that the implementation meets expectations.