Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cleanup-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ permissions:
pull-requests: write
jobs:
cleanup-report:
if: github.repository == 'calcom/cal.diy'
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App token
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ concurrency:
jobs:
delete_reports:
name: Delete Reports
if: github.repository == 'calcom/cal.diy'
runs-on: ubuntu-latest
env:
# Contains all reports for deleted branch
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ permissions:

jobs:
draft_release:
if: github.repository == 'calcom/cal.diy'
runs-on: ubuntu-latest

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency:
jobs:
i18n:
name: Run i18n
if: ${{ secrets.CI_LINGO_DOT_DEV_API_KEY != '' }}
if: ${{ github.repository == 'calcom/cal.diy' && secrets.CI_LINGO_DOT_DEV_API_KEY != '' }}
runs-on: ubuntu-latest
permissions:
actions: write
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ permissions:

jobs:
release:
if: github.repository == 'calcom/cal.diy'
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App token
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ on:
jobs:
prepare:
name: "Prepare Release"
if: github.repository == 'calcom/cal.diy'
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.determine-tag.outputs.release_tag }}
Expand Down
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Changelog — Crove Cal

All notable changes to the **Crove Cal** platform will be documented in this file.

---

## [2.0.0] - 2026-08-26

### Added
- **2-Tier Hybrid Architecture Adoption**: Implemented standard Crove OS 2-tier architecture combining Database/Webhook sync (Tier 1) and MCP protocol for AI agentic actions (Tier 2).
- **DOS.Me ID Centralized Authentication (OIDC / OAuth 2.1)**:
- Native integration with Supabase OAuth 2.1 + PKCE server.
- Configured `ES256` token signature algorithm for Supabase Auth JWT compatibility.
- Implemented `allowDangerousEmailAccountLinking` and dynamic runtime provider evaluation.
- **Two-Way Organization Synchronization (Hybrid Sync)**:
- Inbound JIT (Just-In-Time) organization & profile sync on OIDC login (`syncDosOrganizations`).
- Real-time webhook listener at `/api/webhooks/dos-org-sync` with HMAC-SHA256 signature verification supporting `organization.*` and `org.*` event conventions.
- **Automated Branding Pipeline**:
- Standardized environment variables: `NEXT_PUBLIC_APP_NAME`, `NEXT_PUBLIC_COMPANY_NAME`, `NEXT_PUBLIC_SUPPORT_MAIL_ADDRESS`.
- Added automated localization patching script `yarn patch:branding` (`scripts/patch-crove-branding.ts`).
- Added comprehensive architecture specification at `docs/Architecture.md`.

### Fixed
- Fixed NextAuth OIDC discovery and token exchange by properly registering `wellKnown` and PKCE checks.
- Fixed root route rewrite collision by scoping routing configurations.
- Guarded upstream-only CI workflows against failing on fork repository.

### Optimized
- Optimized Docker container startup by pre-baking production URL `https://cal.crove.com`, eliminating cold start string replacement overhead.
- Automated Docker image build and push to GHCR (`ghcr.io/dos/crove-cal:latest`).
119 changes: 119 additions & 0 deletions docs/Architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Crove Cal — Architecture & Ecosystem Integration Guide

**Phiên bản:** 2.0.0
**Cập nhật lần cuối:** 2026-08-26
**Chủ quản:** Crove OS & DOS.Me Ecosystem

---

## I. Tổng quan Kiến trúc (Architectural Overview)

**Crove Cal** là nền tảng đặt lịch hẹn & quản lý lịch thông minh thế hệ mới (fork từ Cal.com / Cal.diy `v6.2.0`), được tối ưu hóa và tích hợp sâu vào hệ điều hành doanh nghiệp **Crove OS** và hệ thống định danh tập trung **DOS ID** (`id.dos.me` / `api.dos.me`).

Căn cứ theo quy chuẩn kiến trúc toàn hệ sinh thái, Crove Cal tuân thủ mô hình **Kiến trúc Lai 2 Tầng (2-Tier Hybrid Architecture)** kết hợp giữa đồng bộ dữ liệu cốt lõi (Database / Webhook Sync) và giao thức điều khiển nghiệp vụ sâu qua AI Agent (**Model Context Protocol - MCP**).

---

## II. Chuẩn Kiến trúc Đồng bộ 2 Tầng (2-Tier Hybrid Architecture)

