Evaluating LLM-Generated Frontend Code: A Solar System SVG Animation Case Study

    This article examines how to evaluate frontend code produced by large language models, using a generated SVG solar system animation as a test case. It moves beyond "it runs on screen" to ask whether the code is structurally sound, semantically accurate, stable across browsers and screen sizes, and accessible. The article breaks down the capability boundaries of a typical generation result, shows a reference implementation that separates data from the view, explains how to write prompts as acceptance contracts, and proposes engineering quality gates covering structure, runtime, visual regression, performance, security, and human review. It closes with practical guidance for teams that want to embed LLM output into a controlled, measurable development workflow.

    1. From “Looks Usable” to “Acceptable in Engineering”

    Once generative coding entered the frontend development workflow, one of the easiest mistakes to make is being impressed by a good-looking demo and immediately concluding that the model can reliably produce production pages. In real engineering acceptance, a runnable animation is only the starting point. Developers need to ask further: Is the code clearly structured? Does its behavior match the intended semantics? Is it stable across different screens and browsers? Do animation performance and accessibility meet the bar? Is it easy to maintain and extend later?

    Using “generate an animation that simulates the solar system with SVG” as a test entry point is a suitable scenario. It covers several dimensions at once: prompt understanding, spatial coordinate modeling, graphic structure organization, animation mechanism selection, responsive adaptation, semantic expression, and basic physics knowledge. Compared with simply generating a button or a card, a solar system animation more easily exposes the typical “works for a demo, not necessarily usable in engineering” problem.

    2. Capability Boundaries of a Typical Generation Result

    When the prompt is narrowed to “generate an animation that simulates the solar system with SVG,” a common result usually includes: multiple circular orbits centered on the Sun, planets of different colors and sizes, simple animations orbiting the planets, and in some cases extra details such as the Moon orbiting Earth or Saturn’s rings. If the goal is a demo, this kind of result already has strong visual appeal; but from an engineering perspective, it needs further breakdown.

    2.1 Semantic Understanding

    The model has to infer several implicit requirements from a single sentence: use inline SVG rather than drawing only with CSS; there is a central body with orbiting motion; the animation should loop; the scene should stay complete and scalable. If the result includes planets, orbits, the Moon, and planetary rings at the same time, it shows a certain ability to complete the scene.

    But completion does not equal accuracy. For example, planet proportions, orbital radii, revolution periods, orbital inclinations, and the angle of Saturn’s rings all belong to science-communication semantics. If the page is only illustrative, it should be clearly labeled “not to scale”; if it is aimed at teaching, a more rigorous orbital model is needed. In engineering evaluation, it is important to distinguish “visual illustration” from “scientific simulation,” and to avoid letting the model’s commonsense completion replace professional validation.

    2.2 Code Correctness

    Frontend code correctness involves at least three layers:

    • It can run directly without additional dependencies;
    • The animation is continuous, smooth, and free of obvious misalignment;
    • The code uses valid SVG, CSS, and JavaScript structures.

    For example, in SVG the viewBox defines the coordinate system; if layer coordinates and responsive width/height handling are done poorly, content may be cropped on small screens. CSS rotation animations need to handle transform-origin correctly; otherwise, planets may rotate around the wrong center. If inline SVG lacks closing tags, namespaces, or accessibility descriptions, it also hurts compatibility and maintainability.

    2.3 Visual Fidelity and Information Expression

    “Having eight planets” does not mean “the solar system relationships are expressed correctly.” The mental model should make clear: whether the Sun is at the center; whether the orbits are closed; whether the planets orbit in the same plane; whether there is a parent-child hierarchy between Earth and the Moon; whether Saturn’s rings move with the planet. Visually, information should also stay readable — avoid colors that are too dark, elements that are too small, or overlapping orbits. For science-communication pages, it is even more important to add a legend, titles, and necessary explanations.

    2.4 Animation Mechanism and Performance

    Generated code commonly uses one of three animation approaches: CSS keyframe animations, SVG native animation capabilities, or frame-by-frame updates driven by scripts. The CSS approach is simple and strongly declarative, well suited to constant-speed loops; the script approach is flexible and can express elliptical orbits, speed changes, and interactive control, but costs more to implement. Engineering evaluation should choose an approach based on complexity rather than only asking “does it move?”

    A maintainable implementation should try to separate celestial-body data from rendering logic. For example, use data to describe a planet’s radius, orbital radius, and revolution period, and let the renderer generate the graphics uniformly. This makes it clearer to add planets, adjust speeds, or connect a control panel later.

    3. An Illustrative Implementation: Separating Data and View

    Below is a simplified example. It uses native HTML, CSS, and SVG, controls the revolution duration of different planets through CSS variables, and adds an accessibility adaptation for reduced motion. The example does not aim for a complete astronomical simulation; it focuses on demonstrating a structured way of writing.

    1. <!doctype html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="utf-8" />
    5. <meta name="viewport" content="width=device-width, initial-scale=1" />
    6. <style>
    7. .stage {
    8. width: min(92vw, 720px);
    9. aspect-ratio: 1;
    10. display: block;
    11. margin: 2rem auto;
    12. background: #05070d;
    13. border-radius: 24px;
    14. }
    15. .orbit {
    16. fill: none;
    17. stroke: rgba(255, 255, 255, .18);
    18. stroke-width: .6;
    19. }
    20. .planet {
    21. transform-box: view-box;
    22. transform-origin: 100px 100px;
    23. animation: spin var(--dur, 12s) linear infinite;
    24. }
    25. @keyframes spin {
    26. to { transform: rotate(360deg); }
    27. }
    28. @media (prefers-reduced-motion: reduce) {
    29. .planet { animation: none; }
    30. }
    31. </style>
    32. </head>
    33. <body>
    34. <svg class="stage" viewBox="0 0 200 200" role="img"
    35. aria-labelledby="title desc">
    36. <title id="title">Solar system animation demo</title>
    37. <desc id="desc">The Sun is at the center, with several planets orbiting along circular paths.</desc>
    38. <defs>
    39. <radialGradient id="sunFill">
    40. <stop offset="0" stop-color="#fff7b0" />
    41. <stop offset="1" stop-color="#ff9f1a" />
    42. </radialGradient>
    43. </defs>
    44. <circle cx="100" cy="100" r="15" fill="url(#sunFill)" />
    45. <g class="planet" style="--dur:8s">
    46. <circle class="orbit" cx="100" cy="100" r="28" />
    47. <circle cx="128" cy="100" r="3.5" fill="#9bd7ff" />
    48. </g>
    49. <g class="planet" style="--dur:14s">
    50. <circle class="orbit" cx="100" cy="100" r="42" />
    51. <circle cx="142" cy="100" r="5" fill="#4d9cff" />
    52. </g>
    53. <g class="planet" style="--dur:22s">
    54. <circle class="orbit" cx="100" cy="100" r="58" />
    55. <ellipse cx="158" cy="100" rx="9" ry="3.5"
    56. fill="none" stroke="#f5d38a" stroke-width="1.5" />
    57. <circle cx="158" cy="100" r="5" fill="#ffd27a" />
    58. </g>
    59. </svg>
    60. </body>
    61. </html>

    The advantages of this approach are a clear structure, few dependencies, and easy embedding into pages; the drawback is limited support for complex orbits and interactive control. To implement the Moon orbiting Earth, you can add a nested group inside the corresponding planet layer, or use a script to compute the position of each body uniformly. In engineering, choose an approach based on requirements, and avoid keeping hard-coded, hard-to-maintain repetitive code in the generated result.

    4. Prompts Should Be Written as “Acceptance Contracts”

    To improve the usability of generated results, a prompt should describe not only “what to do” but also “by what standard to deliver.” The following structure can be used:

    • Role and goal: Ask for the perspective of a senior frontend engineer, outputting a directly runnable single-file example.
    • Technical constraints: Use only native HTML, CSS, JavaScript, and inline SVG, with no external dependencies.
    • Structure and readability: Separate celestial-body data from rendering logic, use clear variable names, and comment key coordinates and animation parameters.
    • Visual requirements: Use viewBox for adaptivity, keep orbit and planet hierarchy clear, and ensure sufficient color contrast.
    • Animation requirements: Use loopable animations, avoid high-frequency script reflows, and support the system’s reduced-motion setting.
    • Accessibility: Include title, desc, and appropriate ARIA descriptions in the SVG.
    • Security and compatibility: No external requests, no inline event handlers, and compatibility with mainstream modern browsers.
    • Acceptance checklist: After outputting the code, include self-check results explaining the animation mechanism, maintainability, and known limitations.

    Designing the prompt as “requirements + constraints + acceptance checklist” can significantly reduce the rework cost caused by the model’s free improvisation. For enterprise development workflows, you can further inject the team’s coding standards, design variables, browser compatibility matrix, and component conventions into the context so that generated results align more closely with the actual engineering system.

    5. Engineering Quality Gates

    A satisfying demo is not enough to prove stable capability. A more reasonable approach is to bring generated frontend code into the existing quality gates.

    5.1 Structure Check

    Check whether the output is a complete, runnable document, whether tags are closed, and whether any disallowed external resources are referenced. For SVG, validate the viewBox, graphic coordinates, naming conflicts, and accessibility nodes.

    5.2 Runtime Check

    Load the page in an isolated environment, capturing script errors, resource-loading failures, and layout overflow. If the page contains animations or interactions, set up basic end-to-end validation: whether the animation starts, whether it loops, and whether pause logic works.

    5.3 Visual Regression

    Take screenshots of key pages and compare them against reasonable pixel thresholds. Although a solar system animation is simple, it can still verify orbit positions, element proportions, and small-screen layout. Visual regression should not rely too heavily on a single screenshot; check across different sizes and reduced-motion modes together.

    5.4 Performance Budget

    Set budgets for the number of SVG nodes, the number of animated elements, and the frequency of script execution. If every planet is updated by high-frequency scripts, it can bring unnecessary computational overhead; relatively simple loop animations are better suited to a declarative approach. Complex scenarios can use strategies such as layered rendering, pausing invisible animations, and on-demand updates.

    5.5 Security Boundary

    Before generated code enters a preview environment, isolate resources and scripts. Avoid executing unknown content directly; restrict possible script injection, external requests, and permission access. The preview environment should be untrusted by default, and only enter a real page after review passes.

    5.6 Human Review

    The model is good at completing common patterns but may overlook scientific accuracy, business rules, and brand standards. Human review should focus on semantic correctness, data sources, the meaning of interactions, and long-term maintenance cost, rather than only checking “whether the page moves.”

    6. Recommendations for Team Adoption

    For teams that want to improve frontend development efficiency, it is advisable to start with small, verifiable scenarios rather than opening up full page-generation capability all at once. You can begin with lower-risk tasks such as static displays, reusable charts, simple animations, and prototype validation, and gradually accumulate prompt templates, code templates, and acceptance checklists.

    At the toolchain level, you can integrate generation into an assistive step before code review, outputting patches or standalone preview pages for developers to confirm before merging. For page skeletons with high repetition, you can combine model generation with internal component standards, data formats, and test cases to reduce unconstrained generation. For complex business logic, developers should still lead the design, with the model taking roles such as drafting, local refinement, and organizing repetitive code.

    For team-wide adoption, you can also combine general-purpose model services from Baidu AI Cloud with foundational cloud services such as logging and monitoring to build an auditable chain among generation, preview, review, testing, and release. The key is not to pursue “go live with a single sentence,” but to let generated results enter a controlled, rollback-capable, and measurable development workflow.

    7. Conclusion

    The solar system SVG animation case shows that large models can already understand frontend generation tasks fairly well and output prototypes with visual appeal and a certain level of completeness. However, there is still a clear gap between demo-level results and engineering-level delivery. Whether the semantics are accurate, whether the code is robust, whether the animation is efficient, whether the page is accessible, and whether the content is maintainable all need to be part of the evaluation framework.

    For developers, a more valuable approach is to treat the large model as an efficient frontend draft generator and solution explorer, embedding its capabilities into the software development lifecycle through clear prompt contracts, structured code templates, automated quality gates, and necessary human review. Only then can a “solar system animation”-style impressive experience be turned into reusable, measurable development-efficiency gains.