knowledge-base
This file contains domain knowledge about the Cal.diy product and codebase. For coding…
**Impact: CRITICAL**
$ npx -y skills add calcom/cal.diy --agent claude-codeHow it fires
How this agent gets triggered: by you, by Claude, or both.
Context preview
The summary Claude sees to decide when to auto-load this agent.
**Impact: CRITICAL**
title: Use DTOs at Every Architectural Boundary impact: CRITICAL impactDescription: Prevents technology coupling and security risks tags: data, dto, boundaries, security, types
**Impact: CRITICAL**
Database types should not leak to the frontend. This has become a popular shortcut in our tech stack, but it's a code smell that creates multiple problems.
**Problems with leaking database types:**
**Incorrect (database types leaking):**
// API route returning Prisma types directly
import type { User } from "@prisma/client";
export async function GET(): Promise<User> {
const user = await prisma.user.findFirst();
return user; // Leaks all database fields including sensitive ones
}
// Frontend using Prisma types
import type { User } from "@prisma/client";
function UserProfile({ user }: { user: User }) {
// Component now coupled to database schema
}**Correct (explicit DTOs):**
// Define explicit DTOs
interface UserDTO {
id: number;
name: string;
email: string;
// Only fields needed by the client
}
// API route transforms to DTO
export async function GET(): Promise<UserDTO> {
const user = await userRepository.findById(id);
return UserResponseSchema.parse(user); // Validate with Zod
}
// Frontend uses DTO
function UserProfile({ user }: { user: UserDTO }) {
// Component decoupled from database
}**The standard:** 1. **Data layer → Application layer → API**: Transform database models into application-layer DTOs, then transform application DTOs into API-specific DTOs 2. **API → Application layer → Data layer**: Transform API DTOs through application layer and into data-specific DTOs 3. All DTO conversions through Zod to ensure all data is validated before sending to user
**Location**: All DTOs go in `packages/lib/dto/`
**Naming conventions**:
**Enum/union pattern** - use string literal unions to stay ORM-agnostic:
// Good - ORM-agnostic string literal union
export type BookingStatusDto = "CANCELLED" | "ACCEPTED" | "REJECTED" | "PENDING";
// Bad - importing Prisma enum
import { BookingStatus } from "@calcom/prisma/client";**Type safety** - never use `as any` in DTO mapping functions. If types don't align, fix the mapping explicitly.
Yes, this requires more code. Yes, it's worth it. Explicit boundaries prevent the architectural erosion that creates long-term maintenance nightmares.
Reference: [Cal.diy Engineering Blog](https://cal.com/blog/engineering-in-2026-and-beyond)
Repo: calcom/cal.com
This file contains domain knowledge about the Cal.diy product and codebase. For coding…
The `packages/features` package should contain only framework-agnostic code: - Repositories…