Back to Blog
Guides

How to Build a Scheduling App with AI

Build a Calendly-style booking app in Layerwise with event types, booking rules, time zone handling, and no double booking, then test and publish it.

QWQing Wang
Table of contents

A scheduling app looks small: a calendar, a list of times, and a form. The decisions that shape it are less visible. Is 9:00 in the host's time zone or the guest's? Which times are open once buffers, notice, and days off are counted? What happens when two guests pick the same slot at once? Who can move a booking, and how does the other person find out? Answer those before asking an AI to write code, and the first version is much easier to test.

This guide builds an appointment booking web app, like Calendly or Cal.com, in Layerwise. You will define event types and bookings, compute open times across time zones, prevent double booking, start from the Slotly template or a prompt, test with two time zones and two guests, and publish. If you are weighing hosted tools first, see our guide to the best Calendly alternatives.

Slotly scheduling app template landing page with a sample booking widget

1. Define event types and bookings

A booking app has three records. An event type is something a guest can book: a title, URL slug, duration, location, and its own booking rules. The host's profile holds a username, time zone, weekly hours, date overrides, and buffers. A booking ties one guest to one event type at one time. This is a simplified version of the records in Slotly:

type EventType = {
  id: string;
  ownerId: string; // the host
  slug: string; // guests book at /book/<username>/<slug>
  title: string;
  duration: number; // minutes
  minNotice: number; // minutes between now and the earliest start
  bookingWindow: number; // how many days ahead guests can book
  slotInterval: number; // start times every N minutes
  dailyLimit: number | null; // confirmed bookings per day, or no limit
  locationKind: 'none' | 'video' | 'phone' | 'in_person' | 'custom';
  locationValue: string; // a link, phone number, address, or note
  active: boolean;
};

type Booking = {
  id: string;
  token: string; // random UUID in the guest's private link
  ownerId: string;
  eventId: string;
  start: number; // UTC milliseconds
  end: number;
  busyStart: number; // start minus the buffer before
  busyEnd: number; // end plus the buffer after
  guestName: string;
  guestEmail: string;
  guestTimezone: string; // IANA name, such as Europe/London
  notes: string;
  status: 'confirmed' | 'cancelled';
  cancelReason: string; // optional, shown on both sides
  cancelledBy: 'guest' | 'host' | null;
  cancelledAt: number | null;
  createdAt: number;
};

A few fields matter more than they look. busyStart and busyEnd save the blocked interval with the booking, so lowering a buffer later never shrinks time already protected. status makes cancellation a change of state, which keeps history, and the cancellation fields record who cancelled, when, and why. For the same reason, Slotly will not delete an event type with bookings; you turn off Accept bookings instead, which takes its link offline and keeps every booking.

Location is a kind and a value. An in-person address or a custom note appears on the public booking page. A video link or phone number appears only after the guest books, so sharing a booking link does not hand your meeting room to everyone who opens it.

2. Store instants, compute open times in the host's time zone

Store booking times as UTC instants, and availability the way the host thinks about it: wall-clock hours in a named time zone. In Slotly, each weekday has one window such as 09:00 to 17:00, the profile has a time zone such as America/New_York, and a date override either blocks a date or replaces its hours. Buffers before and after meetings apply across event types.

For a date in the guest's time zone, the server steps through real instants five minutes apart and keeps a start time that:

  • falls on the event's Start times every grid on the host's clock, such as :00 and :30;
  • is at least Minimum notice away and no further out than Bookable up to allows;
  • lets the whole meeting fit one day's window in the host's time zone;
  • overlaps no confirmed booking for the host, across event types, buffers included;
  • leaves the event type under its Daily limit, counted on the host's calendar day.

Stepping through instants, rather than adding hours to a local time, keeps daylight saving changes correct. The server checks the same rules again when a booking is saved, so a crafted request cannot book outside the host's hours.

The booking page starts in the guest's browser time zone, lets the guest pick another, and saves the chosen zone with the booking. Days that the hours, notice, and booking window rule out are disabled on the calendar. A day can still turn out to be full, so the time list is the final word, and it refreshes every 30 seconds while the page is open.

A guest in London picking a coaching session time on Slotly's booking page

3. Prevent double booking and handle changes

A list of open times is a snapshot. If code reads bookings and then inserts, two guests submitting seconds apart can both get through. Slotly puts the check inside the write: one INSERT ... SELECT ... WHERE NOT EXISTS statement adds the booking only if the event type is active, no confirmed booking for the host overlaps it, and the daily limit has room. Otherwise the guest sees "That time was just taken. Please choose another time." Overlaps use the larger of each booking's saved buffer and the current one, so raising a buffer also protects meetings booked before the change.

Each confirmation lives at a private link containing the booking's token. Anyone with that link can view, reschedule, or cancel, so the page is marked noindex and sends no referrer. Slotly sends no booking emails; the guest uses Copy next to Private link to this booking, and Add to calendar, which downloads an .ics file. Decide early whether a saved link is enough.

Rescheduling runs the same check in one UPDATE, ignoring the booking being moved. The update also requires the start time the request read first, so two reschedules racing from different tabs cannot both apply. If the new time is taken, the booking keeps its old one. Guests cancel from their link, and hosts cancel from the booking's details in Bookings. Either side can add a reason the other sees, and only future bookings can be cancelled.

Host actions check the signed-in user and touch only that user's records. Hosts sign in with a password or an emailed code through the project's authentication, and records live in its built-in database.

Keep the single-statement check when you add limits. Turn on Plan mode, described in Direct the agent, to review the approach before code changes:

Add an event type setting that limits each guest email to one upcoming
booking of that type. Enforce it in the same statement that checks for
overlaps and the daily limit, not in a separate query. Let a guest still
reschedule their existing booking, and show a clear message when they
already have one.

4. Choose a starting point

Download Layerwise, sign in, and select a team.

Slotly includes everything above, plus a landing page, a read-only demo workspace, an overview with booking counts and today's agenda, and bookings in list and calendar views with guest search. It sends no booking emails and does not sync external calendars. To start from it, open Slotly, choose Use this template, pick a team and project name in Layerwise, then choose Copy to Layerwise. Slot computation, time zones, booking rules, and the double-booking check are already implemented and tested, so your work is adapting them. Other workflows are in the template gallery.

To start from scratch, enter a description in Describe the app you want to build... on the team home page, including the decisions above:

Build a scheduling app like Calendly. A signed-in host sets weekly hours,
date overrides, buffers, and a time zone, and creates event types with a
duration, location, minimum notice, booking window, start time interval,
and optional daily limit. Guests book without an account and see times in
their own time zone. Store times in UTC. Save each booking in one statement
that fails if it overlaps another of the host's bookings or passes the daily
limit. Show video links only after booking. Give guests a private link to
reschedule or cancel with a reason.

A blank start lets you choose each behavior, but you must verify each one yourself. The prompting guide explains how to describe users, data, and screens.

5. Test with two time zones and two guests

Once the local preview loads, choose Try the demo on the landing page. The demo workspace has sample event types and bookings, so you can judge the layout right away. It is read-only; saving anything asks you to create an account.

Create two hosts with Add user in Authentication. Then:

  1. Sign in as the first host. In Settings, choose a Username and Save profile. In Availability, check the time zone, use Add under Date overrides to make the next weekday unavailable, set After meetings to 10 min, and choose Save changes.
  2. In Event types, choose New event type, enter a title and any https:// meeting link for Video call, and choose Create event type. Use Copy on its card.
  3. Open the preview in your default browser from the preview header. That browser doesn't share your session, so paste the link there as a guest. The page should say "Details sent after booking" instead of showing the link, and the blocked day should be disabled. Switch the time zone menu to a distant zone such as Asia/Tokyo; the same openings should appear at different local times. Book one, and the confirmation should show Join video call.
  4. As the host, open Bookings. The booking should be under Upcoming, and its details should show Guest's time in Tokyo. On the booking page, a time starting when that meeting ends should no longer be offered, because the buffer blocks it.
  5. Open the booking page in two tabs, pick the same time, and submit both. One should succeed and the other should show "That time was just taken. Please choose another time." Slotly's tests book one slot from 12 concurrent connections; ask the agent to run them after changing booking rules.
  6. From the guest's confirmation page, choose Reschedule and move the booking, then Cancel booking with a reason. Both times should be offered again, and the host should see the reason in the booking's details under Cancelled. Book once more and cancel it as the host from its details; the guest's page should show Booking cancelled with your reason.
  7. In Database, select Local and check guest_timezone, cancelled_by, and cancel_reason in the booking table. Finally, sign in as the second host and confirm none of the first host's event types or bookings appear.

Slotly bookings list grouped by day, with each guest's event type and status

Check phone width last. If a check fails, open the preview console from Preview actions, or find the failed request in Logs. If the console shows an error you don't recognize, look it up in the vibe coding errors reference.

6. Publish and improve it

Choose Publish in the preview header, then Publish in the menu, and open the live URL when the release finishes. Local and Online use separate databases, so test hosts and bookings are not copied. Sign up on the live app, set up availability and event types again, then book from your phone as a guest would. The publishing guide covers release status.

Choose the next change from what you observe. Analytics breaks pageviews down by path, showing which booking links get opened. Slotly does not send email or sync external calendars, so email is the usual first addition. Layerwise delivers your app's email, so there is no email service to set up:

When a booking is created, rescheduled, or cancelled, email the guest and the
host the time in each person's time zone, the cancellation reason if there
is one, and the guest's private link. Use Layerwise Email, and do not fail a
booking if email fails.

Start from Slotly if one host with weekly hours fits your business, or from a prompt if you need team scheduling or payments. Either way, settle time storage and the double-booking check before adding features. For the full project workflow, follow the Quick start.

View all posts →