> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Calendar & Scheduling Integration — Integration Document

> Feature ID: CE-21 Status: ✅ Complete Created: 2026-03-31

**Feature ID:** CE-21\
**Status:** ✅ Complete\
**Created:** 2026-03-31

***

## Integration Summary

CE-21 integrates external calendar providers (Google, Microsoft) with the CE module for two-way event synchronization and meeting scheduling.

## Integration Touchpoints

### CE-04: Activities & Task Management

* **Type:** Data (FK)
* **Direction:** CE-21 → CE-04
* **Contract:** `ce_calendar_events.activity_id` references `ce_activities.id`
* **Behavior:** Outbound scheduled meetings create a linked CE activity for timeline visibility

### PF-10: Notifications

* **Type:** Platform Layer
* **Direction:** CE-21 → PF-10
* **Contract:** Pre-meeting notifications sent via `pf_notifications` based on `calendar_pre_meeting_notification_minutes`

### PF-29: Tasks

* **Type:** Platform Layer
* **Direction:** CE-21 → PF-29 (planned)
* **Contract:** Meeting follow-up tasks can be created from calendar events

## Database Objects

| Object                               | Type     | Purpose                                      |
| ------------------------------------ | -------- | -------------------------------------------- |
| `ce_calendar_connections`            | Table    | OAuth connections per user/org               |
| `ce_calendar_events`                 | Table    | Synced calendar events                       |
| `ce_module_settings` (3 cols)        | Columns  | Duration, poll interval, notification timing |
| `ce_user_owns_calendar_connection()` | Function | SECURITY DEFINER RLS helper                  |

## Edge Functions

| Function                  | Invocation     | Purpose                              |
| ------------------------- | -------------- | ------------------------------------ |
| `calendar-oauth-callback` | OAuth redirect | Token exchange + connection creation |
| `calendar-sync`           | Cron / webhook | Two-way event sync                   |
| `calendar-freebusy`       | On-demand      | Availability queries                 |
| `calendar-schedule`       | On-demand      | External event creation              |

## Permissions

| Key                    | Granted To |
| ---------------------- | ---------- |
| `ce.calendar.connect`  | org\_admin |
| `ce.calendar.schedule` | org\_admin |
| `ce.calendar.view`     | org\_admin |
| `ce.calendar.view-all` | org\_admin |

## RLS Strategy

* `ce_calendar_connections`: Owner-only CRUD via `user_id = auth.uid()`
* `ce_calendar_events`: Owner via `ce_user_owns_calendar_connection()` or org-wide via `ce.calendar.view-all` permission
* Both tables enforce `FORCE ROW LEVEL SECURITY`

## UI Components

| Component                        | Route/Usage                         |
| -------------------------------- | ----------------------------------- |
| `CalendarConnectionSettingsPage` | `/ce/settings/calendar`             |
| `ScheduleMeetingDialog`          | Invoked from activity/contact pages |
| `CalendarActivityIndicator`      | Activity timeline badge             |
