Skip to content

Conversation

@aidankmcalister
Copy link
Member

@aidankmcalister aidankmcalister commented Aug 13, 2025

Summary by CodeRabbit

  • New Features
    • Automatic user provisioning via Clerk webhooks (handles user.created events) and persists users to the database.
  • Documentation
    • Added setup step to run the initial Prisma migration.
  • Refactor
    • Prisma schema updated: IDs switched to integers with autoincrement; generator output path adjusted. Requires running migrations.
  • Chores
    • Dependency upgrades (Next.js, Clerk, Prisma, Tailwind, TypeScript) and package rename.
    • Simplified ignore rules and adjusted TypeScript path mapping.
  • Style
    • Code formatting and import path cleanups with no functional changes.

@coderabbitai
Copy link

coderabbitai bot commented Aug 13, 2025

Walkthrough

Introduces a new Clerk webhook API route under app/, migrates Prisma client setup from src/ to lib/, updates Prisma schema (IDs to Int, generator/provider/output path), adjusts tsconfig alias, modifies .gitignore scope, updates dependencies and removes ESLint config, and makes minor formatting and README setup changes.

Changes

Cohort / File(s) Summary of changes
Webhook API route migration
orm/clerk-nextjs/app/api/webhooks/clerk/route.ts, orm/clerk-nextjs/src/app/api/webhooks/clerk/route.ts
Added App Router POST handler verifying Clerk webhooks and upserting user on user.created; removed old src-based webhook route using Svix.
Prisma client relocation
orm/clerk-nextjs/lib/prisma.ts, orm/clerk-nextjs/src/lib/prisma.ts
Added Prisma client singleton with withAccelerate() under lib/; removed prior src/lib version.
Prisma schema and generation paths
orm/clerk-nextjs/prisma/schema.prisma, orm/clerk-nextjs/.gitignore, orm/clerk-nextjs/tsconfig.json, orm/clerk-nextjs/README.md
Switched generator provider to "prisma-client" and output to ../app/generated/prisma; changed model IDs to Int autoincrement (User, Post; Post.authorId Int); narrowed .gitignore to /app/generated/prisma; updated "@/*" path to root; added migration step to README.
Package and tooling updates
orm/clerk-nextjs/package.json, orm/clerk-nextjs/eslint.config.mjs
Bumped deps (Next, Clerk, Accelerate), removed @prisma/client and svix, refreshed devDeps ranges; deleted ESLint flat config file.
UI/source formatting
orm/clerk-nextjs/app/components/PostInputs.tsx, orm/clerk-nextjs/app/layout.tsx, orm/clerk-nextjs/app/page.tsx
Applied formatting (quotes/semicolons/import path tweak); no behavioral changes aside from minor type signature punctuation in RootLayout.

Sequence Diagram(s)

sequenceDiagram
  participant Clerk as Clerk
  participant Route as Next.js Route (/api/webhooks/clerk)
  participant Verify as Clerk SDK (verifyWebhook)
  participant DB as Prisma

  Clerk->>Route: POST webhook (headers + body)
  Route->>Verify: verifyWebhook(headers, body)
  alt verification ok
    Verify-->>Route: event (type, data)
    alt event.type == "user.created"
      Route->>DB: upsert User by clerkId (email, name)
      DB-->>Route: upsert result
      Route-->>Clerk: 200 "Webhook received"
    else other event
      Route-->>Clerk: 200
    end
  else verification fails
    Route-->>Clerk: 400 "Error verifying webhook"
  end
Loading

Possibly related PRs

  • DC-4745 AI SDK Example Project #8276: Similar migration of Prisma generator output to ../app/generated/prisma, addition of lib/prisma.ts with withAccelerate(), and aligned .gitignore/README/tsconfig updates.

Suggested reviewers

  • mhessdev
  • nikolasburk
  • nurul3101
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch DC-4755-fix-example-projects

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🔭 Outside diff range comments (2)
orm/clerk-nextjs/package.json (2)

5-10: Lint script likely fails in CI without eslint installed

You removed ESLint deps but kept "lint": "next lint". In CI, Next will prompt to install ESLint and exit non‑zero. Either re-add ESLint deps or drop the script.

Option A: Re-add ESLint packages (recommended if you intend to lint):

   "scripts": {
     "dev": "next dev --turbopack",
     "build": "next build",
     "start": "next start",
-    "lint": "next lint"
+    "lint": "next lint"
   },

Add these devDependencies (outside this hunk):

{
  "devDependencies": {
    "eslint": "^9",
    "eslint-config-next": "15.4.6"
  }
}

Option B: Remove the lint script:

   "scripts": {
     "dev": "next dev --turbopack",
     "build": "next build",
-    "start": "next start",
-    "lint": "next lint"
+    "start": "next start"
   },

5-10: Guarantee Prisma client generation in local and CI via a postinstall hook

With the custom generator/output and no @prisma/client dependency, generation must run before build/tests. Add a postinstall (or prepare) script.

Apply this diff:

   "scripts": {
     "dev": "next dev --turbopack",
     "build": "next build",
     "start": "next start",
-    "lint": "next lint"
+    "lint": "next lint",
+    "postinstall": "prisma generate"
   },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63d6b80 and d2fe646.

