Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Oct 29, 2025

Summary by CodeRabbit

  • New Features

    • Fastify framework is now supported as a backend option for server-side API integration
  • Chores

    • Added Fastify and fastify-plugin as optional peer dependencies for improved framework flexibility
  • Tests

    • Added comprehensive test suite for Fastify adapter covering CRUD operations, filtering, aggregation, and error handling scenarios

Copilot AI review requested due to automatic review settings October 29, 2025 21:16
@claude
Copy link

claude bot commented Oct 29, 2025

Claude finished @ymc9's task —— View job


Code Review for Fastify Adapter Migration

I've completed my review of this PR that adds Fastify adapter support to the server package. Here's my comprehensive feedback:

Todo List:

  • Review package.json changes and dependencies
  • Analyze the new common adapter utilities
  • Review Fastify plugin implementation
  • Check Express middleware refactoring
  • Review Next.js adapter changes
  • Review test coverage and quality
  • Provide comprehensive feedback

Strengths

  1. Well-structured implementation: The new Fastify adapter follows similar patterns to existing Express and Next.js adapters, maintaining consistency across the codebase.

  2. Good abstraction with common utilities: The introduction of CommonAdapterOptions in packages/server/src/adapter/common.ts:7 provides a clean abstraction that reduces code duplication.

  3. Comprehensive test coverage: The test suite in packages/server/test/adapter/fastify.test.ts covers both RPC and REST handlers with thorough integration tests.

  4. Proper dependency management: Fastify dependencies are correctly marked as optional peer dependencies in packages/server/package.json:86-98.

🔍 Issues and Recommendations

Critical Issues

  1. Missing build configuration 📋

    • The tsup.config.ts file at packages/server/tsup.config.ts:3-8 doesn't include the new Fastify adapter entry point
    • Fix needed: Add fastify: 'src/adapter/fastify/index.ts' to the entry configuration
    • Impact: The Fastify adapter won't be built and distributed
  2. Missing package.json export 📦

    • The package.json exports section doesn't include a Fastify export path
    • Fix needed: Add Fastify export similar to Express at packages/server/package.json:42-51
    • Impact: Users cannot import the Fastify adapter

Security Concerns

  1. Inconsistent error handling ⚠️

    • In packages/server/src/adapter/fastify/plugin.ts:46, errors are exposed in response messages: ${err}
    • Risk: Could leak sensitive information in error messages
    • Recommendation: Follow Express pattern with generic error messages in production
  2. Client validation inconsistency 🔒

    • Fastify plugin at packages/server/src/adapter/fastify/plugin.ts:31-34 returns a 500 error when client is null, but continues execution
    • Express middleware properly handles this case with early returns
    • Fix needed: Add proper early return after sending error response

Code Quality Issues

  1. Documentation inconsistency 📝

    • Comment at packages/server/src/adapter/fastify/plugin.ts:18 mentions "PrismaClient" but should be "ClientContract" or "ZenStackClient"
    • Error message at line 32 also mentions "prisma" instead of proper client name
  2. Type casting concerns 🎯

    • Use of (request.params as any)['*'] at packages/server/src/adapter/fastify/plugin.ts:39 is not type-safe
    • Recommendation: Add proper type definitions for the wildcard parameter
  3. Missing parameter validation

    • The prefix parameter defaults to empty string but should validate format
    • Recommendation: Add validation for prefix format (should start with '/')

Performance Considerations

  1. URL parsing efficiency 🚀
    • Express middleware reconstructs URLs for query parameter parsing, but Fastify doesn't need this overhead
    • Good: Fastify implementation correctly uses request.query directly

Test Coverage Assessment

  1. Good coverage but missing edge cases
    • Tests cover both RPC and REST handlers thoroughly
    • Missing: Tests for error scenarios (null client, malformed requests)
    • Missing: Tests for different prefix configurations

🔧 Minor Improvements

  1. Code style consistency
    • Extra blank line at packages/server/src/adapter/fastify/index.ts:3 should be removed
    • Consider adding JSDoc comments for the plugin function

📋 Recommended Actions

Before merging:

  1. Add Fastify entry to tsup.config.ts
  2. Add Fastify export to package.json
  3. Fix error handling in plugin.ts
  4. Update documentation references from "Prisma" to "ZenStackClient"
  5. Add proper TypeScript types for wildcard params

Future improvements:

  1. Add comprehensive error scenario tests
  2. Consider adding validation for plugin options
  3. Add performance benchmarks comparing adapters

