Skip to content

Architecture

Principles

  • Postgres is the source of truth for everything MeetAlias owns: meetings, clients, settings, booking tokens. The provider's calendar (Google Calendar or Outlook, one per install) holds the events and Meet or Teams links. MeetAlias only tracks events it created and never imports others.
  • One process. The web app, the calendar sync, reminders and daily emails all run in one Node process; there's no queue or separate scheduler.
  • Services know nothing about HTTP. Pages and server actions call functions in src/lib, which talk to the database and to Google or Microsoft through a small provider interface. Tests use the same services with a fake gateway.

Modules

Module Responsibility
lib/slots.ts Pure slot calculator: weekly hours + timezone + meeting type + busy intervals + now → bookable start times. No I/O.
lib/provider/ The Provider interface (create/update/cancel/get event, busy times, send email), the product wording per provider (WORDS), and the in-memory fake.ts for tests. index.ts picks Google or Microsoft from the install settings. Revoked access becomes a typed ProviderAuthError.
lib/google/ The only code that talks to Google: OAuth and the Calendar, FreeBusy and Gmail calls.
lib/microsoft/ The only code that talks to Microsoft: Entra sign-in (oauth.ts, including plain-text AADSTS errors) and Microsoft Graph (real.ts: events with Teams links, busy times from calendarView, sendMail). Exchange sends invites itself (sendsInvites: true).
lib/install.ts, lib/setup.ts The install's provider and encrypted credentials, the setup wizard and its test sign-in, the Microsoft secret's expiry warnings.
lib/meetings.ts Staff meetings: create, update, cancel, list, load, emails to attendees, notices to organizers.
lib/booking.ts Public booking: find host and types, compute free slots, book, reschedule, cancel by token, bot limits.
lib/clients.ts Clients, contacts, search, client matching for bookings, unconfirmed bookers.
lib/invite.ts Builds invite emails (HTML + text) and .ics files with a stable UID and increasing SEQUENCE, so calendar apps update events instead of duplicating them.
lib/sync.ts Every 10 minutes: re-read each active app-created event and copy over moves and deletions. Records per-user Google or Microsoft errors.
lib/notify.ts Reminders to bookers and the daily email.
lib/settings.ts Profile, weekly hours, booking pages, meeting types.
lib/photo.ts Profile photos: validation by content, storage, Google or Microsoft photo import.
lib/session*.ts, lib/crypto.ts Signed session cookies and booking tokens; AES-GCM for refresh tokens; keys derived from SECRET_KEY per purpose.
lib/brand*.ts Sites from brands.json, chosen by request host.
lib/config-guard.ts Startup checks of the environment.

Key flows

Creating a meeting

sequenceDiagram
  participant U as Staff (browser)
  participant A as Server action
  participant M as lib/meetings
  participant G as Provider (Google or Microsoft)
  participant DB as Postgres
  U->>A: submit New meeting form
  A->>M: createMeeting(user, input)
  M->>M: validate, suggest/check slug
  M->>G: createEvent (Meet or Teams link, attendees)
  M->>DB: insert meeting + attendees
  M->>G: sendEmail (branded invite; .ics only on Google) per attendee
  M-->>A: meeting, email error if any
  A-->>U: redirect to meeting page with notice

Booking a slot

  1. The visitor's browser asks /api/slots for free times of a month. The server reads the host's hours and meeting type, asks the provider for busy times (Google FreeBusy, or Microsoft Graph calendarView), and runs the slot calculator.
  2. On Confirm booking, the server checks the bot limits, then claims the slot in the database first: an exclusion constraint on (organizer, time range) for active meetings makes a parallel booking of the same time fail.
  3. It creates the calendar event. If that fails, the row is deleted, releasing the slot.
  4. It matches the booker to a client, sends the invite (with a signed reschedule/cancel link) and notifies the host.

Sync

For each organizer with active app-created meetings, the sync job reads those events by id and copies time changes and cancellations into the database, bumping SEQUENCE past the provider's. It sends no emails. A ProviderAuthError is stored on the user and shown as the "sign in again" banner.

Data model

erDiagram
  users ||--o{ meetings : organizes
  users ||--o{ booking_pages : owns
  users ||--o{ availability : "weekly hours"
  booking_pages ||--o{ meeting_types : lists
  meeting_types ||--o{ meetings : "booked as"
  clients ||--o{ contacts : has
  clients ||--o{ meetings : "linked to"
  meetings ||--o{ meeting_attendees : invites
  users ||--o{ meeting_templates : "created by"

Every site-scoped table has a brand column holding the site key. The schema lives in numbered files in db/migrations/; db/migrate.mjs applies each once and records it in schema_migrations.

Security-relevant design

  • Server actions re-check the session and treat every bound id as untrusted input.
  • Public booking never echoes booker text into emails from staff mailboxes.
  • Booking tokens, session cookies and the encryption of refresh tokens and the client secret use separate keys derived from SECRET_KEY.
  • See Security for the operator's view.