forked from calcom/cal.diy
-
Notifications
You must be signed in to change notification settings - Fork 0
docs: add 2-tier hybrid architecture guide, changelog, and guard upstream-only workflows #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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`). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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` | ||
| 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). | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few discrepancies between this documentation and the actual webhook implementation in
apps/web/app/api/webhooks/dos-org-sync/route.ts:organization.member.addedandorganization.member.removed(using dot notation) are supported in the webhook handler but are not documented here.user.updatedevent is listed here, but it is currently not handled in the webhook'sswitchstatement (it falls through to thedefaultcase and is ignored).Let's update the documentation to accurately reflect the implemented events.