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 layoutspages/- Legacy Pages Router routespublic/- Static assetscomponents/- 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 definitionmigrations/- Database migration filesseed.ts- Database seeding script
packages/trpc/
Type-safe API layer using tRPC.
Structure:
server/routers/- API endpoint definitionsreact/- React hooks for tRPC
packages/features/
Feature-based organization (73 features).
Examples:
bookings/- Booking logicee/- Enterprise featuresauth/- Authenticationcalendars/- Calendar integrationswebhooks/- Webhook handling
packages/app-store/
Third-party integrations (112 apps).
Structure:
- Each app has its own directory
config.json- App configurationapi/- API endpointslib/- Business logiccomponents/- 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 accountsTeam- Team/organization dataEventType- Event type configurationsBooking- Booking recordsAvailability- User availability schedulesCredential- Integration credentialsWebhook- Webhook configurationsPayment- Payment recordsWorkflow- Automation workflows
API Architecture
tRPC Routers
Located inpackages/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 inapps/web/app/:
Permission checks must be in
page.tsx, never in layout.tsx.Pages Router (Legacy)
Legacy routes inapps/web/pages/:
Component Organization
Shared Components
Feature Components
Service Layer
Architecture Pattern
File Naming Conventions
Services
Repositories
Build System (Turborepo)
Key Commands
Defined inturbo.json:
build- Build all packages and appsdev- Start development serverslint- Run linterstype-check- Type check all packagestest- Run unit testsdb-migrate- Run database migrations
Task Dependencies
Turborepo manages dependencies between tasks:Configuration Files
Key Files
package.json- Root package configurationturbo.json- Turborepo configurationtsconfig.json- TypeScript base configuration.env.example- Environment variable template.env.appStore.example- App Store environment variablesbiome.json- Biome linting/formatting config
TypeScript Configuration
Shared configs inpackages/tsconfig/:
base.json- Base TypeScript confignextjs.json- Next.js specific configreact-library.json- React library config
Deployment Architecture
Vercel Deployment
- Main app:
apps/web - API routes: Serverless functions
- Static assets: CDN
Docker Deployment
Environment Variables
Seeturbo.json for the complete list of 300+ environment variables.
Critical variables:
DATABASE_URL- Database connectionNEXTAUTH_SECRET- Auth secretCALENDSO_ENCRYPTION_KEY- Encryption keyNEXT_PUBLIC_WEBAPP_URL- Base URL
Next Steps
- Learn about Coding Guidelines
- Explore Testing Practices
- Review Development Setup