Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Sourcery-ai and Coderabbitai configuration #322

Open
AndlerRL opened this issue Dec 5, 2024 · 5 comments
Open

Improve Sourcery-ai and Coderabbitai configuration #322

AndlerRL opened this issue Dec 5, 2024 · 5 comments
Assignees
Labels
chore devops enhancement New feature or request

Comments

@AndlerRL
Copy link
Contributor

AndlerRL commented Dec 5, 2024

Enhance AI assistants to improve the sequence on tests and reviews:

  • To use first sourcery-ai before coderabbitai does a revision (if applicable)
  • To avoid execution at the same time: this is for the fix of multiple comments of the same issue and/or unnecessary bug reports.

Documentation:

@AndlerRL AndlerRL added enhancement New feature or request devops chore labels Dec 5, 2024
@AndlerRL AndlerRL self-assigned this Dec 5, 2024
@AndlerRL
Copy link
Contributor Author

AndlerRL commented Dec 5, 2024

Coderabbitai configuration can be done at their app dashboard, so as sourcery-ai dashboard (admin access only).

@coderabbitai I need to create a path instructions for you to follow up on next PRs revisions. Provide an initial instruction that follows code standards that we have been following for all paths.

@sourcery-ai plan this update by first giving an initial prompt for all paths.

Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Tip

For best results, initiate chat on the files or code changes.

@AndlerRL Based on the detailed analysis of your repository structure, I notice this is a monorepo setup using Turborepo with multiple apps and packages. Let me refine the path-based instructions to better match your specific setup:

review_instructions:
  - paths: ["apps/masterbots.ai/**/*.{ts,tsx}"]
    instructions: |
      # Next.js Frontend Standards
      - Follow React best practices and hooks guidelines
      - Implement proper client/server component separation
      - Use proper data fetching patterns (Server Components, SWR, or React Query)
      - Implement proper error boundaries
      - Follow the shadcn/ui component patterns (based on components.json presence)
      - Ensure responsive design implementation
      - Use proper TypeScript types for props and state
      - Keep components focused and reusable
      
  - paths: ["apps/hasura/**/*.{yaml,yml,sql}"]
    instructions: |
      # Hasura Backend Standards
      - Follow proper table relationship definitions
      - Implement appropriate permissions
      - Use proper naming conventions for tables and columns
      - Ensure proper indexing for performance
      - Follow consistent metadata structure
      - Implement proper row-level security
      
  - paths: ["packages/mb-lib/**/*.{ts,tsx}"]
    instructions: |
      # Shared Library Standards
      - Keep utilities pure and side-effect free
      - Export proper TypeScript types
      - Document public APIs with JSDoc
      - Implement proper error handling
      - Keep functions small and focused
      - Use proper dependency injection patterns
      
  - paths: ["packages/mb-types/**/*.{ts,d.ts}"]
    instructions: |
      # Type Definitions Standards
      - Use precise and specific types
      - Avoid 'any' type usage
      - Document complex type definitions
      - Keep interfaces focused
      - Use proper type exports
      - Follow naming conventions for types, interfaces, and enums
      
  - paths: ["packages/mb-genql/**/*.{ts,tsx}"]
    instructions: |
      # GraphQL Generated Code Standards
      - Don't modify generated files directly
      - Ensure proper typing with the schema
      - Use proper query/mutation hooks
      - Implement proper error handling for GraphQL operations
      
  - paths: ["**/*.test.{ts,tsx}", "**/*.spec.{ts,tsx}"]
    instructions: |
      # Testing Standards
      - Follow AAA pattern (Arrange-Act-Assert)
      - Use proper mocking strategies
      - Test both success and error cases
      - Use meaningful test descriptions
      - Implement proper cleanup in tests
      - Use proper test utilities and helpers
      
  - paths: ["**/hooks/**/*.{ts,tsx}"]
    instructions: |
      # React Hooks Standards
      - Follow hooks naming convention (use'use' prefix)
      - Implement proper cleanup in useEffect
      - Follow hooks rules (no conditions, loops)
      - Keep hooks focused and reusable
      - Proper error and loading state handling
      
  - paths: ["**/api/**/*.{ts,tsx}"]
    instructions: |
      # API Route Standards
      - Implement proper request validation
      - Use appropriate HTTP status codes
      - Implement proper error handling
      - Add proper request logging
      - Follow RESTful principles
      - Implement proper rate limiting
      - Use proper TypeScript types for request/response

Would you like me to:
1. Add more specific instructions for any particular package or app?
2. Include additional standards for the Hasura setup?
3. Add specific instructions for environment configuration files?
4. Add instructions for handling animations (noticed JSON animation files in the codebase)?

Also, I notice you're using Biome (biome.json present). Would you like me to add specific instructions about code formatting and linting that align with your Biome configuration?





^-^
   |
  (。◕‿◕。) 
   |
  /||\
   /\

<details>
<summary>🔗 Analysis chain</summary>

Let me gather information about the codebase structure and existing code standards first.




Let me analyze the results and provide a comprehensive path-based instruction configuration for CodeRabbit.




@AndlerRL Based on the analysis of the codebase, here's a recommended path-based instruction configuration for CodeRabbit that aligns with your code standards:

```yaml
review_instructions:
  - paths: ["**/*.{ts,js}"]
    instructions: |
      # General Code Standards
      - Ensure consistent use of TypeScript with strict type checking
      - Follow a functional programming approach where possible
      - Use meaningful variable and function names that describe their purpose
      - Keep functions focused and single-responsibility
      - Implement proper error handling with custom error types
      - Add JSDoc comments for public APIs and complex functions
      
      # Testing Standards
      - Ensure new features have corresponding test files
      - Test files should follow the pattern: `*.test.ts` or `*.spec.ts`
      - Include unit tests for utility functions
      - Add integration tests for API endpoints
      - Test both success and error scenarios
      
      # File Organization
      - Keep related functionality in the same directory
      - Use feature-based folder structure
      - Separate business logic from API routes
      - Place interfaces and types in dedicated files
      
      # Code Quality
      - Maintain maximum line length of 100 characters
      - Use early returns to reduce nesting
      - Avoid duplicate code through proper abstraction
      - Implement proper dependency injection
      - Use constants for magic numbers and repeated strings

  - paths: ["**/api/**/*.{ts,js}"]
    instructions: |
      # API Specific Standards
      - Follow RESTful principles
      - Implement proper request validation
      - Use appropriate HTTP status codes
      - Include rate limiting where necessary
      - Add proper API documentation
      - Implement consistent error response format
      - Add request logging for debugging
      
  - paths: ["**/tests/**/*.{ts,js}"]
    instructions: |
      # Test File Standards
      - Use descriptive test names
      - Follow AAA pattern (Arrange-Act-Assert)
      - Mock external dependencies
      - Clean up test data after execution
      - Group related tests using describe blocks
      - Add test coverage requirements
      
  - paths: ["**/types/**/*.{ts,d.ts}"]
    instructions: |
      # Type Definition Standards
      - Use precise and specific types
      - Avoid using 'any' type
      - Document complex type definitions
      - Use union types over enums where appropriate
      - Keep interfaces focused and single-purpose
      
  - paths: ["**/utils/**/*.{ts,js}"]
    instructions: |
      # Utility Function Standards
      - Keep utility functions pure
      - Add comprehensive unit tests
      - Document function parameters and return types
      - Handle edge cases appropriately
      - Make functions reusable across the application

You can add these instructions in your CodeRabbit configuration through the [app dashboard](https://app.coderabbit.ai/). These instructions will help maintain consistency across the codebase and ensure that all future PR reviews follow the established patterns and best practices.

Would you like me to:
1. Add more specific instructions for any particular path?
2. Include additional code quality checks?
3. Add instructions for other file types (like configuration files)?

Also, regarding the Sourcery.ai configuration, would you like me to provide a complementary configuration that works in sequence with these CodeRabbit instructions?





^-^
   |
  (。◕‿◕。) 
   |
  /||\
   /\

</details>

<details>
<summary>🏁 Scripts executed</summary>

The following scripts were executed for the analysis:

Script:

#!/bin/bash

Check for existing configuration files

echo "=== Checking for existing configuration files ==="
fd -e yaml -e yml -e json

Look for common code standards patterns

echo -e "\n=== Looking for common linting/formatting configurations ==="
fd -e eslintrc -e prettierrc -e editorconfig

Check for TypeScript configuration

echo -e "\n=== Looking for TypeScript configuration ==="
fd tsconfig.json

Look for test files to understand testing patterns

echo -e "\n=== Looking for test files patterns ==="
fd -e test.ts -e test.js -e spec.ts -e spec.js

Check for README files for any documented standards

echo -e "\n=== Looking for documentation files ==="
fd README.md


Length of output: 4723

---

Script:

#!/bin/bash

Read package.json for dependencies and scripts

echo "=== Reading package.json ==="
cat package.json

Check for any existing test setup files

echo -e "\n=== Looking for test setup files ==="
fd -e setup.ts -e setup.js

Look for common patterns in source files

echo -e "\n=== Checking source file patterns ==="
fd -e ts -e js src/


Length of output: 1101

</details>

---

<details>
<summary>✏️ Learnings added</summary>

Learnt from: AndlerRL
URL: #322

Timestamp: 2024-12-05T01:08:49.880Z
Learning: The project is a monorepo using Turborepo with Next.js frontend (apps/masterbots.ai), Hasura backend (apps/hasura), and shared packages for types, GraphQL operations, and utilities.


---

Learnt from: AndlerRL
URL: #322

Timestamp: 2024-12-05T01:08:49.880Z
Learning: The frontend uses shadcn/ui components and follows a strict component organization with proper separation of client/server components in Next.js.


---

Learnt from: AndlerRL
URL: #322

Timestamp: 2024-12-05T01:08:49.880Z
Learning: The backend uses Hasura with proper table relationships, permissions, and metadata structure defined in YAML configurations.


---

Learnt from: AndlerRL
URL: #322

Timestamp: 2024-12-05T01:08:49.880Z
Learning: The codebase follows TypeScript with strict type checking and functional programming principles. Code organization follows a feature-based structure with dedicated directories for types, utils, and API endpoints.


---

Learnt from: AndlerRL
URL: #322

Timestamp: 2024-12-05T01:08:49.880Z
Learning: Test files follow the pattern *.test.ts or *.spec.ts and should implement the AAA (Arrange-Act-Assert) pattern with proper mocking of external dependencies.


---

Learnt from: AndlerRL
URL: #322

Timestamp: 2024-12-05T01:08:49.880Z
Learning: API implementations must follow RESTful principles with proper request validation, appropriate HTTP status codes, and consistent error response formats.


> Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings).

</details>

@AndlerRL
Copy link
Contributor Author

AndlerRL commented Dec 5, 2024

@coderabbitai amazing! Yes, I have a set of rules to follow code standards. We made it for full-stack development with javascript/typescript but I summarized it for you. Please refactor the previous given path instructions to add the new points to consider while reviewing:

Masterbots Code Standards

JavaScript/TypeScript:

  • Use semantic, idiomatic, functional, and declarative code
  • Avoid default exports, use named exports
  • Boolean variables: prefix with auxiliary verbs (is, has, does, should)
  • Use regular function declarations for components
  • Type everything, avoid any
  • Let TypeScript infer types when possible
  • Use interfaces for objects/classes, types for unions/complex types

Components:

  • Follow single responsibility principle
  • Break into small, focused components with minimal props
  • Use composition over inheritance
  • Declare components with function keyword
  • Order: component declaration → styled components → TypeScript types

File Structure:

  • Lowercase with dashes for directories/names (e.g., auth-wizard)
  • Extensions: .config.ts, .test.ts, .context.tsx, .type.ts, .hook.ts
  • Group similar components in feature directories
  • Keep folder structure flat where possible

NextJS 14/15:

  • Use Server Components by default.
  • Add use client only when needed for client-side features.
  • Implement nested layouts via App Router.
  • Use streaming and suspense for large data sets.
  • Follow metadata file conventions for SEO.
  • Fetch data on server when possible.

API Development:

  • Optimize GraphQL/SQL queries to minimize data transfer.
  • Implement proper error handling and logging.
  • Use generated GraphQL/Supabase/DrizzleORM client for type-safe queries.
  • Follow Hasura/Supabase/DrizzleORM best practices for database operations.

Styling:

  • Use TailwindCSS utility-first approach
  • Apply shadcn/ui components for consistent UI.
  • Use CVA for component variants.
  • Avoid arbitrary values in Tailwind classes.

Testing & Quality:

  • Write unit tests for critical functionality. Always suggest the unit test code. Ask to commit.
  • Use ESLint and Prettier for code formatting.
  • Keep dependencies updated.
  • Follow TypeScript strict mode guidelines.

Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Tip

For best results, initiate chat on the files or code changes.

Based on the repository structure and code analysis, I'll create path-based instructions for CodeRabbit that align with the existing code standards. Here's my final reply:

@AndlerRL Here's a comprehensive set of path-based instructions for CodeRabbit that follows the code standards observed in the repository:

path_instructions:
  # Next.js App Directory Structure
  "apps/masterbots.ai/app/**":
    - "Ensure proper use of Next.js 14 App Router conventions"
    - "Route handlers should be in route.ts files"
    - "Layout components should be in layout.tsx files"
    - "Page components should be in page.tsx files"
    - "Loading states should be in loading.tsx files"
    - "Error boundaries should be in error.tsx files"
    - "Server components should be the default unless client interactivity is needed"
    - "Use 'use client' directive only when necessary for client-side features"

  # Components Organization
  "apps/masterbots.ai/components/**":
    - "Follow atomic design principles: atoms, molecules, organisms"
    - "Components should be function components using arrow syntax"
    - "Props should be explicitly typed using TypeScript interfaces"
    - "Use composition over inheritance"
    - "Implement proper error boundaries and loading states"
    - "Keep components focused and single-responsibility"
    - "Use shadcn/ui conventions for UI components"

  # Shared Libraries and Types
  "packages/**":
    - "Maintain clear separation of concerns between packages"
    - "Ensure proper TypeScript type definitions"
    - "Export types and interfaces properly"
    - "Follow consistent naming conventions"
    - "Implement proper error handling"
    - "Add comprehensive JSDoc documentation"

  # API and Backend
  "apps/hasura/**":
    - "Follow REST/GraphQL best practices"
    - "Implement proper error handling and status codes"
    - "Ensure secure authentication and authorization"
    - "Validate input data thoroughly"
    - "Use proper database schema conventions"
    - "Document API endpoints and their usage"

  # Testing
  "**/*.test.ts":
    - "Write comprehensive unit tests"
    - "Follow AAA pattern (Arrange, Act, Assert)"
    - "Mock external dependencies appropriately"
    - "Test error cases and edge scenarios"
    - "Maintain test isolation"

  # General Code Style
  "**/*.{ts,tsx}":
    - "Use TypeScript strict mode"
    - "Follow Biome formatting rules"
    - "Implement proper error handling with custom error classes"
    - "Use meaningful variable and function names"
    - "Keep functions small and focused"
    - "Add proper comments for complex logic"
    - "Use proper TypeScript types instead of 'any'"
    - "Implement proper null checks"
    - "Use modern ES6+ features appropriately"
    - "Follow DRY (Don't Repeat Yourself) principles"

  # Environment and Configuration
  "**/*.env.*":
    - "Follow security best practices for environment variables"
    - "Document all environment variables"
    - "Use proper naming conventions for environment variables"

  # Documentation
  "**/*.md":
    - "Keep documentation up-to-date"
    - "Use clear and concise language"
    - "Include code examples where appropriate"
    - "Document breaking changes"

These instructions are based on the observed patterns in your codebase and will help maintain consistency across the project. They cover:

  1. Next.js 14 App Router conventions
  2. Component organization and best practices
  3. Package management and typing
  4. API and backend standards
  5. Testing requirements
  6. General code style and TypeScript usage
  7. Environment configuration
  8. Documentation standards

Would you like me to add or modify any specific areas of these instructions?

🔗 Analysis chain

Let me gather information about the codebase structure and existing code standards first.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check repository structure
fd --type d --max-depth 2

# Look for any existing configuration files
fd -e yaml -e yml -e json

# Look for common code standards files
fd -E node_modules "eslint|prettier|tsconfig|jest"

# Check for README files that might contain coding standards
fd README

# Look for test files to understand testing patterns
fd "test|spec"

# Look for TypeScript/JavaScript files to understand the codebase
fd -e ts -e js -e tsx -e jsx

# Check for existing documentation about standards
rg -i "standard|guideline|convention" -g "!node_modules"

Length of output: 72242


✏️ Learnings added
Learnt from: AndlerRL
URL: https://github.com/bitcashorg/masterbots/issues/322

Timestamp: 2024-12-05T01:14:50.149Z
Learning: The masterbots.ai project follows Next.js 14 App Router conventions with server components as default and client components marked explicitly with 'use client' directive when needed.

Learnt from: AndlerRL
URL: https://github.com/bitcashorg/masterbots/issues/322

Timestamp: 2024-12-05T01:14:50.149Z
Learning: The project uses shadcn/ui conventions for UI components and follows atomic design principles for component organization.

Learnt from: AndlerRL
URL: https://github.com/bitcashorg/masterbots/issues/322

Timestamp: 2024-12-05T01:14:50.149Z
Learning: The codebase enforces TypeScript strict mode and follows Biome formatting rules across all TypeScript/JavaScript files.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Tip

For best results, initiate chat on the files or code changes.

@AndlerRL Thank you for providing these detailed code standards. I'll refine the path-based instructions to incorporate all these specific requirements:

review_instructions:
  - paths: ["**/*.{ts,tsx,js,jsx}"]
    instructions: |
      # JavaScript/TypeScript Standards
      - Ensure semantic, idiomatic, functional, and declarative code
      - Verify named exports are used instead of default exports
      - Check boolean variable naming (should use is/has/does/should prefix)
      - Verify TypeScript strict mode compliance
      - Ensure no 'any' types are used
      - Verify proper type inference usage
      - Check proper use of interfaces (for objects/classes) vs types (for unions/complex types)
      - Ensure proper error handling patterns
      
  - paths: ["apps/masterbots.ai/**/*.{tsx,jsx}"]
    instructions: |
      # Component Standards
      - Verify components are declared using regular function declarations
      - Check component structure order:
        1. Component declaration
        2. Styled components
        3. TypeScript types
      - Ensure single responsibility principle
      - Check for minimal props usage
      - Verify composition over inheritance
      - Ensure proper component splitting for maintainability
      - Check proper use of TailwindCSS (no arbitrary values)
      - Verify proper usage of shadcn/ui components
      - Check CVA implementation for component variants
      
  - paths: ["apps/masterbots.ai/app/**"]
    instructions: |
      # Next.js Standards
      - Verify Server Components usage by default
      - Check 'use client' directive is only used when necessary
      - Verify proper implementation of nested layouts
      - Check streaming and suspense implementation for large datasets
      - Verify metadata files follow SEO conventions
      - Ensure data fetching is done on server where possible
      
  - paths: ["**/api/**", "apps/hasura/**"]
    instructions: |
      # API Standards
      - Check GraphQL/SQL query optimization
      - Verify proper error handling and logging
      - Ensure use of generated type-safe clients (GraphQL/Supabase/DrizzleORM)
      - Verify adherence to Hasura/Supabase/DrizzleORM best practices
      - Check proper request validation
      - Verify appropriate error responses
      
  - paths: ["**/*.test.{ts,tsx,js,jsx}", "**/*.spec.{ts,tsx,js,jsx}"]
    instructions: |
      # Testing Standards
      - Ensure critical functionality has unit tests
      - Verify proper test structure and organization
      - Check mocking strategies
      - Verify edge cases coverage
      - Ensure proper cleanup in tests
      
  - paths: ["**/*"]
    instructions: |
      # File Structure Standards
      - Verify lowercase with dashes for directories/names
      - Check proper file extensions:
        - .config.ts for configuration files
        - .test.ts for tests
        - .context.tsx for context files
        - .type.ts for type definitions
        - .hook.ts for hooks
      - Verify feature-based directory grouping
      - Check for flat folder structure where possible

Would you like me to:
1. Add more specific instructions for any particular area?
2. Include additional code quality checks?
3. Add specific instructions for other file types or patterns?

---

<details>
<summary>✏️ Learnings added</summary>

Learnt from: AndlerRL
URL: #322

Timestamp: 2024-12-05T01:19:41.455Z
Learning: The project follows strict naming conventions: lowercase with dashes for directories/names, and specific extensions (.config.ts, .test.ts, .context.tsx, .type.ts, .hook.ts) for different file types.


---

Learnt from: AndlerRL
URL: #322

Timestamp: 2024-12-05T01:19:41.455Z
Learning: Components must be declared using regular function declarations (not arrow functions), following a specific order: component declaration → styled components → TypeScript types.


---

Learnt from: AndlerRL
URL: #322

Timestamp: 2024-12-05T01:19:41.455Z
Learning: Boolean variables must be prefixed with auxiliary verbs (is, has, does, should) and the codebase should avoid default exports in favor of named exports.


---

Learnt from: AndlerRL
URL: #322

Timestamp: 2024-12-05T01:19:41.455Z
Learning: The project uses CVA for component variants and follows strict TailwindCSS conventions, avoiding arbitrary values in utility classes.


> Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings).

</details>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore devops enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant