AI Booking Platform Case Study

A booking engine where a business is configuration, not code. Clients book from a live calendar, and an AI assistant answers from a knowledge base the admin manages, with citations, and never acts without the user's confirmation.

A one-minute walkthrough: the calendar (filter, month, list, one-click booking and undo), a cited answer, a confirmation card, then an admin changes a booking rule and the assistant quotes the new value.

The problem

It is 9pm. A client wants to know what a consultation costs, how late they can cancel, and whether they can move next week's appointment. The booking page shows times, but not the answers. The owner is replying to the same questions by email, one at a time, after a full day of appointments.

The questions repeat every week, and each slow reply is a chance for the client to book somewhere else or arrive expecting a price or service the business does not offer.

A receptionist could help during the day, but not at 9pm, and not without the same calendar and policy answers. A chatbot could take the questions, but handing one the power to book or cancel risks moving a real person's appointment on a wrong guess. The business needs an assistant that knows its prices, policies, and calendar, and still asks before it changes anything.

How it fits together

AI Booking Platform puts both halves in one place. Clients book from a live calendar, and the assistant answers from the business's own prices, policies, and availability. Any change it suggests waits for the client to confirm, so a wrong guess cannot move an appointment.

Every change to data goes through one service layer that holds the rules. The pages, the REST routes, and the assistant all use it, so the assistant can't do anything a click couldn't. Its tools only return proposals, and confirming one calls the same REST API a click would.

How the booking platform fits together The browser talks to route handlers, which call one service layer that holds the rules and talks to PostgreSQL. The assistant uses retrieval over pgvector for answers and can only send proposals to the same service layer. BrowserReact UI Route handlersZod, auth, rate limits Service layerrules + transactions AI assistantrole-scoped tools + LLM Retrievalrole-filtered search PostgreSQLPrisma + pgvector proposals only asks
  1. Pages and clicks: the browser calls route handlers (Zod validation, auth, rate limits), which call the service layer (rules and transactions), which writes to PostgreSQL.
  2. The assistant: it searches the knowledge base through retrieval that only returns what the asking role may read, and it can only send proposals to the same service layer.

Four decisions

The assistant prepares, the user confirms

A booking assistant that acts on a wrong guess is worse than none. Its tools return proposals that appear as a confirmation card, and only the user's click runs them. Tool output sent from the browser is discarded, so nobody can forge a proposal.

Trade-off: one extra click and slower than a fully autonomous agent, in exchange for an assistant that can't double-book or cancel the wrong appointment. A live suite of about 120 checks (prompt injection, data leaks, scope, ambiguity, Arabic, multi-turn) gates every prompt change.

A knowledge base the admin controls

Admins add, edit, upload, and hide documents in the app, file them under their own sections, and choose which roles can read each one. Retrieval filters on that in SQL, so the assistant never cites something the asking role can't see.

The booking rules are part of it: change the cancellation cutoff in Settings and the assistant quotes the new value straight away, as in the video.

Trade-off: every edit is chunked and embedded, and switching the embedding model means re-indexing everything.

A business is configuration, not code

The code never names its domain. What clients, providers, and appointments are called, the field labels, the landing copy, the assistant's scope, the guest personas, the knowledge base, and the sample data all come from one domain profile. Two ship side by side, a business-setup consultancy and a university, and a unit test fails if a profile's words leak into code. The engine grew out of my AI Appointment Scheduler.

Trade-off: generic names in the code (client, provider, admin) and some up-front abstraction, paid back by switching business without touching code.

Sharing an admin login with strangers

The guest admin's password is on the landing page, so I treat it as anyone on the internet. It can't lift the abuse limits or close registration, its knowledge changes expire after 24 hours, and settings and document saves carry the version they loaded, so a stale form gets a conflict instead of overwriting a newer change.

Trade-off: visitors share the guest accounts and their daily limits, and a visitor can still make a mess until the weekly reset. A real deployment has none of this, because the guest accounts are switched off.

Details

The full feature set and the engineering behind it, including security, concurrency, email, and testing.

Features

Clients
  • Browse every advisor's open slots on a week, month or list calendar, filter by practice area, and book in one click with an optional note.
  • Reschedule, cancel and undo, export to a calendar app (.ics), and get reminders and live notifications, plus booking, change and reminder emails when they turn email on.
Advisors
  • Publish availability as single slots, back-to-back runs or weekly repeats, and close or reopen slots.
  • Move or cancel appointments, and undo their own changes for 15 minutes.
Admins
  • An overview, user management (create clients, advisors or admins, edit, deactivate; each role's main account can't be deactivated), appointment cancellation, and a cross-user activity log.
  • Settings without a deploy: booking rules within the engine's safe range, feature toggles (rescheduling, note edits, weekly repeats, undo, a required cancellation reason), per-account abuse limits and the registration policy, effective immediately, journaled, and quoted by the assistant.
  • Knowledge base: create, edit, upload, delete and restore the documents the assistant answers from, each visible to everyone or to chosen roles, organised in sections.
AI assistant
  • Scoped to each role; answers questions about services and policies with citations.
  • Prepares bookings, reschedules, cancellations, notes and slot changes as confirmation cards that run only after you confirm.
  • Understands follow-ups, relative dates and Arabic, never invents prices, and leaves case-specific advice to a consultation.
Everyone
  • One-click guest sign-in for client, advisor and admin, a header switch between the three guest roles, and a weekly sample-data refresh.

Technical details