🎯 Overall Assessment

This is a solid implementation that follows good patterns established in the codebase. The main concerns are around build configuration and error handling that need to be addressed before merging. The test coverage is good, and the abstraction with common utilities is well-designed.

Recommendation: Approve after addressing critical issues 1, 2, and 4.

@coderabbitai
Copy link

coderabbitai bot commented Oct 29, 2025

Walkthrough

The PR introduces Fastify adapter support for ZenStack by extracting a common adapter options interface, implementing a new Fastify plugin that routes RPC and REST API requests, and updating existing adapters to use the shared CommonAdapterOptions. Fastify and fastify-plugin are added as optional peer dependencies with corresponding dev dependencies.

Changes

Cohort / File(s) Summary
Dependency Configuration
packages/server/package.json
Added fastify (^5.6.1) and fastify-plugin (^5.1.0) as devDependencies; added as peerDependencies (^5.0.0 range); marked fastify, fastify-plugin, and next as optional in peerDependenciesMeta.
Common Adapter Interface
packages/server/src/adapter/common.ts
Introduced new exported interface CommonAdapterOptions<Schema extends SchemaDef> with apiHandler property, centralizing shared adapter configuration.
Adapter Interface Refactoring
packages/server/src/adapter/express/middleware.ts, packages/server/src/adapter/next/index.ts
Updated MiddlewareOptions and route handler options to extend CommonAdapterOptions; removed direct apiHandler dependency from Next adapter; replaced local CommonAdapterOptions import with external module import.
Fastify Adapter Implementation
packages/server/src/adapter/fastify/plugin.ts, packages/server/src/adapter/fastify/index.ts
Implemented new Fastify plugin (ZenStackFastifyPlugin) with PluginOptions interface extending CommonAdapterOptions; plugin registers catch-all route, invokes apiHandler.handleRequest, and includes error handling; re-exported from index.
Fastify Adapter Tests
packages/server/test/adapter/fastify.test.ts
Added comprehensive test suite covering RPC and REST handler paths, validating CRUD operations, filters, aggregations, groupBy, and error handling with appropriate HTTP status codes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • Focus areas:
    • Verify CommonAdapterOptions extraction is consistently applied across all adapters (Next, Express, Fastify)
    • Validate Fastify plugin error handling and request/response mapping logic in plugin.ts
    • Confirm test coverage adequately exercises both RPC and REST paths with realistic client scenarios
    • Check that optional peer dependency declarations align with actual usage requirements

Possibly related PRs

Poem

🐰 With whiskers twitching, hopping with glee,
A Fastify gateway for all the APIs!
Common options shared, the adapters align,
Express and Next and Fastify combine! 🚀

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat(server): migrate fastify adapter" is fully related to the main changes in the changeset. The primary focus of this PR is introducing and implementing a new Fastify adapter for the ZenStack server, including the creation of a Fastify plugin module with handler logic, test coverage, and supporting dependency additions. While the PR also includes refactoring efforts (such as extracting CommonAdapterOptions into a shared interface and updating other adapters), these are secondary to the primary objective of adding Fastify adapter support. The title is concise, specific, and accurately conveys the main change in a way that teammates can quickly understand the purpose of the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/migrate-fastify

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds Fastify adapter support to the ZenStack server package, enabling users to integrate ZenStack with Fastify applications. The implementation follows the existing adapter pattern used for Express and Next.js.

  • Adds Fastify plugin implementation with support for both RPC and REST API handlers
  • Refactors common adapter options into a shared interface to reduce code duplication
  • Adds comprehensive test coverage for the new Fastify adapter

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pnpm-lock.yaml Adds Fastify dependencies (fastify@5.6.1, fastify-plugin@5.1.0) and their transitive dependencies
packages/server/package.json Adds Fastify as optional peer dependencies and dev dependencies
packages/server/src/adapter/common.ts Creates shared CommonAdapterOptions interface to reduce duplication across adapters
packages/server/src/adapter/fastify/plugin.ts Implements the Fastify plugin for handling ZenStack CRUD requests
packages/server/src/adapter/fastify/index.ts Exports the Fastify plugin and its options interface
packages/server/src/adapter/express/middleware.ts Refactors to extend CommonAdapterOptions instead of duplicating the interface
packages/server/src/adapter/next/index.ts Refactors to extend CommonAdapterOptions instead of duplicating the interface
packages/server/test/adapter/fastify.test.ts Adds comprehensive test suite for Fastify adapter with RPC and REST handlers
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/server/package.json (1)

27-51: Add export entry for the Fastify adapter.

The package.json adds Fastify dependencies but is missing an export entry for the new adapter. Users won't be able to import @zenstackhq/server/fastify without it.

Add this export entry after the express export:

         "require": {
             "types": "./dist/express.d.cts",
             "default": "./dist/express.cjs"
         }
+    },
+    "./fastify": {
+        "import": {
+            "types": "./dist/fastify.d.ts",
+            "default": "./dist/fastify.js"
+        },
+        "require": {
+            "types": "./dist/fastify.d.cts",
+            "default": "./dist/fastify.cjs"
+        }
     }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95da8d2 and f826155.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • packages/server/package.json (2 hunks)
  • packages/server/src/adapter/common.ts (1 hunks)
  • packages/server/src/adapter/express/middleware.ts (1 hunks)
  • packages/server/src/adapter/fastify/index.ts (1 hunks)
  • packages/server/src/adapter/fastify/plugin.ts (1 hunks)
  • packages/server/src/adapter/next/index.ts (1 hunks)
  • packages/server/test/adapter/fastify.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
{packages,samples,tests}/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place packages only under packages/, samples/, or tests/

Files:

  • packages/server/src/adapter/fastify/index.ts
  • packages/server/src/adapter/next/index.ts
  • packages/server/src/adapter/common.ts
  • packages/server/package.json
  • packages/server/src/adapter/fastify/plugin.ts
  • packages/server/test/adapter/fastify.test.ts
  • packages/server/src/adapter/express/middleware.ts
🧬 Code graph analysis (4)
packages/server/src/adapter/common.ts (2)
packages/sdk/src/schema/schema.ts (1)
  • SchemaDef (10-18)
packages/server/src/types.ts (1)
  • ApiHandler (67-77)
packages/server/src/adapter/fastify/plugin.ts (3)
packages/sdk/src/schema/schema.ts (1)
  • SchemaDef (10-18)
packages/server/src/adapter/common.ts (1)
  • CommonAdapterOptions (7-12)
packages/orm/src/client/contract.ts (1)
  • ClientContract (50-170)
packages/server/test/adapter/fastify.test.ts (2)
packages/testtools/src/client.ts (1)
  • createTestClient (52-169)
packages/server/test/utils.ts (1)
  • makeUrl (31-33)
packages/server/src/adapter/express/middleware.ts (2)
packages/sdk/src/schema/schema.ts (1)
  • SchemaDef (10-18)
packages/server/src/adapter/common.ts (1)
  • CommonAdapterOptions (7-12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Cleanup artifacts
  • GitHub Check: build-test (20.x, postgresql)
  • GitHub Check: build-test (20.x, sqlite)
  • GitHub Check: claude-review
🔇 Additional comments (10)
packages/server/src/adapter/fastify/index.ts (1)

1-2: LGTM!

Clean re-export pattern for the Fastify adapter module.

packages/server/src/adapter/common.ts (1)

1-12: LGTM!

Well-designed shared interface that standardizes adapter options across Express, Fastify, and Next.js adapters.

packages/server/src/adapter/express/middleware.ts (2)

4-4: LGTM!

Clean migration to use the shared CommonAdapterOptions interface.


9-25: LGTM!

The interface properly extends CommonAdapterOptions while adding Express-specific options (getClient and sendResponse). This maintains backward compatibility while standardizing the base options.

packages/server/src/adapter/next/index.ts (2)

5-5: LGTM!

Clean migration to the shared CommonAdapterOptions interface.


12-37: LGTM!

Both Next.js adapter interfaces properly extend CommonAdapterOptions while adding their Next.js-specific options. This maintains consistency across adapters.

packages/server/test/adapter/fastify.test.ts (3)

1-7: LGTM!

Clean imports and proper use of test utilities.


8-109: LGTM!

Comprehensive test coverage for the RPC handler path including:

  • Basic CRUD operations (create, read, update, delete)
  • Query filtering
  • Aggregations (count, aggregate, groupBy)
  • Relations (nested creates)
  • Error handling (invalid paths and malformed queries)

141-198: LGTM!

Thorough test coverage for the REST handler path with proper JSON:API format validation and filtering tests.

packages/server/src/adapter/fastify/plugin.ts (1)

55-57: LGTM!

Proper use of fastify-plugin to wrap the plugin handler, allowing it to be registered with proper encapsulation behavior.

@ymc9 ymc9 merged commit 5699e5b into dev Oct 29, 2025
4 checks passed
@claude
Copy link

claude bot commented Oct 29, 2025

Claude finished @ymc9's task —— View job


Code Review for Fastify Adapter Migration

I've completed my review of this PR that adds Fastify adapter support to the server package. Here's my comprehensive feedback:

Todo List:

  • Review package.json changes and dependencies
  • Analyze the new common adapter utilities
  • Review Fastify plugin implementation
  • Check Express middleware refactoring
  • Review Next.js adapter changes
  • Review test coverage and quality
  • Provide comprehensive feedback

Strengths

  1. Well-structured implementation: The new Fastify adapter follows similar patterns to existing Express and Next.js adapters, maintaining consistency across the codebase.

  2. Good abstraction with common utilities: The introduction of CommonAdapterOptions in packages/server/src/adapter/common.ts:7 provides a clean abstraction that reduces code duplication.

  3. Comprehensive test coverage: The test suite in packages/server/test/adapter/fastify.test.ts covers both RPC and REST handlers with thorough integration tests.

  4. Proper dependency management: Fastify dependencies are correctly marked as optional peer dependencies in packages/server/package.json:86-98.

🔍 Issues and Recommendations

Critical Issues

  1. Missing build configuration 📋

    • The tsup.config.ts file at packages/server/tsup.config.ts:3-8 doesn't include the new Fastify adapter entry point
    • Fix needed: Add fastify: 'src/adapter/fastify/index.ts' to the entry configuration
    • Impact: The Fastify adapter won't be built and distributed
  2. Missing package.json export 📦

    • The package.json exports section doesn't include a Fastify export path
    • Fix needed: Add Fastify export similar to Express at packages/server/package.json:42-51
    • Impact: Users cannot import the Fastify adapter

Security Concerns

  1. Inconsistent error handling ⚠️

    • In packages/server/src/adapter/fastify/plugin.ts:46, errors are exposed in response messages: ${err}
    • Risk: Could leak sensitive information in error messages
    • Recommendation: Follow Express pattern with generic error messages in production
  2. Client validation inconsistency 🔒

    • Fastify plugin at packages/server/src/adapter/fastify/plugin.ts:31-34 returns a 500 error when client is null, but continues execution
    • Express middleware properly handles this case with early returns
    • Fix needed: Add proper early return after sending error response

Code Quality Issues

  1. Documentation inconsistency 📝

    • Comment at packages/server/src/adapter/fastify/plugin.ts:18 mentions "PrismaClient" but should be "ClientContract" or "ZenStackClient"
    • Error message at line 32 also mentions "prisma" instead of proper client name
  2. Type casting concerns 🎯

    • Use of (request.params as any)['*'] at packages/server/src/adapter/fastify/plugin.ts:39 is not type-safe
    • Recommendation: Add proper type definitions for the wildcard parameter
  3. Missing parameter validation

    • The prefix parameter defaults to empty string but should validate format
    • Recommendation: Add validation for prefix format (should start with '/')

Performance Considerations

  1. URL parsing efficiency 🚀
    • Express middleware reconstructs URLs for query parameter parsing, but Fastify doesn't need this overhead
    • Good: Fastify implementation correctly uses request.query directly

Test Coverage Assessment

  1. Good coverage but missing edge cases
    • Tests cover both RPC and REST handlers thoroughly
    • Missing: Tests for error scenarios (null client, malformed requests)
    • Missing: Tests for different prefix configurations

🔧 Minor Improvements

  1. Code style consistency
    • Extra blank line at packages/server/src/adapter/fastify/index.ts:3 should be removed
    • Consider adding JSDoc comments for the plugin function

📋 Recommended Actions

Before merging:

  1. Add Fastify entry to tsup.config.ts
  2. Add Fastify export to package.json
  3. Fix error handling in plugin.ts
  4. Update documentation references from "Prisma" to "ZenStackClient"
  5. Add proper TypeScript types for wildcard params

Future improvements:

  1. Add comprehensive error scenario tests
  2. Consider adding validation for plugin options
  3. Add performance benchmarks comparing adapters

🎯 Overall Assessment

This is a solid implementation that follows good patterns established in the codebase. The main concerns are around build configuration and error handling that need to be addressed before merging. The test coverage is good, and the abstraction with common utilities is well-designed.

Recommendation: Approve after addressing critical issues 1, 2, and 4.


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