Files
armonia-api/docs/decisions/0003-mandatory-buffer-times-and-calendar-sync.md
T
kiskaadee 67f41ca2f1 feat(models): implement SQLModel table models, portable database engine, and align INDIVIDUAL schema
- Define SQLModel table models for AdminAllowlist, AdminAuditLog, Client, Service, Package, Booking, and Payment with foreign keys and strict validation.
- Configure portable SQLModel create_engine in app/db/database.py supporting local SQLite and Turso Cloud (sqlite+libsql://) with PRAGMA foreign_keys = ON.
- Provide get_session generator dependency for FastAPI routers.
- Align ONE_ON_ONE service type to INDIVIDUAL across schema.sql, routers, seeds, and documentation.
- Add unit tests for all models and database connectivity (75 tests passing).

Refs: #6
2026-10-19 12:58:59 -05:00

2.4 KiB

ADR 0003: Mandatory Buffer Times and Recoverable Google Calendar Synchronization

Status

Accepted (Amended 2026-10-18)

Context

Discovery feedback from long-term clients revealed chronic 10-to-35-minute delays in therapy sessions caused by emotional consultation overruns and back-to-back scheduling without buffers. Additionally, Jasmin relies on Google Calendar to view her daily schedule on her phone, while armonia-api (backed by Turso) must remain the authoritative record of business state.

Decision

  1. Mandatory Post-Session Buffers: Every individual appointment (INDIVIDUAL) enforces an unbookable 15-to-20-minute buffer interval immediately following the session. A 60-minute consultation blocks 75 minutes on the scheduling engine for any RESERVED booking.
  2. Backend-Owned Truth with Google Calendar Coordination:
    • armonia-api owns the authoritative booking and payment decision in Turso; Google Calendar reflects the schedule:
      • [PAGO PENDIENTE] when booking_status = 'RESERVED', payment_arrangement = 'PREPAID_DEFAULT', and payment_status = 'AWAITING_ACKNOWLEDGMENT'.
      • [PAGO DIFERIDO] when booking_status = 'RESERVED', payment_arrangement = 'DELAYED_ALLOWED', and payment_status = 'AWAITING_ACKNOWLEDGMENT'.
      • [CONFIRMADO] when payment_status = 'ACKNOWLEDGED' or payment_arrangement = 'PACKAGE_REDEEMED'.
      • Event deleted/cancelled when booking_status transitions to RELEASED or CANCELLED.
  3. Visible & Recoverable Integration State:
    • Each booking stores gcal_event_id, gcal_sync_status (PENDING, SYNCED, FAILED, NOT_CONFIGURED), gcal_sync_error, and gcal_synced_at.
    • If the Google Calendar API fails transiently, the Turso record is preserved with gcal_sync_status = 'FAILED' and administrators can retry synchronization via POST /bookings/{id}/sync-calendar.

Consequences

Positive

  • Prevents cascade delays across consultations and frees slots immediately when a booking is RELEASED.
  • Prevents silent divergence between Turso and Google Calendar by surfacing gcal_sync_status and gcal_sync_error directly to the dashboard.
  • Works cleanly in local development and tests (NOT_CONFIGURED fallback when GCP credentials are absent).

Negative / Trade-offs

  • Slightly reduces theoretical maximum daily capacity (e.g., maximum 5 sessions/day instead of 6) in exchange for punctuality and therapist well-being.