• 2 min read

SmartCal

A Calendly-style booking app with a scheduling agent that proposes calendar changes and applies them only after the host approves.

Next.jsPostgreSQLPrismaGeminiTool callingVitest

SmartCal dashboard with the scheduling assistant open

What it is

A scheduling app in the style of Calendly, with an assistant built in.

A host sets up booking links, working hours, buffers, lead times, daily and weekly limits, and focus blocks. Invitees get a public page at /{handle}/{slug} that only shows times the server can actually book, in their own timezone.

Public booking page with dates and available times

The assistant can read the calendar, find open time, block focus time, prepare a booking, reschedule or cancel one, and create a new booking link. Invitees can also type something like “tomorrow morning” and get real slots back.

How the agent is kept in check

The agent can read freely but it can’t write anything on its own.

  • POST /api/ai/chat runs a Gemini tool loop capped at three iterations.
  • Read tools run right away, and only see the signed-in host’s data.
  • Write tools return a proposal and a signed approval token. They don’t change any data.
  • The chat shows each proposal as a card. When the host approves it, POST /api/ai/approve checks the session, the signature, the expiry and one-time use before running the command.
  • Approved actions go through the same booking code as the UI, which re-checks availability before writing.

The model never picks a time outside the server’s candidate list. It can’t run SQL, make HTTP calls, see OAuth tokens or send email directly. Each run is saved as an AgentRun with ordered AgentStep records, with emails, secrets and tokens redacted.

Hosts can also write rules in plain language. “No meetings before 10am” becomes {"windowStart":"10:00"}, and saving it still needs approval.

Working Hours page with the plain-language scheduling rule card

Bookings and side effects

  • Public bookings and reschedules carry an Idempotency-Key. A replay gets the stored response, and the same key with different data is rejected.
  • A PostgreSQL range constraint rejects overlapping active bookings for a host, even if two requests race.
  • Emails and calendar events go through an outbox with deduplication, leases and bounded retries.
  • Google OAuth tokens are stored encrypted.

Results

From the dated verification run on Aug 9 2026:

CheckResult
Unit and component tests387 passing, 21 files
Agent, outbox, rate-limit and idempotency tests32 passing, 9 files
Production build41 / 41 static pages
Database migrations6 applied, schema up to date

The browser pass also caught three real bugs that I fixed: an origin check that rejected 127.0.0.1, Gemini rejecting tool schemas with additionalProperties, and an empty contents array on system-only prompts.

I haven’t yet tested real Google Calendar sync, real email delivery, race conditions or DST edges against live providers. Until that runs, the agent stays in approve-every-action mode.

Stack

Next.js 16 (App Router), React, TypeScript, Tailwind CSS, NextAuth, Prisma 6 on Neon PostgreSQL, Gemini with function calling, Google Calendar API, Resend, Vitest.

Back to top