⛔ Files ignored due to path filters (1)
  • orm/clerk-nextjs/app/favicon.ico is excluded by !**/*.ico
📒 Files selected for processing (13)
  • orm/clerk-nextjs/.gitignore (1 hunks)
  • orm/clerk-nextjs/README.md (1 hunks)
  • orm/clerk-nextjs/app/api/webhooks/clerk/route.ts (1 hunks)
  • orm/clerk-nextjs/app/components/PostInputs.tsx (2 hunks)
  • orm/clerk-nextjs/app/layout.tsx (2 hunks)
  • orm/clerk-nextjs/app/page.tsx (2 hunks)
  • orm/clerk-nextjs/eslint.config.mjs (0 hunks)
  • orm/clerk-nextjs/lib/prisma.ts (1 hunks)
  • orm/clerk-nextjs/package.json (2 hunks)
  • orm/clerk-nextjs/prisma/schema.prisma (2 hunks)
  • orm/clerk-nextjs/src/app/api/webhooks/clerk/route.ts (0 hunks)
  • orm/clerk-nextjs/src/lib/prisma.ts (0 hunks)
  • orm/clerk-nextjs/tsconfig.json (1 hunks)
💤 Files with no reviewable changes (3)
  • orm/clerk-nextjs/src/app/api/webhooks/clerk/route.ts
  • orm/clerk-nextjs/src/lib/prisma.ts
  • orm/clerk-nextjs/eslint.config.mjs
🧰 Additional context used
🧬 Code Graph Analysis (2)
orm/clerk-nextjs/app/api/webhooks/clerk/route.ts (1)
orm/clerk-nextjs/app/api/posts/route.ts (1)
  • POST (4-25)
orm/clerk-nextjs/app/components/PostInputs.tsx (1)
accelerate/accelerate-hacker-news/app/submit/actions/addPost.ts (1)
  • createPost (5-25)
🔇 Additional comments (15)
orm/clerk-nextjs/tsconfig.json (1)

22-22: LGTM: Path mapping updated to support root-level imports.

The change from "./src/*" to "./*" properly aligns with the project structure migration from src/ to root-level directories, enabling imports like @/lib/prisma and @/app/components/*.

orm/clerk-nextjs/README.md (1)

46-46: Essential step added for Prisma setup.

The added migration step is crucial for setting up the database schema after adding the connection URL. This ensures the database is properly initialized before running the application.

orm/clerk-nextjs/.gitignore (1)

44-44: LGTM: Gitignore updated for new Prisma client location.

The ignore rule correctly targets the new generated Prisma client location at /app/generated/prisma, which aligns with the schema output path change.

orm/clerk-nextjs/lib/prisma.ts (4)

4-6: LGTM: Proper global singleton pattern implementation.

The global type extension correctly types the globalForPrisma object for storing the Prisma client instance across module reloads in development.


8-9: LGTM: Singleton with Accelerate extension.

The implementation correctly creates a singleton Prisma client with the Accelerate extension applied, following Next.js best practices for database connections.


11-11: LGTM: Development-only caching.

Properly caches the Prisma instance on the global object only in non-production environments to prevent connection exhaustion during development hot reloads.


13-13: LGTM: Clean default export.

The default export provides a clean interface for importing the configured Prisma client throughout the application.

orm/clerk-nextjs/app/layout.tsx (4)

1-11: Minor formatting improvements applied.

The changes improve code consistency with proper quote usage and import formatting. All changes are stylistic and don't affect functionality.


13-26: LGTM: Font configuration updated with consistent formatting.

The Geist font configurations maintain the same functionality while applying consistent formatting with proper quotes and spacing.


28-32: Minor type formatting improvement.

The addition of a semicolon after React.ReactNode in the type definition improves consistency with TypeScript formatting conventions.


37-37: LGTM: Template literal and formatting improvements.

The changes improve code readability with proper template literal formatting and consistent semicolon usage.

Also applies to: 43-43, 57-58

orm/clerk-nextjs/app/api/webhooks/clerk/route.ts (1)

1-1: Import path for verifyWebhook is correct
Verified that @clerk/nextjs@6.30.1 exports verifyWebhook from the @clerk/nextjs/webhooks subpath (see Clerk docs¹). No changes needed.

Citations:

  1. https://clerk.com/docs/users/sync-data-to-your-backend?utm_source=chatgpt.com
orm/clerk-nextjs/prisma/schema.prisma (1)

12-12: Breaking change to ID type: ensure migrations and dependent code are updated

Changing your Prisma model’s id field from String to Int is a breaking change. Before merging, please:

  • Verify your Prisma migration either transforms existing string IDs into integers or resets them cleanly.
  • Confirm all API routes consume numeric IDs (e.g. in app/api/posts/route.ts, authorId = user.id should be an Int).
  • Audit client-side code, auth callbacks/sessions, URL parameters, and any tests or fixtures that reference .id to ensure they expect numbers, not strings.
  • Check seed scripts or custom SQL to maintain referential integrity after the change.

Let me know if you’d like a sample Prisma migration script for resetting vs. transforming your existing data.

orm/clerk-nextjs/package.json (1)

12-17: Clerk webhook verification supported via @clerk/nextjs/webhooks

The webhooks subpath is exported in @clerk/nextjs@6.30.1, so you can safely import from
"@clerk/nextjs/webhooks" for your route.ts verification helper. No need to reintroduce svix or adjust the current setup.

orm/clerk-nextjs/app/page.tsx (1)

1-12: LGTM: Path alias usage and query look consistent with the new Prisma/User shape

Imports resolve to the new prisma client wrapper, and the relation filter on author.clerkId aligns with the schema changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants