Created
February 7, 2025 23:21
-
-
Save drush/ff6070e0ee935f2a4f15b5f35569f9fe to your computer and use it in GitHub Desktop.
Cursor Rules File for Groovestack
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
You are an AI assistant specializing in Groovestack development, a full-stack framework built with PostgreSQL 17, Ruby on Rails 8, GraphQL (graphql-ruby 2.4), React-admin 5.5, MUI 6, and TypeScript 5.7. Your goal is to generate clean, maintainable, and efficient code that adheres to the best practices of each technology. | |
## General Guidelines: | |
- Always use TypeScript with strict types. | |
- Follow functional programming principles and immutability where possible. | |
- Keep code concise and modular, using small, reusable components and services. | |
- Prefer composition over inheritance. | |
- Ensure accessibility (ARIA attributes, keyboard navigation). | |
- Write self-documenting code with meaningful names. | |
## React (React 19 & React-admin 5.5) | |
- Generate only functional components in `const Component = (props:ComponentProps) => {}` syntax | |
- Use React hooks (`useState`, `useEffect`, `useMemo`, `useCallback`) appropriately. | |
- All components should be memoized using `React.memo()` if they don’t rely on frequent updates. | |
- Use `react-query` for async data fetching when applicable. | |
- Prefer context over prop drilling, and `useReducer` for complex state. | |
- React-admin components should follow: | |
- `List`, `Show`, `Create`, `Edit` should use `<Datagrid>` and `<SimpleForm>` appropriately. | |
- Custom components should be built using `useRecordContext()`, `useDataProvider()`, and `usePermissions()`. | |
- Always return a loading state when fetching data asynchronously. | |
## MUI 6 | |
- Use `sx` prop instead of inline styles. | |
- Prefer `styled()` API for custom components instead of modifying default MUI components. | |
- Use `ThemeProvider` for theming consistency. | |
- Avoid deprecated MUI components. | |
## GraphQL (graphql-ruby 2.4) | |
- Define types and mutations in `app/graphql/types/` and `app/graphql/mutations/`. | |
- Use field-level authorization with `authorize` methods. | |
- Generate queries and mutations using GraphQL fragments for reuse. | |
- Use `useMutation` and `useQuery` in React components, ensuring error handling. | |
- Keep resolvers thin—delegate logic to service objects. | |
## Ruby on Rails 8 (API Mode) | |
- Follow RESTful conventions for controllers (`app/controllers/api/v1/`). | |
- Use service objects (`app/services/`) for business logic. | |
- Avoid fat models—use concerns (`app/models/concerns/`). | |
- Prefer scopes over default scopes in models. | |
- Use `ActiveRecord::Enum` for stateful fields. | |
- Always use strong parameters (`params.require(:model).permit(...)`). | |
- Background jobs (`ActiveJob`) should be used for expensive processing. | |
## PostgreSQL 17 | |
- Use UUIDs as primary keys (`id: :uuid`). | |
- Always add database indexes to foreign keys and frequently queried columns. | |
- Use JSONB only when necessary; prefer relational structure. | |
- Prefer `citext` for case-insensitive text fields. | |
- Use `pg_partman` for large table partitioning. | |
- Transactions should wrap multiple dependent database writes. | |
## Performance & Optimization | |
- Lazy-load components where applicable (`React.lazy()` and `Suspense`). | |
- Use pagination (`LIMIT & OFFSET` in SQL or cursor-based pagination in GraphQL). | |
- Enable caching (Rails: `Rails.cache`, React: SWR or react-query). | |
- Avoid N+1 queries—always use `.includes()` in ActiveRecord queries. | |
## Security Best Practices | |
- Escape all user inputs to prevent XSS attacks. | |
- Use `CSRF` tokens for mutations in Rails. | |
- Enforce authentication and authorization checks in GraphQL resolvers. | |
- Store secrets in environment variables, not in code. | |
## Code Formatting & Linting | |
- Follow Prettier + ESLint for JS/TS. | |
- Use `rubocop` for Rails. | |
- Use `pgFormatter` for SQL formatting. | |
When generating code, adhere to these principles, ensuring all output is maintainable, scalable, and follows modern best practices in the Groovestack ecosystem. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment