refactor: Move repositories from @calcom/lib to @calcom/features domain folders#27570
refactor: Move repositories from @calcom/lib to @calcom/features domain folders#27570
Conversation
- Move HolidayRepository to features/holidays/repositories - Move PrismaTrackingRepository to features/bookings/repositories - Move PrismaBookingPaymentRepository to features/bookings/repositories - Move PrismaRoutingFormResponseRepository to features/routing-forms/repositories - Move PrismaAssignmentReasonRepository to features/assignment-reason/repositories - Move VerificationTokenRepository to features/auth/repositories - Move WorkspacePlatformRepository to features/workspace-platform/repositories - Move DTO files to their respective feature domains - Merge lib DestinationCalendarRepository into features version - Merge lib SelectedCalendarRepository into features version - Update all import paths across the codebase This follows the vertical slice architecture pattern by organizing repositories by domain rather than by technical layer. Co-Authored-By: benny@cal.com <sldisek783@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: benny@cal.com <sldisek783@gmail.com>
Co-Authored-By: benny@cal.com <sldisek783@gmail.com>
Co-Authored-By: benny@cal.com <sldisek783@gmail.com>
| import { prisma } from "@calcom/prisma"; | ||
| import type { Prisma } from "@calcom/prisma/client"; | ||
| import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential"; | ||
| import type { SelectedCalendarEventTypeIds } from "@calcom/types/Calendar"; | ||
|
|
||
| import { buildCredentialPayloadForPrisma } from "../buildCredentialPayloadForCalendar"; | ||
|
|
||
| export type UpdateArguments = { | ||
| where: FindManyArgs["where"]; | ||
| data: Prisma.SelectedCalendarUpdateManyArgs["data"]; | ||
| }; | ||
| export type FindManyArgs = { | ||
| // https://github.com/microsoft/TypeScript/issues/55217 It crashes atoms build with this if we become too generic here. Seems like a TS bug with complex prisma types. |
There was a problem hiding this comment.
Merged into packages/features/selectedCalendar/repositories/SelectedCalendarRepository.ts
…-lib-repos-to-features
| import type { PrismaClient } from "@calcom/prisma"; | ||
|
|
||
| export class DestinationCalendarRepository { | ||
| constructor(private prisma: PrismaClient) {} | ||
|
|
||
| async getCustomReminderByCredentialId(credentialId: number): Promise<number | null> { | ||
| const destinationCalendar = await this.prisma.destinationCalendar.findFirst({ | ||
| where: { credentialId }, | ||
| select: { customCalendarReminder: true }, |
There was a problem hiding this comment.
Merged into packages/features/calendars/repositories/DestinationCalendarRepository.ts
671dd9b to
1f399d8
Compare
| } | ||
|
|
||
| // Static methods for direct usage (from lib version) | ||
| private static async findConflicting(data: { |
There was a problem hiding this comment.
In a follow-up PR, I will turn the static methods into instance methods
| private prismaClient: PrismaClient; | ||
|
|
||
| constructor(prismaClient?: PrismaClient) { | ||
| this.prismaClient = prismaClient ?? prisma; | ||
| } | ||
|
|
||
| async getCustomReminderByCredentialId(credentialId: number): Promise<number | null> { | ||
| const destinationCalendar = await this.prismaClient.destinationCalendar.findFirst({ | ||
| where: { credentialId }, | ||
| select: { customCalendarReminder: true }, | ||
| }); | ||
| return destinationCalendar?.customCalendarReminder ?? null; | ||
| } | ||
|
|
||
| async updateCustomReminder({ |
There was a problem hiding this comment.
In a follow-up PR, I will turn the static methods (the existing ones in this repository) into instance methods for consistency
| @@ -1,493 +0,0 @@ | |||
| import prismock from "@calcom/testing/lib/__mocks__/prisma"; | |||
There was a problem hiding this comment.
Merged into packages/features/selectedCalendar/repositories/SelectedCalendarRepository.test.ts
… file Co-Authored-By: benny@cal.com <sldisek783@gmail.com>
There was a problem hiding this comment.
1 issue found across 4 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/app-store/salesforce/lib/repositories/PrismaAssignmentReasonRepository.ts">
<violation number="1">
P2: Add a `select` to limit the Prisma query to the fields actually needed (e.g., `reasonString`) to avoid fetching the full AssignmentReason row.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
packages/app-store/salesforce/lib/repositories/PrismaAssignmentReasonRepository.ts
Show resolved
Hide resolved
Devin AI is addressing Cubic AI's review feedbackA Devin session has been created to address the issues identified by Cubic AI. |
E2E results are ready! |
keithwillcode
left a comment
There was a problem hiding this comment.
Can you please add a new rule to disallow this moving forward?
…-lib-repos-to-features
|
@keithwillcode Done!
Below is an evidence that it works:
|
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="biome.json">
<violation number="1" location="biome.json:263">
P1: Circular dependency detected: `VerificationTokenService` in `packages/lib` now imports from `packages/features`, creating a dependency cycle (`lib` → `features` → `lib`).
The refactor moved `VerificationTokenRepository` to `features`, but `VerificationTokenService` remains in `lib` and now imports the repository from `features`. This violates the architectural rule that `lib` cannot depend on `features`.
**Action Required:**
1. Move `packages/lib/server/service/VerificationTokenService.ts` (and its tests) to `packages/features/auth`.
2. Update the `noRestrictedImports` rule for `packages/lib` (lines 224-250) to explicitly ban `@calcom/features` and `@calcom/features/**` to prevent future circular dependencies via alias imports.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Devin AI is addressing Cubic AI's review feedbackA Devin session has been created to address the issues identified by Cubic AI. |
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/app-store/stripepayment/lib/VerificationTokenService.test.ts">
<violation number="1" location="packages/app-store/stripepayment/lib/VerificationTokenService.test.ts:3">
P2: The import path was updated to "./repositories/..." but the test still mocks "../repositories/...", so the mock no longer matches the imported module. Update the mock path to match the new import so the repository is properly mocked.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Devin AI is addressing Cubic AI's review feedbackA Devin session has been created to address the issues identified by Cubic AI. |
…ts rule Addresses Cubic AI review feedback (confidence 9/10): the existing noRestrictedImports rule for packages/lib only banned relative imports (../features/**) but not alias imports (@calcom/features). This could allow circular dependencies via alias imports to bypass the lint rule. Co-Authored-By: unknown <>
Cubic AI Review Feedback - AddressedReviewed all Cubic AI comments and their confidence scores: Fixed (confidence 9/10):
Skipped (confidence below 9/10):
|
05e4f95 to
90ffee4
Compare
There was a problem hiding this comment.
3 issues found across 1 file (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="biome.json">
<violation number="1">
P2: Dropping the @calcom/trpc alias patterns lets lib import from trpc via package aliases, bypassing the intended circular-dependency restriction. Restore the alias patterns.</violation>
<violation number="2">
P2: This removes @calcom/features alias restrictions, allowing lib to bypass the circular-dependency guard via package imports. Keep the alias patterns in the restricted group.</violation>
<violation number="3">
P2: This change allows lib to import from app-store via @calcom/app-store aliases, which defeats the circular-dependency restriction. Keep the alias patterns so both relative and package imports are blocked.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Devin AI is addressing Cubic AI's review feedbackNew feedback has been sent to the existing Devin session. ✅ Pushed commit |
40750e8 to
f92e7b3
Compare
…-lib-repos-to-features


What does this PR do?
Reorganizes repository files following the vertical slice architecture pattern by moving repositories from
packages/lib/server/repository/to their respective domain folders inpackages/features/.Repositories moved:
SelectedCalendarRepository→features/selectedCalendar/repositories/VerificationTokenRepository→features/auth/repositories/WorkspacePlatformRepository→features/workspace-platform/repositories/PrismaTrackingRepository→features/bookings/repositories/RoutingFormResponseRepository→features/routing-forms/repositories/PrismaBookingPaymentRepository→features/bookings/repositories/Note:
DestinationCalendarRepositoryandSelectedCalendarRepositorysupport both static methods (for direct usage) and instance methods (for dependency injection).