```
┌─────────────────────────────────────────────────────────────────────────────────────────┐
│ CROVE OS 2-TIER HYBRID ARCHITECTURE │
├──────────────────────────────────────────┬──────────────────────────────────────────────┤
│ TẦNG 1: Đồng bộ Dữ liệu Danh tính & Tổ chức│ TẦNG 2: Deep Agentic Business Actions │
│ (Organizations, Memberships, Contacts) │ (Lên lịch, Tạo Booking, Tra cứu Rảnh/Bận) │
├──────────────────────────────────────────┼──────────────────────────────────────────────┤
│ DATABASE & WEBHOOK SYNC │ MCP PROTOCOL │
│ (Local Mirror & Realtime Events) │ (Model Context Protocol Tool Calling) │
│ │ │ │ │
│ • DOS-Me (api.dos.me): Master SSOT │ • crove_cal.get_available_slots(...) │
│ • Schema Isolation: cal.users, cal.Team │ • crove_cal.create_booking(...) │
│ • Inbound JIT OIDC Sync │ • crove_cal.reschedule_booking(...) │
│ • Bi-directional Webhook Dispatch │ • twenty_crm, crove_sign, crove_desk tools │
└──────────────────────────────────────────┴──────────────────────────────────────────────┘
```

### 1. Tầng 1: Đồng bộ Dữ liệu Danh tính & Tổ chức (Identity & Organization Sync)

Tầng 1 đảm bảo dữ liệu danh tính người dùng và cấu trúc tổ chức luôn nhất quán trên toàn hệ sinh thái mà không phụ thuộc vào độ trễ mạng:

1. **Single Source of Truth (SSOT)**:
- Hệ thống trung tâm `api.dos.me` và bảng `public.organizations`, `public.org_members` trên Supabase là nơi lưu trữ gốc duy nhất cho danh tính và tổ chức.
2. **Cách ly Dữ liệu (Schema Isolation)**:
- Cơ sở dữ liệu của Crove Cal hoạt động độc lập trên schema `cal` với role chuyên dụng `cal_app`, bảo vệ an toàn toàn vẹn dữ liệu.
3. **Đồng bộ Tức thời khi Đăng nhập (Inbound JIT Sync)**:
- Khi người dùng đăng nhập qua DOS ID (OIDC / OAuth 2.1), hàm `syncDosOrganizations` đọc mảng claims `organizations` trong JWT token / UserInfo:
```json
{
"sub": "48fc3631-ec8c-4e78-aa98-ec89c1c3624d",
"email": "joy@dos.ai",
"name": "JOY",
"active_org_id": "acbb5565-bdbb-43f9-a658-2bc8a326c85f",
"organizations": [
{
"id": "acbb5565-bdbb-43f9-a658-2bc8a326c85f",
"name": "JOY",
"slug": "joy",
"role": "OWNER"
}
]
}
```
- Tự động tạo / cập nhật `cal.Team` (với `isOrganization = true` và `metadata.dosOrgId`), bản ghi `cal.Membership`, và `cal.Profile`.
4. **Đồng bộ Thời gian thực qua Webhook (Event-Driven Webhook Sync)**:
- Endpoint: `/api/webhooks/dos-org-sync` tiếp nhận các sự kiện được ký HMAC-SHA256:
- `organization.created` / `org.created`
- `organization.updated` / `org.updated`
- `organization.deleted` / `org.deleted`
- `organization.member_added` / `org.member_added`
- `organization.member_removed` / `org.member_removed`
- `user.updated`
Comment on lines +63 to +70

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There are a few discrepancies between this documentation and the actual webhook implementation in apps/web/app/api/webhooks/dos-org-sync/route.ts:

  1. Missing Events: The events organization.member.added and organization.member.removed (using dot notation) are supported in the webhook handler but are not documented here.
  2. Unimplemented Event: The user.updated event is listed here, but it is currently not handled in the webhook's switch statement (it falls through to the default case and is ignored).

Let's update the documentation to accurately reflect the implemented events.

Suggested change
4. **Đồng bộ Thời gian thực qua Webhook (Event-Driven Webhook Sync)**:
- Endpoint: `/api/webhooks/dos-org-sync` tiếp nhận các sự kiện được ký HMAC-SHA256:
- `organization.created` / `org.created`
- `organization.updated` / `org.updated`
- `organization.deleted` / `org.deleted`
- `organization.member_added` / `org.member_added`
- `organization.member_removed` / `org.member_removed`
- `user.updated`
4. **Đồng bộ Thời gian thực qua Webhook (Event-Driven Webhook Sync)**:
- Endpoint: `/api/webhooks/dos-org-sync` tiếp nhận các sự kiện được ký HMAC-SHA256:
- `organization.created` / `org.created`
- `organization.updated` / `org.updated`
- `organization.deleted` / `org.deleted`
- `organization.member_added` / `organization.member.added` / `org.member_added`
- `organization.member_removed` / `organization.member.removed` / `org.member_removed`

5. **Tạo Tổ chức Chiều đi (Outbound Creation Protocol)**:
- Khi tạo tổ chức mới từ giao diện Crove Cal, backend gọi trực tiếp `POST https://api.dos.me/organizations` kèm `Authorization: Bearer <user_token>`. Không tự sinh UUID local ngẫu nhiên.

---

### 2. Tầng 2: Deep Agentic Business Actions (Giao thức MCP cho AI Agent)

Khi AI Agent (như Crove Desk AI, DOSClaw, DOS AI) cần thực hiện các tác vụ nghiệp vụ có side-effect hoặc tra cứu phức tạp, hệ thống sử dụng **Model Context Protocol (MCP)**:

| MCP Tool Name | Mục đích |
|---|---|
| `crove_cal.get_available_slots` | Tra cứu các khung giờ rảnh khả dụng của người dùng hoặc nhóm |
| `crove_cal.create_booking` | Tự động đặt lịch hẹn mới từ hội thoại hoặc ticket hỗ trợ |
| `crove_cal.reschedule_booking` | Đổi lịch hẹn theo yêu cầu của khách hàng |
| `crove_cal.cancel_booking` | Hủy lịch hẹn và giải phóng slot |
| `twenty_crm.*` | Tương tác dữ liệu CRM (khách hàng, cơ hội, nhiệm vụ) |
| `crove_sign.*` | Tra cứu và gửi hợp đồng điện tử |

---

## III. Xác thực Tập trung (OIDC / OAuth 2.1 via DOS ID)

Crove Cal kết nối trực tiếp với OIDC Server chuẩn của DOS ID:

- **Issuer URL**: `https://gulptwduchsjcsbndmua.supabase.co/auth/v1`
- **Discovery Endpoint**: `https://gulptwduchsjcsbndmua.supabase.co/auth/v1/.well-known/openid-configuration`
- **Authorization Endpoint**: `https://gulptwduchsjcsbndmua.supabase.co/auth/v1/oauth/authorize`
- **Token Endpoint**: `https://gulptwduchsjcsbndmua.supabase.co/auth/v1/oauth/token`
- **UserInfo Endpoint**: `https://gulptwduchsjcsbndmua.supabase.co/auth/v1/oauth/userinfo`
- **Client ID**: `18790ccb-4d71-48cd-ad24-aee5f3ced3da`
- **Client Secret**: Quản lý an toàn qua GCP Secret Manager (`CROVE_OAUTH_CLIENT_SECRET`)
- **PKCE**: Bắt buộc (`checks: ["pkce", "state"]`)
- **JWT Signature Algorithm**: `ES256`

---

## IV. Quy chuẩn Nhận diện Thương hiệu & Fork Maintenance

Để đảm bảo khả năng merge và đồng bộ mượt mà với phiên bản gốc (`upstream/main` của Cal.com):

1. **Configuration Over Code**:
- Tất cả thông tin nhận diện được cấu hình qua biến môi trường:
- `NEXT_PUBLIC_APP_NAME="Crove"`
- `NEXT_PUBLIC_COMPANY_NAME="MetaDOS LLC"`
- `NEXT_PUBLIC_SUPPORT_MAIL_ADDRESS="help@crove.com"`
2. **Kịch bản Patch Branding Tự động**:
- Chạy lệnh `yarn patch:branding` (`scripts/patch-crove-branding.ts`) để tự động cập nhật localization catalogs khi sync code mới từ upstream.
3. **Root URL Optimization**:
- Trực tiếp bake URL sản xuất `https://cal.crove.com` vào Dockerfile để loại bỏ quét sed khi khởi động container, đảm bảo thời gian khởi động tức thì (<2 giây).
Loading