feat: Setup workspaces, generated schemas, and PoC#859
feat: Setup workspaces, generated schemas, and PoC#859CodeWithCJ merged 5 commits intoCodeWithCJ:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the project's architecture by introducing a monorepo setup with pnpm workspaces. The core improvement is the implementation of automated Zod schema generation from the database, which provides robust type safety and runtime validation for API interactions. This change is demonstrated through a proof of concept on the backup feature, ensuring data consistency between the backend and frontend. The new structure promotes code reusability and maintainability across different parts of the application. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a great step forward in improving the project's architecture by introducing a shared workspace and auto-generated Zod schemas for type safety. The migration of the backup feature serves as a good proof of concept.
My review focuses on two main areas to ensure the new setup is robust and maintainable:
- The scripts for generating types in
shared/package.jsonhave some issues with paths and variable naming that will prevent them from working as intended. - The generated Zod schemas frequently use
z.any()for foreign key relationships (likeuser_id), which significantly reduces the type-safety benefits.
Fixing these issues will solidify the foundation of this new type-safe architecture.
Note: Security Review did not run due to the size of the PR.
| }), | ||
| ); | ||
|
|
||
| const userIdSchema = z.any(); |
There was a problem hiding this comment.
Using z.any() for userIdSchema undermines the type safety that Zod is meant to provide. This seems to be a recurring pattern across many of the newly generated schema files for foreign key IDs.
The schema for Users (shared/src/schemas/Users.zod.ts) defines a branded type usersIdSchema which seems to be the correct type for this foreign key. It would be much safer to import and use that specific schema here.
I'd recommend replacing const userIdSchema = z.any(); with an import at the top of the file:
import { usersIdSchema } from "./Users.zod";And then using usersIdSchema for the user_id fields. This should be applied to all other schemas referencing a user ID.
There was a problem hiding this comment.
Not the right time to fine tune 6000 lines of schemes
13ff28c to
c0e4570
Compare
Description
This PR establishes the shared package architecture and introduces automated Zod schemas generated from the database directly using kanel and ts-to-zod. This means that the types are as accurate as possible. The automatic creation from the database was just a one time thing because I think that would add too much complexity. Writing a new schema if you add a database table is easier and more beginner friendly
A proof of concept has been implemented for the backup feature in the frontend. The types are defined by the schemas so we only have a single source of truth. This only applies to types that are used to communicate with the backend. Other types should not be converted to zod schemas, but can be shared aswell if that's helpful.
Changes
@workspace/shared.ts-to-zodto automatically generate Zod schemas and inferred types from existing TypeScript interfaces.BackupSettings,BackupSettingsMutator). This guarantees that any mismatch between the backend data and expected frontend types is caught immediately at runtime, preventing silent data corruption or UI errors.package-lock.jsonto strictly enforcepnpmusage.CI/Docker
Related Issue
PR type [ ] Issue [ ] New Feature [ ] Documentation
Linked Issue: #
Checklist
Please check all that apply:
pnpm run validate(especially for Frontend).en) translation file (if applicable).rls_policies.sqlfor any new user-specific tables.Screenshots (if applicable)
Before
[Insert screenshot/GIF here]
After
[Insert screenshot/GIF here]