Refactor: Improve code structure with shared types and API client#2
Open
Refactor: Improve code structure with shared types and API client#2
Conversation
- Centralized all API-related Zod schemas and TypeScript types into `src/lib/types/api-schemas.ts`. - Updated API routes and client components to use these shared types. - Created an API client module `src/lib/api-client.ts` to encapsulate fetch calls to backend AI API routes. - Refactored client components (Analysis page, Dashboard, Training Bot interface) to use the new API client. These changes improve type safety, reduce code duplication, and make client-side API interactions cleaner and more maintainable.
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the chess analysis application to improve code organization and type safety by centralizing API-related schemas and creating a dedicated API client module. The changes eliminate the dependency on Genkit AI flows and implement direct Next.js API routes for all backend functionality.
Key changes:
- Centralized all Zod schemas and TypeScript types into a shared
api-schemas.tsfile - Created a unified API client module to handle all backend API interactions
- Converted AI flows to standard Next.js API routes with proper validation and error handling
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/lib/types/api-schemas.ts |
New centralized file containing all API schemas and TypeScript types |
src/lib/api-client.ts |
New API client module with typed methods for all backend endpoints |
src/components/train/training-bot-interface.tsx |
Updated to use new API client instead of direct flow imports |
src/app/api/ai/*/route.ts |
New Next.js API routes replacing Genkit AI flows |
src/app/(app)/page.tsx |
Updated dashboard to use new API client |
src/app/(app)/analysis/page.tsx |
Updated analysis page to use new API client |
src/ai/flows/*.ts |
Removed old Genkit flow files |
package.json |
Removed Genkit dependencies and scripts |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
src/lib/types/api-schemas.ts.src/lib/api-client.tsto encapsulate fetch calls to backend AI API routes.These changes improve type safety, reduce code duplication, and make client-side API interactions cleaner and more maintainable.