Skip to main content

Monorepo Structure

Cal.com uses a Yarn/Turbo monorepo architecture with multiple applications and shared packages.

Key Directories

Apps

apps/web/

The main Next.js 13+ application using App Router. Key subdirectories:
  • app/ - App Router pages and layouts
  • pages/ - Legacy Pages Router routes
  • public/ - Static assets
  • components/ - Web-specific components

apps/api/v1/

Legacy REST API for public consumption.

apps/api/v2/

New Platform API with enhanced capabilities.
When importing from @calcom/features or @calcom/trpc into apps/api/v2, re-export from packages/platform/libraries/index.ts and import from @calcom/platform-libraries to avoid module resolution issues.

Packages

packages/prisma/

Central database management. Key files:
  • schema.prisma - Database schema definition
  • migrations/ - Database migration files
  • seed.ts - Database seeding script

packages/trpc/

Type-safe API layer using tRPC. Structure:
  • server/routers/ - API endpoint definitions
  • react/ - React hooks for tRPC

packages/features/

Feature-based organization (73 features). Examples:
  • bookings/ - Booking logic
  • ee/ - Enterprise features
  • auth/ - Authentication
  • calendars/ - Calendar integrations
  • webhooks/ - Webhook handling

packages/app-store/

Third-party integrations (112 apps). Structure:
  • Each app has its own directory
  • config.json - App configuration
  • api/ - API endpoints
  • lib/ - Business logic
  • components/ - UI components

packages/ui/

Shared UI component library. Components:
  • Buttons, forms, modals
  • Design system primitives
  • Tailwind-based styling

packages/lib/

Shared utilities and helpers (32 libraries). Examples:
  • Date/time utilities
  • Validation helpers
  • Type definitions
  • Constants

Tech Stack

Frontend

  • Framework: Next.js 13+ (App Router + Pages Router)
  • Language: TypeScript (strict mode)
  • Styling: Tailwind CSS
  • UI Library: Custom component library (@calcom/ui)
  • State Management: React hooks + tRPC
  • Forms: React Hook Form
  • Internationalization: next-i18next

Backend

  • API: tRPC for type-safe APIs
  • Database: PostgreSQL
  • ORM: Prisma
  • Authentication: NextAuth.js
  • Validation: Zod schemas
  • Email: SendGrid, Nodemailer
  • SMS: Twilio

Testing

  • Unit Tests: Vitest
  • E2E Tests: Playwright
  • Mocking: Prismock (Prisma), vitest-mock-extended

Build & Development

  • Monorepo: Turborepo
  • Package Manager: Yarn (v4.12.0)
  • Linting: Biome
  • Formatting: Biome
  • Type Checking: TypeScript compiler

Infrastructure

  • Deployment: Vercel, Docker
  • CI/CD: GitHub Actions
  • Monitoring: Sentry
  • Analytics: PostHog
  • Rate Limiting: Unkey (optional)

Database Architecture

Schema Location

Key Models

  • User - User accounts
  • Team - Team/organization data
  • EventType - Event type configurations
  • Booking - Booking records
  • Availability - User availability schedules
  • Credential - Integration credentials
  • Webhook - Webhook configurations
  • Payment - Payment records
  • Workflow - Automation workflows
Security: Never expose the credential.key field in API responses or queries. Always use select instead of include in Prisma queries.

API Architecture

tRPC Routers

Located in packages/trpc/server/routers/:

Error Handling

  • tRPC Routers: Use TRPCError
  • Services/Repositories: Use ErrorWithCode
  • Always provide descriptive error messages with context

Routing

App Router (Next.js 13+)

Primary routing system in apps/web/app/:
Permission checks must be in page.tsx, never in layout.tsx.

Pages Router (Legacy)

Legacy routes in apps/web/pages/:

Component Organization

Shared Components

Import directly from source:

Feature Components

Each feature can contain its own components.

Service Layer

Architecture Pattern

File Naming Conventions

Services

Repositories

  • File names must match exported class names (PascalCase)
  • Never put business logic in repositories
  • Avoid generic names like AppService.ts

Build System (Turborepo)

Key Commands

Defined in turbo.json:
  • build - Build all packages and apps
  • dev - Start development servers
  • lint - Run linters
  • type-check - Type check all packages
  • test - Run unit tests
  • db-migrate - Run database migrations

Task Dependencies

Turborepo manages dependencies between tasks:

Configuration Files

Key Files

  • package.json - Root package configuration
  • turbo.json - Turborepo configuration
  • tsconfig.json - TypeScript base configuration
  • .env.example - Environment variable template
  • .env.appStore.example - App Store environment variables
  • biome.json - Biome linting/formatting config

TypeScript Configuration

Shared configs in packages/tsconfig/:
  • base.json - Base TypeScript config
  • nextjs.json - Next.js specific config
  • react-library.json - React library config

Deployment Architecture

Vercel Deployment

  • Main app: apps/web
  • API routes: Serverless functions
  • Static assets: CDN

Docker Deployment

Environment Variables

See turbo.json for the complete list of 300+ environment variables. Critical variables:
  • DATABASE_URL - Database connection
  • NEXTAUTH_SECRET - Auth secret
  • CALENDSO_ENCRYPTION_KEY - Encryption key
  • NEXT_PUBLIC_WEBAPP_URL - Base URL

Next Steps