Architecture
  • Next.js 16 (App Router), React 19, TypeScript in strict mode and Tailwind CSS 4.
  • Route handlers validate every input with Zod.
  • One write path: every change goes through lib/services (checks, then a transaction that journals the change for undo); limits live in lib/rules.ts, which feeds enforcement, the rules popover, the assistant's prompt and the tests.
  • Everything is entered and shown in the business's time zone (IANA, DST-safe).
The business is configuration
  • The code never names its domain: what clients, providers and appointments are called, the field labels, landing copy, the assistant's scope, guest personas, knowledge base and seed data all come from one domain profile.
  • Two profiles ship side by side (a business-setup consultancy and a university), and a unit test fails if a profile's words leak into code.
Configurable knowledge base
  • Admins manage it in the app, with no deploy: create and edit documents, upload up to 20 markdown or text files in one all-or-nothing batch, hide and restore them, and file them under sections they add, rename and reorder.
  • Per-role visibility: each document, and each section's default for new ones, is visible to everyone or to any set of roles, and retrieval filters on that in SQL, so the assistant never cites a document the asking role can't read.
  • Rules feed the assistant: the booking-rules document and the role guides are rendered from templates with the current settings, so a rule changed in Admin is quoted by the assistant straight away.
  • Every edit, upload and rule change is chunked, embedded and written through the same service, journaled, and searchable and filterable in the database.
  • Uploads are text-only, size-capped by counting bytes and never written to disk, and invisible or bidirectional text is rejected, with an adversarial test suite behind it.
  • On the public build, the shared guest admin's changes expire after 24 hours.
Data and concurrency
  • PostgreSQL 16 with pgvector through Prisma 7.
  • A slot is claimed with a conditional update; the client's row is locked so overlap and fairness checks (no double-booking, at most 2 upcoming appointments per advisor) cannot race.
  • Concurrency is tested against a real Postgres.
AI assistant
  • Retrieval: documents are chunked (about 600 tokens, 12% overlap), embedded as 384-dimension vectors and fetched from pgvector, with each role retrieving only its own guide, filtered in SQL.
  • Generation: DeepSeek through the Vercel AI SDK with 15 role-scoped tools and streamed answers with citations.
  • Safety: tools only return proposals, a confirmation calls the same REST API a click would, and client-sent tool output is discarded.
  • Cost and abuse: per-user and per-IP limits, a shared daily assistant budget on the public build, and a prompt layout that keeps 93–94% of the assistant's input served from the provider's cache on full live runs.
  • Evaluation: a retrieval eval of 22 golden questions and a live suite of about 120 checks (injection, data leaks, scope, ambiguity, Arabic, multi-turn) that gates prompt changes.
Security
  • Roles and deactivation are re-read from the database on every request; every API route outside sign-in, registration and health is guarded; admin, slot and booking routes require their role; ownership is checked in the service layer rather than assumed from an id; and admin pages re-check before any data loads.
  • bcrypt passwords with timing-safe failed sign-ins, HttpOnly, SameSite and Secure session cookies with Auth.js's CSRF token, per-IP and per-account sign-in limits (Upstash), and a password change that signs out every other device.
  • Nonce-based CSP with strict-dynamic, HSTS, nosniff, frame denial, a strict referrer policy and a permissions policy; Zod on every input, JSON-only bodies with byte-counted caps, parameterized Prisma queries, React escaping with chat and knowledge shown as plain text, and database connections that verify TLS certificates.
  • A public admin login that's safe to share: the guest admin can't lift abuse limits or close registration, its knowledge changes expire after 24 hours, and stale forms get a conflict instead of overwriting a newer change.
  • Sentry error tracking with personal-data collection off; Dependabot and a CI dependency audit; secrets only from the environment, and the Docker image runs as a non-root user.
Appointment email
  • After the write, never inside it: booking confirmations, cancellation and reschedule notices, and reminders are queued in an outbox, and the notices are written only once the change commits, so a mail failure can't fail the booking.
  • Sent by an hourly job through Resend, with retries, stale-row recovery and dedupe keys; a bounce or spam complaint turns email off for that account.
  • Guest accounts and anyone with email off are skipped, and an account can send itself a test email from Account settings.
Testing and delivery
  • 357 unit, 320 integration (against Postgres) and 89 end-to-end tests, including axe accessibility scans (WCAG 2.1 AA) in light and dark.
  • CI on every push; a Docker image with managed Postgres, expand-then-contract migrations so the live site keeps working while the database changes, and a weekly sample-data refresh.

What I'd do for a real business

The public build's features are switched off or inert on a real deployment, and nothing has to be deleted: turn off the guest accounts, start from an empty database with a first admin, and load the business's own knowledge base. Around that: an always-on instance with an uptime alert and a custom domain, a verified sending domain for appointment email, a managed Postgres with point-in-time restore, a spending limit on the AI model, and a privacy policy that names who processes what (the host, the AI provider, which sees chat messages and the passages it retrieves, and the embedding provider). Before inviting users, the business's own questions go through the retrieval eval, each role is tried once on the live site, and a restore from backup is tested.

What it doesn't cover yet

  • The retrieval eval describes the content files, so it doesn't cover documents an admin creates or edits in the app; the live assistant suite's knowledge scenarios do.
  • The live assistant suite covers the consultancy profile only; the university profile has its own knowledge base but no restored scenario set yet.
  • Email goes out for appointment confirmations, changes and reminders, but there's no password recovery or email verification yet, and no multi-factor sign-in.
  • One business per deployment, and no payments.
  • It's a public build: the guest accounts are shared with every visitor and reset weekly, so it shows the product rather than running a business.

← Continue or get in touch.