Skip to content

Comments

feat: split eventTypes router into individual sub-routers per handler#23545

Closed
keithwillcode wants to merge 7 commits intomainfrom
devin/split-eventtypes-router-1756907432
Closed

feat: split eventTypes router into individual sub-routers per handler#23545
keithwillcode wants to merge 7 commits intomainfrom
devin/split-eventtypes-router-1756907432

Conversation

@keithwillcode
Copy link
Contributor

What does this PR do?

This PR breaks out the monolithic eventTypes tRPC router into 15 individual sub-routers to enable better bundle splitting and reduce initial load times.

Problem: The monolithic router was causing unnecessary imports - for example, just loading the /event-types page would import duplicate.handler.ts, which then imports the entire calendar service chain, even though duplicate functionality isn't needed for viewing event types.

Solution: Split each handler into its own router with its own API endpoint, allowing webpack to bundle split more effectively.

Key Changes

  • 15 individual sub-routers created under packages/trpc/server/routers/viewer/eventTypes/[handler]/
  • Individual API endpoints for each handler at apps/web/pages/api/trpc/eventTypes/[handler]/[trpc].ts
  • Updated client calls to use format trpc.viewer.eventTypes.{handler}.{action}() where:
    • .do() for mutations (create, update, delete, duplicate, etc.)
    • .get() for queries (getByViewer, list, etc.)
  • 65 files updated across the codebase to use new router structure
  • Maintained handler logic - no business logic changes, only structural reorganization

Sub-routers Created

Queries (.get()):

  • getByViewer, getUserEventGroups, getEventTypesFromGroup
  • getTeamAndEventTypeOptions, list, listWithTeam
  • get, bulkEventFetch, getHashedLink, getHashedLinks

Mutations (.do()):

  • create, update, delete, duplicate
  • bulkUpdateToDefaultLocation

Example Usage Changes

Before:

trpc.viewer.eventTypes.duplicate.useMutation()
trpc.viewer.eventTypes.list.useQuery()

After:

trpc.viewer.eventTypes.duplicate.do.useMutation()
trpc.viewer.eventTypes.list.get.useQuery()

How should this be tested?

Critical Testing Areas:

  1. Bundle splitting verification: Check that loading /event-types no longer imports duplicate.handler.ts in dev tools
  2. Event type CRUD operations: Create, read, update, delete, and duplicate event types
  3. Event types listing: Verify infinite scroll and filtering still work
  4. Team event types: Test team-specific event type operations
  5. API endpoints: Verify all 15 new API endpoints respond correctly
  6. Type safety: Run yarn type-check:ci --force to catch any type mismatches

Test Environment:

  • No special environment variables needed
  • Use existing test data
  • Test both individual user and team contexts

Mandatory Tasks

  • I have self-reviewed the code
  • I have updated the developer docs (N/A - internal refactor)
  • I confirm automated tests are in place (existing tests should cover functionality)

Human Review Checklist

High Priority:

  • Verify bundle splitting actually works (check import traces in dev tools)
  • Test all event type operations work correctly
  • Run comprehensive type checking
  • Verify API routing works for all 15 endpoints
  • Check that no client-side references were missed

Medium Priority:

  • Performance impact measurement
  • Backward compatibility verification
  • Error handling consistency across new routers

Link to Devin run: https://app.devin.ai/sessions/18e008a7abaf483393a74d9fa655cad3
Requested by: @keithwillcode

⚠️ Note: This is a large refactor (65 files changed) with significant API structure changes. Thorough testing is recommended before merging.

- Break out monolithic eventTypes router into 15 separate sub-routers
- Create individual API endpoints for each handler under /eventTypes/[handler]/
- Update all client-side references to use new sub-router structure
- Use .do() for mutations and .get() for queries as requested
- Update router registration in viewer router to use individual routers
- Fix localStorage import and unused variable lint issues
- Maintain backward compatibility during transition
- Improves bundle splitting and reduces initial load times

Sub-routers created:
- getByViewer, getUserEventGroups, getEventTypesFromGroup
- getTeamAndEventTypeOptions, list, listWithTeam
- create, get, update, delete, duplicate
- bulkEventFetch, bulkUpdateToDefaultLocation
- getHashedLink, getHashedLinks

This prevents unused handlers like duplicate.handler.ts from being
imported when loading pages that don't need them, achieving the
bundle splitting optimization goal.

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
@keithwillcode keithwillcode added core area: core, team members only foundation labels Sep 3, 2025
- Add individual eventTypes sub-router endpoints to ENDPOINTS array
- Update resolveEndpoint function to handle 4-segment paths like viewer.eventTypes.duplicate.do
- Route eventTypes sub-router calls to correct API endpoints (e.g., eventTypes/duplicate)

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
@vercel
Copy link

vercel bot commented Sep 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Sep 3, 2025 3:57pm
cal-eu Ignored Ignored Sep 3, 2025 3:57pm

devin-ai-integration bot and others added 3 commits September 3, 2025 14:51
- Update remaining variable references to use underscore-prefixed names
- Fix metadata, seatsPerTimeSlot, recurringEvent, bookingLimits, and durationLimits references
- All TypeScript errors now resolved

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
- Modify resolveEndpoint function to generate URLs like /api/trpc/eventTypes/duplicate/get
- Update ENDPOINTS array to include full paths with method names
- Fixes URL generation bug where dots were used instead of slashes

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
…:calcom/cal.com into devin/split-eventtypes-router-1756907432
@keithwillcode
Copy link
Contributor Author

This reduces compilation time for /event-types by 40-50% on my machine.
@calcom/web:dev: ✓ Compiled /event-types in 4.5s

@keithwillcode
Copy link
Contributor Author

Closing since this was just a test. We don't actually want to go this route. Exploring #23555 instead.

@keithwillcode keithwillcode deleted the devin/split-eventtypes-router-1756907432 branch September 17, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only foundation size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant