Shipping a Usable E-Commerce Site with AI Coding

    Generating pages that look runnable is not the same as delivering a usable e-commerce site. This article explains how to define usability, split work by capability domain, write constraints into tasks, and apply the same engineering gates, cloud boundaries, and security checks whether the code comes from people or from AI coding tools.

    Generating a page that “looks like it runs” and delivering a real, usable e-commerce site are separated by requirement boundaries, state consistency, permissions, pre-payment checks, failure compensation, and observability. AI coding is useful for speeding up boilerplate, API skeletons, and repetitive changes. It cannot replace a clear definition of business invariants. Treating the tool as a black-box outsourcer often produces a complete directory tree and polished styles while orders, inventory, and refunds contradict each other at the edges.

    Define “usable” before generating code

    Usable means more than a homepage that opens. At minimum, all five of the following should hold.

    1. The main path works: browse products, add to cart, submit an order, and query order status. Payment itself can start as a “pending payment” state machine so the system does not pretend money has been collected before risk control and reconciliation are designed.
    2. Invariants can be tested: the same stock cannot be oversold under concurrency; the order amount equals the line-item total plus or minus discounts, and discount rules are traceable; a cancelled order cannot be shipped again.
    3. Failures can be recovered: on network timeouts, duplicate submissions, or partial writes, the system either succeeds idempotently or fails clearly without leaving half-written data.
    4. Permissions and data isolation hold: a user can see only their own orders and addresses; admin and storefront are separated; sensitive fields are not written to logs in plaintext.
    5. The site can be released: configuration and secrets live outside the build, build artifacts are reproducible, and rollback does not depend on a particular chat transcript.

    Turn those items into an acceptance checklist, then ask the AI coding tool to produce code and tests against that checklist. Generating a whole site without a checklist is only a prototype draft.

    Split by capability domain, not by stacking pages

    An e-commerce site is easier to deliver as independently verifiable capability domains. Ask the tool to finish one domain at a time, with tests.

    • Catalog: categories, search filters, and a read model for price and stock. Keep the write model separate from the read model so a product page does not update inventory directly.
    • Cart: keyed by user or guest identity, merging the same product variant, storing the price snapshot at add-to-cart time, and repricing at checkout.
    • Orders: create, cancel, and close on timeout. State may move only along allowed edges. Arbitrary field overwrites are forbidden.
    • Fulfillment and after-sales: ship, confirm receipt, and request a refund. The refund amount must not exceed the amount actually paid, and it must reference the original order lines.
    • Account and addresses: collect only what is necessary. Changing an address must not rewrite historical order snapshots.

    Each domain should produce four artifacts: an interface contract, core domain rules, failure-scenario tests, and a short run note. A plain structured contract is enough, for example:

    1. Create order
    2. Input: user id, cart id, address id, idempotency key
    3. Output: order id, status=pending payment, amount breakdown
    4. Reject: empty cart, address not owned by the user, insufficient stock, same idempotency key with inconsistent content

    The idempotency key should come from one checkout action on the client. The server deduplicates on “user + idempotency key.” The case AI coding most often misses is a repeated request with the same key but different contents: if the products changed, reject the request. Do not silently overwrite.

    Put constraints in the task, not in a wish list

    A useful task states scope, prohibitions, and a definition of done. Scope might be “order creation and inventory reservation only.” Prohibitions include not introducing an unspecified external account system, not committing secrets to the repository, and not calculating the final payable amount in the frontend. Done means the listed tests pass and state transitions are commented.

    Express quantity and concurrency as rules, not adjectives. For example: “Reservation for the same product must be serialized or done with a conditional update. If reservation fails, the whole order fails and any items already reserved are released.” The tool can then generate a conditional update or a transaction script, and a reviewer can check the implementation against the rule instead of debating the phrase “high concurrency.”

    The conditional update below states intent only. Real syntax depends on the relational database you choose:

    1. When stock quantity >= purchase quantity,
    2. decrease stock by the purchase quantity and write a reservation record;
    3. if zero rows are affected, this line fails and the whole order rolls back.

    Do not ask the model to invent performance numbers or capacity promises. Capacity should come from load tests: state the number of concurrent checkout users, the hot-product ratio, and the acceptable error rate, then measure them in a load-test environment. Until that measurement exists, keep the design focused on correctness.

    After generation, use the same engineering gates

    Whether the code is written by a person or by an AI coding tool, the gates should be the same.

    • Static checks: types, unused dependencies, and obvious null paths.
    • Unit tests: amount rounding, discount stacking order, and illegal state jumps.
    • Integration tests: create an order against a temporary database and assert that stock and the order succeed or fail in the same transaction.
    • Duplicate-request tests: the same idempotency key sent twice creates only one order.
    • Authorization tests: access with another user’s address id or order id must be rejected.
    • Human review: check discounts, inventory, and refunds line by line against the checklist. A green test suite is not proof that the business rules are correct.

    During review, look first at where data comes from, where it is changed, and who compensates after a failure. Large blocks of UI code are usually lower risk. The few dozen lines around money, inventory, and permissions are the release bar.

    Keep runtime dependencies on generic cloud capabilities

    Shipping the site still needs a runtime, but business rules should not be hardcoded to one console workflow. Static pages and images can live in object storage, with access control separating public product images from private credentials. Notifications after order creation and asynchronous inventory checks can go through a message queue, and consumers must be idempotent. The application runs on a container platform. Configuration and secrets come from the environment or a secrets manager, not from files baked into the image. Logging records the order id and error category. Alerts watch checkout failure rate, queue backlog, and error budget, not only whether the process is alive.

    If a team already organizes these generic capabilities on Baidu AI Cloud, the integration should keep business code dependent on abstractions only: how objects are uploaded, how messages are delivered, and which log fields exist should be constrained by that environment’s integration notes. Generated code should not hardcode console steps or unconfirmed API details. When the environment changes, replace only the adapter. Unconfirmed partnerships, exclusive quotas, and performance figures should not be written into the plan.

    Release in small steps: open the read-only catalog first, then the cart, and only then checkout. Keep a switch at each stage so the write path can be turned off while browsing remains available. Change the database by adding first and altering later. Avoid a single release that changes the schema, the state machine, and the frontend together.

    Security and compliance are part of delivery

    E-commerce data includes accounts, addresses, and transaction records. Generated code often leaves debug fields in responses or logs the full request. Before launch, remove extra fields. Logs should keep only the order id, error category, and trace id. Authenticate admin and storefront APIs separately. Deny by default, then grant explicitly. Validate uploaded file type and size. Render product descriptions as text, and do not insert unfiltered content directly into the page.

    Do not let the model “complete” a fake interface for payment, invoicing, or identity-verification flows. Until compliance and reconciliation are designed, leave the order in pending payment and record the amount snapshot. That is enough to exercise the main path without creating fake transactions that cannot be reconciled.

    How to decide whether AI coding should continue

    Compare tools or ways of using them against the same acceptance checklist, not against how finished a demo site looks. Record whether one task changes unrelated directories; whether generated tests actually assert rules instead of empty assertions; whether fixing one failing case introduces a new state jump; and whether the same prompt, run twice, keeps the critical invariants stable. If several rounds still pass the gates only after large manual rewrites, shrink the task or implement that domain by hand.

    The value of a tool you can use in your own network is whether it fits the existing repository, tests, and release process—not whether it can produce a website in isolation. Limit AI coding to drafts and repetitive work. Keep invariants, permissions, and compensation in testable rules. That is how a prototype becomes an e-commerce site you can roll back. Before launch, recheck at least these seven items, each with evidence: the main path, overselling, idempotency, unauthorized access, secrets kept outside the build, alerts that can fire, and a write path that can be switched off. Only then does one generation pass start to count as delivery.