AI Agent–Generated Flight Booking Pages: Key Points for Seat Locking

    This article explains how to turn an AI Agent–generated flight booking page into a production-ready implementation. It covers data-driven frontend rendering, performant CSS animations, and the two concurrency risks in the original sample's seat-booking code, along with a corrected Node.js/Mongoose implementation that uses unique indexes and conditional updates to guarantee that a seat can only be booked once.

    The original article’s title mentioned three scenarios, but the body only covered the website of a near-Earth-orbit travel company. Therefore, this article discusses only the flight booking page and does not cover the deep-sea exploration agency website or the perfume showcase page.

    Conclusion First

    Given clear requirements, an AI Agent can quickly generate a runnable page with routes, data models, and basic APIs. However, seat concurrency, animation performance, and cloud deployment still require deliberate design and verification by developers. The original demo did not include independent load testing, so the practices below should be treated as an implementation checklist.

    Frontend: Data-Driven Pages and Animations

    The page includes a full-screen background, an indicator light showing the system is online, a monospace flight data panel, and a vertical timeline. The timeline runs from ground preparation all the way to capsule splashdown.

    Every stage of the timeline should come from a single data source. Do not hardcode text and statuses in the template. Here is a sample data file:

    1. [
    2. { "t": "T-60:00", "title": "Ground preparation", "status": "done" },
    3. { "t": "T-00:10", "title": "Fuel loading complete", "status": "active" },
    4. { "t": "T+92:00", "title": "Capsule splashdown", "status": "pending" }
    5. ]

    The status indicator can be implemented with CSS @keyframes. Animations should prefer modifying transform and opacity, as these properties usually do not trigger page reflow. Modifying width, height, or position forces the browser to recalculate layout, which easily causes frame drops on low-end devices.

    1. .status-dot {
    2. animation: breathe 2s ease-in-out infinite;
    3. will-change: transform, opacity;
    4. }
    5. @keyframes breathe {
    6. 0%, 100% { opacity: 0.4; transform: scale(1); }
    7. 50% { opacity: 1; transform: scale(1.15); }
    8. }
    9. @media (prefers-reduced-motion: reduce) {
    10. .status-dot { animation: none; }
    11. }

    The prefers-reduced-motion check lets users who are sensitive to motion disable the effects.

    Backend: The Key Risks in Seat Booking

    The original sample code had two risks. First, when a flight did not exist, the code reported “seats are full”—an error message that did not match the actual cause. Second, the code read the remaining seat count before deciding whether to book. Under concurrent requests, the number read may already be stale, and two requests could both pass the check.

    The improvement has two layers.

    1. Split seats into independent documents, one record per seat, and create a unique index on (flightId, seatNumber). A unique index can only prevent duplicate records for the same seat; it cannot prevent two requests from simultaneously booking the same existing seat.
    2. Use a conditional update when booking. The seat is modified only if its status is still available, and the result returned by the database is the sole source of truth—do not rely on a number read beforehand.

    The following code runs on Node.js 20 or higher, Mongoose 8.x, and MongoDB 6.0 or higher.

    1. // Create the index only once. If duplicate data already exists,
    2. // clean it up before creating the index.
    3. // db.seats.createIndex({ flightId: 1, seatNumber: 1 }, { unique: true })
    4. const mongoose = require('mongoose');
    5. const Flight = mongoose.model(
    6. 'Flight',
    7. new mongoose.Schema({ code: { type: String, required: true, unique: true } })
    8. );
    9. const seatSchema = new mongoose.Schema(
    10. {
    11. flightId: { type: mongoose.Schema.Types.ObjectId, required: true, ref: 'Flight' },
    12. seatNumber: { type: String, required: true, trim: true },
    13. status: { type: String, enum: ['available', 'booked'], default: 'available' },
    14. passengerId: { type: mongoose.Schema.Types.ObjectId, default: null },
    15. bookedAt: { type: Date, default: null },
    16. },
    17. { versionKey: false }
    18. );
    19. seatSchema.index({ flightId: 1, seatNumber: 1 }, { unique: true });
    20. const Seat = mongoose.model('Seat', seatSchema);
    21. class BookingError extends Error {
    22. constructor(code, message) {
    23. super(message);
    24. this.name = 'BookingError';
    25. this.code = code;
    26. }
    27. }
    28. async function bookSeat(flightId, seatNumber, passengerId) {
    29. // 1. Validate parameters. The seat number format follows business rules;
    30. // here we use "a letter followed by digits" as an example.
    31. if (!mongoose.isValidObjectId(flightId)) {
    32. throw new BookingError('INVALID_FLIGHT_ID', 'Invalid flightId format');
    33. }
    34. if (typeof seatNumber !== 'string' || !/^[A-Z]\d{1,2}$/.test(seatNumber)) {
    35. throw new BookingError('INVALID_SEAT_NUMBER', 'Invalid seat number format');
    36. }
    37. if (!mongoose.isValidObjectId(passengerId)) {
    38. throw new BookingError('INVALID_PASSENGER_ID', 'Invalid passengerId format');
    39. }
    40. // 2. Confirm the flight exists first, to avoid misreporting
    41. // "flight not found" as "seats are full"
    42. const flightExists = await Flight.exists({ _id: flightId });
    43. if (!flightExists) {
    44. throw new BookingError('FLIGHT_NOT_FOUND', 'Flight does not exist');
    45. }
    46. // 3. Conditional update. The seat is modified only if its status is
    47. // "available"; the returned value is the sole basis for the decision.
    48. const seat = await Seat.findOneAndUpdate(
    49. { flightId, seatNumber, status: 'available' },
    50. { $set: { status: 'booked', passengerId, bookedAt: new Date() } },
    51. { new: true }
    52. ).lean();
    53. if (seat) return seat;
    54. // 4. If the update failed, distinguish the cause afterwards
    55. const seatExists = await Seat.exists({ flightId, seatNumber });
    56. if (!seatExists) {
    57. throw new BookingError('SEAT_NOT_FOUND', 'This flight has no such seat');
    58. }
    59. throw new BookingError('SEAT_TAKEN', 'Seat is already booked');
    60. }
    61. // Seed seats. A unique index conflict means the seat already exists;
    62. // skip it and log the event.
    63. async function seed